Client: Sync Player & Costume info on connect

This commit is contained in:
Nick Renieris 2022-06-26 06:11:06 +03:00
parent 71b4237d84
commit 86de220619
2 changed files with 15 additions and 9 deletions

View File

@ -241,10 +241,10 @@ class Client {
int lastCollectedShine = -1; int lastCollectedShine = -1;
PlayerInf lastPlayerInfPacket = // Backups for our last player/game packets, used for example to re-send them for newly connected clients
PlayerInf(); // Info struct for storing our currently logged player information PlayerInf lastPlayerInfPacket = PlayerInf();
GameInf lastGameInfPacket = GameInf(); GameInf lastGameInfPacket = GameInf();
CostumeInf lastCostumeInfPacket = CostumeInf();
Keyboard* mKeyboard = nullptr; // keyboard for setting server IP Keyboard* mKeyboard = nullptr; // keyboard for setting server IP

View File

@ -435,15 +435,20 @@ void Client::readFunc() {
break; break;
case PacketType::PLAYERCON: case PacketType::PLAYERCON:
updatePlayerConnect((PlayerConnect*)curPacket); updatePlayerConnect((PlayerConnect*)curPacket);
// send game info packet when client recieves connection
if (lastGameInfPacket.mUserID != mUserID) { // Send relevant info packets when another client is connected
// assume game info packet is empty from first connection
// Assume game packets are empty from first connection
if (lastGameInfPacket.mUserID != mUserID)
lastGameInfPacket.mUserID = mUserID; lastGameInfPacket.mUserID = mUserID;
// leave rest blank
}
mSocket->SEND(&lastGameInfPacket); 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; break;
case PacketType::COSTUMEINF: case PacketType::COSTUMEINF:
updateCostumeInfo((CostumeInf*)curPacket); updateCostumeInfo((CostumeInf*)curPacket);
@ -698,6 +703,7 @@ void Client::sendCostumeInfPacket(const char* body, const char* cap) {
CostumeInf packet = CostumeInf(body, cap); CostumeInf packet = CostumeInf(body, cap);
packet.mUserID = sInstance->mUserID; packet.mUserID = sInstance->mUserID;
sInstance->mSocket->SEND(&packet); sInstance->mSocket->SEND(&packet);
sInstance->lastCostumeInfPacket = packet;
} }
/** /**