Register/unregister server by changing cv_advertise

This commit is contained in:
James R 2020-09-11 06:49:41 -07:00
parent 901ea3c18b
commit 93d3808307

View file

@ -59,6 +59,8 @@ static void Update_parameters (void);
static void MasterServer_OnChange(void);
static void Advertise_OnChange(void);
static CV_PossibleValue_t masterserver_update_rate_cons_t[] = {
{2, "MIN"},
{60, "MAX"},
@ -71,7 +73,7 @@ consvar_t cv_server_contact = {"server_contact", "", CV_SAVE|CV_CALL|CV_NOINIT,
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_advertise = {"advertise", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL};
consvar_t cv_advertise = {"advertise", "Yes", CV_SAVE|CV_CALL|CV_NOINIT, CV_YesNo, Advertise_OnChange, 0, NULL, NULL, 0, 0, NULL};
#if defined (MASTERSERVER) && defined (HAVE_THREADS)
int ms_QueryId;
@ -263,6 +265,9 @@ Finish_unlist (void)
Lock_state();
{
registered = MSRegistered;
if (MSId == MSRegisteredId)
MSId++;
}
Unlock_state();
@ -284,13 +289,6 @@ Finish_unlist (void)
#endif
}
Lock_state();
{
if (MSId == MSRegisteredId)
MSId++;
}
Unlock_state();
#ifdef HAVE_DISCORDRPC
DRPC_UpdatePresence();
#endif
@ -540,3 +538,30 @@ static void MasterServer_OnChange(void)
RegisterServer();
#endif/*MASTERSERVER*/
}
static void
Advertise_OnChange(void)
{
int different;
if (cv_advertise.value)
{
if (serverrunning)
{
Lock_state();
{
different = ( MSId != MSRegisteredId );
}
Unlock_state();
if (different)
{
RegisterServer();
}
}
}
else
{
UnregisterServer();
}
}