MCPcopy Create free account
hub / github.com/ddnet/ddnet / SetState

Method SetState

src/engine/client/client.cpp:401–443  ·  view source on GitHub ↗

------ state handling -----

Source from the content-addressed store, hash-verified

399
400// ------ state handling -----
401void CClient::SetState(EClientState State)
402{
403 if(m_State == IClient::STATE_QUITTING || m_State == IClient::STATE_RESTARTING)
404 return;
405 if(m_State == State)
406 return;
407
408 if(g_Config.m_Debug)
409 {
410 char aBuf[64];
411 str_format(aBuf, sizeof(aBuf), "state change. last=%d current=%d", m_State, State);
412 m_pConsole->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", aBuf);
413 }
414
415 const EClientState OldState = m_State;
416 m_State = State;
417
418 m_StateStartTime = time_get();
419 GameClient()->OnStateChange(m_State, OldState);
420
421 if(State == IClient::STATE_OFFLINE && m_ReconnectTime == 0)
422 {
423 if(g_Config.m_ClReconnectFull > 0 && (str_find_nocase(ErrorString(), "full") || str_find_nocase(ErrorString(), "reserved")))
424 m_ReconnectTime = time_get() + time_freq() * g_Config.m_ClReconnectFull;
425 else if(g_Config.m_ClReconnectTimeout > 0 && (str_find_nocase(ErrorString(), "Timeout") || str_find_nocase(ErrorString(), "Too weak connection")))
426 m_ReconnectTime = time_get() + time_freq() * g_Config.m_ClReconnectTimeout;
427 }
428
429 if(State == IClient::STATE_ONLINE)
430 {
431 const bool Registered = m_ServerBrowser.IsRegistered(ServerAddress());
432 CServerInfo CurrentServerInfo;
433 GetServerInfo(&CurrentServerInfo);
434
435 Discord()->SetGameInfo(CurrentServerInfo, GameClient()->Map()->BaseName(), Registered);
436 Steam()->SetGameInfo(ServerAddress(), GameClient()->Map()->BaseName(), Registered);
437 }
438 else if(OldState == IClient::STATE_ONLINE)
439 {
440 Discord()->ClearGameInfo();
441 Steam()->ClearGameInfo();
442 }
443}
444
445// called when the map is loaded and we should init for a new round
446void CClient::OnEnterGame(bool Dummy)

Callers

nothing calls this directly

Calls 11

str_formatFunction · 0.85
time_getFunction · 0.85
str_find_nocaseFunction · 0.85
time_freqFunction · 0.85
IsRegisteredMethod · 0.80
PrintMethod · 0.45
OnStateChangeMethod · 0.45
SetGameInfoMethod · 0.45
BaseNameMethod · 0.45
MapMethod · 0.45
ClearGameInfoMethod · 0.45

Tested by

no test coverage detected