From 0846024adcbee7e5e34ade11f043ea7cca747802 Mon Sep 17 00:00:00 2001 From: Hanicef Date: Sun, 16 Jun 2024 15:00:51 +0200 Subject: [PATCH] Add CVar for changing room ID --- src/d_main.c | 2 +- src/m_menu.c | 4 ++-- src/netcode/mserv.c | 16 +++++++++++++++- src/netcode/mserv.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 3a3a0b26a..9935dcaa1 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1600,7 +1600,7 @@ void D_SRB2Main(void) { if (!M_IsNextParm()) I_Error("usage: -room \nCheck the Master Server's webpage for room ID numbers.\n"); - ms_RoomId = atoi(M_GetNextParm()); + CV_SetValue(&cv_masterserver_room_id, atoi(M_GetNextParm())); #ifdef UPDATE_ALERT GetMODVersion_Console(); diff --git a/src/m_menu.c b/src/m_menu.c index 38165472e..d3df61b65 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11524,10 +11524,10 @@ static void M_ChooseRoom(INT32 choice) #endif if (choice == 0) - ms_RoomId = -1; + CV_SetValue(&cv_masterserver_room_id, 0); else { - ms_RoomId = roomIds[choice-1]; + CV_SetValue(&cv_masterserver_room_id, roomIds[choice-1]); menuRoomIndex = choice - 1; } diff --git a/src/netcode/mserv.c b/src/netcode/mserv.c index 74ee120f9..db0f640d7 100644 --- a/src/netcode/mserv.c +++ b/src/netcode/mserv.c @@ -55,6 +55,7 @@ static boolean ServerName_CanChange (const char*); static void Update_parameters (void); static void MasterServer_OnChange(void); +static void RoomId_OnChange(void); static CV_PossibleValue_t masterserver_update_rate_cons_t[] = { {2, "MIN"}, @@ -66,8 +67,9 @@ consvar_t cv_masterserver = CVAR_INIT ("masterserver", "https://ds.ms.srb2.org/M consvar_t cv_servername = CVAR_INIT_WITH_CALLBACKS ("servername", "SRB2 server", CV_SAVE|CV_NETVAR|CV_CALL|CV_NOINIT|CV_ALLOWLUA, NULL, Update_parameters, ServerName_CanChange); consvar_t cv_masterserver_update_rate = CVAR_INIT ("masterserver_update_rate", "15", CV_SAVE|CV_CALL|CV_NOINIT, masterserver_update_rate_cons_t, Update_parameters); +consvar_t cv_masterserver_room_id = CVAR_INIT ("masterserver_room_id", "0", CV_CALL, CV_Unsigned, RoomId_OnChange); -INT16 ms_RoomId = -1; +INT16 ms_RoomId = 0; #if defined (MASTERSERVER) && defined (HAVE_THREADS) int ms_QueryId; @@ -92,6 +94,7 @@ void AddMServCommands(void) { CV_RegisterVar(&cv_masterserver); CV_RegisterVar(&cv_masterserver_update_rate); + CV_RegisterVar(&cv_masterserver_room_id); CV_RegisterVar(&cv_masterserver_timeout); CV_RegisterVar(&cv_masterserver_debug); CV_RegisterVar(&cv_masterserver_token); @@ -534,6 +537,17 @@ Update_parameters (void) #endif/*MASTERSERVER*/ } +static void RoomId_OnChange(void) +{ + if (ms_RoomId != cv_masterserver_room_id.value) + { + UnregisterServer(); + ms_RoomId = cv_masterserver_room_id.value; + if (Online()) + RegisterServer(); + } +} + static void MasterServer_OnChange(void) { #ifdef MASTERSERVER diff --git a/src/netcode/mserv.h b/src/netcode/mserv.h index 0bc8c8e6b..419c11a89 100644 --- a/src/netcode/mserv.h +++ b/src/netcode/mserv.h @@ -66,6 +66,7 @@ typedef struct extern consvar_t cv_masterserver, cv_servername; extern consvar_t cv_masterserver_update_rate; +extern consvar_t cv_masterserver_room_id; extern consvar_t cv_masterserver_timeout; extern consvar_t cv_masterserver_debug; extern consvar_t cv_masterserver_token;