From a8d26b6ce32066812fd46ac88804048d38218db3 Mon Sep 17 00:00:00 2001 From: fusion32 Date: Mon, 1 Jun 2026 01:52:28 -0300 Subject: fix player state desync on login (#59) --- src/cr.hh | 1 + src/crplayer.cc | 15 ++++++++++++--- src/crskill.cc | 3 --- 3 files changed, 13 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/cr.hh b/src/cr.hh index 8bf6ce8..cc25d24 100644 --- a/src/cr.hh +++ b/src/cr.hh @@ -857,6 +857,7 @@ struct TPlayer: TCreature { void SetQuestValue(int QuestNr, int Value); void CheckOutfit(void); void CheckState(void); + void SyncState(void); void AddBuddy(const char *Name); void RemoveBuddy(uint32 CharacterID); void SendBuddies(void); diff --git a/src/crplayer.cc b/src/crplayer.cc index 8878bda..86b0c47 100644 --- a/src/crplayer.cc +++ b/src/crplayer.cc @@ -205,7 +205,7 @@ TPlayer::TPlayer(TConnection *Connection, uint32 CharacterID): SendAmbiente(Connection); AnnounceChangedCreature(CharacterID, CREATURE_LIGHT_CHANGED); SendPlayerSkills(Connection); - this->CheckState(); + this->SyncState(); this->SendBuddies(); if(PlayerData->LastLoginTime != 0){ @@ -750,7 +750,6 @@ void TPlayer::TakeOver(TConnection *Connection){ strcpy(this->Guild, PlayerData->Guild); strcpy(this->Rank, PlayerData->Rank); strcpy(this->Title, PlayerData->Title); - this->OldState = 0; this->CheckOutfit(); this->ClearRequest(); @@ -770,7 +769,7 @@ void TPlayer::TakeOver(TConnection *Connection){ SendAmbiente(Connection); SendPlayerData(Connection); SendPlayerSkills(Connection); - this->CheckState(); + this->SyncState(); this->SendBuddies(); } @@ -1254,6 +1253,16 @@ void TPlayer::CheckState(void){ } } +void TPlayer::SyncState(void){ + // NOTE(fusion): This is only called after a new connection is established, + // when we know that the current client state is ZERO but `OldState` may not. + // It'll typically be the case in `TPlayer::TakeOver` but can also happen + // in the player constructor if `TPlayer::CheckState` is called from within + // any helper function before `TConnection::EnterGame` (see `BeginSendData`). + this->OldState = 0; + this->CheckState(); +} + void TPlayer::AddBuddy(const char *Name){ if(Name == NULL){ error("TPlayer::AddBuddy: Name ist NULL.\n"); diff --git a/src/crskill.cc b/src/crskill.cc index e098b25..5b20402 100644 --- a/src/crskill.cc +++ b/src/crskill.cc @@ -107,9 +107,6 @@ void TSkill::Load(int Act, int Max, int Min, int DAct, int MDAct, TCreature *Master = this->Master; if(Master && Cycle != 0){ - // NOTE(fusion): It seems we had `TSkillBase::SetTimer` inlined here. - // For whatever reason I hadn't noticed the error message referencing - // it, LOL. Master->SetTimer(this->SkNr, Cycle, Count, MaxCount, FactorPercent); } } -- cgit v1.2.3