Merge pull request #8038 from Robyt3/Client-SetState-Refactoring

Minor refactoring of `CClient::SetState`
This commit is contained in:
Dennis Felsing 2024-03-01 18:45:04 +00:00 committed by GitHub
commit 4be92b227f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 28 deletions

View file

@ -305,43 +305,44 @@ int *CClient::GetInput(int Tick, int IsDummy) const
}
// ------ state handling -----
void CClient::SetState(EClientState s)
void CClient::SetState(EClientState State)
{
if(m_State == IClient::STATE_QUITTING || m_State == IClient::STATE_RESTARTING)
return;
if(m_State == State)
return;
int Old = m_State;
if(g_Config.m_Debug)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "state change. last=%d current=%d", m_State, s);
char aBuf[64];
str_format(aBuf, sizeof(aBuf), "state change. last=%d current=%d", m_State, State);
m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", aBuf);
}
m_State = s;
if(Old != s)
const EClientState OldState = m_State;
m_State = State;
m_StateStartTime = time_get();
GameClient()->OnStateChange(m_State, OldState);
if(State == IClient::STATE_OFFLINE && m_ReconnectTime == 0)
{
m_StateStartTime = time_get();
GameClient()->OnStateChange(m_State, Old);
if(g_Config.m_ClReconnectFull > 0 && (str_find_nocase(ErrorString(), "full") || str_find_nocase(ErrorString(), "reserved")))
m_ReconnectTime = time_get() + time_freq() * g_Config.m_ClReconnectFull;
else if(g_Config.m_ClReconnectTimeout > 0 && (str_find_nocase(ErrorString(), "Timeout") || str_find_nocase(ErrorString(), "Too weak connection")))
m_ReconnectTime = time_get() + time_freq() * g_Config.m_ClReconnectTimeout;
}
if(s == IClient::STATE_OFFLINE && m_ReconnectTime == 0)
{
if(g_Config.m_ClReconnectFull > 0 && (str_find_nocase(ErrorString(), "full") || str_find_nocase(ErrorString(), "reserved")))
m_ReconnectTime = time_get() + time_freq() * g_Config.m_ClReconnectFull;
else if(g_Config.m_ClReconnectTimeout > 0 && (str_find_nocase(ErrorString(), "Timeout") || str_find_nocase(ErrorString(), "Too weak connection")))
m_ReconnectTime = time_get() + time_freq() * g_Config.m_ClReconnectTimeout;
}
if(s == IClient::STATE_ONLINE)
{
const bool AnnounceAddr = m_ServerBrowser.IsRegistered(ServerAddress());
Discord()->SetGameInfo(ServerAddress(), m_aCurrentMap, AnnounceAddr);
Steam()->SetGameInfo(ServerAddress(), m_aCurrentMap, AnnounceAddr);
}
else if(Old == IClient::STATE_ONLINE)
{
Discord()->ClearGameInfo();
Steam()->ClearGameInfo();
}
if(State == IClient::STATE_ONLINE)
{
const bool AnnounceAddr = m_ServerBrowser.IsRegistered(ServerAddress());
Discord()->SetGameInfo(ServerAddress(), m_aCurrentMap, AnnounceAddr);
Steam()->SetGameInfo(ServerAddress(), m_aCurrentMap, AnnounceAddr);
}
else if(OldState == IClient::STATE_ONLINE)
{
Discord()->ClearGameInfo();
Steam()->ClearGameInfo();
}
}

View file

@ -299,7 +299,7 @@ public:
const char *LatestVersion() const override;
// ------ state handling -----
void SetState(EClientState s);
void SetState(EClientState State);
// called when the map is loaded and we should init for a new round
void OnEnterGame(bool Dummy);