static void server_stats_create (void) { #ifdef USE_GEOIP unsigned g; // HACK: position UNKNOWN_SERVER is used for total number of all games unsigned i = (sizeof(struct country_stats) + geoip_num_countries()*sizeof(struct country_num)) * (UNKNOWN_SERVER + 1); srv_countries = g_malloc0 (i); // HACK: position UNKNOWN_SERVER is used for total number of all games for (g = KNOWN_SERVER_START; g <= UNKNOWN_SERVER; ++g) { srv_countries[g].country = (struct country_num*)((void*)srv_countries + sizeof(struct country_stats)*(UNKNOWN_SERVER + 1) + g*geoip_num_countries()*sizeof(struct country_num)); } #endif // HACK: position UNKNOWN_SERVER is used for total number of all games srv_stats = g_malloc0 (sizeof (struct server_stats) * (UNKNOWN_SERVER + 1)); srv_archs = g_malloc0 (sizeof (struct arch_stats) * UNKNOWN_SERVER); players = g_malloc0 (sizeof (struct arch_stats) * UNKNOWN_SERVER); servers_count = 0; players_count = 0; }
static void server_stats_create (void) { #ifdef USE_GEOIP unsigned g; // position GAMES_TOTAL is used for total number of all games unsigned i = (sizeof(struct country_stats) + geoip_num_countries()*sizeof(struct country_num)) * (GAMES_TOTAL+1); srv_countries = g_malloc0 (i); for (g = 0; g < GAMES_TOTAL+1; ++g) { srv_countries[g].country = (struct country_num*)((void*)srv_countries + sizeof(struct country_stats)*(GAMES_TOTAL+1) + g*geoip_num_countries()*sizeof(struct country_num)); } #endif // position GAMES_TOTAL is used for total number of all games srv_stats = g_malloc0 (sizeof (struct server_stats) * (GAMES_TOTAL+1)); srv_archs = g_malloc0 (sizeof (struct arch_stats) * GAMES_TOTAL); players = g_malloc0 (sizeof (struct arch_stats) * GAMES_TOTAL); servers_count = 0; players_count = 0; }
void geoip_init(void) { const char* geoipdat = getenv("xqf_GEOIPDAT"); if (gi) return; // already initialized if (geoipdat) gi = GeoIP_open(geoipdat, GEOIP_STANDARD); if (!gi) gi = GeoIP_new(GEOIP_STANDARD); if (gi && geoip_num_countries()) flags = g_malloc0((MaxCountries+1) *sizeof(struct pixmap)); /*+1-> flag for LAN server*/ else { geoip_done(); xqf_error("GeoIP initialization failed"); } }
static void collect_statistics (void) { GSList *servers; GSList *tmp; struct server *s; char **info; enum OS os; enum CPU cpu; int countthisserver; servers = all_servers (); /* Free at end of this function */ if (servers) { for (tmp = servers; tmp; tmp = tmp->next) { s = (struct server *) tmp->data; info = s->info; cpu = CPU_UNKNOWN; os = OS_UNKNOWN; countthisserver=0; servers_count++; srv_stats[s->type].servers++; srv_stats[s->type].players += s->curplayers; players_count += s->curplayers; if (s->ping < MAX_PING) { if (s->ping >= 0) { srv_stats[s->type].ok++; countthisserver=1; } else srv_stats[s->type].na++; } else { if (s->ping == MAX_PING) srv_stats[s->type].timeout++; else srv_stats[s->type].down++; } #ifdef USE_GEOIP if (s->country_id >= 0 && s->country_id < geoip_num_countries()) { if (++srv_countries[s->type].country[s->country_id].n == 1) { srv_countries[s->type].country[s->country_id].c = s->country_id; ++srv_countries[s->type].nonzero; } if (++srv_countries[GAMES_TOTAL].country[s->country_id].n == 1) { srv_countries[GAMES_TOTAL].country[s->country_id].c = s->country_id; ++srv_countries[GAMES_TOTAL].nonzero; } } #endif if (info && games[s->type].arch_identifier) { while (info[0]) { if (g_ascii_strcasecmp (info[0], games[s->type].arch_identifier) == 0) { if (!info[1]) break; if (games[s->type].identify_cpu) cpu = games[s->type].identify_cpu(s, info[1]); else cpu = CPU_UNKNOWN; if (games[s->type].identify_os) os = games[s->type].identify_os(s, info[1]); else os = OS_UNKNOWN; break; } info += 2; } if (countthisserver) { srv_archs[s->type].oscpu[os][cpu]++; srv_archs[s->type].count++; players[s->type].on_os[os] += s->curplayers; players[s->type].total += s->curplayers; } } } server_list_free (servers); } #ifdef USE_GEOIP { unsigned g; for (g = 0; g < GAMES_TOTAL+1; ++g) { qsort(srv_countries[g].country, geoip_num_countries(), sizeof(struct country_num), country_stat_compare_func); } } #endif }