Skip to content

Commit

Permalink
Implement svc_exec support in the engine and HLTV (#737)
Browse files Browse the repository at this point in the history
* Added `svc_exec` to the list of svc commands in engine
* Added `svc_exec` support to HLTV code
* Made the engine code forward-compatible with future svc_* additions
* Added reserved svc_* slots in the enumerations
  • Loading branch information
WPMGPRoSToTeMa committed May 18, 2020
1 parent 7513e71 commit 987ee51
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 3 deletions.
20 changes: 20 additions & 0 deletions rehlds/HLTV/Core/src/Server.cpp
Expand Up @@ -89,6 +89,7 @@ Server::svc_func_s Server::m_ClientFuncs[]
{ svc_resourcelocation, "svc_resourcelocation", &Server::ParseResourceLocation },
{ svc_sendcvarvalue, "svc_sendcvarvalue", &Server::ParseSendCvarValue },
{ svc_sendcvarvalue2, "svc_sendcvarvalue2", &Server::ParseSendCvarValue2 },
{ svc_exec, "svc_exec", &Server::ParseExec },
{ svc_endoflist, "End of List", nullptr }
};

Expand Down Expand Up @@ -377,7 +378,12 @@ void Server::ProcessMessage(unsigned int seqNr)
break;
}

// With `HLTV_FIXES` enabled meaning of `svc_startofusermessages` changed a bit: now it is an id of the first user message
#ifdef HLTV_FIXES
if (cmd >= svc_startofusermessages)
#else // HLTV_FIXES
if (cmd > svc_startofusermessages)
#endif // HLTV_FIXES
{
if (!ParseUserMessage(cmd)) {
break;
Expand Down Expand Up @@ -2291,7 +2297,12 @@ void Server::Reset()
char *Server::GetCmdName(int cmd)
{
static char description[64];
// With `HLTV_FIXES` enabled meaning of `svc_startofusermessages` changed a bit: now it is an id of the first user message
#ifdef HLTV_FIXES
if (cmd >= svc_startofusermessages && m_World)
#else // HLTV_FIXES
if (cmd > svc_startofusermessages && m_World)
#endif // HLTV_FIXES
{
UserMsg *usermsg = m_World->GetUserMsg(cmd);
if (usermsg)
Expand Down Expand Up @@ -2345,6 +2356,15 @@ void Server::ParseSendCvarValue2()
char *name = m_Instream->ReadString();
}

void Server::ParseExec()
{
bool execClassScript = m_Instream->ReadByte() != 0;
if (execClassScript)
{
int scriptId = m_Instream->ReadByte();
}
}

void Server::ReceiveSignal(ISystemModule *module, unsigned int signal, void *data)
{
BaseSystemModule::ReceiveSignal(module, signal, data);
Expand Down
1 change: 1 addition & 0 deletions rehlds/HLTV/Core/src/Server.h
Expand Up @@ -216,6 +216,7 @@ class Server: public IServer, public BaseSystemModule {
void ParseResourceLocation();
void ParseSendCvarValue();
void ParseSendCvarValue2();
void ParseExec();

protected:
struct svc_func_s {
Expand Down
17 changes: 16 additions & 1 deletion rehlds/HLTV/common/net_internal.h
Expand Up @@ -159,10 +159,25 @@ enum svc_commands_e
svc_resourcelocation,
svc_sendcvarvalue,
svc_sendcvarvalue2,
svc_startofusermessages = svc_sendcvarvalue2,
svc_exec,
svc_reserve60,
svc_reserve61,
svc_reserve62,
svc_reserve63,
// Let's just use an id of the first user message instead of the last svc_*
// This change doesn't make the parsing code forward-compatible with future svc_* additions, but error-reporting should be better
#ifdef HLTV_FIXES
svc_startofusermessages = svc_reserve63 + 1,
#else // HLTV_FIXES
svc_startofusermessages = svc_exec,
#endif // HLTV_FIXES
svc_endoflist = 255,
};

#ifdef HLTV_FIXES
static_assert(svc_startofusermessages == 64, "svc_startofusermessages should be equal to 64 for backward and forward compatibility");
#endif // HLTV_FIXES

enum clc_commands : byte
{
clc_bad,
Expand Down
17 changes: 16 additions & 1 deletion rehlds/engine/net.h
Expand Up @@ -208,10 +208,25 @@ typedef enum svc_commands_e
svc_resourcelocation,
svc_sendcvarvalue,
svc_sendcvarvalue2,
svc_startofusermessages = svc_sendcvarvalue2,
svc_exec,
svc_reserve60,
svc_reserve61,
svc_reserve62,
svc_reserve63,
// Let's just use an id of the first user message instead of the last svc_*
// This change makes code in `PF_MessageEnd_I` forward-compatible with future svc_* additions
#ifdef REHLDS_FIXES
svc_startofusermessages = svc_reserve63 + 1,
#else // REHLDS_FIXES
svc_startofusermessages = svc_exec,
#endif // REHLDS_FIXES
svc_endoflist = 255,
} svc_commands_t;

#ifdef REHLDS_FIXES
static_assert(svc_startofusermessages == 64, "svc_startofusermessages should be equal to 64 for backward and forward compatibility");
#endif // REHLDS_FIXES

typedef enum clc_commands_e
{
clc_bad,
Expand Down
11 changes: 10 additions & 1 deletion rehlds/engine/pr_cmds.cpp
Expand Up @@ -2122,8 +2122,12 @@ void EXT_FUNC PF_MessageEnd_I(void)
if (gMsgBuffer.flags & SIZEBUF_OVERFLOWED)
Sys_Error("%s: called, but message buffer from .dll had overflowed\n", __func__);


// With `REHLDS_FIXES` enabled meaning of `svc_startofusermessages` changed a bit: now it is an id of the first user message
#ifdef REHLDS_FIXES
if (gMsgType >= svc_startofusermessages)
#else // REHLDS_FIXES
if (gMsgType > svc_startofusermessages)
#endif // REHLDS_FIXES
{
UserMsg* pUserMsg = sv_gpUserMsgs;
while (pUserMsg && pUserMsg->iMsg != gMsgType)
Expand Down Expand Up @@ -2164,7 +2168,12 @@ void EXT_FUNC PF_MessageEnd_I(void)
if ((gMsgDest == MSG_BROADCAST && gMsgBuffer.cursize + pBuffer->cursize > pBuffer->maxsize) || !pBuffer->data)
return;

// With `REHLDS_FIXES` enabled meaning of `svc_startofusermessages` changed a bit: now it is an id of the first user message
#ifdef REHLDS_FIXES
if (gMsgType >= svc_startofusermessages && (gMsgDest == MSG_ONE || gMsgDest == MSG_ONE_UNRELIABLE))
#else // REHLDS_FIXES
if (gMsgType > svc_startofusermessages && (gMsgDest == MSG_ONE || gMsgDest == MSG_ONE_UNRELIABLE))
#endif // REHLDS_FIXES
{
int entnum = NUM_FOR_EDICT((const edict_t *)gMsgEntity);
if (entnum < 1 || entnum > g_psvs.maxclients)
Expand Down
5 changes: 5 additions & 0 deletions rehlds/engine/sv_main.cpp
Expand Up @@ -105,7 +105,12 @@ qboolean allow_cheats;
char *gNullString = "";
int SV_UPDATE_BACKUP = SINGLEPLAYER_BACKUP;
int SV_UPDATE_MASK = (SINGLEPLAYER_BACKUP - 1);
// With `REHLDS_FIXES` enabled we can simply use `svc_startofusermessages` instead of the hard-coded constant
#ifdef REHLDS_FIXES
int giNextUserMsg = svc_startofusermessages;
#else // REHLDS_FIXES
int giNextUserMsg = 64;
#endif // REHLDS_FIXES

cvar_t sv_lan = { "sv_lan", "0", 0, 0.0f, NULL };
cvar_t sv_lan_rate = { "sv_lan_rate", "20000.0", 0, 0.0f, NULL };
Expand Down

0 comments on commit 987ee51

Please sign in to comment.