From 86de2206195587f7cae4fa5639143a9733986c9b Mon Sep 17 00:00:00 2001 From: Nick Renieris Date: Sun, 26 Jun 2022 06:11:06 +0300 Subject: [PATCH] Client: Sync Player & Costume info on connect --- include/server/Client.hpp | 6 +++--- source/server/Client.cpp | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/include/server/Client.hpp b/include/server/Client.hpp index d3bf076..876b76d 100644 --- a/include/server/Client.hpp +++ b/include/server/Client.hpp @@ -241,10 +241,10 @@ class Client { int lastCollectedShine = -1; - PlayerInf lastPlayerInfPacket = - PlayerInf(); // Info struct for storing our currently logged player information - + // Backups for our last player/game packets, used for example to re-send them for newly connected clients + PlayerInf lastPlayerInfPacket = PlayerInf(); GameInf lastGameInfPacket = GameInf(); + CostumeInf lastCostumeInfPacket = CostumeInf(); Keyboard* mKeyboard = nullptr; // keyboard for setting server IP diff --git a/source/server/Client.cpp b/source/server/Client.cpp index a3accbd..8ae385c 100644 --- a/source/server/Client.cpp +++ b/source/server/Client.cpp @@ -435,15 +435,20 @@ void Client::readFunc() { break; case PacketType::PLAYERCON: updatePlayerConnect((PlayerConnect*)curPacket); - // send game info packet when client recieves connection - if (lastGameInfPacket.mUserID != mUserID) { - // assume game info packet is empty from first connection + // Send relevant info packets when another client is connected + + // Assume game packets are empty from first connection + if (lastGameInfPacket.mUserID != mUserID) lastGameInfPacket.mUserID = mUserID; - // leave rest blank - } - mSocket->SEND(&lastGameInfPacket); + + // No need to send player/costume packets if they're empty + if (lastPlayerInfPacket.mUserID == mUserID) + mSocket->SEND(&lastPlayerInfPacket); + if (lastCostumeInfPacket.mUserID == mUserID) + mSocket->SEND(&lastCostumeInfPacket); + break; case PacketType::COSTUMEINF: updateCostumeInfo((CostumeInf*)curPacket); @@ -698,6 +703,7 @@ void Client::sendCostumeInfPacket(const char* body, const char* cap) { CostumeInf packet = CostumeInf(body, cap); packet.mUserID = sInstance->mUserID; sInstance->mSocket->SEND(&packet); + sInstance->lastCostumeInfPacket = packet; } /**