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
This commit is contained in:
smallmodel 2025-04-22 21:40:34 +02:00
parent 01367d0731
commit a2bbf6cff8
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
12 changed files with 176 additions and 8 deletions

View file

@ -7,6 +7,11 @@ add_subdirectory("../cgame" "./cgame")
file(GLOB SOURCES_CLIENT "./*.c*") file(GLOB SOURCES_CLIENT "./*.c*")
file(GLOB_RECURSE SOURCES_UILIB "../uilib/*.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 # Made as an interface and not static, as static only links used methods
add_library(omohclient INTERFACE) add_library(omohclient INTERFACE)
target_compile_definitions(omohclient INTERFACE APP_MODULE) target_compile_definitions(omohclient INTERFACE APP_MODULE)

36
code/gamespy/cl_gamespy.c Normal file
View file

@ -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();
}

25
code/gamespy/cl_gamespy.h Normal file
View file

@ -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

View file

@ -48,8 +48,16 @@ Fax(714)549-0757
// Added in 2.0 // Added in 2.0
#include "gcrypt.h" #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 SERVER_GROWBY 64
#define LAN_SEARCH_TIME 3000 //3 sec #define LAN_SEARCH_TIME 3000 //3 sec
#define LIST_NUMKEYBUCKETS 500 #define LIST_NUMKEYBUCKETS 500

40
code/gamespy/q_gamespy.c Normal file
View file

@ -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;
}

29
code/gamespy/q_gamespy.h Normal file
View file

@ -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();

View file

@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "../qcommon/q_version.h" #include "../qcommon/q_version.h"
#include "sv_gqueryreporting.h" #include "sv_gqueryreporting.h"
#include "sv_gamespy.h" #include "sv_gamespy.h"
#include "q_gamespy.h"
#include "gcdkey/gcdkeys.h" #include "gcdkey/gcdkeys.h"
#include "common/gsCommon.h" #include "common/gsCommon.h"
@ -501,3 +502,13 @@ void SV_GamespyAuthorize(netadr_t from, const char *response)
break; break;
} }
} }
const char *qr_get_master_host()
{
return Com_GetMasterHost();
}
int qr_get_master_port()
{
return Com_GetMasterHeartbeatPort();
}

View file

@ -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 #pragma once
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -161,7 +161,7 @@ static const char* queries[] = {"", "basic", "info", "rules", "players", "status
static struct sockaddr_in hbaddr; static struct sockaddr_in hbaddr;
struct qr_implementation_s static_rec = {INVALID_SOCKET, INVALID_SOCKET}; struct qr_implementation_s static_rec = {INVALID_SOCKET, INVALID_SOCKET};
static qr_t current_rec = &static_rec; 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 struct sockaddr_in MasterList[8];
static char keyvalue[8192]; static char keyvalue[8192];

View file

@ -65,10 +65,9 @@ as the base port. Generally there is no reason to modify this value.
/******** /********
DEFINES DEFINES
********/ ********/
#define MASTER_SERVER_HOST "master.333networks.com" #define MASTER_PORT qr_get_master_port()
#define MASTER_PORT 27900
//#define MASTER_ADDR "master." GSI_DOMAIN_NAME //#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 FIRST_HB_TIME 30000 /* 30 sec */
#define HB_TIME 300000 /* 5 minutes */ #define HB_TIME 300000 /* 5 minutes */
#define MAX_FIRST_COUNT 10 /* 10 tries = 5 minutes */ #define MAX_FIRST_COUNT 10 /* 10 tries = 5 minutes */
@ -82,6 +81,14 @@ IP can be stored here before calling
qr_init */ qr_init */
extern char qr_hostname[64]; 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 qr_querycallback_t
------------------- -------------------

View file

@ -79,8 +79,7 @@ set(SOURCES_COMMON
"${CMAKE_SOURCE_DIR}/code/qcommon/q_shared.c" "${CMAKE_SOURCE_DIR}/code/qcommon/q_shared.c"
"${CMAKE_SOURCE_DIR}/code/qcommon/unzip.c" "${CMAKE_SOURCE_DIR}/code/qcommon/unzip.c"
# Gamespy # Gamespy
"${CMAKE_SOURCE_DIR}/code/gamespy/sv_gamespy.c" "${CMAKE_SOURCE_DIR}/code/gamespy/q_gamespy.c"
"${CMAKE_SOURCE_DIR}/code/gamespy/sv_gqueryreporting.c"
) )
add_subdirectory("../skeletor" "./skeletor") add_subdirectory("../skeletor" "./skeletor")

View file

@ -6,6 +6,12 @@ add_subdirectory("../fgame" "./fgame")
file(GLOB_RECURSE SOURCES_SERVER "./*.c*") 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) add_library(omohserver INTERFACE)
target_sources(omohserver INTERFACE ${SOURCES_SERVER}) target_sources(omohserver INTERFACE ${SOURCES_SERVER})
target_compile_features(omohserver INTERFACE cxx_nullptr) target_compile_features(omohserver INTERFACE cxx_nullptr)