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;
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

View file

@ -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;
}
/**