MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / keyCallback

Method keyCallback

plugins/webstats/webstats.cpp:337–645  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

335}
336
337void WebStats::keyCallback(std::string& data, const std::string& key) {
338 bz_BasePlayerRecord* rec = NULL;
339 if (playeRecord) {
340 rec = playeRecord;
341 }
342 else if (teamSortItr != teamSort.end() && playerInTeam < teamSortItr->second.size()) {
343 rec = teamSortItr->second[playerInTeam];
344 }
345
346 int flagID = flagReportID;
347 if (rec) {
348 flagID = rec->currentFlagID;
349 }
350
351 data = "";
352
353 double uptime = bz_getCurrentTime() - serverStartTime;
354
355 if (key == "playercount") {
356 data = format("%d", bz_getPlayerCount());
357 }
358 else if (key == "gametype") {
359 switch (bz_getGameType()) {
360 case eTeamFFAGame:
361 data = "Team FFA";
362 break;
363
364 case eClassicCTFGame:
365 data = "Team Capture the Flag";
366 break;
367
368 case eRabbitGame:
369 data = "Rabbit Hunt";
370 break;
371
372 case eOpenFFAGame:
373 data = "Open FFA";
374 break;
375
376 default:
377 data = "other";
378 break;
379 }
380 }
381 else if (key == "uptime") {
382 int days = (int)(uptime / 86400.0);
383 uptime -= days * 86400.0;
384 int hours = (int)(uptime / 3600.0);
385 uptime -= hours * 3600.0;
386 int min = (int)(uptime / 60.0);
387 uptime -= min * 60.0;
388 int seconds = (int)(uptime);
389 data = format("%d days %d hours %d minutes %d seconds", days, hours, min, seconds);
390 }
391 else if (key == "totalplayers") {
392 size_t count = registeredPlayerMap.size() + nonRegedPlayerMap.size();
393 data = format("%d", (int)count);
394 }

Callers

nothing calls this directly

Calls 15

bz_getCurrentTimeFunction · 0.85
bz_getPlayerCountFunction · 0.85
bzu_GetTeamNameFunction · 0.85
getStatusFunction · 0.85
bz_getTeamCountFunction · 0.85
bz_getTeamScoreFunction · 0.85
bz_getTeamWinsFunction · 0.85
bz_getTeamLossesFunction · 0.85
bz_getNumFlagsFunction · 0.85
bz_getPlayerCallsignFunction · 0.85
bz_flagPlayerFunction · 0.85
bz_getFlagPositionFunction · 0.85

Tested by

no test coverage detected