Skip to content
Snippets Groups Projects
Commit f9ec2a63 authored by James R.'s avatar James R.
Browse files

Fix switching the master server

parent 47bc3bff
No related branches found
No related tags found
No related merge requests found
...@@ -502,6 +502,7 @@ typedef enum ...@@ -502,6 +502,7 @@ typedef enum
} kickreason_t; } kickreason_t;
extern boolean server; extern boolean server;
extern boolean serverrunning;
#define client (!server) #define client (!server)
extern boolean dedicated; // For dedicated server extern boolean dedicated; // For dedicated server
extern UINT16 software_MAXPACKETLENGTH; extern UINT16 software_MAXPACKETLENGTH;
......
...@@ -22,6 +22,7 @@ Documentation available here. ...@@ -22,6 +22,7 @@ Documentation available here.
#include "m_menu.h" #include "m_menu.h"
#include "mserv.h" #include "mserv.h"
#include "i_tcp.h"/* for current_port */ #include "i_tcp.h"/* for current_port */
#include "i_threads.h"
/* I just stop myself from making macros anymore. */ /* I just stop myself from making macros anymore. */
#define Blame( ... ) \ #define Blame( ... ) \
...@@ -34,6 +35,11 @@ consvar_t cv_masterserver_debug = { ...@@ -34,6 +35,11 @@ consvar_t cv_masterserver_debug = {
static int hms_started; static int hms_started;
static char *hms_api;
#ifdef HAVE_THREADS
static I_mutex hms_api_mutex;
#endif
static char *hms_server_token; static char *hms_server_token;
struct HMS_buffer struct HMS_buffer
...@@ -101,13 +107,21 @@ HMS_connect (const char *format, ...) ...@@ -101,13 +107,21 @@ HMS_connect (const char *format, ...)
return NULL; return NULL;
} }
seek = strlen(ms_API) + 1;/* + '/' */ #ifdef HAVE_THREADS
I_lock_mutex(&hms_api_mutex);
#endif
seek = strlen(hms_api) + 1;/* + '/' */
va_start (ap, format); va_start (ap, format);
url = malloc(seek + vsnprintf(0, 0, format, ap) + 1); url = malloc(seek + vsnprintf(0, 0, format, ap) + 1);
va_end (ap); va_end (ap);
sprintf(url, "%s/", ms_API); sprintf(url, "%s/", hms_api);
#ifdef HAVE_THREADS
I_unlock_mutex(hms_api_mutex);
#endif
va_start (ap, format); va_start (ap, format);
vsprintf(&url[seek], format, ap); vsprintf(&url[seek], format, ap);
...@@ -590,3 +604,18 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size) ...@@ -590,3 +604,18 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size)
return ok; return ok;
} }
void
HMS_set_api (char *api)
{
#ifdef HAVE_THREADS
I_lock_mutex(&hms_api_mutex);
#endif
{
free(hms_api);
hms_api = api;
}
#ifdef HAVE_THREADS
I_unlock_mutex(hms_api_mutex);
#endif
}
...@@ -61,7 +61,6 @@ consvar_t cv_servername = {"servername", "SRB2Kart server", CV_SAVE|CV_CALL|CV_N ...@@ -61,7 +61,6 @@ consvar_t cv_servername = {"servername", "SRB2Kart server", CV_SAVE|CV_CALL|CV_N
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, Update_parameters, 0, NULL, NULL, 0, 0, NULL};
char *ms_API;
INT16 ms_RoomId = -1; INT16 ms_RoomId = -1;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
...@@ -377,6 +376,19 @@ Unlist_server_thread (int *id) ...@@ -377,6 +376,19 @@ Unlist_server_thread (int *id)
free(id); free(id);
} }
static void
Change_masterserver_thread (char *api)
{
Lock_state();
{
while (MSRegistered)
I_hold_cond(&MSCond, MSMutex);
}
Unlock_state();
HMS_set_api(api);
}
#endif/*HAVE_THREADS*/ #endif/*HAVE_THREADS*/
void RegisterServer(void) void RegisterServer(void)
...@@ -421,7 +433,7 @@ void UnregisterServer(void) ...@@ -421,7 +433,7 @@ void UnregisterServer(void)
static boolean static boolean
Online (void) Online (void)
{ {
return ( server && ms_RoomId > 0 ); return ( serverrunning && ms_RoomId > 0 );
} }
static inline void SendPingToMasterServer(void) static inline void SendPingToMasterServer(void)
...@@ -480,21 +492,26 @@ void MasterClient_Ticker(void) ...@@ -480,21 +492,26 @@ void MasterClient_Ticker(void)
SendPingToMasterServer(); SendPingToMasterServer();
} }
static void MasterServer_OnChange(void) static void
Set_api (const char *api)
{ {
boolean auto_register; #ifdef HAVE_THREADS
I_spawn_thread(
//auto_register = ( con_state != MSCS_NONE ); "change-masterserver",
auto_register = false; (I_thread_fn)Change_masterserver_thread,
strdup(api)
);
#else
HMS_set_api(strdup(api));
#endif
}
if (ms_API) static void MasterServer_OnChange(void)
{ {
UnregisterServer(); UnregisterServer();
Z_Free(ms_API);
}
ms_API = Z_StrDup(cv_masterserver.string); Set_api(cv_masterserver.string);
if (auto_register) if (Online())
RegisterServer(); RegisterServer();
} }
...@@ -70,8 +70,6 @@ extern consvar_t cv_masterserver, cv_servername; ...@@ -70,8 +70,6 @@ extern consvar_t cv_masterserver, cv_servername;
extern consvar_t cv_masterserver_update_rate; extern consvar_t cv_masterserver_update_rate;
extern consvar_t cv_masterserver_debug; extern consvar_t cv_masterserver_debug;
extern char *ms_API;
// < 0 to not connect (usually -1) (offline mode) // < 0 to not connect (usually -1) (offline mode)
// == 0 to show all rooms, not a valid hosting room // == 0 to show all rooms, not a valid hosting room
// anything else is whatever room the MS assigns to that number (online mode) // anything else is whatever room the MS assigns to that number (online mode)
...@@ -101,7 +99,7 @@ extern msg_rooms_t room_list[NUM_LIST_ROOMS+1]; ...@@ -101,7 +99,7 @@ extern msg_rooms_t room_list[NUM_LIST_ROOMS+1];
void AddMServCommands(void); void AddMServCommands(void);
/* HTTP */ /* HTTP */
int HMS_in_use (void); void HMS_set_api (char *api);
int HMS_fetch_rooms (int joining, int id); int HMS_fetch_rooms (int joining, int id);
int HMS_register (void); int HMS_register (void);
int HMS_unlist (void); int HMS_unlist (void);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment