mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-01-11 09:12:22 +00:00
Master Server Listing rules prompts
Ported from KartKrew/Kart-Public!286 Unlike the previous entry in the series, this actually defers outbound rules checks for either selecting "Host Game" on the menu, or starting a server via the console/command line parameters. Only attempting to host a non-advertised game via the menu will have sent out an unnecessary rules request to the MS!
This commit is contained in:
parent
5b958f5a0c
commit
782d98fb09
5 changed files with 162 additions and 3 deletions
|
|
@ -516,6 +516,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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -841,6 +841,7 @@ extern struct mpmenu_s {
|
|||
} mpmenu;
|
||||
|
||||
void M_PleaseWait(void);
|
||||
void M_PopupMasterServerRules(void);
|
||||
|
||||
// Time Attack
|
||||
void M_PrepareTimeAttack(INT32 choice);
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
#include "../k_menu.h"
|
||||
#include "../s_sound.h"
|
||||
#include "../z_zone.h"
|
||||
#include "../mserv.h"
|
||||
|
||||
// MULTIPLAYER HOST SCREEN -- see mhost_e
|
||||
menuitem_t PLAY_MP_Host[] =
|
||||
|
|
@ -43,13 +45,41 @@ menu_t PLAY_MP_HostDef = {
|
|||
NULL
|
||||
};
|
||||
|
||||
void M_PopupMasterServerRules(void)
|
||||
{
|
||||
#ifdef MASTERSERVER
|
||||
if (cv_advertise.value && (serverrunning || currentMenu == &PLAY_MP_HostDef))
|
||||
{
|
||||
char *rules = GetMasterServerRules();
|
||||
|
||||
if (rules != NULL)
|
||||
{
|
||||
M_StartMessage("Server List Rules", rules, NULL, MM_NOTHING, NULL, NULL);
|
||||
Z_Free(rules);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void M_MPHostInit(INT32 choice)
|
||||
{
|
||||
|
||||
(void)choice;
|
||||
mpmenu.modewinextend[0][0] = 1;
|
||||
M_SetupNextMenu(&PLAY_MP_HostDef, true);
|
||||
itemOn = mhost_go;
|
||||
|
||||
Get_rules();
|
||||
// There's one downside to doing it this way:
|
||||
// if you turn advertise on via the console,
|
||||
// then access this menu for the first time,
|
||||
// no rules will pop up because they haven't
|
||||
// arrived yet.
|
||||
M_PopupMasterServerRules();
|
||||
// HOWEVER, this menu popup isn't for people
|
||||
// who know how to use the Developer Console.
|
||||
// People who CAN do that should already know
|
||||
// what kind of service they're connecting to.
|
||||
// (it'll still appear in the logs later, too!)
|
||||
}
|
||||
|
||||
void M_HandleHostMenuGametype(INT32 choice)
|
||||
|
|
|
|||
98
src/mserv.c
98
src/mserv.c
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "doomstat.h"
|
||||
#include "doomdef.h"
|
||||
#include "console.h" // con_startup
|
||||
#include "command.h"
|
||||
#include "i_threads.h"
|
||||
#include "mserv.h"
|
||||
|
|
@ -40,6 +41,8 @@ static boolean MSUpdateAgain;
|
|||
|
||||
static time_t MSLastPing;
|
||||
|
||||
static char *MSRules;
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static I_mutex MSMutex;
|
||||
static I_cond MSCond;
|
||||
|
|
@ -157,6 +160,43 @@ static void Command_Listserv_f(void)
|
|||
}
|
||||
}
|
||||
|
||||
static boolean firstmsrules = false;
|
||||
|
||||
static void
|
||||
Get_masterserver_rules (boolean checkfirst)
|
||||
{
|
||||
char rules[256];
|
||||
|
||||
if (checkfirst)
|
||||
{
|
||||
boolean MSRulesExist;
|
||||
|
||||
Lock_state();
|
||||
MSRulesExist = (MSRules != NULL);
|
||||
Unlock_state();
|
||||
|
||||
if (MSRulesExist)
|
||||
return;
|
||||
}
|
||||
|
||||
if (HMS_fetch_rules(rules, sizeof rules))
|
||||
{
|
||||
Lock_state();
|
||||
Z_Free(MSRules);
|
||||
MSRules = Z_StrDup(rules);
|
||||
|
||||
if (MSRegistered == true)
|
||||
{
|
||||
CONS_Printf("\n");
|
||||
CONS_Alert(CONS_NOTICE, "%s\n", rules);
|
||||
}
|
||||
|
||||
firstmsrules = true;
|
||||
|
||||
Unlock_state();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Finish_registration (void)
|
||||
{
|
||||
|
|
@ -175,6 +215,17 @@ Finish_registration (void)
|
|||
}
|
||||
Unlock_state();
|
||||
|
||||
char *rules = GetMasterServerRules();
|
||||
if (rules == NULL)
|
||||
{
|
||||
Get_masterserver_rules(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CONS_Printf("\n");
|
||||
CONS_Alert(CONS_NOTICE, "%s\n", rules);
|
||||
}
|
||||
|
||||
if (registered)
|
||||
CONS_Printf("Master server registration successful.\n");
|
||||
}
|
||||
|
|
@ -257,6 +308,15 @@ Finish_unlist (void)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
Finish_masterserver_change (char *api)
|
||||
{
|
||||
HMS_set_api(api);
|
||||
|
||||
if (!con_startup)
|
||||
Get_masterserver_rules(false);
|
||||
}
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
static int *
|
||||
Server_id (void)
|
||||
|
|
@ -350,7 +410,14 @@ Change_masterserver_thread (char *api)
|
|||
}
|
||||
Unlock_state();
|
||||
|
||||
HMS_set_api(api);
|
||||
Finish_masterserver_change(api);
|
||||
}
|
||||
|
||||
static void
|
||||
Get_masterserver_rules_thread (void)
|
||||
{
|
||||
// THIS FUNC has its own lock check in it
|
||||
Get_masterserver_rules(true);
|
||||
}
|
||||
#endif/*HAVE_THREADS*/
|
||||
|
||||
|
|
@ -397,6 +464,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)
|
||||
{
|
||||
|
|
@ -447,7 +525,21 @@ Set_api (const char *api)
|
|||
strdup(api)
|
||||
);
|
||||
#else
|
||||
HMS_set_api(strdup(api));
|
||||
Finish_masterserver_change(strdup(api));
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
Get_rules (void)
|
||||
{
|
||||
#ifdef HAVE_THREADS
|
||||
I_spawn_thread(
|
||||
"get-masterserver-rules",
|
||||
(I_thread_fn)Get_masterserver_rules_thread,
|
||||
NULL
|
||||
);
|
||||
#else
|
||||
Get_masterserver_rules(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -521,6 +613,8 @@ void Advertise_OnChange(void)
|
|||
#ifdef HAVE_DISCORDRPC
|
||||
DRPC_UpdatePresence();
|
||||
#endif
|
||||
|
||||
M_PopupMasterServerRules();
|
||||
}
|
||||
|
||||
#ifdef DEVELOP
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ extern I_mutex ms_ServerList_mutex;
|
|||
void RegisterServer(void);
|
||||
void UnregisterServer(void);
|
||||
|
||||
void Get_rules(void);
|
||||
|
||||
void MasterClient_Ticker(void);
|
||||
|
||||
msg_server_t *GetShortServersList(int id);
|
||||
|
|
@ -84,6 +86,8 @@ msg_server_t *GetShortServersList(int id);
|
|||
char *GetMODVersion(int id);
|
||||
#endif
|
||||
|
||||
char *GetMasterServerRules(void);
|
||||
|
||||
void AddMServCommands(void);
|
||||
|
||||
/* HTTP */
|
||||
|
|
@ -94,6 +98,7 @@ 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue