Skip to content

Commit

Permalink
Merge branch 'dreamstalker:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathan-up authored Jul 13, 2024
2 parents 20096bf + 9c1e843 commit c7f87bd
Show file tree
Hide file tree
Showing 25 changed files with 1,690 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ This means that plugins that do binary code analysis (Orpheu for example) probab
<li>sv_net_incoming_decompression_max_size <16|65536> // Sets the max allowed size for decompressed file transfer data. Default: 65536 bytes
<li>sv_net_incoming_decompression_punish // Time in minutes for which the player will be banned for malformed/abnormal bzip2 fragments (0 - Permanent, use a negative number for a kick). Default: -1
<li>sv_tags &lt;comma-delimited string list of tags&gt; // Sets a string defining the "gametags" for this server, this is optional, but if it is set it allows users/scripts to filter in the matchmaking/server-browser interfaces based on the value. Default: ""
<li>sv_filterban &lt;-1|0|1&gt;// Set packet filtering by IP mode. -1 - All players will be rejected without any exceptions. 0 - No checks will happen. 1 - All incoming players will be checked if they're IP banned (if they have an IP filter entry), if they are, they will be kicked. Default: 1
</ul>
</details>

Expand Down
1 change: 1 addition & 0 deletions rehlds/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ set(ENGINE_SRCS
rehlds/public_amalgamation.cpp
rehlds/rehlds_api_impl.cpp
rehlds/rehlds_interfaces_impl.cpp
rehlds/rehlds_messagemngr_impl.cpp
rehlds/rehlds_security.cpp
)

Expand Down
3 changes: 3 additions & 0 deletions rehlds/common/quakedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@

typedef int BOOL;

// The maximum user messages
#define MAX_USERMESSAGES 256

// user message
#define MAX_USER_MSG_DATA 192

Expand Down
3 changes: 2 additions & 1 deletion rehlds/engine/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ void EXT_FUNC SV_ClientPrintf_internal(const char *Dest)
{
char string[1024];

Q_strlcpy(string, Dest, min(strlen(Dest) + 1, sizeof(string)));
Q_strlcpy(string, Dest);

MSG_WriteByte(&host_client->netchan.message, svc_print);
MSG_WriteString(&host_client->netchan.message, string);
}
Expand Down
2 changes: 1 addition & 1 deletion rehlds/engine/net_chan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cvar_t net_drawslider = { "net_drawslider", "0", 0, 0.0f, nullptr};
cvar_t net_chokeloopback = { "net_chokeloop", "0", 0, 0.0f, nullptr};

cvar_t sv_net_incoming_decompression = { "sv_net_incoming_decompression", "1", 0, 1.0f, nullptr };
cvar_t sv_net_incoming_decompression_max_ratio = { "sv_net_incoming_decompression_max_ratio", "75.0", 0, 75.0f, nullptr };
cvar_t sv_net_incoming_decompression_max_ratio = { "sv_net_incoming_decompression_max_ratio", "80.0", 0, 80.0f, nullptr };
cvar_t sv_net_incoming_decompression_max_size = { "sv_net_incoming_decompression_max_size", "65536", 0, 65536.0f, nullptr };
cvar_t sv_net_incoming_decompression_punish = { "sv_net_incoming_decompression_punish", "-1", 0, -1.0f, NULL };

Expand Down
5 changes: 3 additions & 2 deletions rehlds/engine/pr_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
8 changes: 1 addition & 7 deletions rehlds/engine/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,6 @@ typedef enum redirect_e
RD_PACKET = 2,
} redirect_t;

typedef enum server_state_e
{
ss_dead = 0,
ss_loading = 1,
ss_active = 2,
} server_state_t;

typedef struct server_s
{
qboolean active;
Expand Down Expand Up @@ -468,6 +461,7 @@ void SV_QueryMovevarsChanged(void);
void SV_SendServerinfo(sizebuf_t *msg, client_t *client);
void SV_SendServerinfo_internal(sizebuf_t *msg, client_t *client);
void SV_SendResources(sizebuf_t *msg);
void SV_SendResources_internal(sizebuf_t *msg);
void SV_WriteClientdataToMessage(client_t *client, sizebuf_t *msg);
void SV_WriteSpawn(sizebuf_t *msg);
void SV_SendUserReg(sizebuf_t *msg);
Expand Down
25 changes: 22 additions & 3 deletions rehlds/engine/sv_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,11 @@ void SV_SendServerinfo_internal(sizebuf_t *msg, client_t *client)
}

void SV_SendResources(sizebuf_t *msg)
{
g_RehldsHookchains.m_SV_SendResources.callChain(SV_SendResources_internal, msg);
}

void EXT_FUNC SV_SendResources_internal(sizebuf_t *msg)
{
unsigned char nullbuffer[32];
Q_memset(nullbuffer, 0, sizeof(nullbuffer));
Expand Down Expand Up @@ -3836,13 +3841,20 @@ void SV_ProcessFile(client_t *cl, char *filename)

qboolean SV_FilterPacket(void)
{
// sv_filterban filtering IP mode
// -1: all players will be rejected without any exceptions
// 0: no checks will happen
// 1: all incoming players will be checked if they're IP banned (if they have an IP filter entry), if they are, they will be kicked

qboolean bNegativeFilter = (sv_filterban.value == 1) ? TRUE : FALSE;

for (int i = numipfilters - 1; i >= 0; i--)
{
ipfilter_t* curFilter = &ipfilters[i];
if (curFilter->compare.u32 == 0xFFFFFFFF || curFilter->banEndTime == 0.0f || curFilter->banEndTime > realtime)
{
if ((*(uint32*)net_from.ip & curFilter->mask) == curFilter->compare.u32)
return (int)sv_filterban.value;
return bNegativeFilter;
}
else
{
Expand All @@ -3852,7 +3864,8 @@ qboolean SV_FilterPacket(void)
--numipfilters;
}
}
return sv_filterban.value == 0.0f;

return !bNegativeFilter;
}

void SV_SendBan(void)
Expand Down Expand Up @@ -6555,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;
Expand Down
3 changes: 1 addition & 2 deletions rehlds/engine/sv_upld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,13 @@ void SV_Customization(client_t *pPlayer, resource_t *pResource, qboolean bSkipPl
// Creates customizations list for the current player and sends resources to other players.
void SV_RegisterResources(void)
{
resource_t *pResource;
client_t *pHost = host_client;

pHost->uploading = FALSE;
#ifdef REHLDS_FIXES
SV_CreateCustomizationList(pHost); // FIXED: Call this function only once. It was crazy to call it for each resource available.
#else // REHLDS_FIXES
for (pResource = pHost->resourcesonhand.pNext; pResource != &pHost->resourcesonhand; pResource = pResource->pNext)
for (resource_t *pResource = pHost->resourcesonhand.pNext; pResource != &pHost->resourcesonhand; pResource = pResource->pNext)
{
SV_CreateCustomizationList(pHost);
SV_Customization(pHost, pResource, TRUE);
Expand Down
4 changes: 4 additions & 0 deletions rehlds/engine/sys_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,10 @@ void LoadThisDll(const char *szDllFilename)
goto IgnoreThisDLL;
}

#ifdef REHLDS_API
MessageManager().Init();
#endif

pfnGiveFnptrsToDll(&g_engfuncsExportedToDlls, &gGlobalVariables);
if (g_iextdllMac == MAX_EXTENSION_DLL)
{
Expand Down
5 changes: 4 additions & 1 deletion rehlds/engine/usermsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
3 changes: 3 additions & 0 deletions rehlds/msvc/ReHLDS.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<ClCompile Include="..\rehlds\FlightRecorderImpl.cpp" />
<ClCompile Include="..\rehlds\flight_recorder.cpp" />
<ClCompile Include="..\rehlds\main.cpp" />
<ClCompile Include="..\rehlds\rehlds_messagemngr_impl.cpp" />
<ClCompile Include="..\rehlds\rehlds_api_impl.cpp" />
<ClCompile Include="..\rehlds\rehlds_interfaces_impl.cpp" />
<ClCompile Include="..\rehlds\hookchains_impl.cpp" />
Expand Down Expand Up @@ -386,6 +387,7 @@
<ClInclude Include="..\public\rehlds\eiface.h" />
<ClInclude Include="..\public\rehlds\FlightRecorder.h" />
<ClInclude Include="..\public\rehlds\hookchains.h" />
<ClInclude Include="..\public\rehlds\IMessageManager.h" />
<ClInclude Include="..\public\rehlds\keydefs.h" />
<ClInclude Include="..\public\rehlds\maintypes.h" />
<ClInclude Include="..\public\rehlds\model.h" />
Expand Down Expand Up @@ -439,6 +441,7 @@
<ClInclude Include="..\rehlds\FlightRecorderImpl.h" />
<ClInclude Include="..\rehlds\flight_recorder.h" />
<ClInclude Include="..\rehlds\hookchains_impl.h" />
<ClInclude Include="..\rehlds\rehlds_messagemngr_impl.h" />
<ClInclude Include="..\rehlds\platform.h" />
<ClInclude Include="..\rehlds\precompiled.h" />
<ClInclude Include="..\rehlds\RehldsRuntimeConfig.h" />
Expand Down
9 changes: 9 additions & 0 deletions rehlds/msvc/ReHLDS.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@
<ClCompile Include="..\testsuite\memory.cpp">
<Filter>testsuite</Filter>
</ClCompile>
<ClCompile Include="..\rehlds\rehlds_messagemngr_impl.cpp">
<Filter>rehlds</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\version\version.h">
Expand Down Expand Up @@ -1060,5 +1063,11 @@
<ClInclude Include="..\testsuite\memory.h">
<Filter>testsuite</Filter>
</ClInclude>
<ClInclude Include="..\rehlds\rehlds_messagemngr_impl.h">
<Filter>rehlds</Filter>
</ClInclude>
<ClInclude Include="..\public\rehlds\IMessageManager.h">
<Filter>public\rehlds</Filter>
</ClInclude>
</ItemGroup>
</Project>
Loading

0 comments on commit c7f87bd

Please sign in to comment.