Refresh variables that were modified

This commit is contained in:
smallmodel 2025-04-27 19:58:41 +02:00
parent 63bea5156a
commit b593da7c2a
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 77 additions and 20 deletions

View file

@ -23,8 +23,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#pragma once #pragma once
#include "q_gamespy.h" #include "q_gamespy.h"
#include "../qcommon/q_shared.h"
#include "../qcommon/qcommon.h" #include "../qcommon/qcommon.h"
#include "cl_gamespy.h"
#include "sv_gamespy.h"
#define MAX_MASTERS 8 #define MAX_MASTERS 8
#define MASTER_DEFAULT_MSPORT 28900 #define MASTER_DEFAULT_MSPORT 28900
@ -37,19 +38,53 @@ cvar_t *com_master_hbport[MAX_MASTERS];
master_entry_t entries[MAX_MASTERS]; master_entry_t entries[MAX_MASTERS];
int num_entries = 0; int num_entries = 0;
static void CreateMasterVar(int index, const char *host, int msport, int hbport) { static void Com_RestartGameSpy_f(void);
com_master_host[index] = Cvar_Get(va("com_master%d_host", index), host, CVAR_INIT);
com_master_msport[index] = Cvar_Get(va("com_master%d_msport", index), va("%d", msport), CVAR_INIT);
com_master_hbport[index] = Cvar_Get(va("com_master%d_hbport", index), va("%d", hbport), CVAR_INIT);
}
void Com_InitGameSpy() { static qboolean ShouldRefreshMasters()
{
int i; int i;
for (i = 0; i < MAX_MASTERS; i++) {
if (com_master_host[i] && com_master_host[i]->latchedString) {
return qtrue;
}
if (com_master_msport[i] && com_master_msport[i]->latchedString) {
return qtrue;
}
if (com_master_hbport[i] && com_master_hbport[i]->latchedString) {
return qtrue;
}
}
return qfalse;
}
static void CreateMasterVar(int index, const char *host, int msport, int hbport)
{
// //
// These entries come from the 333networks community and use the same software // These variables should be modified for testing purposes only.
// So prevent them to be saved in the configuration file.
//
com_master_host[index] = Cvar_Get(va("com_master%d_host", index), host, CVAR_LATCH | CVAR_TEMP);
com_master_msport[index] = Cvar_Get(va("com_master%d_msport", index), va("%d", msport), CVAR_LATCH | CVAR_TEMP);
com_master_hbport[index] = Cvar_Get(va("com_master%d_hbport", index), va("%d", hbport), CVAR_LATCH | CVAR_TEMP);
com_master_host[index]->flags &= ~CVAR_ARCHIVE;
com_master_msport[index]->flags &= ~CVAR_ARCHIVE;
com_master_hbport[index]->flags &= ~CVAR_ARCHIVE;
}
qboolean Com_RefreshGameSpyMasters()
{
int i;
qboolean shouldRestart;
shouldRestart = ShouldRefreshMasters();
//
// These masters come from the 333networks community and use the same software
// that emulate the GameSpy protocol -- see https://333networks.com/ // that emulate the GameSpy protocol -- see https://333networks.com/
// These masters are managed by different entities, they are independent and are syncing eachother. // They are managed by different entities, are independent and sync with eachother.
// //
CreateMasterVar(0, "master.333networks.com", MASTER_DEFAULT_MSPORT, MASTER_DEFAULT_HBPORT); CreateMasterVar(0, "master.333networks.com", MASTER_DEFAULT_MSPORT, MASTER_DEFAULT_HBPORT);
CreateMasterVar(1, "master.errorist.eu", MASTER_DEFAULT_MSPORT, MASTER_DEFAULT_HBPORT); CreateMasterVar(1, "master.errorist.eu", MASTER_DEFAULT_MSPORT, MASTER_DEFAULT_HBPORT);
@ -76,6 +111,25 @@ void Com_InitGameSpy() {
num_entries++; num_entries++;
} }
} }
return shouldRestart;
}
void Com_InitGameSpy()
{
Com_RefreshGameSpyMasters();
Cmd_AddCommand("net_gamespy_restart", Com_RestartGameSpy_f);
}
static void Com_RestartGameSpy_f(void)
{
Com_RefreshGameSpyMasters();
#ifndef DEDICATED
CL_RestartGamespy_f();
#endif
SV_RestartGamespy_f();
} }
unsigned int Com_GetNumMasterEntries() unsigned int Com_GetNumMasterEntries()

View file

@ -24,6 +24,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#pragma once #pragma once
#include "../qcommon/q_shared.h"
typedef struct { typedef struct {
const char *host; const char *host;
int queryport; int queryport;
@ -31,6 +33,7 @@ typedef struct {
} master_entry_t; } master_entry_t;
void Com_InitGameSpy(); void Com_InitGameSpy();
qboolean Com_RefreshGameSpyMasters();
unsigned int Com_GetNumMasterEntries(); unsigned int Com_GetNumMasterEntries();
void Com_GetMasterEntry(int index, master_entry_t* entry); void Com_GetMasterEntry(int index, master_entry_t* entry);