Fix dummy disconnecting on hot reload

This commit is contained in:
KebsCS 2024-09-07 17:44:02 +02:00
parent 3d30ce4bf2
commit ed7d4d4f66
No known key found for this signature in database
GPG key ID: 5A8C0761A75E7309
5 changed files with 63 additions and 17 deletions

View file

@ -720,20 +720,23 @@ void CClient::DummyConnect()
log_info("client", "Dummy is not allowed on this server.");
return;
}
if(DummyConnected() || DummyConnecting())
if((DummyConnected() || DummyConnecting()) && !m_DummyReconnectOnReload)
{
log_info("client", "Dummy is already connected/connecting.");
return;
}
if(DummyConnectingDelayed())
if(DummyConnectingDelayed() && !m_DummyReconnectOnReload)
{
log_info("client", "Wait before connecting dummy again.");
return;
}
m_DummySendConnInfo = true;
if(!m_DummyReconnectOnReload)
{
m_LastDummyConnectTime = GlobalTime();
m_aRconAuthed[1] = 0;
m_DummySendConnInfo = true;
g_Config.m_ClDummyCopyMoves = 0;
g_Config.m_ClDummyHammer = 0;
@ -745,6 +748,7 @@ void CClient::DummyConnect()
else
m_aNetClient[CONN_DUMMY].Connect(m_aNetClient[CONN_MAIN].ServerAddress(), 1);
}
}
void CClient::DummyDisconnect(const char *pReason)
{
@ -1520,7 +1524,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
}
}
if(m_DummyConnected)
if(m_DummyConnected && !m_DummyReconnectOnReload)
{
DummyDisconnect(0);
}
@ -1649,9 +1653,25 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
}
}
}
else if(Conn == CONN_MAIN && (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_MAP_RELOAD)
{
if(m_DummyConnected)
{
m_DummyReconnectOnReload = true;
m_DummySwapOnReconnect = g_Config.m_ClDummy == 1 ? false : true;
g_Config.m_ClDummy = 0;
}
else
m_DummySwapOnReconnect = false;
}
else if(Conn == CONN_MAIN && (pPacket->m_Flags & NET_CHUNKFLAG_VITAL) != 0 && Msg == NETMSG_CON_READY)
{
GameClient()->OnConnected();
if(m_DummyReconnectOnReload)
{
DummyConnect();
m_DummyReconnectOnReload = false;
}
}
else if(Conn == CONN_DUMMY && Msg == NETMSG_CON_READY)
{
@ -1659,7 +1679,7 @@ void CClient::ProcessServerPacket(CNetChunk *pPacket, int Conn, bool Dummy)
m_DummyConnecting = false;
g_Config.m_ClDummy = 1;
Rcon("crashmeplx");
if(m_aRconAuthed[0])
if(m_aRconAuthed[0] && !m_aRconAuthed[1])
RconAuth(m_aRconUsername, m_aRconPassword);
}
else if(Msg == NETMSG_PING)
@ -2746,6 +2766,16 @@ void CClient::Update()
}
}
if(m_DummySwapOnReconnect && g_Config.m_ClDummy == 1)
{
m_DummySwapOnReconnect = false;
g_Config.m_ClDummy = 0;
}
else if(!m_DummyConnected && m_DummySwapOnReconnect)
{
m_DummySwapOnReconnect = false;
}
m_LastDummy = (bool)g_Config.m_ClDummy;
}

View file

@ -182,6 +182,8 @@ class CClient : public IClient, public CDemoPlayer::IListener
bool m_DummyConnecting = false;
bool m_DummyConnected = false;
float m_LastDummyConnectTime = 0.0f;
bool m_DummyReconnectOnReload = false;
bool m_DummySwapOnReconnect = false;
// graphs
CGraph m_InputtimeMarginGraph;

View file

@ -243,6 +243,7 @@ CServer::CServer()
}
m_MapReload = false;
m_SameMapReload = false;
m_ReloadedWhenEmpty = false;
m_aCurrentMap[0] = '\0';
@ -1269,6 +1270,12 @@ void CServer::SendMapData(int ClientId, int Chunk)
}
}
void CServer::SendMapReload(int ClientId)
{
CMsgPacker Msg(NETMSG_MAP_RELOAD, true);
SendMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH, ClientId);
}
void CServer::SendConnectionReady(int ClientId)
{
CMsgPacker Msg(NETMSG_CON_READY, true);
@ -2553,7 +2560,7 @@ void CServer::ChangeMap(const char *pMap)
void CServer::ReloadMap()
{
m_MapReload = true;
m_SameMapReload = true;
}
int CServer::LoadMap(const char *pMapName)
@ -2805,7 +2812,7 @@ int CServer::Run()
int NewTicks = 0;
// load new map
if(m_MapReload || m_CurrentGameTick >= MAX_TICK) // force reload to make sure the ticks stay within a valid range
if(m_MapReload || m_SameMapReload || m_CurrentGameTick >= MAX_TICK) // force reload to make sure the ticks stay within a valid range
{
// load map
if(LoadMap(Config()->m_SvMap))
@ -2831,12 +2838,16 @@ int CServer::Run()
if(m_aClients[ClientId].m_State <= CClient::STATE_AUTH)
continue;
if(m_SameMapReload)
SendMapReload(ClientId);
SendMap(ClientId);
bool HasPersistentData = m_aClients[ClientId].m_HasPersistentData;
m_aClients[ClientId].Reset();
m_aClients[ClientId].m_HasPersistentData = HasPersistentData;
m_aClients[ClientId].m_State = CClient::STATE_CONNECTING;
}
m_SameMapReload = false;
m_GameStartTime = time_get();
m_CurrentGameTick = MIN_TICK;
@ -3509,7 +3520,7 @@ void CServer::ConStopRecord(IConsole::IResult *pResult, void *pUser)
void CServer::ConMapReload(IConsole::IResult *pResult, void *pUser)
{
((CServer *)pUser)->m_MapReload = true;
((CServer *)pUser)->ReloadMap();
}
void CServer::ConLogout(IConsole::IResult *pResult, void *pUser)

View file

@ -219,6 +219,7 @@ public:
int m_RunServer;
bool m_MapReload;
bool m_SameMapReload;
bool m_ReloadedWhenEmpty;
int m_RconClientId;
int m_RconAuthLevel;
@ -324,6 +325,7 @@ public:
void SendCapabilities(int ClientId);
void SendMap(int ClientId);
void SendMapData(int ClientId, int Chunk);
void SendMapReload(int ClientId);
void SendConnectionReady(int ClientId);
void SendRconLine(int ClientId, const char *pLine);
// Accepts -1 as ClientId to mean "all clients with at least auth level admin"

View file

@ -35,3 +35,4 @@ UUID(NETMSG_CHECKSUM_ERROR, "checksum-error@ddnet.tw")
UUID(NETMSG_REDIRECT, "redirect@ddnet.org")
UUID(NETMSG_RCON_CMD_GROUP_START, "rcon-cmd-group-start@ddnet.org")
UUID(NETMSG_RCON_CMD_GROUP_END, "rcon-cmd-group-end@ddnet.org")
UUID(NETMSG_MAP_RELOAD, "map-reload@ddnet.org")