From 4fcd24d8480a2ac00b8290dc07b8327dc8ba8faf Mon Sep 17 00:00:00 2001
From: James R <justsomejames2@gmail.com>
Date: Mon, 13 Apr 2020 23:10:06 -0700
Subject: [PATCH] masterserver_update_rate cvar determines wait between updates
 in minutes

The new default is 15 minutes as well. And if you think that's too long, I have
confirmed that the Master Server delists inactive servers after a whopping 40
minutes, at least.
---
 src/mserv.c | 13 ++++++++++++-
 src/mserv.h |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/mserv.c b/src/mserv.c
index cbe9042803..20c2754305 100644
--- a/src/mserv.c
+++ b/src/mserv.c
@@ -34,15 +34,25 @@ int  HMS_compare_mod_version (char *buffer, size_t size_of_buffer);
 
 static time_t MSLastPing;
 
+static inline void SendPingToMasterServer(void);
+
 #ifndef NONET
 static void Command_Listserv_f(void);
 #endif
 static void MasterServer_OnChange(void);
 static void ServerName_OnChange(void);
 
+static CV_PossibleValue_t masterserver_update_rate_cons_t[] = {
+	{2,  "MIN"},
+	{60, "MAX"},
+	{0}
+};
+
 consvar_t cv_masterserver = {"masterserver", "https://mb.srb2.org/MS/0", CV_SAVE|CV_CALL, NULL, MasterServer_OnChange, 0, NULL, NULL, 0, 0, NULL};
 consvar_t cv_servername = {"servername", "SRB2Kart server", CV_SAVE|CV_CALL|CV_NOINIT, NULL, ServerName_OnChange, 0, NULL, NULL, 0, 0, NULL};
 
+consvar_t cv_masterserver_update_rate = {"masterserver_update_rate", "15", CV_SAVE|CV_CALL|CV_NOINIT, masterserver_update_rate_cons_t, SendPingToMasterServer, 0, NULL, NULL, 0, 0, NULL};
+
 char *ms_API;
 INT16 ms_RoomId = -1;
 
@@ -63,6 +73,7 @@ void AddMServCommands(void)
 {
 #ifndef NONET
 	CV_RegisterVar(&cv_masterserver);
+	CV_RegisterVar(&cv_masterserver_update_rate);
 	CV_RegisterVar(&cv_masterserver_debug);
 	CV_RegisterVar(&cv_servername);
 	COM_AddCommand("listserv", Command_Listserv_f);
@@ -171,7 +182,7 @@ static void UpdateServer(void)
 static inline void SendPingToMasterServer(void)
 {
 // Here, have a simpler MS Ping... - Cue
-	if(time(NULL) > (MSLastPing+(60*2)) && con_state != MSCS_NONE)
+	if(time(NULL) > (MSLastPing+(60*cv_masterserver_update_rate.value)) && con_state != MSCS_NONE)
 	{
 		UpdateServer();
 	}
diff --git a/src/mserv.h b/src/mserv.h
index 76eb8a74ae..564f71fe74 100644
--- a/src/mserv.h
+++ b/src/mserv.h
@@ -65,6 +65,7 @@ typedef struct
 // ================================ GLOBALS ===============================
 
 extern consvar_t cv_masterserver, cv_servername;
+extern consvar_t cv_masterserver_update_rate;
 extern consvar_t cv_masterserver_debug;
 
 extern char *ms_API;
-- 
GitLab