From b7bd3f7720bb42c59724828d6332d9e009816da3 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Fri, 13 Nov 2015 00:50:34 +0600 Subject: [PATCH] ReHLDS API: Implemented SV_ActivateServer hook and added GetResourcesNum, GetDecalNameNum Fix: using defines instead of magic numbers Added include qlimits.h Reduced the size global variable localinfo, ipfilters, userfilters --- rehlds/common/const.h | 12 ++++++++ rehlds/common/qlimits.h | 39 ++++++++++++++++++++++++ rehlds/common/quakedef.h | 3 ++ rehlds/engine/consistency.h | 1 + rehlds/engine/filter.h | 7 +++++ rehlds/engine/info.h | 5 +++ rehlds/engine/net.h | 6 +++- rehlds/engine/pr_cmds.cpp | 6 ++-- rehlds/engine/server.h | 22 +++++-------- rehlds/engine/sv_main.cpp | 33 +++++++++++--------- rehlds/engine/sys_dll.cpp | 2 +- rehlds/msvc/ReHLDS.vcxproj | 1 + rehlds/msvc/ReHLDS.vcxproj.filters | 3 ++ rehlds/public/rehlds/common_rehlds.h | 1 + rehlds/public/rehlds/custom.h | 1 + rehlds/public/rehlds/rehlds_api.h | 5 +++ rehlds/public/rehlds/rehlds_interfaces.h | 2 ++ rehlds/rehlds/rehlds_api_impl.cpp | 4 +++ rehlds/rehlds/rehlds_api_impl.h | 6 ++++ rehlds/rehlds/rehlds_interfaces_impl.cpp | 8 +++++ rehlds/rehlds/rehlds_interfaces_impl.h | 2 ++ 21 files changed, 136 insertions(+), 33 deletions(-) create mode 100644 rehlds/common/qlimits.h diff --git a/rehlds/common/const.h b/rehlds/common/const.h index e8ba7c0..f539684 100644 --- a/rehlds/common/const.h +++ b/rehlds/common/const.h @@ -19,6 +19,18 @@ #pragma once #endif +// Max # of clients allowed in a server. +#define MAX_CLIENTS 32 + +// How many bits to use to encode an edict. +#define MAX_EDICT_BITS 11 // # of bits needed to represent max edicts +// Max # of edicts in a level (2048) +#define MAX_EDICTS (1< ../common/quakedef.h:29 */ typedef int BOOL; /* size: 4 */ +// user message +#define MAX_USER_MSG_DATA 192 + /* <627f> ../common/quakedef.h:137 */ //moved to com_model.h //typedef struct cache_user_s diff --git a/rehlds/engine/consistency.h b/rehlds/engine/consistency.h index 9e0b6f8..900be17 100644 --- a/rehlds/engine/consistency.h +++ b/rehlds/engine/consistency.h @@ -32,6 +32,7 @@ #pragma once #endif +#define MAX_CONSISTENCY_LIST 512 /* <7508> ../engine/consistency.h:9 */ typedef struct consistency_s diff --git a/rehlds/engine/filter.h b/rehlds/engine/filter.h index 7da90fe..ebd87c6 100644 --- a/rehlds/engine/filter.h +++ b/rehlds/engine/filter.h @@ -34,6 +34,13 @@ #include "userid.h" +#ifdef REHLDS_FIXES +#define MAX_IPFILTERS 4096 +#define MAX_USERFILTERS 4096 +#else +#define MAX_IPFILTERS 32768 +#define MAX_USERFILTERS 32768 +#endif // REHLDS_FIXES /* ../engine/filter.h:12 */ typedef struct ipfilter_s diff --git a/rehlds/engine/info.h b/rehlds/engine/info.h index d726392..364aafa 100644 --- a/rehlds/engine/info.h +++ b/rehlds/engine/info.h @@ -42,6 +42,11 @@ #define INFO_MAX_BUFFER_VALUES 4 +#ifdef REHLDS_FIXES +#define MAX_LOCALINFO 4096 +#else +#define MAX_LOCALINFO MAX_INFO_STRING * 128 +#endif // REHLDS_FIXES const char *Info_ValueForKey(const char *s, const char *key); void Info_RemoveKey(char *s, const char *key); diff --git a/rehlds/engine/net.h b/rehlds/engine/net.h index e5757bc..5fc041b 100644 --- a/rehlds/engine/net.h +++ b/rehlds/engine/net.h @@ -43,7 +43,11 @@ // MAX_CHALLENGES is made large to prevent a denial // of service attack that could cycle all of them // out before legitimate users connected -#define MAX_CHALLENGES 1024 +#ifdef REHLDS_OPT_PEDANTIC +#define MAX_CHALLENGES 64 +#else +#define MAX_CHALLENGES 1024 +#endif // REHLDS_OPT_PEDANTIC // Client connection is initiated by requesting a challenge value // the server sends this value back diff --git a/rehlds/engine/pr_cmds.cpp b/rehlds/engine/pr_cmds.cpp index 8e768c1..cd1d34f 100644 --- a/rehlds/engine/pr_cmds.cpp +++ b/rehlds/engine/pr_cmds.cpp @@ -2163,12 +2163,14 @@ void EXT_FUNC PF_MessageEnd_I(void) if (pUserMsg->iSize == -1) { MsgIsVarLength = 1; - if (gMsgBuffer.cursize > 192) + + // Limit packet sizes + if (gMsgBuffer.cursize > MAX_USER_MSG_DATA) Host_Error( "PF_MessageEnd_I: Refusing to send user message %s of %i bytes to client, user message size limit is %i bytes\n", pUserMsg->szName, gMsgBuffer.cursize, - 192 + MAX_USER_MSG_DATA ); } else diff --git a/rehlds/engine/server.h b/rehlds/engine/server.h index 0b27466..0c27b94 100644 --- a/rehlds/engine/server.h +++ b/rehlds/engine/server.h @@ -35,18 +35,9 @@ #include "maintypes.h" // TODO: I think this defines must be in /common/ -#define MAX_CLIENTS 32 -#define MAX_EDICTS 900 +#define NUM_EDICTS 900 #define MAX_NAME 32 -#define MAX_LIGHTSTYLES 64 #define MAX_PACKET_ENTITIES 256 -#define MAX_RESOURCE_LIST 1280 -#define MAX_CONSISTENCY_LIST 512 -#ifdef REHLDS_OPT_PEDANTIC -#define MAX_CHALLENGES 64 -#else -#define MAX_CHALLENGES 1024 -#endif #include "custom_int.h" #include "crc.h" @@ -470,7 +461,7 @@ extern cvar_t lservercfgfile; extern cvar_t logsdir; extern cvar_t bannedcfgfile; -extern decalname_t sv_decalnames[512]; +extern decalname_t sv_decalnames[MAX_BASE_DECALS]; extern int sv_decalnamecount; extern UserMsg *sv_gpNewUserMsgs; @@ -572,12 +563,12 @@ extern unsigned char fatpas[1024]; extern int gPacketSuppressed; -extern char localinfo[MAX_INFO_STRING * 128]; -extern char localmodels[512][5]; +extern char localinfo[MAX_LOCALINFO]; +extern char localmodels[MAX_MODELS][5]; -extern ipfilter_t ipfilters[32768]; +extern ipfilter_t ipfilters[MAX_IPFILTERS]; extern int numipfilters; -extern userfilter_t userfilters[32768]; +extern userfilter_t userfilters[MAX_USERFILTERS]; extern int numuserfilters; extern challenge_t g_rg_sv_challenges[MAX_CHALLENGES]; @@ -730,6 +721,7 @@ void SV_BuildReconnect(sizebuf_t *msg); NOXREF void SV_ReconnectAllClients(void); void SetCStrikeFlags(void); void SV_ActivateServer(int runPhysics); +void SV_ActivateServer_internal(int runPhysics); void SV_ServerShutdown(void); int SV_SpawnServer(qboolean bIsDemo, char *server, char *startspot); void SV_LoadEntities(void); diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index 11271a3..af56d1f 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -61,7 +61,7 @@ server_t g_psv; rehlds_server_t g_rehlds_sv; -decalname_t sv_decalnames[512]; +decalname_t sv_decalnames[MAX_BASE_DECALS]; int sv_decalnamecount; UserMsg *sv_gpNewUserMsgs; @@ -79,12 +79,12 @@ delta_t *g_peventdelta; int gPacketSuppressed; -char localinfo[MAX_INFO_STRING * 128]; -char localmodels[512][5]; +char localinfo[MAX_LOCALINFO]; +char localmodels[MAX_MODELS][5]; -ipfilter_t ipfilters[32768]; +ipfilter_t ipfilters[MAX_IPFILTERS]; int numipfilters; -userfilter_t userfilters[32768]; +userfilter_t userfilters[MAX_USERFILTERS]; int numuserfilters; @@ -117,8 +117,8 @@ qboolean allow_cheats; #ifndef HOOK_ENGINE char *gNullString = ""; -int SV_UPDATE_BACKUP = 8; -int SV_UPDATE_MASK = 7; +int SV_UPDATE_BACKUP = SINGLEPLAYER_BACKUP; +int SV_UPDATE_MASK = (SINGLEPLAYER_BACKUP - 1); int giNextUserMsg = 64; cvar_t sv_lan = { "sv_lan", "0", 0, 0.0f, NULL }; @@ -847,7 +847,7 @@ qboolean SV_BuildSoundMsg(edict_t *entity, int channel, const char *sample, int if (field_mask & SND_FL_ATTENUATION) MSG_WriteBits((uint32)(attenuation * 64.0f), 8); MSG_WriteBits(channel, 3); - MSG_WriteBits(ent, 11); + MSG_WriteBits(ent, MAX_EDICT_BITS); MSG_WriteBits(sound_num, (field_mask & SND_FL_LARGE_INDEX) ? 16 : 8); MSG_WriteBitVec3Coord(origin); if (field_mask & SND_FL_PITCH) @@ -2531,7 +2531,7 @@ void SV_ResetModInfo(void) Q_memset(&gmodinfo, 0, sizeof(modinfo_t)); gmodinfo.version = 1; gmodinfo.svonly = TRUE; - gmodinfo.num_edicts = MAX_EDICTS; + gmodinfo.num_edicts = NUM_EDICTS; Q_snprintf(szDllListFile, sizeof(szDllListFile), "%s", "liblist.gam"); hLibListFile = FS_Open(szDllListFile, "rb"); @@ -5328,8 +5328,13 @@ void SetCStrikeFlags(void) } } -/* ../engine/sv_main.c:7107 */ void SV_ActivateServer(int runPhysics) +{ + g_RehldsHookchains.m_SV_ActivateServer.callChain(SV_ActivateServer_internal, runPhysics); +} + +/* ../engine/sv_main.c:7107 */ +void EXT_FUNC SV_ActivateServer_internal(int runPhysics) { int i; unsigned char data[NET_MAX_PAYLOAD]; @@ -5511,8 +5516,8 @@ int SV_SpawnServer(qboolean bIsDemo, char *server, char *startspot) for (i = 0; i < g_psvs.maxclientslimit; i++, cl++) SV_ClearFrames(&cl->frames); - SV_UPDATE_BACKUP = g_psvs.maxclients != 1 ? 64 : 8; - SV_UPDATE_MASK = g_psvs.maxclients != 1 ? 63 : 7; + SV_UPDATE_BACKUP = (g_psvs.maxclients == 1) ? SINGLEPLAYER_BACKUP : MULTIPLAYER_BACKUP; + SV_UPDATE_MASK = (SV_UPDATE_BACKUP - 1); SV_AllocClientFrames(); Q_memset(&g_psv, 0, sizeof(server_t)); @@ -7075,9 +7080,9 @@ void SV_Init(void) Cvar_RegisterVariable(&sv_allow_dlfile); Cvar_RegisterVariable(&sv_force_ent_intersection); - for (int i = 0; i < ARRAYSIZE(localmodels); i++) + for (int i = 0; i < MAX_MODELS; i++) { - Q_snprintf(localmodels[i], 5u, "*%i", i); + Q_snprintf(localmodels[i], sizeof(localmodels[i]), "*%i", i); } g_psvs.isSecure = FALSE; diff --git a/rehlds/engine/sys_dll.cpp b/rehlds/engine/sys_dll.cpp index fe7fd26..e48603e 100644 --- a/rehlds/engine/sys_dll.cpp +++ b/rehlds/engine/sys_dll.cpp @@ -76,7 +76,7 @@ qboolean g_bPrintingKeepAliveDots; qboolean gHasMMXTechnology; #endif // _WIN32 //volatile int sys_checksum; -//char *argv[50]; +//char *argv[MAX_NUM_ARGVS]; qboolean con_debuglog; #ifdef REHLDS_FIXES diff --git a/rehlds/msvc/ReHLDS.vcxproj b/rehlds/msvc/ReHLDS.vcxproj index 425a745..e2d3e68 100644 --- a/rehlds/msvc/ReHLDS.vcxproj +++ b/rehlds/msvc/ReHLDS.vcxproj @@ -343,6 +343,7 @@ + diff --git a/rehlds/msvc/ReHLDS.vcxproj.filters b/rehlds/msvc/ReHLDS.vcxproj.filters index 29382ae..6991b59 100644 --- a/rehlds/msvc/ReHLDS.vcxproj.filters +++ b/rehlds/msvc/ReHLDS.vcxproj.filters @@ -1065,6 +1065,9 @@ rehlds + + common + diff --git a/rehlds/public/rehlds/common_rehlds.h b/rehlds/public/rehlds/common_rehlds.h index 6bd6833..c0004a8 100644 --- a/rehlds/public/rehlds/common_rehlds.h +++ b/rehlds/public/rehlds/common_rehlds.h @@ -28,6 +28,7 @@ #pragma once #include "const.h" +#include "qlimits.h" #ifdef REHLDS_FIXES #define COM_TOKEN_LEN 2048 diff --git a/rehlds/public/rehlds/custom.h b/rehlds/public/rehlds/custom.h index 1bbd85d..190d769 100644 --- a/rehlds/public/rehlds/custom.h +++ b/rehlds/public/rehlds/custom.h @@ -18,6 +18,7 @@ #include "const.h" #define MAX_QPATH 64 // Must match value in quakedefs.h +#define MAX_RESOURCE_LIST 1280 ///////////////// // Customization diff --git a/rehlds/public/rehlds/rehlds_api.h b/rehlds/public/rehlds/rehlds_api.h index 5ae051b..f16d6bc 100644 --- a/rehlds/public/rehlds/rehlds_api.h +++ b/rehlds/public/rehlds/rehlds_api.h @@ -149,6 +149,10 @@ typedef IHookChainRegistry IRehldsHoo typedef IVoidHookChain IRehldsHook_SV_DropClient; typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_DropClient; +//SV_ActivateServer hook +typedef IVoidHookChain IRehldsHook_SV_ActivateServer; +typedef IVoidHookChainRegistry IRehldsHookRegistry_SV_ActivateServer; + class IRehldsHookchains { public: virtual ~IRehldsHookchains() { } @@ -181,6 +185,7 @@ public: virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate() = 0; virtual IRehldsHookRegistry_SV_CheckConsistencyResponce* SV_CheckConsistencyResponce() = 0; virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient() = 0; + virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer() = 0; }; struct RehldsFuncs_t { diff --git a/rehlds/public/rehlds/rehlds_interfaces.h b/rehlds/public/rehlds/rehlds_interfaces.h index 9d5de98..efcbd83 100644 --- a/rehlds/public/rehlds/rehlds_interfaces.h +++ b/rehlds/public/rehlds/rehlds_interfaces.h @@ -115,4 +115,6 @@ public: virtual void SetModelName(const char* modelname) = 0; virtual void SetConsistencyNum(int num) = 0; virtual int GetConsistencyNum() = 0; + virtual int GetResourcesNum() = 0; + virtual int GetDecalNameNum() = 0; }; diff --git a/rehlds/rehlds/rehlds_api_impl.cpp b/rehlds/rehlds/rehlds_api_impl.cpp index 229cafc..a1790ea 100644 --- a/rehlds/rehlds/rehlds_api_impl.cpp +++ b/rehlds/rehlds/rehlds_api_impl.cpp @@ -268,6 +268,10 @@ IRehldsHookRegistry_SV_DropClient* CRehldsHookchains::SV_DropClient() { return &m_SV_DropClient; } +IRehldsHookRegistry_SV_ActivateServer* CRehldsHookchains::SV_ActivateServer() { + return &m_SV_ActivateServer; +} + int EXT_FUNC CRehldsApi::GetMajorVersion() { return REHLDS_API_VERSION_MAJOR; diff --git a/rehlds/rehlds/rehlds_api_impl.h b/rehlds/rehlds/rehlds_api_impl.h index e5d1e78..bbad6f3 100644 --- a/rehlds/rehlds/rehlds_api_impl.h +++ b/rehlds/rehlds/rehlds_api_impl.h @@ -143,6 +143,10 @@ typedef IHookChainRegistryImpl CRehld typedef IVoidHookChainImpl CRehldsHook_SV_DropClient; typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_SV_DropClient; +//SV_ActivateServer hook +typedef IVoidHookChainImpl CRehldsHook_SV_ActivateServer; +typedef IVoidHookChainRegistryImpl CRehldsHookRegistry_SV_ActivateServer; + class CRehldsHookchains : public IRehldsHookchains { public: CRehldsHookRegistry_Steam_NotifyClientConnect m_Steam_NotifyClientConnect; @@ -173,6 +177,7 @@ public: CRehldsHookRegistry_SV_WriteFullClientUpdate m_SV_WriteFullClientUpdate; CRehldsHookRegistry_SV_CheckConsistencyResponce m_SV_CheckConsistencyResponce; CRehldsHookRegistry_SV_DropClient m_SV_DropClient; + CRehldsHookRegistry_SV_ActivateServer m_SV_ActivateServer; public: virtual IRehldsHookRegistry_Steam_NotifyClientConnect* Steam_NotifyClientConnect(); @@ -203,6 +208,7 @@ public: virtual IRehldsHookRegistry_SV_WriteFullClientUpdate* SV_WriteFullClientUpdate(); virtual IRehldsHookRegistry_SV_CheckConsistencyResponce* SV_CheckConsistencyResponce(); virtual IRehldsHookRegistry_SV_DropClient* SV_DropClient(); + virtual IRehldsHookRegistry_SV_ActivateServer* SV_ActivateServer(); }; extern CRehldsHookchains g_RehldsHookchains; diff --git a/rehlds/rehlds/rehlds_interfaces_impl.cpp b/rehlds/rehlds/rehlds_interfaces_impl.cpp index 8a532aa..9fc85cc 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.cpp +++ b/rehlds/rehlds/rehlds_interfaces_impl.cpp @@ -199,6 +199,14 @@ int EXT_FUNC CRehldsServerData::GetConsistencyNum() { return g_psv.num_consistency; } +int EXT_FUNC CRehldsServerData::GetResourcesNum() { + return g_psv.num_resources; +} + +int EXT_FUNC CRehldsServerData::GetDecalNameNum() { + return sv_decalnamecount; +} + void Rehlds_Interfaces_FreeClients() { if (g_GameClients == NULL) diff --git a/rehlds/rehlds/rehlds_interfaces_impl.h b/rehlds/rehlds/rehlds_interfaces_impl.h index cdc99e6..61da653 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.h +++ b/rehlds/rehlds/rehlds_interfaces_impl.h @@ -101,6 +101,8 @@ public: virtual void SetModelName(const char* modelname); virtual void SetConsistencyNum(int num); virtual int GetConsistencyNum(); + virtual int GetResourcesNum(); + virtual int GetDecalNameNum(); }; extern CGameClient** g_GameClients;