From 7a05a8acf73ac0f012135339447c9a935e3b7939 Mon Sep 17 00:00:00 2001 From: James R Date: Sun, 16 Aug 2020 21:42:58 -0700 Subject: [PATCH] Do not do master server things when NOCURL --- src/d_clisrv.c | 21 ++++++++++++---- src/doomdef.h | 6 +++++ src/http-mserv.c | 8 ++++++ src/m_menu.c | 27 +++++++++++++------- src/mserv.c | 65 ++++++++++++++++++++++++++++++++---------------- 5 files changed, 91 insertions(+), 36 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index c4df72f5..9e399ce7 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1824,7 +1824,7 @@ static void SL_InsertServer(serverinfo_pak* info, SINT8 node) M_SortServerList(); } -#ifdef HAVE_THREADS +#if defined (MASTERSERVER) && defined (HAVE_THREADS) struct Fetch_servers_ctx { int room; @@ -1869,7 +1869,7 @@ Fetch_servers_thread (struct Fetch_servers_ctx *ctx) free(ctx); } -#endif/*HAVE_THREADS*/ +#endif/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/ void CL_QueryServerList (msg_server_t *server_list) { @@ -1906,9 +1906,8 @@ void CL_QueryServerList (msg_server_t *server_list) void CL_UpdateServerList(boolean internetsearch, INT32 room) { -#ifdef HAVE_THREADS - struct Fetch_servers_ctx *ctx; -#endif + (void)internetsearch; + (void)room; SL_ClearServerList(0); @@ -1925,9 +1924,12 @@ void CL_UpdateServerList(boolean internetsearch, INT32 room) 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 */ @@ -1954,6 +1956,7 @@ void CL_UpdateServerList(boolean internetsearch, INT32 room) } #endif } +#endif/*MASTERSERVER*/ } #endif // ifndef NONET @@ -3427,8 +3430,10 @@ void D_QuitNetGame(void) for (i = 0; i < MAXNETNODES; i++) if (nodeingame[i]) HSendPacket(i, true, 0, 0); +#ifdef MASTERSERVER if (serverrunning && ms_RoomId > 0) UnregisterServer(); +#endif } else if (servernode > 0 && servernode < MAXNETNODES && nodeingame[(UINT8)servernode]) { @@ -3676,8 +3681,10 @@ boolean SV_SpawnServer(void) if (netgame && I_NetOpenSocket) { I_NetOpenSocket(); +#ifdef MASTERSERVER if (ms_RoomId > 0) RegisterServer(); +#endif } // non dedicated server just connect to itself @@ -5395,7 +5402,9 @@ FILESTAMP GetPackets(); FILESTAMP +#ifdef MASTERSERVER MasterClient_Ticker(); +#endif if (client) { @@ -5452,7 +5461,9 @@ FILESTAMP // client send the command after a receive of the server // the server send before because in single player is beter +#ifdef MASTERSERVER MasterClient_Ticker(); // Acking the Master Server +#endif if (client) { diff --git a/src/doomdef.h b/src/doomdef.h index 9ee55d94..f8eade65 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -681,4 +681,10 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Hardware renderer: OpenGL #define GL_SHADERS +#ifdef HAVE_CURL +#define MASTERSERVER +#else +#undef UPDATE_ALERT +#endif + #endif // __DOOMDEF__ diff --git a/src/http-mserv.c b/src/http-mserv.c index 9d05b80e..13c7b43d 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -14,7 +14,9 @@ Documentation available here. */ +#ifdef HAVE_CURL #include +#endif #include "doomdef.h" #include "d_clisrv.h" @@ -49,6 +51,8 @@ consvar_t cv_masterserver_token = { NULL, 0, NULL, NULL, 0, 0, NULL/* C90 moment */ }; +#ifdef MASTERSERVER + static int hms_started; static char *hms_api; @@ -666,10 +670,14 @@ HMS_set_api (char *api) #endif } +#endif/*MASTERSERVER*/ + static void MasterServer_Debug_OnChange (void) { +#ifdef MASTERSERVER /* TODO: change to 'latest-log.txt' for log files revision. */ if (cv_masterserver_debug.value) CONS_Printf("Master server debug messages will appear in log.txt\n"); +#endif } diff --git a/src/m_menu.c b/src/m_menu.c index 850b8d74..3bdb78d3 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3310,7 +3310,7 @@ void M_SetupNextMenu(menu_t *menudef) { INT16 i; -#ifdef HAVE_THREADS +#if defined (MASTERSERVER) && defined (HAVE_THREADS) if (currentMenu == &MP_RoomDef || currentMenu == &MP_ConnectDef) { I_lock_mutex(&ms_QueryId_mutex); @@ -3392,7 +3392,7 @@ void M_Ticker(void) setmodeneeded = vidm_previousmode + 1; } -#ifdef HAVE_THREADS +#if defined (MASTERSERVER) && defined (HAVE_THREADS) I_lock_mutex(&ms_ServerList_mutex); { if (ms_ServerList) @@ -8603,8 +8603,9 @@ static boolean M_CheckMODVersion(int id) } else return true; } +#endif/*UPDATE_ALERT*/ -#ifdef HAVE_THREADS +#if defined (MASTERSERVER) && defined (HAVE_THREADS) static void Check_new_version_thread (int *id) { @@ -8613,7 +8614,9 @@ Check_new_version_thread (int *id) okay = 0; +#ifdef UPDATE_ALERT if (M_CheckMODVersion(*id)) +#endif { I_lock_mutex(&ms_QueryId_mutex); { @@ -8657,8 +8660,7 @@ Check_new_version_thread (int *id) free(id); } -#endif/*HAVE_THREADS*/ -#endif/*UPDATE_ALERT*/ +#endif/*defined (MASTERSERVER) && defined (HAVE_THREADS)*/ static void M_ConnectMenu(INT32 choice) { @@ -8699,7 +8701,7 @@ UINT32 roomIds[NUM_LIST_ROOMS]; static void M_RoomMenu(INT32 choice) { INT32 i; -#ifdef HAVE_THREADS +#if defined (MASTERSERVER) && defined (HAVE_THREADS) int *id; #endif @@ -8721,9 +8723,14 @@ static void M_RoomMenu(INT32 choice) MP_RoomDef.prevMenu = currentMenu; M_SetupNextMenu(&MP_RoomDef); -#ifdef UPDATE_ALERT +#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); @@ -8737,17 +8744,19 @@ static void M_RoomMenu(INT32 choice) 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/*UPDATE_ALERT*/ +#endif/*MASTERSERVER*/ } static void M_ChooseRoom(INT32 choice) { -#ifdef HAVE_THREADS +#if defined (MASTERSERVER) && defined (HAVE_THREADS) I_lock_mutex(&ms_QueryId_mutex); { ms_QueryId++; diff --git a/src/mserv.c b/src/mserv.c index f3d414c9..4c044fed 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -23,6 +23,8 @@ #include "m_menu.h" #include "z_zone.h" +#ifdef MASTERSERVER + static int MSId; static int MSRegisteredId = -1; @@ -43,11 +45,14 @@ static I_cond MSCond; # define Unlock_state() #endif/*HAVE_THREADS*/ -static void Update_parameters (void); - #ifndef NONET static void Command_Listserv_f(void); #endif + +#endif/*MASTERSERVER*/ + +static void Update_parameters (void); + static void MasterServer_OnChange(void); static CV_PossibleValue_t masterserver_update_rate_cons_t[] = { @@ -63,7 +68,7 @@ consvar_t cv_masterserver_update_rate = {"masterserver_update_rate", "15", CV_SA INT16 ms_RoomId = -1; -#ifdef HAVE_THREADS +#if defined (MASTERSERVER) && defined (HAVE_THREADS) int ms_QueryId; I_mutex ms_QueryId_mutex; @@ -91,10 +96,14 @@ void AddMServCommands(void) CV_RegisterVar(&cv_masterserver_debug); CV_RegisterVar(&cv_masterserver_token); CV_RegisterVar(&cv_servername); +#ifdef MASTERSERVER COM_AddCommand("listserv", Command_Listserv_f); #endif +#endif } +#ifdef MASTERSERVER + static void WarnGUI (void) { #ifdef HAVE_THREADS @@ -395,6 +404,7 @@ Change_masterserver_thread (char *api) void RegisterServer(void) { +#ifdef MASTERSERVER #ifdef HAVE_THREADS I_spawn_thread( "register-server", @@ -404,6 +414,7 @@ void RegisterServer(void) #else Finish_registration(); #endif +#endif/*MASTERSERVER*/ } static void UpdateServer(void) @@ -421,6 +432,7 @@ static void UpdateServer(void) void UnregisterServer(void) { +#ifdef MASTERSERVER #ifdef HAVE_THREADS I_spawn_thread( "unlist-server", @@ -430,6 +442,7 @@ void UnregisterServer(void) #else Finish_unlist(); #endif +#endif/*MASTERSERVER*/ } static boolean @@ -465,9 +478,33 @@ static inline void SendPingToMasterServer(void) } } +void MasterClient_Ticker(void) +{ +#ifdef MASTERSERVER + SendPingToMasterServer(); +#endif +} + +static void +Set_api (const char *api) +{ +#ifdef HAVE_THREADS + I_spawn_thread( + "change-masterserver", + (I_thread_fn)Change_masterserver_thread, + strdup(api) + ); +#else + HMS_set_api(strdup(api)); +#endif +} + +#endif/*MASTERSERVER*/ + static void Update_parameters (void) { +#ifdef MASTERSERVER int registered; int delayed; @@ -487,29 +524,12 @@ Update_parameters (void) if (! delayed && registered) UpdateServer(); } -} - -void MasterClient_Ticker(void) -{ - SendPingToMasterServer(); -} - -static void -Set_api (const char *api) -{ -#ifdef HAVE_THREADS - I_spawn_thread( - "change-masterserver", - (I_thread_fn)Change_masterserver_thread, - strdup(api) - ); -#else - HMS_set_api(strdup(api)); -#endif +#endif/*MASTERSERVER*/ } static void MasterServer_OnChange(void) { +#ifdef MASTERSERVER UnregisterServer(); /* @@ -527,4 +547,5 @@ static void MasterServer_OnChange(void) if (Online()) RegisterServer(); +#endif/*MASTERSERVER*/ }