mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 20:31:30 +00:00
Merge branch 'master-server-2' into 'next'
Master Server 2 See merge request KartKrew/Kart-Public!224
This commit is contained in:
commit
0f19b1357c
10 changed files with 327 additions and 727 deletions
109
src/d_clisrv.c
109
src/d_clisrv.c
|
@ -1973,57 +1973,30 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node)
|
|||
M_SortServerList();
|
||||
}
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
struct Fetch_servers_ctx
|
||||
void CL_UpdateServerList (void)
|
||||
{
|
||||
int room;
|
||||
int id;
|
||||
};
|
||||
SL_ClearServerList(0);
|
||||
|
||||
static void
|
||||
Fetch_servers_thread (struct Fetch_servers_ctx *ctx)
|
||||
{
|
||||
msg_server_t *server_list;
|
||||
|
||||
server_list = GetShortServersList(ctx->room, ctx->id);
|
||||
|
||||
if (server_list)
|
||||
if (!netgame && I_NetOpenSocket)
|
||||
{
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
if (I_NetOpenSocket())
|
||||
{
|
||||
if (ctx->id != ms_QueryId)
|
||||
{
|
||||
free(server_list);
|
||||
server_list = NULL;
|
||||
}
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
if (server_list)
|
||||
{
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
{
|
||||
if (m_waiting_mode == M_WAITING_SERVERS)
|
||||
m_waiting_mode = M_NOT_WAITING;
|
||||
}
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
|
||||
I_lock_mutex(&ms_ServerList_mutex);
|
||||
{
|
||||
ms_ServerList = server_list;
|
||||
}
|
||||
I_unlock_mutex(ms_ServerList_mutex);
|
||||
netgame = true;
|
||||
multiplayer = true;
|
||||
}
|
||||
}
|
||||
|
||||
free(ctx);
|
||||
// search for local servers
|
||||
if (netgame)
|
||||
SendAskInfo(BROADCASTADDR);
|
||||
}
|
||||
#endif/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/
|
||||
|
||||
void CL_QueryServerList (msg_server_t *server_list)
|
||||
{
|
||||
INT32 i;
|
||||
|
||||
CL_UpdateServerList();
|
||||
|
||||
for (i = 0; server_list[i].header.buffer[0]; i++)
|
||||
{
|
||||
// Make sure MS version matches our own, to
|
||||
|
@ -2052,62 +2025,6 @@ void CL_QueryServerList (msg_server_t *server_list)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CL_UpdateServerList(boolean internetsearch, INT32 room)
|
||||
{
|
||||
(void)internetsearch;
|
||||
(void)room;
|
||||
|
||||
SL_ClearServerList(0);
|
||||
|
||||
if (!netgame && I_NetOpenSocket)
|
||||
{
|
||||
if (I_NetOpenSocket())
|
||||
{
|
||||
netgame = true;
|
||||
multiplayer = true;
|
||||
}
|
||||
}
|
||||
|
||||
// search for local servers
|
||||
if (netgame)
|
||||
SendAskInfo(BROADCASTADDR);
|
||||
|
||||
#ifdef MASTERSERVER
|
||||
if (internetsearch)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
struct Fetch_servers_ctx *ctx;
|
||||
|
||||
ctx = malloc(sizeof *ctx);
|
||||
|
||||
/* This called from M_Refresh so I don't use a mutex */
|
||||
m_waiting_mode = M_WAITING_SERVERS;
|
||||
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
ctx->id = ms_QueryId;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
ctx->room = room;
|
||||
|
||||
I_spawn_thread("fetch-servers", (I_thread_fn)Fetch_servers_thread, ctx);
|
||||
#else
|
||||
msg_server_t *server_list;
|
||||
|
||||
server_list = GetShortServersList(room, 0);
|
||||
|
||||
if (server_list)
|
||||
{
|
||||
CL_QueryServerList(server_list);
|
||||
free(server_list);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif/*MASTERSERVER*/
|
||||
}
|
||||
|
||||
#endif // ifndef NONET
|
||||
|
||||
static void M_ConfirmConnect(event_t *ev)
|
||||
|
@ -3759,7 +3676,7 @@ void D_QuitNetGame(void)
|
|||
if (nodeingame[i])
|
||||
HSendPacket(i, true, 0, 0);
|
||||
#ifdef MASTERSERVER
|
||||
if (serverrunning && ms_RoomId > 0)
|
||||
if (serverrunning && cv_advertise.value)
|
||||
UnregisterServer();
|
||||
#endif
|
||||
}
|
||||
|
@ -4021,7 +3938,7 @@ boolean SV_SpawnServer(void)
|
|||
{
|
||||
I_NetOpenSocket();
|
||||
#ifdef MASTERSERVER
|
||||
if (ms_RoomId > 0)
|
||||
if (cv_advertise.value)
|
||||
RegisterServer();
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -591,7 +591,7 @@ void CL_Reset(void);
|
|||
void CL_ClearPlayer(INT32 playernum);
|
||||
void CL_RemovePlayer(INT32 playernum, INT32 reason);
|
||||
void CL_QueryServerList(msg_server_t *list);
|
||||
void CL_UpdateServerList(boolean internetsearch, INT32 room);
|
||||
void CL_UpdateServerList(void);
|
||||
// Is there a game running
|
||||
boolean Playing(void);
|
||||
|
||||
|
|
12
src/d_main.c
12
src/d_main.c
|
@ -69,7 +69,6 @@ int snprintf(char *str, size_t n, const char *fmt, ...);
|
|||
#include "m_cheat.h"
|
||||
#include "y_inter.h"
|
||||
#include "p_local.h" // chasecam
|
||||
#include "mserv.h" // ms_RoomId
|
||||
#include "m_misc.h" // screenshot functionality
|
||||
#include "dehacked.h" // Dehacked list test
|
||||
#include "m_cond.h" // condition initialization
|
||||
|
@ -1424,17 +1423,6 @@ void D_SRB2Main(void)
|
|||
CONS_Printf("ST_Init(): Init status bar.\n");
|
||||
ST_Init();
|
||||
|
||||
if (M_CheckParm("-room"))
|
||||
{
|
||||
if (!M_IsNextParm())
|
||||
I_Error("usage: -room <room_id>\nCheck the Master Server's webpage for room ID numbers.\n");
|
||||
ms_RoomId = atoi(M_GetNextParm());
|
||||
|
||||
#ifdef UPDATE_ALERT
|
||||
GetMODVersion_Console();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Set up splitscreen players before joining!
|
||||
if (!dedicated && (M_CheckParm("-splitscreen") && M_IsNextParm()))
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "p_tick.h"
|
||||
#include "m_menu.h" // gametype_cons_t
|
||||
#include "r_things.h" // skins
|
||||
#include "mserv.h" // ms_RoomId
|
||||
#include "mserv.h" // cv_advertise
|
||||
#include "z_zone.h"
|
||||
#include "byteptr.h"
|
||||
|
||||
|
@ -505,14 +505,13 @@ void DRPC_UpdatePresence(void)
|
|||
// Server info
|
||||
if (netgame)
|
||||
{
|
||||
switch (ms_RoomId)
|
||||
if (cv_advertise.value)
|
||||
{
|
||||
case -1: discordPresence.state = "Private"; break; // Private server
|
||||
case 33: discordPresence.state = "Standard"; break;
|
||||
case 28: discordPresence.state = "Casual"; break;
|
||||
case 38: discordPresence.state = "Custom Gametypes"; break;
|
||||
case 31: discordPresence.state = "OLDC"; break;
|
||||
default: discordPresence.state = "Unknown Room"; break; // HOW
|
||||
discordPresence.state = "Public";
|
||||
}
|
||||
else
|
||||
{
|
||||
discordPresence.state = "Private";
|
||||
}
|
||||
|
||||
discordPresence.partyId = server_context; // Thanks, whoever gave us Mumble support, for implementing the EXACT thing Discord wanted for this field!
|
||||
|
|
|
@ -181,32 +181,13 @@ extern char logfilename[1024];
|
|||
// Please change to apply to your modification (we don't want everyone asking where your mod is on SRB2.org!).
|
||||
#define UPDATE_ALERT_STRING \
|
||||
"A new update is available for SRB2Kart.\n"\
|
||||
"Please visit mb.srb2.org to download it.\n"\
|
||||
"Please visit kartkrew.org to download it.\n"\
|
||||
"\n"\
|
||||
"You are using version: %s\n"\
|
||||
"The newest version is: %s\n"\
|
||||
"\n"\
|
||||
"This update is required for online\n"\
|
||||
"play using the Master Server.\n"\
|
||||
"You will not be able to connect to\n"\
|
||||
"the Master Server until you update to\n"\
|
||||
"the newest version of the game.\n"\
|
||||
"\n"\
|
||||
"(Press a key)\n"
|
||||
|
||||
// The string used in the I_Error alert upon trying to host through command line parameters.
|
||||
// Generally less filled with newlines, since Windows gives you lots more room to work with.
|
||||
#define UPDATE_ALERT_STRING_CONSOLE \
|
||||
"A new update is available for SRB2Kart.\n"\
|
||||
"Please visit mb.srb2.org to download it.\n"\
|
||||
"\n"\
|
||||
"You are using version: %s\n"\
|
||||
"The newest version is: %s\n"\
|
||||
"\n"\
|
||||
"This update is required for online play using the Master Server.\n"\
|
||||
"You will not be able to connect to the Master Server\n"\
|
||||
"until you update to the newest version of the game.\n"
|
||||
|
||||
// For future use, the codebase is the version of SRB2 that the modification is based on,
|
||||
// and should not be changed unless you have merged changes between versions of SRB2
|
||||
// (such as 2.0.4 to 2.0.5, etc) into your working copy.
|
||||
|
|
269
src/http-mserv.c
269
src/http-mserv.c
|
@ -11,7 +11,7 @@
|
|||
/*
|
||||
Documentation available here.
|
||||
|
||||
<http://mb.srb2.org/MS/tools/api/v1/>
|
||||
<https://ms.kartkrew.org/tools/api/2/>
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CURL
|
||||
|
@ -141,7 +141,7 @@ HMS_connect (const char *format, ...)
|
|||
if (cv_masterserver_token.string[0])
|
||||
{
|
||||
quack_token = curl_easy_escape(curl, cv_masterserver_token.string, 0);
|
||||
token_length = ( sizeof "?token="-1 )+ strlen(quack_token);
|
||||
token_length = ( sizeof "&token="-1 )+ strlen(quack_token);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -156,7 +156,9 @@ HMS_connect (const char *format, ...)
|
|||
seek = strlen(hms_api) + 1;/* + '/' */
|
||||
|
||||
va_start (ap, format);
|
||||
url = malloc(seek + vsnprintf(0, 0, format, ap) + token_length + 1);
|
||||
url = malloc(seek + vsnprintf(0, 0, format, ap) +
|
||||
sizeof "?v=2" - 1 +
|
||||
token_length + 1);
|
||||
va_end (ap);
|
||||
|
||||
sprintf(url, "%s/", hms_api);
|
||||
|
@ -169,8 +171,11 @@ HMS_connect (const char *format, ...)
|
|||
seek += vsprintf(&url[seek], format, ap);
|
||||
va_end (ap);
|
||||
|
||||
strcpy(&url[seek], "?v=2");
|
||||
seek += sizeof "?v=2" - 1;
|
||||
|
||||
if (quack_token)
|
||||
sprintf(&url[seek], "?token=%s", quack_token);
|
||||
sprintf(&url[seek], "&token=%s", quack_token);
|
||||
|
||||
CONS_Printf("HMS: connecting '%s'...\n", url);
|
||||
|
||||
|
@ -258,117 +263,6 @@ HMS_end (struct HMS_buffer *buffer)
|
|||
free(buffer);
|
||||
}
|
||||
|
||||
int
|
||||
HMS_fetch_rooms (int joining, int query_id)
|
||||
{
|
||||
struct HMS_buffer *hms;
|
||||
int ok;
|
||||
|
||||
int doing_shit;
|
||||
|
||||
char *id;
|
||||
char *title;
|
||||
char *room_motd;
|
||||
|
||||
int id_no;
|
||||
|
||||
char *p;
|
||||
char *end;
|
||||
|
||||
int i;
|
||||
|
||||
(void)query_id;
|
||||
|
||||
hms = HMS_connect("rooms");
|
||||
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
||||
if (HMS_do(hms))
|
||||
{
|
||||
doing_shit = 1;
|
||||
|
||||
p = hms->buffer;
|
||||
|
||||
for (i = 0; i < NUM_LIST_ROOMS && ( end = strstr(p, "\n\n\n") );)
|
||||
{
|
||||
*end = '\0';
|
||||
|
||||
id = strtok(p, "\n");
|
||||
title = strtok(0, "\n");
|
||||
room_motd = strtok(0, "");
|
||||
|
||||
if (id && title && room_motd)
|
||||
{
|
||||
id_no = atoi(id);
|
||||
|
||||
/*
|
||||
Don't show the 'All' room if hosting. And it's a hack like this
|
||||
because I'm way too lazy to add another feature to the MS.
|
||||
*/
|
||||
if (joining || id_no != 0)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
if (query_id != ms_QueryId)
|
||||
doing_shit = 0;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
if (! doing_shit)
|
||||
break;
|
||||
#endif
|
||||
|
||||
room_list[i].header.buffer[0] = 1;
|
||||
|
||||
room_list[i].id = id_no;
|
||||
strlcpy(room_list[i].name, title, sizeof room_list[i].name);
|
||||
strlcpy(room_list[i].motd, room_motd, sizeof room_list[i].motd);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
p = ( end + 3 );/* skip the three linefeeds */
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
if (doing_shit)
|
||||
room_list[i].header.buffer[0] = 0;
|
||||
|
||||
ok = 1;
|
||||
|
||||
if (doing_shit)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
{
|
||||
for (i = 0; room_list[i].header.buffer[0]; i++)
|
||||
{
|
||||
if(*room_list[i].name != '\0')
|
||||
{
|
||||
MP_RoomMenu[i+1].text = room_list[i].name;
|
||||
roomIds[i] = room_list[i].id;
|
||||
MP_RoomMenu[i+1].status = IT_STRING|IT_CALL;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
ok = 0;
|
||||
|
||||
HMS_end(hms);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
HMS_register (void)
|
||||
{
|
||||
|
@ -377,29 +271,26 @@ HMS_register (void)
|
|||
|
||||
char post[256];
|
||||
|
||||
char *title;
|
||||
char *contact;
|
||||
|
||||
hms = HMS_connect("rooms/%d/register", ms_RoomId);
|
||||
hms = HMS_connect(
|
||||
"games/%s/%d/servers/register", SRB2APPLICATION, MODVERSION);
|
||||
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
||||
title = curl_easy_escape(hms->curl, cv_servername.string, 0);
|
||||
contact = curl_easy_escape(hms->curl, cv_server_contact.string, 0);
|
||||
|
||||
snprintf(post, sizeof post,
|
||||
"port=%d&"
|
||||
"title=%s&"
|
||||
"version=%d.%d",
|
||||
"contact=%s",
|
||||
|
||||
current_port,
|
||||
|
||||
title,
|
||||
|
||||
VERSION,
|
||||
SUBVERSION
|
||||
contact
|
||||
);
|
||||
|
||||
curl_free(title);
|
||||
curl_free(contact);
|
||||
|
||||
curl_easy_setopt(hms->curl, CURLOPT_POSTFIELDS, post);
|
||||
|
||||
|
@ -473,19 +364,13 @@ HMS_list_servers (void)
|
|||
{
|
||||
struct HMS_buffer *hms;
|
||||
|
||||
char *p;
|
||||
|
||||
hms = HMS_connect("servers");
|
||||
hms = HMS_connect("games/%s/%d/servers", SRB2APPLICATION, MODVERSION);
|
||||
|
||||
if (! hms)
|
||||
return;
|
||||
|
||||
if (HMS_do(hms))
|
||||
{
|
||||
p = &hms->buffer[strlen(hms->buffer)];
|
||||
while (*--p == '\n')
|
||||
;
|
||||
|
||||
CONS_Printf("%s\n", hms->buffer);
|
||||
}
|
||||
|
||||
|
@ -493,35 +378,24 @@ HMS_list_servers (void)
|
|||
}
|
||||
|
||||
msg_server_t *
|
||||
HMS_fetch_servers (msg_server_t *list, int room_number, int query_id)
|
||||
HMS_fetch_servers (msg_server_t *list, int query_id)
|
||||
{
|
||||
struct HMS_buffer *hms;
|
||||
|
||||
int doing_shit;
|
||||
|
||||
char local_version[9];
|
||||
|
||||
char *room;
|
||||
|
||||
char *address;
|
||||
char *port;
|
||||
char *title;
|
||||
char *version;
|
||||
char *contact;
|
||||
|
||||
char *end;
|
||||
char *section_end;
|
||||
char *p;
|
||||
|
||||
int i;
|
||||
|
||||
(void)query_id;
|
||||
|
||||
if (room_number > 0)
|
||||
{
|
||||
hms = HMS_connect("rooms/%d/servers", room_number);
|
||||
}
|
||||
else
|
||||
hms = HMS_connect("servers");
|
||||
hms = HMS_connect("games/%s/%d/servers", SRB2APPLICATION, MODVERSION);
|
||||
|
||||
if (! hms)
|
||||
return NULL;
|
||||
|
@ -530,81 +404,51 @@ HMS_fetch_servers (msg_server_t *list, int room_number, int query_id)
|
|||
{
|
||||
doing_shit = 1;
|
||||
|
||||
snprintf(local_version, sizeof local_version,
|
||||
"%d.%d",
|
||||
VERSION,
|
||||
SUBVERSION
|
||||
);
|
||||
|
||||
p = hms->buffer;
|
||||
i = 0;
|
||||
|
||||
do
|
||||
while (i < MAXSERVERLIST && ( end = strchr(p, '\n') ))
|
||||
{
|
||||
section_end = strstr(p, "\n\n");
|
||||
*end = '\0';
|
||||
|
||||
room = strtok(p, "\n");
|
||||
address = strtok(p, " ");
|
||||
port = strtok(0, " ");
|
||||
contact = strtok(0, "");
|
||||
|
||||
p = strtok(0, "");
|
||||
|
||||
if (! p)
|
||||
break;
|
||||
|
||||
while (i < MAXSERVERLIST && ( end = strchr(p, '\n') ))
|
||||
if (address && port)
|
||||
{
|
||||
*end = '\0';
|
||||
|
||||
address = strtok(p, " ");
|
||||
port = strtok(0, " ");
|
||||
title = strtok(0, " ");
|
||||
version = strtok(0, "");
|
||||
|
||||
if (address && port && title && version)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
if (query_id != ms_QueryId)
|
||||
doing_shit = 0;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
if (query_id != ms_QueryId)
|
||||
doing_shit = 0;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
if (! doing_shit)
|
||||
break;
|
||||
if (! doing_shit)
|
||||
break;
|
||||
#endif
|
||||
|
||||
if (strcmp(version, local_version) == 0)
|
||||
{
|
||||
strlcpy(list[i].ip, address, sizeof list[i].ip);
|
||||
strlcpy(list[i].port, port, sizeof list[i].port);
|
||||
strlcpy(list[i].name, title, sizeof list[i].name);
|
||||
strlcpy(list[i].version, version, sizeof list[i].version);
|
||||
strlcpy(list[i].ip, address, sizeof list[i].ip);
|
||||
strlcpy(list[i].port, port, sizeof list[i].port);
|
||||
|
||||
list[i].room = atoi(room);
|
||||
|
||||
list[i].header.buffer[0] = 1;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (end == section_end)/* end of list for this room */
|
||||
break;
|
||||
else
|
||||
p = ( end + 1 );/* skip server delimiter */
|
||||
}
|
||||
else
|
||||
if (contact)
|
||||
{
|
||||
section_end = 0;/* malformed so quit the parsing */
|
||||
break;
|
||||
strlcpy(list[i].contact, contact, sizeof list[i].contact);
|
||||
}
|
||||
|
||||
list[i].header.buffer[0] = 1;
|
||||
|
||||
i++;
|
||||
|
||||
p = ( end + 1 );/* skip server delimiter */
|
||||
}
|
||||
|
||||
if (! doing_shit)
|
||||
else
|
||||
{
|
||||
/* malformed so quit the parsing */
|
||||
break;
|
||||
|
||||
p = ( section_end + 2 );
|
||||
}
|
||||
}
|
||||
while (section_end) ;
|
||||
|
||||
if (doing_shit)
|
||||
list[i].header.buffer[0] = 0;
|
||||
|
@ -626,7 +470,7 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size)
|
|||
char *version;
|
||||
char *version_name;
|
||||
|
||||
hms = HMS_connect("versions/%d", MODID);
|
||||
hms = HMS_connect("games/%s/version", SRB2APPLICATION);
|
||||
|
||||
if (! hms)
|
||||
return 0;
|
||||
|
@ -655,6 +499,19 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size)
|
|||
return ok;
|
||||
}
|
||||
|
||||
static char *
|
||||
Strip_trailing_slashes (char *api)
|
||||
{
|
||||
char * p = &api[strlen(api)];
|
||||
|
||||
while (*--p == '/')
|
||||
;
|
||||
|
||||
p[1] = '\0';
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
void
|
||||
HMS_set_api (char *api)
|
||||
{
|
||||
|
@ -663,7 +520,7 @@ HMS_set_api (char *api)
|
|||
#endif
|
||||
{
|
||||
free(hms_api);
|
||||
hms_api = api;
|
||||
hms_api = Strip_trailing_slashes(api);
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(hms_api_mutex);
|
||||
|
|
516
src/m_menu.c
516
src/m_menu.c
|
@ -182,7 +182,6 @@ static void M_StopMessage(INT32 choice);
|
|||
|
||||
#ifndef NONET
|
||||
static void M_HandleServerPage(INT32 choice);
|
||||
static void M_RoomMenu(INT32 choice);
|
||||
#endif
|
||||
|
||||
// Prototyping is fun, innit?
|
||||
|
@ -190,6 +189,9 @@ static void M_RoomMenu(INT32 choice);
|
|||
// NEEDED FUNCTION PROTOTYPES GO HERE
|
||||
// ==========================================================================
|
||||
|
||||
void M_SetWaitingMode(int mode);
|
||||
int M_GetWaitingMode(void);
|
||||
|
||||
// the haxor message menu
|
||||
menu_t MessageDef;
|
||||
|
||||
|
@ -263,7 +265,6 @@ static void M_ConnectMenu(INT32 choice);
|
|||
static void M_ConnectMenuModChecks(INT32 choice);
|
||||
static void M_Refresh(INT32 choice);
|
||||
static void M_Connect(INT32 choice);
|
||||
static void M_ChooseRoom(INT32 choice);
|
||||
#endif
|
||||
static void M_StartOfflineServerMenu(INT32 choice);
|
||||
static void M_StartServer(INT32 choice);
|
||||
|
@ -372,7 +373,6 @@ static void M_OGL_DrawColorMenu(void);
|
|||
static void M_DrawMPMainMenu(void);
|
||||
#ifndef NONET
|
||||
static void M_DrawConnectMenu(void);
|
||||
static void M_DrawRoomMenu(void);
|
||||
#endif
|
||||
static void M_DrawJoystick(void);
|
||||
static void M_DrawSetupMultiPlayerMenu(void);
|
||||
|
@ -1017,7 +1017,7 @@ static menuitem_t MP_MainMenu[] =
|
|||
static menuitem_t MP_ServerMenu[] =
|
||||
{
|
||||
{IT_STRING|IT_CVAR, NULL, "Max. Player Count", &cv_maxplayers, 10},
|
||||
{IT_STRING|IT_CALL, NULL, "Room...", M_RoomMenu, 20},
|
||||
{IT_STRING|IT_CVAR, NULL, "Advertise", &cv_advertise, 20},
|
||||
{IT_STRING|IT_CVAR|IT_CV_STRING, NULL, "Server Name", &cv_servername, 30},
|
||||
|
||||
{IT_STRING|IT_CVAR, NULL, "Game Type", &cv_newgametype, 68},
|
||||
|
@ -1047,54 +1047,30 @@ static menuitem_t MP_PlayerSetupMenu[] =
|
|||
#ifndef NONET
|
||||
static menuitem_t MP_ConnectMenu[] =
|
||||
{
|
||||
{IT_STRING | IT_CALL, NULL, "Room...", M_RoomMenu, 4},
|
||||
{IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 12},
|
||||
{IT_STRING | IT_KEYHANDLER, NULL, "Page", M_HandleServerPage, 20},
|
||||
{IT_STRING | IT_CALL, NULL, "Refresh", M_Refresh, 28},
|
||||
{IT_STRING | IT_CVAR, NULL, "Sort By", &cv_serversort, 4},
|
||||
{IT_STRING | IT_KEYHANDLER, NULL, "Page", M_HandleServerPage, 12},
|
||||
{IT_STRING | IT_CALL, NULL, "Refresh", M_Refresh, 20},
|
||||
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 48-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 60-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 72-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 84-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 96-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 108-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 120-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 132-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 144-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 156-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 168-4},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 36},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 48},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 60},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 72},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 84},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 96},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 108},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 120},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 132},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 144},
|
||||
{IT_STRING | IT_SPACE, NULL, "", M_Connect, 156},
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
mp_connect_room,
|
||||
mp_connect_sort,
|
||||
mp_connect_page,
|
||||
mp_connect_refresh,
|
||||
FIRSTSERVERLINE
|
||||
};
|
||||
|
||||
menuitem_t MP_RoomMenu[] =
|
||||
{
|
||||
{IT_STRING | IT_CALL, NULL, "<Offline Mode>", M_ChooseRoom, 9},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 18},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 27},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 36},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 45},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 54},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 63},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 72},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 81},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 90},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 99},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 108},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 117},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 126},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 135},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 144},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 153},
|
||||
{IT_DISABLED, NULL, "", M_ChooseRoom, 162},
|
||||
};
|
||||
#endif
|
||||
|
||||
// ------------------------------------
|
||||
|
@ -1992,17 +1968,6 @@ menu_t MP_ConnectDef =
|
|||
0,
|
||||
M_CancelConnect
|
||||
};
|
||||
menu_t MP_RoomDef =
|
||||
{
|
||||
"M_MULTI",
|
||||
sizeof (MP_RoomMenu)/sizeof (menuitem_t),
|
||||
&MP_ConnectDef,
|
||||
MP_RoomMenu,
|
||||
M_DrawRoomMenu,
|
||||
27, 32,
|
||||
0,
|
||||
NULL
|
||||
};
|
||||
#endif
|
||||
menu_t MP_PlayerSetupDef =
|
||||
{
|
||||
|
@ -3392,30 +3357,6 @@ void M_SetupNextMenu(menu_t *menudef)
|
|||
{
|
||||
INT16 i;
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
if (currentMenu == &MP_RoomDef || currentMenu == &MP_ConnectDef)
|
||||
{
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
ms_QueryId++;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
}
|
||||
|
||||
if (currentMenu == &MP_ConnectDef)
|
||||
{
|
||||
I_lock_mutex(&ms_ServerList_mutex);
|
||||
{
|
||||
if (ms_ServerList)
|
||||
{
|
||||
free(ms_ServerList);
|
||||
ms_ServerList = NULL;
|
||||
}
|
||||
}
|
||||
I_unlock_mutex(ms_ServerList_mutex);
|
||||
}
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
||||
if (currentMenu->quitroutine)
|
||||
{
|
||||
// If you're going from a menu to itself, why are you running the quitroutine? You're not quitting it! -SH
|
||||
|
@ -8406,7 +8347,118 @@ static void M_EndGame(INT32 choice)
|
|||
// Connect Menu
|
||||
//===========================================================================
|
||||
|
||||
#define SERVERHEADERHEIGHT 44
|
||||
void
|
||||
M_SetWaitingMode (int mode)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
{
|
||||
m_waiting_mode = mode;
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
M_GetWaitingMode (void)
|
||||
{
|
||||
int mode;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
{
|
||||
mode = m_waiting_mode;
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
|
||||
return mode;
|
||||
}
|
||||
|
||||
#ifdef MASTERSERVER
|
||||
#ifdef HAVE_THREADS
|
||||
static void
|
||||
Spawn_masterserver_thread (const char *name, void (*thread)(int*))
|
||||
{
|
||||
int *id = malloc(sizeof *id);
|
||||
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
*id = ms_QueryId;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
I_spawn_thread(name, (I_thread_fn)thread, id);
|
||||
}
|
||||
|
||||
static int
|
||||
Same_instance (int id)
|
||||
{
|
||||
int okay;
|
||||
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
okay = ( id == ms_QueryId );
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
return okay;
|
||||
}
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
||||
static void
|
||||
Fetch_servers_thread (int *id)
|
||||
{
|
||||
msg_server_t * server_list;
|
||||
|
||||
(void)id;
|
||||
|
||||
M_SetWaitingMode(M_WAITING_SERVERS);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
server_list = GetShortServersList(*id);
|
||||
#else
|
||||
server_list = GetShortServersList(0);
|
||||
#endif
|
||||
|
||||
if (server_list)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
if (Same_instance(*id))
|
||||
#endif
|
||||
{
|
||||
M_SetWaitingMode(M_NOT_WAITING);
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&ms_ServerList_mutex);
|
||||
{
|
||||
ms_ServerList = server_list;
|
||||
}
|
||||
I_unlock_mutex(ms_ServerList_mutex);
|
||||
#else
|
||||
CL_QueryServerList(server_list);
|
||||
free(server_list);
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_THREADS
|
||||
else
|
||||
{
|
||||
free(server_list);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
free(id);
|
||||
#endif
|
||||
}
|
||||
#endif/*MASTERSERVER*/
|
||||
|
||||
#define SERVERHEADERHEIGHT 36
|
||||
#define SERVERLINEHEIGHT 12
|
||||
|
||||
#define S_LINEY(n) currentMenu->y + SERVERHEADERHEIGHT + (n * SERVERLINEHEIGHT)
|
||||
|
@ -8478,77 +8530,18 @@ static void M_Refresh(INT32 choice)
|
|||
if (rendermode == render_soft)
|
||||
I_FinishUpdate(); // page flip or blit buffer
|
||||
|
||||
// note: this is the one case where 0 is a valid room number
|
||||
// because it corresponds to "All"
|
||||
CL_UpdateServerList(!(ms_RoomId < 0), ms_RoomId);
|
||||
|
||||
// first page of servers
|
||||
serverlistpage = 0;
|
||||
}
|
||||
|
||||
static INT32 menuRoomIndex = 0;
|
||||
|
||||
static void M_DrawRoomMenu(void)
|
||||
{
|
||||
static int frame = -12;
|
||||
int dot_frame;
|
||||
char text[4];
|
||||
|
||||
const char *rmotd;
|
||||
const char *waiting_message;
|
||||
|
||||
int dots;
|
||||
|
||||
if (m_waiting_mode)
|
||||
{
|
||||
dot_frame = frame / 4;
|
||||
dots = dot_frame + 3;
|
||||
|
||||
strcpy(text, " ");
|
||||
|
||||
if (dots > 0)
|
||||
{
|
||||
if (dot_frame < 0)
|
||||
dot_frame = 0;
|
||||
|
||||
strncpy(&text[dot_frame], "...", min(dots, 3 - dot_frame));
|
||||
}
|
||||
|
||||
if (++frame == 12)
|
||||
frame = -12;
|
||||
|
||||
currentMenu->menuitems[0].text = text;
|
||||
}
|
||||
|
||||
// use generic drawer for cursor, items and title
|
||||
M_DrawGenericMenu();
|
||||
|
||||
V_DrawString(currentMenu->x - 16, currentMenu->y, highlightflags, M_GetText("Select a room"));
|
||||
|
||||
if (m_waiting_mode == M_NOT_WAITING)
|
||||
{
|
||||
M_DrawTextBox(144, 24, 20, 20);
|
||||
|
||||
if (itemOn == 0)
|
||||
rmotd = M_GetText("Don't connect to the Master Server.");
|
||||
else
|
||||
rmotd = room_list[itemOn-1].motd;
|
||||
|
||||
rmotd = V_WordWrap(0, 20*8, 0, rmotd);
|
||||
V_DrawString(144+8, 32, V_ALLOWLOWERCASE|V_RETURN8, rmotd);
|
||||
}
|
||||
|
||||
if (m_waiting_mode)
|
||||
{
|
||||
// Display a little "please wait" message.
|
||||
M_DrawTextBox(52, BASEVIDHEIGHT/2-10, 25, 3);
|
||||
if (m_waiting_mode == M_WAITING_VERSION)
|
||||
waiting_message = "Checking for updates...";
|
||||
else
|
||||
waiting_message = "Fetching room info...";
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, 0, waiting_message);
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, (BASEVIDHEIGHT/2)+12, 0, "Please wait.");
|
||||
}
|
||||
#ifdef MASTERSERVER
|
||||
#ifdef HAVE_THREADS
|
||||
Spawn_masterserver_thread("fetch-servers", Fetch_servers_thread);
|
||||
#else/*HAVE_THREADS*/
|
||||
Fetch_servers_thread(NULL);
|
||||
#endif/*HAVE_THREADS*/
|
||||
#else/*MASTERSERVER*/
|
||||
CL_UpdateServerList();
|
||||
#endif/*MASTERSERVER*/
|
||||
}
|
||||
|
||||
static void M_DrawConnectMenu(void)
|
||||
|
@ -8557,6 +8550,7 @@ static void M_DrawConnectMenu(void)
|
|||
const char *gt = "Unknown";
|
||||
const char *spd = "";
|
||||
INT32 numPages = (serverlistcount+(SERVERS_PER_PAGE-1))/SERVERS_PER_PAGE;
|
||||
int waiting;
|
||||
|
||||
for (i = FIRSTSERVERLINE; i < min(localservercount, SERVERS_PER_PAGE)+FIRSTSERVERLINE; i++)
|
||||
MP_ConnectMenu[i].status = IT_STRING | IT_SPACE;
|
||||
|
@ -8564,20 +8558,12 @@ static void M_DrawConnectMenu(void)
|
|||
if (!numPages)
|
||||
numPages = 1;
|
||||
|
||||
// Room name
|
||||
if (ms_RoomId < 0)
|
||||
V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ConnectMenu[mp_connect_room].alphaKey,
|
||||
highlightflags, (itemOn == mp_connect_room) ? "<Select to change>" : "<Offline Mode>");
|
||||
else
|
||||
V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ConnectMenu[mp_connect_room].alphaKey,
|
||||
highlightflags, room_list[menuRoomIndex].name);
|
||||
|
||||
// Page num
|
||||
V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ConnectMenu[mp_connect_page].alphaKey,
|
||||
highlightflags, va("%u of %d", serverlistpage+1, numPages));
|
||||
|
||||
// Horizontal line!
|
||||
V_DrawFill(1, currentMenu->y+40, 318, 1, 0);
|
||||
V_DrawFill(1, currentMenu->y+32, 318, 1, 0);
|
||||
|
||||
if (serverlistcount <= 0)
|
||||
V_DrawString(currentMenu->x,currentMenu->y+SERVERHEADERHEIGHT, 0, "No servers found");
|
||||
|
@ -8623,11 +8609,20 @@ static void M_DrawConnectMenu(void)
|
|||
|
||||
M_DrawGenericMenu();
|
||||
|
||||
if (m_waiting_mode)
|
||||
waiting = M_GetWaitingMode();
|
||||
|
||||
if (waiting)
|
||||
{
|
||||
const char *message;
|
||||
|
||||
if (waiting == M_WAITING_VERSION)
|
||||
message = "Checking for updates...";
|
||||
else
|
||||
message = "Searching for servers...";
|
||||
|
||||
// Display a little "please wait" message.
|
||||
M_DrawTextBox(52, BASEVIDHEIGHT/2-10, 25, 3);
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, 0, "Searching for servers...");
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, 0, message);
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, (BASEVIDHEIGHT/2)+12, 0, "Please wait.");
|
||||
}
|
||||
}
|
||||
|
@ -8711,76 +8706,42 @@ void M_SortServerList(void)
|
|||
|
||||
#ifndef NONET
|
||||
#ifdef UPDATE_ALERT
|
||||
static boolean M_CheckMODVersion(int id)
|
||||
static void M_CheckMODVersion(int id)
|
||||
{
|
||||
char updatestring[500];
|
||||
const char *updatecheck = GetMODVersion(id);
|
||||
if(updatecheck)
|
||||
{
|
||||
sprintf(updatestring, UPDATE_ALERT_STRING, VERSIONSTRING, updatecheck);
|
||||
#ifdef HAVE_THREADS
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
#endif
|
||||
M_StartMessage(updatestring, NULL, MM_NOTHING);
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
#ifdef HAVE_THREADS
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif/*UPDATE_ALERT*/
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
#if defined (UPDATE_ALERT) && defined (HAVE_THREADS)
|
||||
static void
|
||||
Check_new_version_thread (int *id)
|
||||
{
|
||||
int hosting;
|
||||
int okay;
|
||||
M_SetWaitingMode(M_WAITING_VERSION);
|
||||
|
||||
okay = 0;
|
||||
M_CheckMODVersion(*id);
|
||||
|
||||
#ifdef UPDATE_ALERT
|
||||
if (M_CheckMODVersion(*id))
|
||||
#endif
|
||||
if (Same_instance(*id))
|
||||
{
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
okay = ( *id == ms_QueryId );
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
if (okay)
|
||||
{
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
{
|
||||
m_waiting_mode = M_WAITING_ROOMS;
|
||||
hosting = ( currentMenu->prevMenu == &MP_ServerDef );
|
||||
}
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
|
||||
GetRoomsList(hosting, *id);
|
||||
}
|
||||
Fetch_servers_thread(id);
|
||||
}
|
||||
else
|
||||
{
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
okay = ( *id == ms_QueryId );
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
free(id);
|
||||
}
|
||||
|
||||
if (okay)
|
||||
{
|
||||
I_lock_mutex(&m_menu_mutex);
|
||||
{
|
||||
if (m_waiting_mode)
|
||||
{
|
||||
m_waiting_mode = M_NOT_WAITING;
|
||||
MP_RoomMenu[0].text = "<Offline Mode>";
|
||||
}
|
||||
}
|
||||
I_unlock_mutex(m_menu_mutex);
|
||||
}
|
||||
|
||||
free(id);
|
||||
}
|
||||
#endif/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/
|
||||
#endif/*defined (UPDATE_ALERT) && defined (HAVE_THREADS)*/
|
||||
|
||||
static void M_ConnectMenu(INT32 choice)
|
||||
{
|
||||
|
@ -8790,16 +8751,37 @@ static void M_ConnectMenu(INT32 choice)
|
|||
|
||||
// first page of servers
|
||||
serverlistpage = 0;
|
||||
if (ms_RoomId < 0)
|
||||
{
|
||||
M_RoomMenu(0); // Select a room instead of staring at an empty list
|
||||
// This prevents us from returning to the modified game alert.
|
||||
currentMenu->prevMenu = &MP_MainDef;
|
||||
}
|
||||
else
|
||||
M_SetupNextMenu(&MP_ConnectDef);
|
||||
M_SetupNextMenu(&MP_ConnectDef);
|
||||
itemOn = 0;
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
ms_QueryId++;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
I_lock_mutex(&ms_ServerList_mutex);
|
||||
{
|
||||
if (ms_ServerList)
|
||||
{
|
||||
free(ms_ServerList);
|
||||
ms_ServerList = NULL;
|
||||
}
|
||||
}
|
||||
I_unlock_mutex(ms_ServerList_mutex);
|
||||
|
||||
#ifdef UPDATE_ALERT
|
||||
Spawn_masterserver_thread("check-new-version", Check_new_version_thread);
|
||||
#else/*UPDATE_ALERT*/
|
||||
Spawn_masterserver_thread("fetch-servers", Fetch_servers_thread);
|
||||
#endif/*UPDATE_ALERT*/
|
||||
#else/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/
|
||||
#ifdef UPDATE_ALERT
|
||||
M_CheckMODVersion(0);
|
||||
#endif/*UPDATE_ALERT*/
|
||||
M_Refresh(0);
|
||||
#endif/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/
|
||||
}
|
||||
|
||||
static void M_ConnectMenuModChecks(INT32 choice)
|
||||
|
@ -8815,96 +8797,6 @@ static void M_ConnectMenuModChecks(INT32 choice)
|
|||
|
||||
M_ConnectMenu(-1);
|
||||
}
|
||||
|
||||
UINT32 roomIds[NUM_LIST_ROOMS];
|
||||
|
||||
static void M_RoomMenu(INT32 choice)
|
||||
{
|
||||
INT32 i;
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
int *id;
|
||||
#endif
|
||||
|
||||
(void)choice;
|
||||
|
||||
// Display a little "please wait" message.
|
||||
M_DrawTextBox(52, BASEVIDHEIGHT/2-10, 25, 3);
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, BASEVIDHEIGHT/2, 0, "Fetching room info...");
|
||||
V_DrawCenteredString(BASEVIDWIDTH/2, (BASEVIDHEIGHT/2)+12, 0, "Please wait.");
|
||||
I_OsPolling();
|
||||
I_UpdateNoBlit();
|
||||
if (rendermode == render_soft)
|
||||
I_FinishUpdate(); // page flip or blit buffer
|
||||
|
||||
for (i = 1; i < NUM_LIST_ROOMS+1; ++i)
|
||||
MP_RoomMenu[i].status = IT_DISABLED;
|
||||
memset(roomIds, 0, sizeof(roomIds));
|
||||
|
||||
MP_RoomDef.prevMenu = currentMenu;
|
||||
M_SetupNextMenu(&MP_RoomDef);
|
||||
|
||||
#ifdef MASTERSERVER
|
||||
#ifdef HAVE_THREADS
|
||||
#ifdef UPDATE_ALERT
|
||||
m_waiting_mode = M_WAITING_VERSION;
|
||||
#else/*UPDATE_ALERT*/
|
||||
m_waiting_mode = M_WAITING_ROOMS;
|
||||
#endif/*UPDATE_ALERT*/
|
||||
|
||||
MP_RoomMenu[0].text = "";
|
||||
|
||||
id = malloc(sizeof *id);
|
||||
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
*id = ms_QueryId;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
|
||||
I_spawn_thread("check-new-version",
|
||||
(I_thread_fn)Check_new_version_thread, id);
|
||||
#else/*HAVE_THREADS*/
|
||||
#ifdef UPDATE_ALERT
|
||||
if (M_CheckMODVersion(0))
|
||||
#endif/*UPDATE_ALERT*/
|
||||
{
|
||||
GetRoomsList(currentMenu->prevMenu == &MP_ServerDef, 0);
|
||||
}
|
||||
#endif/*HAVE_THREADS*/
|
||||
#endif/*MASTERSERVER*/
|
||||
}
|
||||
|
||||
static void M_ChooseRoom(INT32 choice)
|
||||
{
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
I_lock_mutex(&ms_QueryId_mutex);
|
||||
{
|
||||
ms_QueryId++;
|
||||
}
|
||||
I_unlock_mutex(ms_QueryId_mutex);
|
||||
#endif
|
||||
|
||||
if (choice == 0)
|
||||
ms_RoomId = -1;
|
||||
else
|
||||
{
|
||||
ms_RoomId = roomIds[choice-1];
|
||||
menuRoomIndex = choice - 1;
|
||||
}
|
||||
|
||||
serverlistpage = 0;
|
||||
/*
|
||||
We were on the Multiplayer menu? That means that we must have been trying to
|
||||
view the server browser, but we hadn't selected a room yet. So we need to go
|
||||
to the browser next, not back there.
|
||||
*/
|
||||
if (currentMenu->prevMenu == &MP_MainDef)
|
||||
M_SetupNextMenu(&MP_ConnectDef);
|
||||
else
|
||||
M_SetupNextMenu(currentMenu->prevMenu);
|
||||
if (currentMenu == &MP_ConnectDef)
|
||||
M_Refresh(0);
|
||||
}
|
||||
#endif //NONET
|
||||
|
||||
//===========================================================================
|
||||
|
@ -9120,21 +9012,6 @@ static void M_DrawServerMenu(void)
|
|||
{
|
||||
M_DrawLevelSelectOnly(false, false);
|
||||
M_DrawGenericMenu();
|
||||
|
||||
#ifndef NONET
|
||||
// Room name
|
||||
if (currentMenu == &MP_ServerDef)
|
||||
{
|
||||
#define mp_server_room 1
|
||||
if (ms_RoomId < 0)
|
||||
V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ServerMenu[mp_server_room].alphaKey,
|
||||
highlightflags, (itemOn == mp_server_room) ? "<Select to change>" : "<LAN Mode>");
|
||||
else
|
||||
V_DrawRightAlignedString(BASEVIDWIDTH - currentMenu->x, currentMenu->y + MP_ServerMenu[mp_server_room].alphaKey,
|
||||
highlightflags, room_list[menuRoomIndex].name);
|
||||
#undef mp_server_room
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void M_MapChange(INT32 choice)
|
||||
|
@ -9164,7 +9041,6 @@ static void M_StartServerMenu(INT32 choice)
|
|||
(void)choice;
|
||||
levellistmode = LLM_CREATESERVER;
|
||||
M_PrepareLevelSelect();
|
||||
ms_RoomId = -1;
|
||||
M_SetupNextMenu(&MP_ServerDef);
|
||||
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ typedef enum
|
|||
M_NOT_WAITING,
|
||||
|
||||
M_WAITING_VERSION,
|
||||
M_WAITING_ROOMS,
|
||||
M_WAITING_SERVERS,
|
||||
}
|
||||
M_waiting_mode_t;
|
||||
|
@ -175,9 +174,6 @@ typedef struct menuitem_s
|
|||
|
||||
extern menuitem_t PlayerMenu[MAXSKINS];
|
||||
|
||||
extern menuitem_t MP_RoomMenu[];
|
||||
extern UINT32 roomIds[NUM_LIST_ROOMS];
|
||||
|
||||
typedef struct menu_s
|
||||
{
|
||||
const char *menutitlepic;
|
||||
|
|
78
src/mserv.c
78
src/mserv.c
|
@ -59,18 +59,21 @@ static void Update_parameters (void);
|
|||
|
||||
static void MasterServer_OnChange(void);
|
||||
|
||||
static void Advertise_OnChange(void);
|
||||
|
||||
static CV_PossibleValue_t masterserver_update_rate_cons_t[] = {
|
||||
{2, "MIN"},
|
||||
{60, "MAX"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
consvar_t cv_masterserver = {"masterserver", "https://mb.srb2.org/MS/0", CV_SAVE|CV_CALL, NULL, MasterServer_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_masterserver = {"masterserver", "https://ms.kartkrew.org/ms/api", CV_SAVE|CV_CALL, NULL, MasterServer_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_servername = {"servername", "SRB2Kart server", CV_SAVE|CV_CALL|CV_NOINIT, NULL, Update_parameters, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_server_contact = {"server_contact", "", CV_SAVE|CV_CALL|CV_NOINIT, NULL, Update_parameters, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
consvar_t cv_masterserver_update_rate = {"masterserver_update_rate", "15", CV_SAVE|CV_CALL|CV_NOINIT, masterserver_update_rate_cons_t, Update_parameters, 0, NULL, NULL, 0, 0, NULL};
|
||||
consvar_t cv_masterserver_update_rate = {"masterserver_update_rate", "15", CV_SAVE|CV_CALL|CV_NOINIT, masterserver_update_rate_cons_t, MasterClient_Ticker, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
INT16 ms_RoomId = -1;
|
||||
consvar_t cv_advertise = {"advertise", "Yes", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, Advertise_OnChange, 0, NULL, NULL, 0, 0, NULL};
|
||||
|
||||
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
|
||||
int ms_QueryId;
|
||||
|
@ -82,10 +85,6 @@ I_mutex ms_ServerList_mutex;
|
|||
|
||||
UINT16 current_port = 0;
|
||||
|
||||
// Room list is an external variable now.
|
||||
// Avoiding having to get info ten thousand times...
|
||||
msg_rooms_t room_list[NUM_LIST_ROOMS+1]; // +1 for easy test
|
||||
|
||||
/** Adds variables and commands relating to the master server.
|
||||
*
|
||||
* \sa cv_masterserver, cv_servername,
|
||||
|
@ -99,7 +98,9 @@ void AddMServCommands(void)
|
|||
CV_RegisterVar(&cv_masterserver_timeout);
|
||||
CV_RegisterVar(&cv_masterserver_debug);
|
||||
CV_RegisterVar(&cv_masterserver_token);
|
||||
CV_RegisterVar(&cv_advertise);
|
||||
CV_RegisterVar(&cv_servername);
|
||||
CV_RegisterVar(&cv_server_contact);
|
||||
#ifdef MASTERSERVER
|
||||
COM_AddCommand("listserv", Command_Listserv_f);
|
||||
#endif
|
||||
|
@ -120,14 +121,14 @@ static void WarnGUI (void)
|
|||
}
|
||||
|
||||
#define NUM_LIST_SERVER MAXSERVERLIST
|
||||
msg_server_t *GetShortServersList(INT32 room, int id)
|
||||
msg_server_t *GetShortServersList(int id)
|
||||
{
|
||||
msg_server_t *server_list;
|
||||
|
||||
// +1 for easy test
|
||||
server_list = malloc(( NUM_LIST_SERVER + 1 ) * sizeof *server_list);
|
||||
|
||||
if (HMS_fetch_servers(server_list, room, id))
|
||||
if (HMS_fetch_servers(server_list, id))
|
||||
return server_list;
|
||||
else
|
||||
{
|
||||
|
@ -137,17 +138,6 @@ msg_server_t *GetShortServersList(INT32 room, int id)
|
|||
}
|
||||
}
|
||||
|
||||
INT32 GetRoomsList(boolean hosting, int id)
|
||||
{
|
||||
if (HMS_fetch_rooms( ! hosting, id))
|
||||
return 1;
|
||||
else
|
||||
{
|
||||
WarnGUI();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef UPDATE_ALERT
|
||||
char *GetMODVersion(int id)
|
||||
{
|
||||
|
@ -181,15 +171,6 @@ char *GetMODVersion(int id)
|
|||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Console only version of the above (used before game init)
|
||||
void GetMODVersion_Console(void)
|
||||
{
|
||||
char buffer[16];
|
||||
|
||||
if (HMS_compare_mod_version(buffer, sizeof buffer) > 0)
|
||||
I_Error(UPDATE_ALERT_STRING_CONSOLE, VERSIONSTRING, buffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef NONET
|
||||
|
@ -284,6 +265,9 @@ Finish_unlist (void)
|
|||
Lock_state();
|
||||
{
|
||||
registered = MSRegistered;
|
||||
|
||||
if (MSId == MSRegisteredId)
|
||||
MSId++;
|
||||
}
|
||||
Unlock_state();
|
||||
|
||||
|
@ -305,13 +289,6 @@ Finish_unlist (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
Lock_state();
|
||||
{
|
||||
if (MSId == MSRegisteredId)
|
||||
MSId++;
|
||||
}
|
||||
Unlock_state();
|
||||
|
||||
#ifdef HAVE_DISCORDRPC
|
||||
DRPC_UpdatePresence();
|
||||
#endif
|
||||
|
@ -460,7 +437,7 @@ void UnregisterServer(void)
|
|||
static boolean
|
||||
Online (void)
|
||||
{
|
||||
return ( serverrunning && ms_RoomId > 0 );
|
||||
return ( serverrunning && cv_advertise.value );
|
||||
}
|
||||
|
||||
static inline void SendPingToMasterServer(void)
|
||||
|
@ -561,3 +538,30 @@ static void MasterServer_OnChange(void)
|
|||
RegisterServer();
|
||||
#endif/*MASTERSERVER*/
|
||||
}
|
||||
|
||||
static void
|
||||
Advertise_OnChange(void)
|
||||
{
|
||||
int different;
|
||||
|
||||
if (cv_advertise.value)
|
||||
{
|
||||
if (serverrunning)
|
||||
{
|
||||
Lock_state();
|
||||
{
|
||||
different = ( MSId != MSRegisteredId );
|
||||
}
|
||||
Unlock_state();
|
||||
|
||||
if (different)
|
||||
{
|
||||
RegisterServer();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UnregisterServer();
|
||||
}
|
||||
}
|
||||
|
|
28
src/mserv.h
28
src/mserv.h
|
@ -16,9 +16,6 @@
|
|||
|
||||
#include "i_threads.h"
|
||||
|
||||
// lowered from 32 due to menu changes
|
||||
#define NUM_LIST_ROOMS 16
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(1)
|
||||
#endif
|
||||
|
@ -35,19 +32,10 @@ typedef struct
|
|||
msg_header_t header;
|
||||
char ip[16];
|
||||
char port[8];
|
||||
char name[32];
|
||||
INT32 room;
|
||||
char contact[32];
|
||||
char version[8]; // format is: x.yy.z (like 1.30.2 or 1.31)
|
||||
} ATTRPACK msg_server_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
msg_header_t header;
|
||||
INT32 id;
|
||||
char name[32];
|
||||
char motd[255];
|
||||
} ATTRPACK msg_rooms_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
msg_header_t header;
|
||||
|
@ -65,15 +53,13 @@ typedef struct
|
|||
// ================================ GLOBALS ===============================
|
||||
|
||||
extern consvar_t cv_masterserver, cv_servername;
|
||||
extern consvar_t cv_server_contact;
|
||||
extern consvar_t cv_masterserver_update_rate;
|
||||
extern consvar_t cv_masterserver_timeout;
|
||||
extern consvar_t cv_masterserver_debug;
|
||||
extern consvar_t cv_masterserver_token;
|
||||
|
||||
// < 0 to not connect (usually -1) (offline mode)
|
||||
// == 0 to show all rooms, not a valid hosting room
|
||||
// anything else is whatever room the MS assigns to that number (online mode)
|
||||
extern INT16 ms_RoomId;
|
||||
extern consvar_t cv_advertise;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
extern int ms_QueryId;
|
||||
|
@ -88,24 +74,20 @@ void UnregisterServer(void);
|
|||
|
||||
void MasterClient_Ticker(void);
|
||||
|
||||
msg_server_t *GetShortServersList(INT32 room, int id);
|
||||
INT32 GetRoomsList(boolean hosting, int id);
|
||||
msg_server_t *GetShortServersList(int id);
|
||||
#ifdef UPDATE_ALERT
|
||||
char *GetMODVersion(int id);
|
||||
void GetMODVersion_Console(void);
|
||||
#endif
|
||||
extern msg_rooms_t room_list[NUM_LIST_ROOMS+1];
|
||||
|
||||
void AddMServCommands(void);
|
||||
|
||||
/* HTTP */
|
||||
void HMS_set_api (char *api);
|
||||
int HMS_fetch_rooms (int joining, int id);
|
||||
int HMS_register (void);
|
||||
int HMS_unlist (void);
|
||||
int HMS_update (void);
|
||||
void HMS_list_servers (void);
|
||||
msg_server_t * HMS_fetch_servers (msg_server_t *list, int room, int id);
|
||||
msg_server_t * HMS_fetch_servers (msg_server_t *list, int id);
|
||||
int HMS_compare_mod_version (char *buffer, size_t size_of_buffer);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue