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

Method CacheServerInfo

src/engine/server/server.cpp:2222–2434  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2220}
2221
2222void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients)
2223{
2224 pCache->Clear();
2225
2226 // One chance to improve the protocol!
2227 CPacker p;
2228 char aBuf[128];
2229
2230 // count the players
2231 int PlayerCount = 0, ClientCount = 0;
2232 for(int i = 0; i < MAX_CLIENTS; i++)
2233 {
2234 if(m_aClients[i].IncludedInServerInfo())
2235 {
2236 if(GameServer()->IsClientPlayer(i))
2237 PlayerCount++;
2238
2239 ClientCount++;
2240 }
2241 }
2242
2243 p.Reset();
2244
2245#define ADD_RAW(p, x) (p).AddRaw(x, sizeof(x))
2246#define ADD_INT(p, x) \
2247 do \
2248 { \
2249 str_format(aBuf, sizeof(aBuf), "%d", x); \
2250 (p).AddString(aBuf, 0); \
2251 } while(0)
2252
2253 p.AddString(GameServer()->Version(), 32);
2254 if(Type != SERVERINFO_VANILLA)
2255 {
2256 p.AddString(Config()->m_SvName, 256);
2257 }
2258 else
2259 {
2260 if(m_NetServer.MaxClients() <= VANILLA_MAX_CLIENTS)
2261 {
2262 p.AddString(Config()->m_SvName, 64);
2263 }
2264 else
2265 {
2266 const int MaxClients = maximum(ClientCount, m_NetServer.MaxClients() - Config()->m_SvReservedSlots);
2267 str_format(aBuf, sizeof(aBuf), "%s [%d/%d]", Config()->m_SvName, ClientCount, MaxClients);
2268 p.AddString(aBuf, 64);
2269 }
2270 }
2271 p.AddString(GameServer()->Map()->BaseName(), 32);
2272
2273 if(Type == SERVERINFO_EXTENDED)
2274 {
2275 ADD_INT(p, m_aCurrentMapCrc[MAP_TYPE_SIX]);
2276 ADD_INT(p, m_aCurrentMapSize[MAP_TYPE_SIX]);
2277 }
2278
2279 // gametype

Callers

nothing calls this directly

Calls 15

maximumFunction · 0.85
str_formatFunction · 0.85
IncludedInServerInfoMethod · 0.80
IsClientPlayerMethod · 0.80
GameTypeMethod · 0.80
AddIntMethod · 0.80
ConfigFunction · 0.50
minimumFunction · 0.50
ClearMethod · 0.45
ResetMethod · 0.45
AddStringMethod · 0.45
VersionMethod · 0.45

Tested by

no test coverage detected