Merge branch 'http-ms-rules' into 'next'

Print rules in menu and in console

See merge request KartKrew/Kart-Public!286
This commit is contained in:
toaster 2022-07-09 19:18:47 +00:00
commit 64474c35ae
5 changed files with 92 additions and 6 deletions

View file

@ -11,7 +11,7 @@
/*
Documentation available here.
<https://ms.kartkrew.org/tools/api/2/>
<https://ms.kartkrew.org/tools/api/2.2/>
*/
#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)
{

View file

@ -6334,6 +6334,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
// ======
@ -9140,7 +9154,7 @@ static void M_StartServerMenu(INT32 choice)
levellistmode = LLM_CREATESERVER;
M_PrepareLevelSelect();
M_SetupNextMenu(&MP_ServerDef);
M_PopupMasterServerRules();
}
// ==============

View file

@ -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)\
{\

View file

@ -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();
}

View file

@ -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