From a2bbf6cff8a94e8ec9c36ad83dfedb0a36f10b0a Mon Sep 17 00:00:00 2001 From: smallmodel <15067410+smallmodel@users.noreply.github.com> Date: Tue, 22 Apr 2025 21:40:34 +0200 Subject: [PATCH] Use functions that return master host information This splits gamespy client-specific and server-specific code and add common gamespy code to provide more flexibility in the future --- code/client/CMakeLists.txt | 5 ++++ code/gamespy/cl_gamespy.c | 36 ++++++++++++++++++++++++++++ code/gamespy/cl_gamespy.h | 25 +++++++++++++++++++ code/gamespy/gserverlist.c | 12 ++++++++-- code/gamespy/q_gamespy.c | 40 +++++++++++++++++++++++++++++++ code/gamespy/q_gamespy.h | 29 ++++++++++++++++++++++ code/gamespy/sv_gamespy.c | 11 +++++++++ code/gamespy/sv_gamespy.h | 2 ++ code/gamespy/sv_gqueryreporting.c | 2 +- code/gamespy/sv_gqueryreporting.h | 13 +++++++--- code/qcommon/CMakeLists.txt | 3 +-- code/server/CMakeLists.txt | 6 +++++ 12 files changed, 176 insertions(+), 8 deletions(-) create mode 100644 code/gamespy/cl_gamespy.c create mode 100644 code/gamespy/cl_gamespy.h create mode 100644 code/gamespy/q_gamespy.c create mode 100644 code/gamespy/q_gamespy.h diff --git a/code/client/CMakeLists.txt b/code/client/CMakeLists.txt index b641351c..259e055b 100644 --- a/code/client/CMakeLists.txt +++ b/code/client/CMakeLists.txt @@ -7,6 +7,11 @@ add_subdirectory("../cgame" "./cgame") file(GLOB SOURCES_CLIENT "./*.c*") file(GLOB_RECURSE SOURCES_UILIB "../uilib/*.c*") +set(SOURCES_CLIENT ${SOURCES_CLIENT} + # Gamespy + "${CMAKE_SOURCE_DIR}/code/gamespy/cl_gamespy.c" +) + # Made as an interface and not static, as static only links used methods add_library(omohclient INTERFACE) target_compile_definitions(omohclient INTERFACE APP_MODULE) diff --git a/code/gamespy/cl_gamespy.c b/code/gamespy/cl_gamespy.c new file mode 100644 index 00000000..898f5a19 --- /dev/null +++ b/code/gamespy/cl_gamespy.c @@ -0,0 +1,36 @@ +/* +=========================================================================== +Copyright (C) 2025 the OpenMoHAA team + +This file is part of OpenMoHAA source code. + +OpenMoHAA source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +OpenMoHAA source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with OpenMoHAA source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +#pragma once + +#include "cl_gamespy.h" +#include "q_gamespy.h" + +const char *ServerListGetHost() +{ + return Com_GetMasterHost(); +} + +int ServerListGetMsPort() +{ + return Com_GetMasterQueryPort(); +} diff --git a/code/gamespy/cl_gamespy.h b/code/gamespy/cl_gamespy.h new file mode 100644 index 00000000..3032cd72 --- /dev/null +++ b/code/gamespy/cl_gamespy.h @@ -0,0 +1,25 @@ +/* +=========================================================================== +Copyright (C) 2025 the OpenMoHAA team + +This file is part of OpenMoHAA source code. + +OpenMoHAA source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +OpenMoHAA source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with OpenMoHAA source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +// cl_gamespy.h -- Game-specific client GameSpy code + +#pragma once diff --git a/code/gamespy/gserverlist.c b/code/gamespy/gserverlist.c index e77cbcd3..4015fb9c 100644 --- a/code/gamespy/gserverlist.c +++ b/code/gamespy/gserverlist.c @@ -48,8 +48,16 @@ Fax(714)549-0757 // Added in 2.0 #include "gcrypt.h" -#define MSHOST MASTER_SERVER_HOST -#define MSPORT 28900 +/** + * @brief Custom function used to return the master host, based on game settings + * + * @return const char* The master host + */ +extern const char *ServerListGetHost(); +extern int ServerGetMsPort(); + +#define MSHOST ServerListGetHost() +#define MSPORT ServerListGetMsPort() #define SERVER_GROWBY 64 #define LAN_SEARCH_TIME 3000 //3 sec #define LIST_NUMKEYBUCKETS 500 diff --git a/code/gamespy/q_gamespy.c b/code/gamespy/q_gamespy.c new file mode 100644 index 00000000..853d476c --- /dev/null +++ b/code/gamespy/q_gamespy.c @@ -0,0 +1,40 @@ +/* +=========================================================================== +Copyright (C) 2025 the OpenMoHAA team + +This file is part of OpenMoHAA source code. + +OpenMoHAA source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +OpenMoHAA source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with OpenMoHAA source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +#pragma once + +#include "q_gamespy.h" + +const char *Com_GetMasterHost() +{ + return "master.333networks.com"; +} + +int Com_GetMasterQueryPort() +{ + return 28900; +} + +int Com_GetMasterHeartbeatPort() +{ + return 27900; +} diff --git a/code/gamespy/q_gamespy.h b/code/gamespy/q_gamespy.h new file mode 100644 index 00000000..f002cd0e --- /dev/null +++ b/code/gamespy/q_gamespy.h @@ -0,0 +1,29 @@ +/* +=========================================================================== +Copyright (C) 2025 the OpenMoHAA team + +This file is part of OpenMoHAA source code. + +OpenMoHAA source code is free software; you can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of the License, +or (at your option) any later version. + +OpenMoHAA source code is distributed in the hope that it will be +useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with OpenMoHAA source code; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +=========================================================================== +*/ + +// q_gamespy.h -- Common game-specific GameSpy code shared between client and server + +#pragma once + +const char *Com_GetMasterHost(); +int Com_GetMasterQueryPort(); +int Com_GetMasterHeartbeatPort(); diff --git a/code/gamespy/sv_gamespy.c b/code/gamespy/sv_gamespy.c index 0dbce869..334f6bf9 100644 --- a/code/gamespy/sv_gamespy.c +++ b/code/gamespy/sv_gamespy.c @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "../qcommon/q_version.h" #include "sv_gqueryreporting.h" #include "sv_gamespy.h" +#include "q_gamespy.h" #include "gcdkey/gcdkeys.h" #include "common/gsCommon.h" @@ -501,3 +502,13 @@ void SV_GamespyAuthorize(netadr_t from, const char *response) break; } } + +const char *qr_get_master_host() +{ + return Com_GetMasterHost(); +} + +int qr_get_master_port() +{ + return Com_GetMasterHeartbeatPort(); +} diff --git a/code/gamespy/sv_gamespy.h b/code/gamespy/sv_gamespy.h index ff524699..dc033679 100644 --- a/code/gamespy/sv_gamespy.h +++ b/code/gamespy/sv_gamespy.h @@ -20,6 +20,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =========================================================================== */ +// sv_gamespy.h -- Game-specific server GameSpy code + #pragma once #ifdef __cplusplus diff --git a/code/gamespy/sv_gqueryreporting.c b/code/gamespy/sv_gqueryreporting.c index 3d549504..44fd0efd 100644 --- a/code/gamespy/sv_gqueryreporting.c +++ b/code/gamespy/sv_gqueryreporting.c @@ -161,7 +161,7 @@ static const char* queries[] = {"", "basic", "info", "rules", "players", "status static struct sockaddr_in hbaddr; struct qr_implementation_s static_rec = {INVALID_SOCKET, INVALID_SOCKET}; static qr_t current_rec = &static_rec; -char qr_hostname[64] = MASTER_ADDR; +//char qr_hostname[64] = MASTER_ADDR; static struct sockaddr_in MasterList[8]; static char keyvalue[8192]; diff --git a/code/gamespy/sv_gqueryreporting.h b/code/gamespy/sv_gqueryreporting.h index 5a016b73..e41fbeab 100644 --- a/code/gamespy/sv_gqueryreporting.h +++ b/code/gamespy/sv_gqueryreporting.h @@ -65,10 +65,9 @@ as the base port. Generally there is no reason to modify this value. /******** DEFINES ********/ -#define MASTER_SERVER_HOST "master.333networks.com" -#define MASTER_PORT 27900 +#define MASTER_PORT qr_get_master_port() //#define MASTER_ADDR "master." GSI_DOMAIN_NAME -#define MASTER_ADDR MASTER_SERVER_HOST +#define MASTER_ADDR qr_get_master_host() #define FIRST_HB_TIME 30000 /* 30 sec */ #define HB_TIME 300000 /* 5 minutes */ #define MAX_FIRST_COUNT 10 /* 10 tries = 5 minutes */ @@ -82,6 +81,14 @@ IP can be stored here before calling qr_init */ extern char qr_hostname[64]; +/** + * @brief Custom function used to return the master host, based on game settings + * + * @return const char* The full master server address + */ +extern const char *qr_get_master_host(); +extern int qr_get_master_port(); + /******** qr_querycallback_t ------------------- diff --git a/code/qcommon/CMakeLists.txt b/code/qcommon/CMakeLists.txt index bde54547..cefb08d1 100644 --- a/code/qcommon/CMakeLists.txt +++ b/code/qcommon/CMakeLists.txt @@ -79,8 +79,7 @@ set(SOURCES_COMMON "${CMAKE_SOURCE_DIR}/code/qcommon/q_shared.c" "${CMAKE_SOURCE_DIR}/code/qcommon/unzip.c" # Gamespy - "${CMAKE_SOURCE_DIR}/code/gamespy/sv_gamespy.c" - "${CMAKE_SOURCE_DIR}/code/gamespy/sv_gqueryreporting.c" + "${CMAKE_SOURCE_DIR}/code/gamespy/q_gamespy.c" ) add_subdirectory("../skeletor" "./skeletor") diff --git a/code/server/CMakeLists.txt b/code/server/CMakeLists.txt index a171be65..7c06edb1 100644 --- a/code/server/CMakeLists.txt +++ b/code/server/CMakeLists.txt @@ -6,6 +6,12 @@ add_subdirectory("../fgame" "./fgame") file(GLOB_RECURSE SOURCES_SERVER "./*.c*") +set(SOURCES_SERVER ${SOURCES_SERVER} + # Gamespy + "${CMAKE_SOURCE_DIR}/code/gamespy/sv_gamespy.c" + "${CMAKE_SOURCE_DIR}/code/gamespy/sv_gqueryreporting.c" +) + add_library(omohserver INTERFACE) target_sources(omohserver INTERFACE ${SOURCES_SERVER}) target_compile_features(omohserver INTERFACE cxx_nullptr)