mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-18 14:08:19 +00:00
Only update serverinfo when needed
This commit is contained in:
parent
7f0589bff7
commit
79e4651d5b
|
@ -188,6 +188,7 @@ public:
|
|||
virtual void SetTimeoutProtected(int ClientID) = 0;
|
||||
|
||||
virtual void SetErrorShutdown(const char *pReason) = 0;
|
||||
virtual void ExpireServerInfo() = 0;
|
||||
|
||||
virtual char *GetMapName() = 0;
|
||||
};
|
||||
|
|
|
@ -1265,6 +1265,7 @@ void CServer::ProcessClientPacket(CNetChunk *pPacket)
|
|||
Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
|
||||
m_aClients[ClientID].m_State = CClient::STATE_INGAME;
|
||||
GameServer()->OnClientEnter(ClientID);
|
||||
ExpireServerInfo();
|
||||
}
|
||||
}
|
||||
else if(Msg == NETMSG_INPUT)
|
||||
|
@ -1546,6 +1547,8 @@ void CServer::CCache::Clear()
|
|||
|
||||
void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients)
|
||||
{
|
||||
pCache->Clear();
|
||||
|
||||
// One chance to improve the protocol!
|
||||
CPacker p;
|
||||
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)
|
||||
{
|
||||
|
@ -1797,6 +1811,8 @@ void CServer::UpdateServerInfo()
|
|||
}
|
||||
}
|
||||
|
||||
m_ServerInfoNeedsUpdate = false;
|
||||
}
|
||||
|
||||
void CServer::PumpNetwork()
|
||||
{
|
||||
|
@ -2001,6 +2017,7 @@ int CServer::Run()
|
|||
m_Lastheartbeat = 0;
|
||||
m_GameStartTime = time_get();
|
||||
|
||||
UpdateServerInfo();
|
||||
while(m_RunServer)
|
||||
{
|
||||
if(NonActive)
|
||||
|
@ -2041,7 +2058,7 @@ int CServer::Run()
|
|||
{
|
||||
break;
|
||||
}
|
||||
UpdateServerInfo();
|
||||
UpdateServerInfo(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2145,14 +2162,8 @@ int CServer::Run()
|
|||
// master server stuff
|
||||
m_Register.RegisterUpdate(m_NetServer.NetType());
|
||||
|
||||
for(int i = 0; i < 3; i++)
|
||||
{
|
||||
for(int j = 0; j < 2; j++)
|
||||
{
|
||||
m_ServerInfoCache[i * 2 + j].Clear();
|
||||
CacheServerInfo(&m_ServerInfoCache[i * 2 + j], i, j);
|
||||
}
|
||||
}
|
||||
if(m_ServerInfoNeedsUpdate)
|
||||
UpdateServerInfo();
|
||||
|
||||
if(!NonActive)
|
||||
PumpNetwork();
|
||||
|
@ -2792,7 +2803,7 @@ void CServer::ConchainSpecialInfoupdate(IConsole::IResult *pResult, void *pUserD
|
|||
{
|
||||
pfnCallback(pResult, pCallbackUserData);
|
||||
if(pResult->NumArguments())
|
||||
((CServer *)pUserData)->UpdateServerInfo();
|
||||
((CServer *)pUserData)->UpdateServerInfo(true);
|
||||
}
|
||||
|
||||
void CServer::ConchainMaxclientsperipUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
|
||||
|
|
|
@ -309,11 +309,13 @@ public:
|
|||
void Clear();
|
||||
};
|
||||
CCache m_ServerInfoCache[3 * 2];
|
||||
bool m_ServerInfoNeedsUpdate;
|
||||
|
||||
void ExpireServerInfo();
|
||||
void CacheServerInfo(CCache *pCache, 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 UpdateServerInfo();
|
||||
void UpdateServerInfo(bool Resend = false);
|
||||
|
||||
void PumpNetwork();
|
||||
|
||||
|
|
|
@ -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_ColorBody = pMsg->m_ColorBody;
|
||||
pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet;
|
||||
|
||||
Server()->ExpireServerInfo();
|
||||
}
|
||||
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;
|
||||
Server()->SendPackMsg(&m, MSGFLAG_VITAL|MSGFLAG_FLUSH, ClientID);
|
||||
}
|
||||
|
||||
Server()->ExpireServerInfo();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue