Implement 'SVC_UserMessage' print handler properly

Check if the actual message type is 'TextMsg' before printing, since other data is binary and could be read as 'HUD_PRINTCONSOLE', 'HUD_PRINTCENTER', etc.. resulting in printing binary data. This fix permanently solves that problem. The check has also been applied to the 'ShouldReplayMessage' function.
This commit is contained in:
Kawe Mazidjatari 2023-06-12 02:02:29 +02:00
parent 4290b08fd0
commit c874b7c4d8
3 changed files with 103 additions and 14 deletions

View File

@ -12,6 +12,7 @@
#include "tier1/cvar.h"
#include "engine/net.h"
#include "common/netmessages.h"
#include "game/shared/usermessages.h"
///////////////////////////////////////////////////////////////////////////////////
// re-implementation of 'SVC_Print::Process'
@ -39,21 +40,24 @@ bool SVC_Print::ProcessImpl()
///////////////////////////////////////////////////////////////////////////////////
bool SVC_UserMessage::ProcessImpl()
{
bf_read buf = m_DataIn;
int type = buf.ReadByte();
if (type == HUD_PRINTCONSOLE ||
type == HUD_PRINTCENTER)
if (m_nMsgType == UserMessages_t::TextMsg)
{
char text[MAX_USER_MSG_DATA];
int len;
bf_read buf = m_DataIn;
byte type = byte(buf.ReadByte());
buf.ReadString(text, sizeof(text), false, &len);
Assert(len < sizeof(text));
if (len >= NET_MIN_MESSAGE && len < sizeof(text))
if (type == HUD_PRINTCONSOLE ||
type == HUD_PRINTCENTER)
{
DevMsg(eDLL_T::SERVER, text[len-1] == '\n' ? "%s" : "%s\n", text);
char text[MAX_USER_MSG_DATA];
int len;
buf.ReadString(text, sizeof(text), false, &len);
Assert(len < sizeof(text));
if (len && len < sizeof(text))
{
DevMsg(eDLL_T::SERVER, text[len - 1] == '\n' ? "%s" : "%s\n", text);
}
}
}
@ -107,11 +111,26 @@ bool ShouldReplayMessage(const CNetMessage* msg)
// be broadcasted to the target client. This happens for the
// same reason as the 'net_StringCmd' above.
case NetMessageType::svc_Print:
case NetMessageType::svc_UserMessage:
{
return false;
default:
}
case NetMessageType::svc_UserMessage:
{
SVC_UserMessage* userMsg = (SVC_UserMessage*)msg;
// Just don't replay console prints.
if (userMsg->m_nMsgType == UserMessages_t::TextMsg)
{
return false;
}
return true;
}
default:
{
return true;
}
}
}
void V_NetMessages::Attach() const

View File

@ -21,6 +21,7 @@ add_sources( SOURCE_GROUP "Shared"
"shared/takedamageinfo.h"
"shared/usercmd.cpp"
"shared/usercmd.h"
"shared/usermessages.h"
"shared/util_shared.cpp"
"shared/util_shared.h"
"shared/vscript_shared.cpp"

View File

@ -0,0 +1,69 @@
#ifndef USERMESSAGES_H
#define USERMESSAGES_H
//-----------------------------------------------------------------------------
// Enumerated in the same order, as the order of registration in 'RegisterUserMessages' !!!
//-----------------------------------------------------------------------------
enum UserMessages_t
{
Geiger = 0,
Train,
HudText,
SayText,
AnnounceText,
TextMsg,
HudMsg,
ResetHUD,
ItemPickup,
ShowMenu,
Shake,
Fade,
VGUIMenu,
Rumble,
Damage,
VoiceMask,
RequestState,
WeapProjFireCB,
PredSVEvent,
CreditsMsg,
LogoTimeMsg,
AchievementEvent,
UpdateJalopyRadar,
CurrentTimescale,
DesiredTimescale,
CreditsPortalMsg,
InventoryFlash,
IndicatorFlash,
ControlHelperAnimate,
TakePhoto,
Flash,
HudPingIndicator,
OpenRadialMenu,
AddLocator,
MPMapCompleted,
MPMapIncomplete,
MPMapCompletedData,
MPTauntEarned,
MPTauntUnlocked,
MPTauntLocked,
MPAllTauntsLocked,
PortalFX_Surface,
ChangePaintColor,
StartSurvey,
ApplyHitBoxDamageEffect,
SetMixLayerTriggerFactor,
TransitionFade,
HudElemSetVisibility,
HudElemLabelSetText,
HudElemImageSet,
HudElemSetColor,
HudElemSetColorBG,
RemoteUntypedFunctionCall,
RemoteFunctionCall,
RemoteFunctionCallsChecksum,
PlayerNotifyDidDamage,
RemoteBulletFired,
RemoteWeaponReload,
};
#endif // USERMESSAGES_H