From 2ece48c5359641c0edb4c729dfd91a8cf4c36c05 Mon Sep 17 00:00:00 2001 From: Chris Ison Date: Tue, 3 Apr 2001 05:48:24 +0000 Subject: [PATCH] alpha code for master server queries --- qw/include/cl_slist.h | 3 +++ qw/include/protocol.h | 1 + qw/source/cl_main.c | 11 ++++++++- qw/source/cl_slist.c | 57 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/qw/include/cl_slist.h b/qw/include/cl_slist.h index 3f093f649..cfab99fce 100644 --- a/qw/include/cl_slist.h +++ b/qw/include/cl_slist.h @@ -63,5 +63,8 @@ char *gettokstart(char *str, int req, char delim); int gettoklen(char *str, int req, char delim); void timepassed (double time1, double *time2); + +void MSL_ParseServerList(char *msl_data); + void SList_Init (void); #endif // _CL_SLIST_H diff --git a/qw/include/protocol.h b/qw/include/protocol.h index 28e6fa0cf..d6282718f 100644 --- a/qw/include/protocol.h +++ b/qw/include/protocol.h @@ -62,6 +62,7 @@ #define A2C_CLIENT_COMMAND 'B' // + command line #define S2M_SHUTDOWN 'C' +#define M2C_MASTER_REPLY 'd' // + \n + qw server port list //================== // note that there are some defs.qc that mirror to these numbers diff --git a/qw/source/cl_main.c b/qw/source/cl_main.c index 3064f7d77..395349161 100644 --- a/qw/source/cl_main.c +++ b/qw/source/cl_main.c @@ -855,12 +855,13 @@ void CL_ConnectionlessPacket (void) { char *s; - int c; + int c, clcp_temp; MSG_BeginReading (net_message); MSG_ReadLong (net_message); // skip the -1 c = MSG_ReadByte (net_message); + clcp_temp = 0; if (!cls.demoplayback) Con_Printf ("%s: ", NET_AdrToString (net_from)); // Con_DPrintf ("%s", net_message.data + 5); @@ -986,6 +987,14 @@ CL_ConnectionlessPacket (void) return; } + if (c == M2C_MASTER_REPLY) + { + Con_Printf("Master Server Reply\n"); + clcp_temp = MSG_ReadByte (net_message); + s = MSG_ReadString (net_message); + MSL_ParseServerList(s); + return; + } if (c == svc_disconnect) { if (cls.demoplayback) Host_EndGame ("End of demo"); diff --git a/qw/source/cl_slist.c b/qw/source/cl_slist.c index 83ef1b00b..696d54d1a 100644 --- a/qw/source/cl_slist.c +++ b/qw/source/cl_slist.c @@ -61,6 +61,8 @@ #include "QF/va.h" server_entry_t *slist; +server_entry_t *all_slist; + int slist_last_details; server_entry_t * @@ -76,9 +78,9 @@ SL_Add (server_entry_t *start, char *ip, char *desc) start->prev = 0; start->next = 0; start->server = malloc (strlen (ip) + 1); - start->desc = malloc (strlen (desc) + 1); + start->desc = malloc (strlen (desc ? desc : ip) + 1); strcpy (start->server, ip); - strcpy (start->desc, desc); + strcpy (start->desc, desc ? desc : ip); return (start); } @@ -88,10 +90,10 @@ SL_Add (server_entry_t *start, char *ip, char *desc) p->next->prev = p; p->next->server = malloc (strlen (ip) + 1); - p->next->desc = malloc (strlen (desc) + 1); + p->next->desc = malloc (strlen (desc ? desc : ip) + 1); strcpy (p->next->server, ip); - strcpy (p->next->desc, desc); + strcpy (p->next->desc, desc ? desc : ip); return (start); } @@ -405,6 +407,30 @@ SL_Con_Details (server_entry_t *sldata, int slitemno) Con_Printf("No Details Available\n"); } +void +SL_MasterUpdate(void) +{ + netadr_t addy; + char data[] = "c\n"; + NET_StringToAdr ("qwmaster.ocrana.de:27000", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("qwmaster.barrysworld.com:27000", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("203.55.240.100:27000", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("192.246.40.37:27000", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("192.246.40.37:27002", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("192.246.40.37:27003", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("192.246.40.37:27004", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("192.246.40.37:27006", &addy); + NET_SendPacket (3, data, addy); + NET_StringToAdr ("203.9.148.7:27000", &addy); +} + void SL_Command (void) { @@ -419,6 +445,14 @@ SL_Command (void) else Con_Printf("Syntax: slist update\n"); } + else if (strcasecmp(Cmd_Argv(1),"masterupdate") == 0) + { + SL_MasterUpdate(); + } + else if (strcasecmp(Cmd_Argv(1),"masterlist") == 0) + { + SL_Con_List(all_slist); + } else if (strcasecmp(Cmd_Argv(1),"connect") == 0) { if (Cmd_Argc () == 3) @@ -441,6 +475,20 @@ SL_Command (void) SL_Con_Details(slist,sltemp); } } +void +MSL_ParseServerList(char *msl_data) +{ + int msl_ptr; + for (msl_ptr = 0; msl_ptr < strlen(msl_data); msl_ptr = msl_ptr + 6) + { + all_slist = SL_Add(all_slist, va("%i.%i.%i.%i:%i", + (byte)msl_data[msl_ptr], + (byte)msl_data[msl_ptr+1], + (byte)msl_data[msl_ptr+2], + (byte)msl_data[msl_ptr+3], + ((byte)msl_data[msl_ptr+4]<<8)|(byte)msl_data[msl_ptr+5]), NULL); + } +} void SList_Init (void) { @@ -457,6 +505,7 @@ void SList_Init (void) slist = SL_LoadF (servlist, slist); Qclose (servlist); } + all_slist = NULL; } Cmd_AddCommand("slist",SL_Command,"console commands to access server list\n"); }