Revert "Delay disconnecting until after render call"

This reverts commit 5c90fd2b83.

Delaying the disconnecting causes issues when the client automatically disconnects immediately before connecting to another server or starting demo playback.

It's not necessary to delay the disconnecting to deal with #6387, as #6589 is already enough. It's easier to revert this instead of rewriting the client so connecting and starting demo playback are also delayed.

Closes #6595.
This commit is contained in:
Robert Müller 2023-05-16 14:10:00 +02:00
parent 22df50c9bd
commit 5ecd025d1d
2 changed files with 5 additions and 21 deletions

View file

@ -327,7 +327,6 @@ CClient::CClient() :
m_aRconUsername[0] = '\0';
m_aRconPassword[0] = '\0';
m_aPassword[0] = '\0';
m_aDisconnectReason[0] = '\0';
// version-checking
m_aVersionStr[0] = '0';
@ -831,14 +830,9 @@ void CClient::Connect(const char *pAddress, const char *pPassword)
}
void CClient::DisconnectWithReason(const char *pReason)
{
str_copy(m_aDisconnectReason, pReason == nullptr || pReason[0] == '\0' ? "unknown" : pReason);
}
void CClient::DisconnectWithReasonImpl(const char *pReason)
{
char aBuf[512];
str_format(aBuf, sizeof(aBuf), "disconnecting. reason='%s'", pReason);
str_format(aBuf, sizeof(aBuf), "disconnecting. reason='%s'", pReason ? pReason : "unknown");
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf, gs_ClientNetworkPrintColor);
// stop demo playback and recorder
@ -853,7 +847,7 @@ void CClient::DisconnectWithReasonImpl(const char *pReason)
m_ServerSentCapabilities = false;
m_UseTempRconCommands = 0;
m_pConsole->DeregisterTempAll();
m_aNetClient[CONN_MAIN].Disconnect(str_comp(pReason, "unknown") == 0 ? nullptr : pReason);
m_aNetClient[CONN_MAIN].Disconnect(pReason);
SetState(IClient::STATE_OFFLINE);
m_pMap->Unload();
m_CurrentServerPingInfoType = -1;
@ -895,7 +889,7 @@ void CClient::Disconnect()
if(m_DummyConnected)
DummyDisconnect(0);
if(m_State != IClient::STATE_OFFLINE)
DisconnectWithReason();
DisconnectWithReason(0);
// make sure to remove replay tmp demo
if(g_Config.m_ClReplays)
@ -2531,10 +2525,10 @@ void CClient::PumpNetwork()
// check for errors
if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITTING && m_aNetClient[CONN_MAIN].State() == NETSTATE_OFFLINE)
{
Disconnect();
char aBuf[256];
str_format(aBuf, sizeof(aBuf), "offline error='%s'", m_aNetClient[CONN_MAIN].ErrorString());
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", aBuf, gs_ClientNetworkErrPrintColor);
DisconnectWithReason(m_aNetClient[CONN_MAIN].ErrorString());
}
if(State() != IClient::STATE_OFFLINE && State() < IClient::STATE_QUITTING && m_DummyConnected &&
@ -3305,14 +3299,6 @@ void CClient::Run()
}
}
// Diconnecting is delayed until after the render call, to ensure
// that the map is not unloaded during the render call.
if(m_aDisconnectReason[0] != '\0')
{
DisconnectWithReasonImpl(m_aDisconnectReason);
m_aDisconnectReason[0] = '\0';
}
AutoScreenshot_Cleanup();
AutoStatScreenshot_Cleanup();
AutoCSV_Cleanup();

View file

@ -167,7 +167,6 @@ class CClient : public IClient, public CDemoPlayer::IListener
char m_aRconPassword[32];
int m_UseTempRconCommands;
char m_aPassword[32];
char m_aDisconnectReason[256];
bool m_SendPassword;
bool m_ButtonRender = false;
@ -354,8 +353,7 @@ public:
void EnterGame(int Conn) override;
void Connect(const char *pAddress, const char *pPassword = nullptr) override;
void DisconnectWithReason(const char *pReason = nullptr);
void DisconnectWithReasonImpl(const char *pReason);
void DisconnectWithReason(const char *pReason);
void Disconnect() override;
void DummyDisconnect(const char *pReason) override;