From a95907cb8cf3a9a39031ef0d2b03f84dbf845eea Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 2 Jul 2022 22:20:52 -0700 Subject: [PATCH] Print and display rules from the master server Update HMS version to 2.2. Fetch the rules when master server cvar set. Print rules in console when server register. Display the rules in the menu when entering the server hosting menu or when changing the advertise cvar. --- src/http-mserv.c | 35 ++++++++++++++++++++++++++++++++--- src/m_menu.c | 16 +++++++++++++++- src/m_menu.h | 2 ++ src/mserv.c | 42 ++++++++++++++++++++++++++++++++++++++++-- src/mserv.h | 3 +++ 5 files changed, 92 insertions(+), 6 deletions(-) diff --git a/src/http-mserv.c b/src/http-mserv.c index c149eb9b..e925c50d 100644 --- a/src/http-mserv.c +++ b/src/http-mserv.c @@ -11,7 +11,7 @@ /* Documentation available here. - + */ #ifdef HAVE_CURL @@ -171,8 +171,8 @@ HMS_connect (const char *format, ...) seek += vsprintf(&url[seek], format, ap); va_end (ap); - strcpy(&url[seek], "?v=2"); - seek += sizeof "?v=2" - 1; + strcpy(&url[seek], "?v=2.2"); + seek += sizeof "?v=2.2" - 1; if (quack_token) sprintf(&url[seek], "&token=%s", quack_token); @@ -499,6 +499,35 @@ HMS_compare_mod_version (char *buffer, size_t buffer_size) return ok; } +const char * +HMS_fetch_rules (char *buffer, size_t buffer_size) +{ + struct HMS_buffer *hms; + + hms = HMS_connect("rules"); + + if (! hms) + return NULL; + + if (HMS_do(hms)) + { + char *p = strstr(hms->buffer, "\n\n"); + + if (p) + { + p[1] = '\0'; + + strlcpy(buffer, hms->buffer, buffer_size); + } + else + buffer = NULL; + } + + HMS_end(hms); + + return buffer; +} + static char * Strip_trailing_slashes (char *api) { diff --git a/src/m_menu.c b/src/m_menu.c index 09d0f393..e9c53802 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6330,6 +6330,20 @@ void M_RefreshPauseMenu(void) #endif } +void M_PopupMasterServerRules(void) +{ +#ifdef MASTERSERVER + if (cv_advertise.value && (serverrunning || currentMenu == &MP_ServerDef)) + { + char *rules = GetMasterServerRules(); + + M_StartMessage(va("%s\n(press any key)", rules), NULL, MM_NOTHING); + + Z_Free(rules); + } +#endif +} + // ====== // CHEATS // ====== @@ -9136,7 +9150,7 @@ static void M_StartServerMenu(INT32 choice) levellistmode = LLM_CREATESERVER; M_PrepareLevelSelect(); M_SetupNextMenu(&MP_ServerDef); - + M_PopupMasterServerRules(); } // ============== diff --git a/src/m_menu.h b/src/m_menu.h index 28fdd44e..986a0ba6 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -267,6 +267,8 @@ void M_RefreshPauseMenu(void); INT32 HU_GetHighlightColor(void); +void M_PopupMasterServerRules(void); + // These defines make it a little easier to make menus #define DEFAULTMENUSTYLE(header, source, prev, x, y)\ {\ diff --git a/src/mserv.c b/src/mserv.c index 33128c76..5121a0b6 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -38,6 +38,8 @@ static boolean MSUpdateAgain; static time_t MSLastPing; +static char *MSRules; + #ifdef HAVE_THREADS static I_mutex MSMutex; static I_cond MSCond; @@ -193,9 +195,16 @@ static void Finish_registration (void) { int registered; + char *rules = GetMasterServerRules(); CONS_Printf("Registering this server on the master server...\n"); + if (rules) + { + CONS_Printf("\n"); + CONS_Alert(CONS_NOTICE, "%s\n", rules); + } + registered = HMS_register(); Lock_state(); @@ -289,6 +298,22 @@ Finish_unlist (void) } } +static void +Finish_masterserver_change (char *api) +{ + char rules[256]; + + HMS_set_api(api); + + if (HMS_fetch_rules(rules, sizeof rules)) + { + Lock_state(); + Z_Free(MSRules); + MSRules = Z_StrDup(rules); + Unlock_state(); + } +} + #ifdef HAVE_THREADS static int * Server_id (void) @@ -382,7 +407,7 @@ Change_masterserver_thread (char *api) } Unlock_state(); - HMS_set_api(api); + Finish_masterserver_change(api); } #endif/*HAVE_THREADS*/ @@ -429,6 +454,17 @@ void UnregisterServer(void) #endif/*MASTERSERVER*/ } +char *GetMasterServerRules(void) +{ + char *rules; + + Lock_state(); + rules = MSRules ? Z_StrDup(MSRules) : NULL; + Unlock_state(); + + return rules; +} + static boolean Online (void) { @@ -479,7 +515,7 @@ Set_api (const char *api) strdup(api) ); #else - HMS_set_api(strdup(api)); + Finish_masterserver_change(strdup(api)); #endif } @@ -563,4 +599,6 @@ Advertise_OnChange(void) #ifdef HAVE_DISCORDRPC DRPC_UpdatePresence(); #endif + + M_PopupMasterServerRules(); } diff --git a/src/mserv.h b/src/mserv.h index ef401aba..61e414f2 100644 --- a/src/mserv.h +++ b/src/mserv.h @@ -81,6 +81,8 @@ msg_server_t *GetShortServersList(int id); char *GetMODVersion(int id); #endif +char *GetMasterServerRules(void); + void AddMServCommands(void); /* HTTP */ @@ -91,5 +93,6 @@ int HMS_update (void); void HMS_list_servers (void); msg_server_t * HMS_fetch_servers (msg_server_t *list, int id); int HMS_compare_mod_version (char *buffer, size_t size_of_buffer); +const char * HMS_fetch_rules (char *buffer, size_t size_of_buffer); #endif