Only update serverinfo when needed

This commit is contained in:
Learath2 2019-11-03 01:07:10 +01:00
parent 7f0589bff7
commit 79e4651d5b
4 changed files with 37 additions and 19 deletions

View file

@ -188,6 +188,7 @@ public:
virtual void SetTimeoutProtected(int ClientID) = 0; virtual void SetTimeoutProtected(int ClientID) = 0;
virtual void SetErrorShutdown(const char *pReason) = 0; virtual void SetErrorShutdown(const char *pReason) = 0;
virtual void ExpireServerInfo() = 0;
virtual char *GetMapName() = 0; virtual char *GetMapName() = 0;
}; };

View file

@ -1265,6 +1265,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
m_aClients[ClientID].m_State = CClient::STATE_INGAME; m_aClients[ClientID].m_State = CClient::STATE_INGAME;
GameServer()->OnClientEnter(ClientID); GameServer()->OnClientEnter(ClientID);
ExpireServerInfo();
} }
} }
else if(Msg == NETMSG_INPUT) else if(Msg == NETMSG_INPUT)
@ -1546,6 +1547,8 @@ void CServer::CCache::Clear()
void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients) void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients)
{ {
pCache->Clear();
// One chance to improve the protocol! // One chance to improve the protocol!
CPacker p; CPacker p;
char aBuf[128]; char aBuf[128];
@ -1786,7 +1789,18 @@ void CServer::SendServerInfo(const NETADDR *pAddr, int Token, int Type, bool Sen
} }
} }
void CServer::UpdateServerInfo() void CServer::ExpireServerInfo()
{
m_ServerInfoNeedsUpdate = true;
}
void CServer::UpdateServerInfo(bool Resend)
{
for(int i = 0; i < 3; i++)
for(int j = 0; j < 2; j++)
CacheServerInfo(&m_ServerInfoCache[i * 2 + j], i, j);
if(Resend)
{ {
for(int i = 0; i < MAX_CLIENTS; ++i) for(int i = 0; i < MAX_CLIENTS; ++i)
{ {
@ -1797,6 +1811,8 @@ void CServer::UpdateServerInfo()
} }
} }
m_ServerInfoNeedsUpdate = false;
}
void CServer::PumpNetwork() void CServer::PumpNetwork()
{ {
@ -2001,6 +2017,7 @@ int CServer::Run()
m_Lastheartbeat = 0; m_Lastheartbeat = 0;
m_GameStartTime = time_get(); m_GameStartTime = time_get();
UpdateServerInfo();
while(m_RunServer) while(m_RunServer)
{ {
if(NonActive) if(NonActive)
@ -2041,7 +2058,7 @@ int CServer::Run()
{ {
break; break;
} }
UpdateServerInfo(); UpdateServerInfo(true);
} }
else else
{ {
@ -2145,14 +2162,8 @@ int CServer::Run()
// master server stuff // master server stuff
m_Register.RegisterUpdate(m_NetServer.NetType()); m_Register.RegisterUpdate(m_NetServer.NetType());
for(int i = 0; i < 3; i++) if(m_ServerInfoNeedsUpdate)
{ UpdateServerInfo();
for(int j = 0; j < 2; j++)
{
m_ServerInfoCache[i * 2 + j].Clear();
CacheServerInfo(&m_ServerInfoCache[i * 2 + j], i, j);
}
}
if(!NonActive) if(!NonActive)
PumpNetwork(); PumpNetwork();
@ -2792,7 +2803,7 @@ void CServer::ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserD
{ {
pfnCallback(pResult, pCallbackUserData); pfnCallback(pResult, pCallbackUserData);
if(pResult->NumArguments()) if(pResult->NumArguments())
((CServer *)pUserData)->UpdateServerInfo(); ((CServer *)pUserData)->UpdateServerInfo(true);
} }
void CServer::ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) void CServer::ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)

View file

@ -309,11 +309,13 @@ public:
void Clear(); void Clear();
}; };
CCache m_ServerInfoCache[3 * 2]; CCache m_ServerInfoCache[3 * 2];
bool m_ServerInfoNeedsUpdate;
void ExpireServerInfo();
void CacheServerInfo(CCache *pCache, int Type, bool SendClients); void CacheServerInfo(CCache *pCache, int Type, bool SendClients);
void SendServerInfo(const NETADDR *pAddr, int Token, int Type, bool SendClients); void SendServerInfo(const NETADDR *pAddr, int Token, int Type, bool SendClients);
void SendServerInfoConnless(const NETADDR *pAddr, int Token, int Type); void SendServerInfoConnless(const NETADDR *pAddr, int Token, int Type);
void UpdateServerInfo(); void UpdateServerInfo(bool Resend = false);
void PumpNetwork(); void PumpNetwork();

View file

@ -1837,6 +1837,8 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor; pPlayer->m_TeeInfos.m_UseCustomColor = pMsg->m_UseCustomColor;
pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody; pPlayer->m_TeeInfos.m_ColorBody = pMsg->m_ColorBody;
pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet; pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet;
Server()->ExpireServerInfo();
} }
else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused)
{ {
@ -1955,6 +1957,8 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
CNetMsg_Sv_ReadyToEnter m; CNetMsg_Sv_ReadyToEnter m;
Server()->SendPackMsg(&m, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID); Server()->SendPackMsg(&m, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID);
} }
Server()->ExpireServerInfo();
} }
} }