From 7a4b0ff26b9ff3aa2d8ff4b3bc949c89ac4b849d Mon Sep 17 00:00:00 2001 From: That One Seong <7321839+SeongGino@users.noreply.github.com> Date: Tue, 26 Mar 2024 18:46:21 +0000 Subject: [PATCH] Waiting buffer can be transferred from GameSearching to GameStarted --- qhookermain.cpp | 14 +++++++++++--- qhookermain.h | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/qhookermain.cpp b/qhookermain.cpp index 3ceb8d7..eae6e73 100644 --- a/qhookermain.cpp +++ b/qhookermain.cpp @@ -127,7 +127,7 @@ void qhookerMain::SerialInit() } -void qhookerMain::GameSearching(QString input) +bool qhookerMain::GameSearching(QString input) { // Split the output in case of connecting mid-way. buffer = input.split('\r', Qt::SkipEmptyParts); @@ -196,18 +196,23 @@ void qhookerMain::GameSearching(QString input) tempBuffer.removeFirst(); } } + buffer.removeFirst(); + return true; } else { gameName.clear(); } } buffer.removeFirst(); } + return false; } void qhookerMain::GameStarted(QString input) { - buffer = input.split('\r', Qt::SkipEmptyParts); + if(buffer.isEmpty()) { + buffer = input.split('\r', Qt::SkipEmptyParts); + } while(!buffer.isEmpty()) { buffer[0] = buffer[0].trimmed(); @@ -343,7 +348,10 @@ void qhookerMain::ReadyRead() { buffer.clear(); if(gameName.isEmpty()) { - GameSearching(tcpSocket.readLine()); + // if this returns early as true, then zip straight into the GameStarted function with the remaining buffer. + if(GameSearching(tcpSocket.readLine())) { + GameStarted(""); + } } else { GameStarted(tcpSocket.readLine()); } diff --git a/qhookermain.h b/qhookermain.h index 3c404c5..3d99728 100644 --- a/qhookermain.h +++ b/qhookermain.h @@ -34,7 +34,7 @@ class qhookerMain : public QObject void SerialInit(); - void GameSearching(QString input); + bool GameSearching(QString input); void GameStarted(QString input);