[Chat] Fix logic error in chat code (#547)
This commit is contained in:
parent
474bac78eb
commit
ed3217794e
@ -29,23 +29,35 @@ namespace Components
|
||||
// Prevent callbacks from adding a new callback (would make the vector iterator invalid)
|
||||
CanAddCallback = false;
|
||||
|
||||
if (text[1] == '/')
|
||||
// Chat messages sent through the console do not begin with \x15
|
||||
auto msgIndex = 0;
|
||||
if (text[msgIndex] == '\x15')
|
||||
{
|
||||
msgIndex = 1;
|
||||
}
|
||||
|
||||
if (text[msgIndex] == '/')
|
||||
{
|
||||
SendChat = false;
|
||||
text[1] = text[0];
|
||||
|
||||
if (msgIndex == 1)
|
||||
{
|
||||
// Overwrite / with \x15
|
||||
text[msgIndex] = text[msgIndex - 1];
|
||||
}
|
||||
// Skip over the first character
|
||||
++text;
|
||||
}
|
||||
|
||||
if (IsMuted(player))
|
||||
{
|
||||
SendChat = false;
|
||||
Game::SV_GameSendServerCommand(player - Game::g_entities, Game::SV_CMD_CAN_IGNORE,
|
||||
Utils::String::VA("%c \"You are muted\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(player - Game::g_entities, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"You are muted\"", 0x65));
|
||||
}
|
||||
|
||||
for (const auto& callback : SayCallbacks)
|
||||
{
|
||||
if (!ChatCallback(player, callback.getPos(), (text + 1), mode))
|
||||
if (!ChatCallback(player, callback.getPos(), (text + msgIndex), mode))
|
||||
{
|
||||
SendChat = false;
|
||||
}
|
||||
@ -54,14 +66,13 @@ namespace Components
|
||||
if (sv_disableChat.get<bool>())
|
||||
{
|
||||
SendChat = false;
|
||||
Game::SV_GameSendServerCommand(player - Game::g_entities, Game::SV_CMD_CAN_IGNORE,
|
||||
Utils::String::VA("%c \"Chat is disabled\"", 0x65));
|
||||
Game::SV_GameSendServerCommand(player - Game::g_entities, Game::SV_CMD_CAN_IGNORE, Utils::String::VA("%c \"Chat is disabled\"", 0x65));
|
||||
}
|
||||
|
||||
TextRenderer::StripMaterialTextIcons(text, text, strlen(text) + 1);
|
||||
TextRenderer::StripMaterialTextIcons(text, text, std::strlen(text) + 1);
|
||||
|
||||
Game::Scr_AddEntity(player);
|
||||
Game::Scr_AddString(text + 1);
|
||||
Game::Scr_AddString(text + msgIndex);
|
||||
Game::Scr_NotifyLevel(Game::SL_GetString("say", 0), 2);
|
||||
|
||||
return text;
|
||||
|
@ -441,7 +441,7 @@ namespace Components
|
||||
|
||||
const auto* value = &Game::scrVmPub->top[-index];
|
||||
|
||||
if (value->type != Game::scrParamType_t::VAR_FUNCTION)
|
||||
if (value->type != Game::VAR_FUNCTION)
|
||||
{
|
||||
Game::Scr_ParamError(static_cast<unsigned int>(index), "^1GetCodePosForParam: Expects a function as parameter!\n");
|
||||
return "";
|
||||
|
@ -1260,7 +1260,7 @@ namespace Components
|
||||
return result;
|
||||
}
|
||||
|
||||
void TextRenderer::StripColors(const char* in, char* out, size_t max)
|
||||
void TextRenderer::StripColors(const char* in, char* out, std::size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
@ -1287,12 +1287,12 @@ namespace Components
|
||||
|
||||
std::string TextRenderer::StripColors(const std::string& in)
|
||||
{
|
||||
char buffer[1024] = {0}; // 1024 is a lucky number in the engine
|
||||
char buffer[1024]{}; // 1024 is a lucky number in the engine
|
||||
StripColors(in.data(), buffer, sizeof(buffer));
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
void TextRenderer::StripMaterialTextIcons(const char* in, char* out, size_t max)
|
||||
void TextRenderer::StripMaterialTextIcons(const char* in, char* out, std::size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
@ -1339,7 +1339,7 @@ namespace Components
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
||||
void TextRenderer::StripAllTextIcons(const char* in, char* out, size_t max)
|
||||
void TextRenderer::StripAllTextIcons(const char* in, char* out, std::size_t max)
|
||||
{
|
||||
if (!in || !out) return;
|
||||
|
||||
|
@ -202,11 +202,11 @@ namespace Components
|
||||
static void DrawText2D(const char* text, float x, float y, Game::Font_s* font, float xScale, float yScale, float sinAngle, float cosAngle, Game::GfxColor color, int maxLength, int renderFlags, int cursorPos, char cursorLetter, float padding, Game::GfxColor glowForcedColor, int fxBirthTime, int fxLetterTime, int fxDecayStartTime, int fxDecayDuration, Game::Material* fxMaterial, Game::Material* fxMaterialGlow);
|
||||
static int R_TextWidth_Hk(const char* text, int maxChars, Game::Font_s* font);
|
||||
static unsigned int ColorIndex(char index);
|
||||
static void StripColors(const char* in, char* out, size_t max);
|
||||
static void StripColors(const char* in, char* out, std::size_t max);
|
||||
static std::string StripColors(const std::string& in);
|
||||
static void StripMaterialTextIcons(const char* in, char* out, size_t max);
|
||||
static void StripMaterialTextIcons(const char* in, char* out, std::size_t max);
|
||||
static std::string StripMaterialTextIcons(const std::string& in);
|
||||
static void StripAllTextIcons(const char* in, char* out, size_t max);
|
||||
static void StripAllTextIcons(const char* in, char* out, std::size_t max);
|
||||
static std::string StripAllTextIcons(const std::string& in);
|
||||
|
||||
static bool IsFontIcon(const char*& text, FontIconInfo& fontIcon);
|
||||
|
@ -5475,7 +5475,7 @@ namespace Game
|
||||
char buf[1];
|
||||
};
|
||||
|
||||
enum scrParamType_t
|
||||
enum
|
||||
{
|
||||
VAR_UNDEFINED = 0x0,
|
||||
VAR_BEGIN_REF = 0x1,
|
||||
@ -5509,7 +5509,7 @@ namespace Game
|
||||
VAR_ENDON_LIST = 0x1B,
|
||||
};
|
||||
|
||||
enum $2441F0C7E439C64E6C27842ECB570A7C
|
||||
enum
|
||||
{
|
||||
FIRST_OBJECT = 0x10,
|
||||
FIRST_CLEARABLE_OBJECT = 0x14,
|
||||
@ -5535,7 +5535,7 @@ namespace Game
|
||||
struct VariableValue
|
||||
{
|
||||
VariableUnion u;
|
||||
scrParamType_t type;
|
||||
int type;
|
||||
};
|
||||
|
||||
struct function_stack_t
|
||||
|
Loading…
Reference in New Issue
Block a user