Small code cleanup in the ftemaster code.
git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5884 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
parent
c035801161
commit
3a97a75ab2
1 changed files with 191 additions and 161 deletions
|
@ -553,20 +553,15 @@ static void SVM_Init(void)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
vfsfile_t *SVM_GenerateIndex(const char *requesthost, const char *fname, const char **mimetype, const char *query)
|
vfsfile_t *SVM_Generate_Gamelist(const char **mimetype, const char *query)
|
||||||
{
|
{
|
||||||
|
vfsfile_t *f = VFSPIPE_Open(1, false);
|
||||||
char tmpbuf[256];
|
char tmpbuf[256];
|
||||||
char hostname[1024];
|
char hostname[1024];
|
||||||
const char *url;
|
|
||||||
svm_game_t *game;
|
svm_game_t *game;
|
||||||
svm_server_t *server;
|
svm_server_t *server;
|
||||||
vfsfile_t *f = NULL;
|
|
||||||
unsigned clients=0,bots=0,specs=0, totalclients=0, totalbots=0, totalspecs=0;
|
unsigned clients=0,bots=0,specs=0, totalclients=0, totalbots=0, totalspecs=0;
|
||||||
if (!master_css)
|
|
||||||
SVM_Init();
|
|
||||||
if (!strcmp(fname, "index.html"))
|
|
||||||
{
|
|
||||||
f = VFSPIPE_Open(1, false);
|
|
||||||
VFS_PRINTF(f, "%s", master_css);
|
VFS_PRINTF(f, "%s", master_css);
|
||||||
VFS_PRINTF(f, "<h1>%s</h1>\n", sv_hostname.string);
|
VFS_PRINTF(f, "<h1>%s</h1>\n", sv_hostname.string);
|
||||||
VFS_PRINTF(f, "<table border=1>\n");
|
VFS_PRINTF(f, "<table border=1>\n");
|
||||||
|
@ -607,20 +602,24 @@ vfsfile_t *SVM_GenerateIndex(const char *requesthost, const char *fname, const c
|
||||||
VFS_PRINTF(f, "Your IP is %s<br/>\n", NET_BaseAdrToString(hostname, sizeof(hostname), &net_from));
|
VFS_PRINTF(f, "Your IP is %s<br/>\n", NET_BaseAdrToString(hostname, sizeof(hostname), &net_from));
|
||||||
|
|
||||||
*mimetype = "text/html";
|
*mimetype = "text/html";
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
else if (!strncmp(fname, "server/", 7))
|
vfsfile_t *SVM_Generate_Serverinfo(const char **mimetype, const char *serveraddr, const char *query)
|
||||||
{
|
{
|
||||||
|
vfsfile_t *f = VFSPIPE_Open(1, false);
|
||||||
|
char tmpbuf[256];
|
||||||
|
char hostname[1024];
|
||||||
|
svm_server_t *server;
|
||||||
netadr_t adr[64];
|
netadr_t adr[64];
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
f = VFSPIPE_Open(1, false);
|
|
||||||
VFS_PRINTF(f, "%s", master_css);
|
VFS_PRINTF(f, "%s", master_css);
|
||||||
VFS_PRINTF(f, "<h1>Single Server Info</h1>\n");
|
VFS_PRINTF(f, "<h1>Single Server Info</h1>\n");
|
||||||
|
|
||||||
VFS_PRINTF(f, "<table border=1>\n");
|
VFS_PRINTF(f, "<table border=1>\n");
|
||||||
VFS_PRINTF(f, "<tr><th>Game</th><th>Address</th><th>Hostname</th><th>Mod dir</th><th>Mapname</th><th>Players</th></tr>\n");
|
VFS_PRINTF(f, "<tr><th>Game</th><th>Address</th><th>Hostname</th><th>Mod dir</th><th>Mapname</th><th>Players</th></tr>\n");
|
||||||
//FIXME: block dns lookups here?
|
//FIXME: block dns lookups here?
|
||||||
count = NET_StringToAdr2(fname+7, 0, adr, countof(adr), NULL);
|
count = NET_StringToAdr2(serveraddr, 0, adr, countof(adr), NULL);
|
||||||
while(count-->0)
|
while(count-->0)
|
||||||
{
|
{
|
||||||
server = SVM_GetServer(&adr[count]);
|
server = SVM_GetServer(&adr[count]);
|
||||||
|
@ -635,14 +634,22 @@ vfsfile_t *SVM_GenerateIndex(const char *requesthost, const char *fname, const c
|
||||||
VFS_PRINTF(f, "</table>\n");
|
VFS_PRINTF(f, "</table>\n");
|
||||||
|
|
||||||
*mimetype = "text/html";
|
*mimetype = "text/html";
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
else if (!strncmp(fname, "game/", 5))
|
|
||||||
|
vfsfile_t *SVM_Generate_Serverlist(const char **mimetype, const char *masteraddr, const char *gamename, const char *query)
|
||||||
{
|
{
|
||||||
|
vfsfile_t *f = VFSPIPE_Open(1, false);
|
||||||
|
char tmpbuf[256];
|
||||||
|
char hostname[1024];
|
||||||
|
const char *url;
|
||||||
|
svm_game_t *game;
|
||||||
|
svm_server_t *server;
|
||||||
|
unsigned clients=0,bots=0,specs=0;
|
||||||
|
|
||||||
qboolean showver = query && !!strstr(query, "ver=1");
|
qboolean showver = query && !!strstr(query, "ver=1");
|
||||||
const char *gamename = fname+5;
|
|
||||||
game = SVM_FindGame(gamename, false);
|
game = SVM_FindGame(gamename, false);
|
||||||
|
|
||||||
f = VFSPIPE_Open(1, false);
|
|
||||||
VFS_PRINTF(f, "%s", master_css);
|
VFS_PRINTF(f, "%s", master_css);
|
||||||
|
|
||||||
if (!strcmp(gamename, "UNKNOWN"))
|
if (!strcmp(gamename, "UNKNOWN"))
|
||||||
|
@ -676,7 +683,7 @@ vfsfile_t *SVM_GenerateIndex(const char *requesthost, const char *fname, const c
|
||||||
if (server->brokerid)
|
if (server->brokerid)
|
||||||
{
|
{
|
||||||
url = tmpbuf;
|
url = tmpbuf;
|
||||||
Q_snprintfz(tmpbuf, sizeof(tmpbuf), "rtc://%s/%s", requesthost, server->brokerid);
|
Q_snprintfz(tmpbuf, sizeof(tmpbuf), "rtc://%s/%s", masteraddr, server->brokerid);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
url = NET_AdrToString(tmpbuf, sizeof(tmpbuf), &server->adr);
|
url = NET_AdrToString(tmpbuf, sizeof(tmpbuf), &server->adr);
|
||||||
|
@ -709,10 +716,17 @@ vfsfile_t *SVM_GenerateIndex(const char *requesthost, const char *fname, const c
|
||||||
VFS_PRINTF(f, "Protocol '%s' is not known\n", gamename);
|
VFS_PRINTF(f, "Protocol '%s' is not known\n", gamename);
|
||||||
|
|
||||||
*mimetype = "text/html";
|
*mimetype = "text/html";
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
else if (!strncmp(fname, "raw/", 4))
|
|
||||||
|
vfsfile_t *SVM_Generate_Rawlist(const char **mimetype, const char *masteraddr, const char *gamename, const char *query)
|
||||||
{ //just spews all
|
{ //just spews all
|
||||||
COM_StripExtension(fname+4, tmpbuf, sizeof(tmpbuf));
|
char tmpbuf[256];
|
||||||
|
svm_game_t *game;
|
||||||
|
svm_server_t *server;
|
||||||
|
vfsfile_t *f = VFSPIPE_Open(1, false);
|
||||||
|
|
||||||
|
COM_StripExtension(gamename, tmpbuf, sizeof(tmpbuf));
|
||||||
game = SVM_FindGame(tmpbuf, false);
|
game = SVM_FindGame(tmpbuf, false);
|
||||||
|
|
||||||
f = VFSPIPE_Open(1, false);
|
f = VFSPIPE_Open(1, false);
|
||||||
|
@ -720,13 +734,28 @@ vfsfile_t *SVM_GenerateIndex(const char *requesthost, const char *fname, const c
|
||||||
for (server = (game?game->firstserver:NULL); server; server = server->next)
|
for (server = (game?game->firstserver:NULL); server; server = server->next)
|
||||||
{
|
{
|
||||||
if (server->brokerid)
|
if (server->brokerid)
|
||||||
VFS_PRINTF(f, "rtc:///%s \\maxclients\\%u\\clients\\%u\\bots\\%u\\hostname\\%s\\modname\\%s\\mapname\\%s\\needpass\\%i\n", server->brokerid, server->maxclients, server->clients, server->bots, server->hostname, server->gamedir, server->mapname, server->needpass);
|
VFS_PRINTF(f, "rtc://%s/%s \\maxclients\\%u\\clients\\%u\\bots\\%u\\hostname\\%s\\modname\\%s\\mapname\\%s\\needpass\\%i\n", masteraddr, server->brokerid, server->maxclients, server->clients, server->bots, server->hostname, server->gamedir, server->mapname, server->needpass);
|
||||||
else
|
else
|
||||||
VFS_PRINTF(f, "%s\n", NET_AdrToString(tmpbuf, sizeof(tmpbuf), &server->adr));
|
VFS_PRINTF(f, "%s\n", NET_AdrToString(tmpbuf, sizeof(tmpbuf), &server->adr));
|
||||||
}
|
}
|
||||||
|
|
||||||
*mimetype = "text/plain";
|
*mimetype = "text/plain";
|
||||||
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vfsfile_t *SVM_GenerateIndex(const char *requesthost, const char *fname, const char **mimetype, const char *query)
|
||||||
|
{
|
||||||
|
vfsfile_t *f = NULL;
|
||||||
|
if (!master_css)
|
||||||
|
SVM_Init();
|
||||||
|
if (!strcmp(fname, "index.html"))
|
||||||
|
f = SVM_Generate_Gamelist(mimetype, query);
|
||||||
|
else if (!strncmp(fname, "server/", 7))
|
||||||
|
f = SVM_Generate_Serverinfo(mimetype, fname+7, query);
|
||||||
|
else if (!strncmp(fname, "game/", 5))
|
||||||
|
f = SVM_Generate_Serverlist(mimetype, requesthost, fname+5, query);
|
||||||
|
else if (!strncmp(fname, "raw/", 4))
|
||||||
|
f = SVM_Generate_Rawlist(mimetype, requesthost, fname+4, query);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1255,6 +1284,7 @@ static void SVM_ProcessUDPPacket(void)
|
||||||
{ //response from a FTE-master request (lots of IPs from a 'slave' master that we're stealing)
|
{ //response from a FTE-master request (lots of IPs from a 'slave' master that we're stealing)
|
||||||
netadr_t a = {NA_INVALID};
|
netadr_t a = {NA_INVALID};
|
||||||
msg_readcount = 4+21; //grr
|
msg_readcount = 4+21; //grr
|
||||||
|
msg_badread = false;
|
||||||
svm.total.heartbeats++;
|
svm.total.heartbeats++;
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue