From a761efa75df820ebf5fb4899e863ce41fda099bd Mon Sep 17 00:00:00 2001 From: s1lentq Date: Mon, 13 May 2024 18:48:35 +0700 Subject: [PATCH] Minor cleanup --- rehlds/common/quakedef.h | 3 +++ rehlds/engine/pr_cmds.cpp | 5 +++-- rehlds/engine/sv_main.cpp | 8 +++++++- rehlds/engine/usermsg.h | 5 ++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/rehlds/common/quakedef.h b/rehlds/common/quakedef.h index 21f88e2..17f166d 100644 --- a/rehlds/common/quakedef.h +++ b/rehlds/common/quakedef.h @@ -29,6 +29,9 @@ typedef int BOOL; +// The maximum user messages +#define MAX_USERMESSAGES 256 + // user message #define MAX_USER_MSG_DATA 192 diff --git a/rehlds/engine/pr_cmds.cpp b/rehlds/engine/pr_cmds.cpp index dfd2846..d53a74b 100644 --- a/rehlds/engine/pr_cmds.cpp +++ b/rehlds/engine/pr_cmds.cpp @@ -2124,7 +2124,7 @@ void EXT_FUNC PF_MessageBegin_I(int msg_dest, int msg_type, const float *pOrigin if (msg_type == 0) Sys_Error("%s: Tried to create a message with a bogus message type ( 0 )", __func__); - gMsgStarted = 1; + gMsgStarted = TRUE; gMsgType = msg_type; gMsgEntity = ed; gMsgDest = msg_dest; @@ -2151,7 +2151,7 @@ void EXT_FUNC PF_MessageEnd_I(void) qboolean MsgIsVarLength = 0; if (!gMsgStarted) Sys_Error("%s: called with no active message\n", __func__); - gMsgStarted = 0; + gMsgStarted = FALSE; if (gMsgEntity && (gMsgEntity->v.flags & FL_FAKECLIENT)) return; @@ -2275,6 +2275,7 @@ void EXT_FUNC PF_WriteByte_I(int iValue) { if (!gMsgStarted) Sys_Error("%s: called with no active message\n", __func__); + MSG_WriteByte(&gMsgBuffer, iValue); } diff --git a/rehlds/engine/sv_main.cpp b/rehlds/engine/sv_main.cpp index c015f49..5dd76f2 100644 --- a/rehlds/engine/sv_main.cpp +++ b/rehlds/engine/sv_main.cpp @@ -6568,7 +6568,13 @@ void SV_ClearEntities(void) } int EXT_FUNC RegUserMsg(const char *pszName, int iSize) { - if (giNextUserMsg > 255 || !pszName || Q_strlen(pszName) > 11 || iSize > 192) + if (giNextUserMsg >= MAX_USERMESSAGES) + return 0; + + if (iSize > MAX_USER_MSG_DATA) + return 0; + + if (!pszName || Q_strlen(pszName) >= MAX_USERMESSAGES_LENGTH - 1) return 0; UserMsg *pUserMsgs = sv_gpUserMsgs; diff --git a/rehlds/engine/usermsg.h b/rehlds/engine/usermsg.h index ffff648..b752055 100644 --- a/rehlds/engine/usermsg.h +++ b/rehlds/engine/usermsg.h @@ -31,11 +31,14 @@ #include "maintypes.h" #include "quakedef.h" +// The maximum length of a usermessage name in a network transmission +#define MAX_USERMESSAGES_LENGTH 16 + typedef struct _UserMsg { int iMsg; int iSize; - char szName[16]; + char szName[MAX_USERMESSAGES_LENGTH]; struct _UserMsg *next; pfnUserMsgHook pfn; } UserMsg;