From b9940e119f194729387b722d265db31219c85b38 Mon Sep 17 00:00:00 2001 From: havoc Date: Wed, 15 Mar 2006 00:35:08 +0000 Subject: [PATCH] split up net_slist into net_slist and net_slistqw, and modified menu accordingly to have two search options git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6113 d7cf8633-e32d-0410-b094-e92efae38249 --- menu.c | 54 ++++++++++++++++++++---------- mvm_cmds.c | 2 +- netconn.c | 96 +++++++++++++++++++++++++++++++++--------------------- netconn.h | 5 +-- 4 files changed, 99 insertions(+), 58 deletions(-) diff --git a/menu.c b/menu.c index 8da41f52..d121bbfc 100644 --- a/menu.c +++ b/menu.c @@ -3247,8 +3247,8 @@ void M_Quit_Draw (void) /* LAN CONFIG MENU */ int lanConfig_cursor = -1; -int lanConfig_cursor_table [] = {56, 76, 112}; -#define NUM_LANCONFIG_CMDS 3 +int lanConfig_cursor_table [] = {56, 76, 84, 120}; +#define NUM_LANCONFIG_CMDS 4 int lanConfig_port; char lanConfig_portname[6]; @@ -3301,10 +3301,11 @@ void M_LanConfig_Draw (void) if (JoiningGame) { - M_Print(basex, lanConfig_cursor_table[1], "Search for games..."); - M_Print(basex, lanConfig_cursor_table[2]-16, "Join game at:"); - M_DrawTextBox (basex+8, lanConfig_cursor_table[2]-8, 22, 1); - M_Print(basex+16, lanConfig_cursor_table[2], lanConfig_joinname); + M_Print(basex, lanConfig_cursor_table[1], "Search for DarkPlaces games..."); + M_Print(basex, lanConfig_cursor_table[2], "Search for QuakeWorld games..."); + M_Print(basex, lanConfig_cursor_table[3]-16, "Join game at:"); + M_DrawTextBox (basex+8, lanConfig_cursor_table[3]-8, 22, 1); + M_Print(basex+16, lanConfig_cursor_table[3], lanConfig_joinname); } else { @@ -3315,10 +3316,10 @@ void M_LanConfig_Draw (void) M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1)); if (lanConfig_cursor == 0) - M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [0], 10+((int)(realtime*4)&1)); + M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [lanConfig_cursor], 10+((int)(realtime*4)&1)); - if (lanConfig_cursor == 2) - M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [2], 10+((int)(realtime*4)&1)); + if (lanConfig_cursor == 3) + M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [lanConfig_cursor], 10+((int)(realtime*4)&1)); if (*m_return_reason) M_Print(basex, 168, m_return_reason); @@ -3340,6 +3341,9 @@ void M_LanConfig_Key (int key, char ascii) lanConfig_cursor--; if (lanConfig_cursor < 0) lanConfig_cursor = NUM_LANCONFIG_CMDS-1; + // when in start game menu, skip the unused search qw servers item + if (StartingGame && lanConfig_cursor == 2) + lanConfig_cursor = 1; break; case K_DOWNARROW: @@ -3347,6 +3351,9 @@ void M_LanConfig_Key (int key, char ascii) lanConfig_cursor++; if (lanConfig_cursor >= NUM_LANCONFIG_CMDS) lanConfig_cursor = 0; + // when in start game menu, skip the unused search qw servers item + if (StartingGame && lanConfig_cursor == 1) + lanConfig_cursor = 2; break; case K_ENTER: @@ -3359,7 +3366,7 @@ void M_LanConfig_Key (int key, char ascii) Cvar_SetValue("port", lanConfig_port); - if (lanConfig_cursor == 1) + if (lanConfig_cursor == 1 || lanConfig_cursor == 2) { if (StartingGame) { @@ -3370,7 +3377,7 @@ void M_LanConfig_Key (int key, char ascii) break; } - if (lanConfig_cursor == 2) + if (lanConfig_cursor == 3) Cbuf_AddText ( va ("connect \"%s\"\n", lanConfig_joinname) ); break; @@ -3381,7 +3388,7 @@ void M_LanConfig_Key (int key, char ascii) lanConfig_portname[strlen(lanConfig_portname)-1] = 0; } - if (lanConfig_cursor == 2) + if (lanConfig_cursor == 3) { if (strlen(lanConfig_joinname)) lanConfig_joinname[strlen(lanConfig_joinname)-1] = 0; @@ -3392,7 +3399,7 @@ void M_LanConfig_Key (int key, char ascii) if (ascii < 32) break; - if (lanConfig_cursor == 2) + if (lanConfig_cursor == 3) { l = (int)strlen(lanConfig_joinname); if (l < 21) @@ -3415,7 +3422,7 @@ void M_LanConfig_Key (int key, char ascii) } } - if (StartingGame && lanConfig_cursor == 2) + if (StartingGame && lanConfig_cursor == 3) { if (key == K_UPARROW) lanConfig_cursor = 1; @@ -4305,7 +4312,10 @@ void M_Menu_ServerList_f (void) m_entersound = true; slist_cursor = 0; M_Update_Return_Reason(""); - Net_Slist_f(); + if (lanConfig_cursor == 2) + Net_SlistQW_f(); + else + Net_Slist_f(); } @@ -4341,13 +4351,20 @@ void M_ServerList_Draw (void) M_PrintColored(0, y, serverlist_viewlist[n]->line2);y += 8; } } - else if (realtime - masterquerytime < 3) + else if (realtime - masterquerytime > 10) { if (masterquerycount) M_Print(0, y, "No servers found"); else M_Print(0, y, "No master servers found (network problem?)"); } + else + { + if (serverquerycount) + M_Print(0, y, "Querying servers"); + else + M_Print(0, y, "Querying master servers"); + } } @@ -4360,7 +4377,10 @@ void M_ServerList_Key(int k, char ascii) break; case K_SPACE: - Net_Slist_f(); + if (lanConfig_cursor == 2) + Net_SlistQW_f(); + else + Net_Slist_f(); break; case K_UPARROW: diff --git a/mvm_cmds.c b/mvm_cmds.c index b9bda855..939127e3 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -629,7 +629,7 @@ refreshserverlist() void VM_M_refreshserverlist( void ) { VM_SAFEPARMCOUNT( 0, VM_M_refreshserverlist ); - ServerList_QueryList(); + ServerList_QueryList(true, false); } /* diff --git a/netconn.c b/netconn.c index c27b889c..4a6ea050 100755 --- a/netconn.c +++ b/netconn.c @@ -107,11 +107,11 @@ int serverquerycount = 0; int serverreplycount = 0; // this is only false if there are still servers left to query -int serverlist_querysleep = true; +static qboolean serverlist_querysleep = true; // this is pushed a second or two ahead of realtime whenever a master server // reply is received, to avoid issuing queries while master replies are still // flooding in (which would make a mess of the ping times) -double serverlist_querywaittime = 0; +static double serverlist_querywaittime = 0; static unsigned char sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE]; static unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE]; @@ -397,7 +397,7 @@ static void _ServerList_Test(void) } #endif -void ServerList_QueryList(void) +void ServerList_QueryList(qboolean querydp, qboolean queryqw) { //masterquerytime = realtime; masterquerytime = Sys_DoubleTime(); @@ -411,7 +411,7 @@ void ServerList_QueryList(void) //_ServerList_Test(); - NetConn_QueryMasters(); + NetConn_QueryMasters(querydp, queryqw); } // rest @@ -2227,7 +2227,7 @@ void NetConn_ServerFrame(void) } } -void NetConn_QueryMasters(void) +void NetConn_QueryMasters(qboolean querydp, qboolean queryqw) { int i; int masternum; @@ -2243,43 +2243,48 @@ void NetConn_QueryMasters(void) // note this is IPv4-only, I doubt there are IPv6-only LANs out there LHNETADDRESS_FromString(&broadcastaddress, "255.255.255.255", 26000); - for (i = 0;i < cl_numsockets;i++) + if (querydp) { - if (cl_sockets[i]) + for (i = 0;i < cl_numsockets;i++) { - // search LAN for Quake servers - SZ_Clear(&net_message); - // save space for the header, filled in later - MSG_WriteLong(&net_message, 0); - MSG_WriteByte(&net_message, CCREQ_SERVER_INFO); - MSG_WriteString(&net_message, "QUAKE"); - MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION); - *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK)); - NetConn_Write(cl_sockets[i], net_message.data, net_message.cursize, &broadcastaddress); - SZ_Clear(&net_message); - - // search LAN for DarkPlaces servers - NetConn_WriteString(cl_sockets[i], "\377\377\377\377getinfo", &broadcastaddress); - - // build the getservers message to send to the dpmaster master servers - dpsnprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION); - - // search internet - for (masternum = 0;sv_masters[masternum].name;masternum++) + if (cl_sockets[i]) { - if (sv_masters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i]))) + // search LAN for Quake servers + SZ_Clear(&net_message); + // save space for the header, filled in later + MSG_WriteLong(&net_message, 0); + MSG_WriteByte(&net_message, CCREQ_SERVER_INFO); + MSG_WriteString(&net_message, "QUAKE"); + MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION); + *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK)); + NetConn_Write(cl_sockets[i], net_message.data, net_message.cursize, &broadcastaddress); + SZ_Clear(&net_message); + + // search LAN for DarkPlaces servers + NetConn_WriteString(cl_sockets[i], "\377\377\377\377getinfo", &broadcastaddress); + + // build the getservers message to send to the dpmaster master servers + dpsnprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION); + + // search internet + for (masternum = 0;sv_masters[masternum].name;masternum++) { - masterquerycount++; - NetConn_WriteString(cl_sockets[i], request, &masteraddress); + if (sv_masters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, DPMASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i]))) + { + masterquerycount++; + NetConn_WriteString(cl_sockets[i], request, &masteraddress); + } } } + } + } - // only query QuakeWorld servers when in GAME_NORMAL mode as that - // is all QuakeWorld is designed for, we don't want QuakeWorld - // servers showing up when running another game (not even the - // mission packs, as if a QuakeWorld server was using their data - // you could still play with -game hipnotic rather than -hipnotic) - if (gamemode == GAME_NORMAL) + // only query QuakeWorld servers when the user wants to + if (queryqw) + { + for (i = 0;i < cl_numsockets;i++) + { + if (cl_sockets[i]) { // build the getservers message to send to the qwmaster master servers // note this has no -1 prefix, and the trailing nul byte is sent @@ -2375,11 +2380,25 @@ void Net_Slist_f(void) serverlist_sortdescending = false; if (m_state != m_slist) { Con_Print("Sending requests to master servers\n"); - ServerList_QueryList(); + ServerList_QueryList(true, false); + serverlist_consoleoutput = true; + Con_Print("Listening for replies...\n"); + } else + ServerList_QueryList(true, false); +} + +void Net_SlistQW_f(void) +{ + ServerList_ResetMasks(); + serverlist_sortbyfield = SLIF_PING; + serverlist_sortdescending = false; + if (m_state != m_slist) { + Con_Print("Sending requests to master servers\n"); + ServerList_QueryList(false, true); serverlist_consoleoutput = true; Con_Print("Listening for replies...\n"); } else - ServerList_QueryList(); + ServerList_QueryList(false, true); } void NetConn_Init(void) @@ -2388,7 +2407,8 @@ void NetConn_Init(void) lhnetaddress_t tempaddress; netconn_mempool = Mem_AllocPool("network connections", 0, NULL); Cmd_AddCommand("net_stats", Net_Stats_f, "print network statistics"); - Cmd_AddCommand("net_slist", Net_Slist_f, "query master series and print all server information"); + Cmd_AddCommand("net_slist", Net_Slist_f, "query dp master servers and print all server information"); + Cmd_AddCommand("net_slistqw", Net_SlistQW_f, "query qw master servers and print all server information"); Cmd_AddCommand("heartbeat", Net_Heartbeat_f, "send a heartbeat to the master server (updates your server information)"); Cvar_RegisterVariable(&net_slist_queriespersecond); Cvar_RegisterVariable(&net_slist_queriesperframe); diff --git a/netconn.h b/netconn.h index 59e780d2..883f887b 100755 --- a/netconn.h +++ b/netconn.h @@ -358,17 +358,18 @@ int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnet int NetConn_IsLocalGame(void); void NetConn_ClientFrame(void); void NetConn_ServerFrame(void); -void NetConn_QueryMasters(void); +void NetConn_QueryMasters(qboolean querydp, qboolean queryqw); void NetConn_Heartbeat(int priority); void NetConn_QueryQueueFrame(void); void Net_Stats_f(void); void Net_Slist_f(void); +void Net_SlistQW_f(void); // ServerList interface (public) // manually refresh the view set, do this after having changed the mask or any other flag void ServerList_RebuildViewList(void); void ServerList_ResetMasks(void); -void ServerList_QueryList(void); +void ServerList_QueryList(qboolean querydp, qboolean queryqw); #endif -- 2.39.2