From 19aaea9bfd2b7a6df9f2966c91367eac6fd2d837 Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sat, 29 Sep 2007 13:16:00 +0000 Subject: [PATCH] fixed sorting for the server browsing. added mass server script that starts alot of servers --- scripts/mass_server.py | 51 ++++++++++++++++++++++++++++ src/engine/client/client.c | 68 ++++++++++++++++++++++++++++---------- src/engine/interface.h | 7 ++++ src/tools/fake_server.c | 7 +++- 4 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 scripts/mass_server.py diff --git a/scripts/mass_server.py b/scripts/mass_server.py new file mode 100644 index 000000000..68d22d6dd --- /dev/null +++ b/scripts/mass_server.py @@ -0,0 +1,51 @@ +#from random import choice + +import random +import os + +masterservers = ["localhost 8383"] + +maps = [ + ["dm1", "dm2", "dm6"], + ["dm1", "dm2", "dm6"], + ["ctf1", "ctf2", "ctf3"], +] + +servernames = [ + "%s playhouse", + "%s own server", +] + +nicks = [] +for l in file("scripts/nicks.txt"): + nicks += l.replace(":port80c.se.quakenet.org 353 matricks_ = #pcw :", "").strip().split() +inick = 0 + +def get_nick(): + global inick, nicks + inick += 1 + return nicks[inick].replace("`", "\`") + +for s in xrange(0, 150): + cmd = "./fake_server_d_d " + cmd += '-n "%s" ' % (random.choice(servernames) % get_nick()) + for m in masterservers: + cmd += '-m %s '%m + + max = random.randint(2, 16) + cmd += "-x %d " % max + + t = random.randint(0, 2) + + cmd += '-a "%s" ' % random.choice(maps[t]) + cmd += '-g %d ' % random.randint(0, 100) + cmd += '-t %d ' % t # dm, tdm, ctf + #cmd += "-f %d " % random.randint(0, 2) # dm, tdm, ctf + + + for p in xrange(0, random.randint(0, max)): + cmd += '-p "%s" %d ' % (get_nick(), random.randint(0, 20)) + + print cmd + os.popen2(cmd) + diff --git a/src/engine/client/client.c b/src/engine/client/client.c index 47175ca63..970eae600 100644 --- a/src/engine/client/client.c +++ b/src/engine/client/client.c @@ -387,6 +387,54 @@ static void client_serverbrowse_init() { } +static int serverbrowse_sort = BROWSESORT_NONE; + +static int client_serverbrowse_sort_compare_name(const void *ai, const void *bi) +{ + SERVERENTRY **a = (SERVERENTRY **)ai; + SERVERENTRY **b = (SERVERENTRY **)bi; + return strcmp((*a)->info.name, (*b)->info.name); +} + +static int client_serverbrowse_sort_compare_map(const void *ai, const void *bi) +{ + SERVERENTRY **a = (SERVERENTRY **)ai; + SERVERENTRY **b = (SERVERENTRY **)bi; + return strcmp((*a)->info.map, (*b)->info.map); +} + +static int client_serverbrowse_sort_compare_ping(const void *ai, const void *bi) +{ + SERVERENTRY **a = (SERVERENTRY **)ai; + SERVERENTRY **b = (SERVERENTRY **)bi; + return (*a)->info.latency > (*b)->info.latency; +} + +static int client_serverbrowse_sort_compare_numplayers(const void *ai, const void *bi) +{ + SERVERENTRY **a = (SERVERENTRY **)ai; + SERVERENTRY **b = (SERVERENTRY **)bi; + return (*a)->info.num_players > (*b)->info.num_players; +} + +static void client_serverbrowse_sort() +{ + if(serverbrowse_sort == BROWSESORT_NAME) + qsort(serverlist, num_servers, sizeof(SERVERENTRY *), client_serverbrowse_sort_compare_name); + else if(serverbrowse_sort == BROWSESORT_PING) + qsort(serverlist, num_servers, sizeof(SERVERENTRY *), client_serverbrowse_sort_compare_ping); + else if(serverbrowse_sort == BROWSESORT_MAP) + qsort(serverlist, num_servers, sizeof(SERVERENTRY *), client_serverbrowse_sort_compare_map); + else if(serverbrowse_sort == BROWSESORT_NUMPLAYERS) + qsort(serverlist, num_servers, sizeof(SERVERENTRY *), client_serverbrowse_sort_compare_numplayers); +} + +void client_serverbrowse_set_sort(int mode) +{ + serverbrowse_sort = mode; + client_serverbrowse_sort(); /* resort */ +} + static void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *info) { int hash = addr->ip[0]; @@ -399,6 +447,7 @@ static void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *in entry->info = *info; if(!request) entry->info.latency = (time_get()-entry->request_time)*1000/time_freq(); + client_serverbrowse_sort(); return; } entry = entry->next_ip; @@ -443,6 +492,8 @@ static void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *in first_req_server = entry; last_req_server = entry; } + + client_serverbrowse_sort(); } void client_serverbrowse_refresh(int lan) @@ -570,23 +621,6 @@ static void client_serverbrowse_update() count++; entry = entry->next_req; } - - /* - // timeout old requests - while(info_request_begin < servers.num && info_request_begin < info_request_end) - { - if(now > servers.request_times[info_request_begin]+timeout) - info_request_begin++; - else - break; - } - - // send new requests - while(info_request_end < servers.num && info_request_end-info_request_begin < max_requests) - { - client_serverbrowse_request(info_request_end); - info_request_end++; - }*/ } // ------ state handling ----- diff --git a/src/engine/interface.h b/src/engine/interface.h index 118b858fe..2a4e203aa 100644 --- a/src/engine/interface.h +++ b/src/engine/interface.h @@ -26,6 +26,12 @@ enum CLIENTSTATE_LOADING, CLIENTSTATE_ONLINE, CLIENTSTATE_QUITING, + + BROWSESORT_NONE = 0, + BROWSESORT_NAME, + BROWSESORT_PING, + BROWSESORT_MAP, + BROWSESORT_NUMPLAYERS, }; typedef struct @@ -793,6 +799,7 @@ void client_rcon(const char *cmd); void client_serverbrowse_refresh(int lan); SERVER_INFO *client_serverbrowse_get(int index); int client_serverbrowse_num(); +void client_serverbrowse_set_sort(int mode); /* undocumented graphics stuff */ void gfx_pretty_text(float x, float y, float size, const char *text, int max_width); diff --git a/src/tools/fake_server.c b/src/tools/fake_server.c index 01ba57b0f..b56607cf4 100644 --- a/src/tools/fake_server.c +++ b/src/tools/fake_server.c @@ -182,6 +182,11 @@ int main(int argc, char **argv) argc--; argv++; player_scores[num_players] = atoi(*argv); } + else if(strcmp(*argv, "-a") == 0) + { + argc--; argv++; + map = *argv; + } else if(strcmp(*argv, "-x") == 0) { argc--; argv++; @@ -192,7 +197,7 @@ int main(int argc, char **argv) argc--; argv++; game_type = atoi(*argv); } - else if(strcmp(*argv, "-p") == 0) + else if(strcmp(*argv, "-g") == 0) { argc--; argv++; progression = atoi(*argv);