fixed sorting for the server browsing. added mass server script that starts alot of servers

This commit is contained in:
Magnus Auvinen 2007-09-29 13:16:00 +00:00
parent fa05b5e2de
commit 19aaea9bfd
4 changed files with 115 additions and 18 deletions

51
scripts/mass_server.py Normal file
View file

@ -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)

View file

@ -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) static void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *info)
{ {
int hash = addr->ip[0]; int hash = addr->ip[0];
@ -399,6 +447,7 @@ static void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *in
entry->info = *info; entry->info = *info;
if(!request) if(!request)
entry->info.latency = (time_get()-entry->request_time)*1000/time_freq(); entry->info.latency = (time_get()-entry->request_time)*1000/time_freq();
client_serverbrowse_sort();
return; return;
} }
entry = entry->next_ip; entry = entry->next_ip;
@ -443,6 +492,8 @@ static void client_serverbrowse_set(NETADDR4 *addr, int request, SERVER_INFO *in
first_req_server = entry; first_req_server = entry;
last_req_server = entry; last_req_server = entry;
} }
client_serverbrowse_sort();
} }
void client_serverbrowse_refresh(int lan) void client_serverbrowse_refresh(int lan)
@ -570,23 +621,6 @@ static void client_serverbrowse_update()
count++; count++;
entry = entry->next_req; 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 ----- // ------ state handling -----

View file

@ -26,6 +26,12 @@ enum
CLIENTSTATE_LOADING, CLIENTSTATE_LOADING,
CLIENTSTATE_ONLINE, CLIENTSTATE_ONLINE,
CLIENTSTATE_QUITING, CLIENTSTATE_QUITING,
BROWSESORT_NONE = 0,
BROWSESORT_NAME,
BROWSESORT_PING,
BROWSESORT_MAP,
BROWSESORT_NUMPLAYERS,
}; };
typedef struct typedef struct
@ -793,6 +799,7 @@ void client_rcon(const char *cmd);
void client_serverbrowse_refresh(int lan); void client_serverbrowse_refresh(int lan);
SERVER_INFO *client_serverbrowse_get(int index); SERVER_INFO *client_serverbrowse_get(int index);
int client_serverbrowse_num(); int client_serverbrowse_num();
void client_serverbrowse_set_sort(int mode);
/* undocumented graphics stuff */ /* undocumented graphics stuff */
void gfx_pretty_text(float x, float y, float size, const char *text, int max_width); void gfx_pretty_text(float x, float y, float size, const char *text, int max_width);

View file

@ -182,6 +182,11 @@ int main(int argc, char **argv)
argc--; argv++; argc--; argv++;
player_scores[num_players] = atoi(*argv); player_scores[num_players] = atoi(*argv);
} }
else if(strcmp(*argv, "-a") == 0)
{
argc--; argv++;
map = *argv;
}
else if(strcmp(*argv, "-x") == 0) else if(strcmp(*argv, "-x") == 0)
{ {
argc--; argv++; argc--; argv++;
@ -192,7 +197,7 @@ int main(int argc, char **argv)
argc--; argv++; argc--; argv++;
game_type = atoi(*argv); game_type = atoi(*argv);
} }
else if(strcmp(*argv, "-p") == 0) else if(strcmp(*argv, "-g") == 0)
{ {
argc--; argv++; argc--; argv++;
progression = atoi(*argv); progression = atoi(*argv);