From 14de272dbbcadf29f170d5c332c6b3469a646199 Mon Sep 17 00:00:00 2001 From: Esco Date: Sun, 17 May 2026 01:01:49 +0200 Subject: [PATCH] fix: fix double chat message from amxxmod --- PugMod/PugClientCmd.cpp | 5 ++ PugMod/PugStats.cpp | 103 ++++++++++------------------------------ PugMod/PugStats.h | 2 +- 3 files changed, 32 insertions(+), 78 deletions(-) diff --git a/PugMod/PugClientCmd.cpp b/PugMod/PugClientCmd.cpp index 9ddc4da..3a2a64e 100644 --- a/PugMod/PugClientCmd.cpp +++ b/PugMod/PugClientCmd.cpp @@ -113,6 +113,11 @@ bool CPugClientCmd::Command(edict_t *pEntity) { gPugUtil.ClientCommand(pEntity, "%s\n", CMD_ARGS()); return true; } + + // Log all-chat messages to stats (say only, not say_team) + if (_stricmp(pszCommand, "say") == 0) { + gPugStats.LogChat(Player, pszArgv); + } } } else { auto pCmd = this->Get(pszCommand); diff --git a/PugMod/PugStats.cpp b/PugMod/PugStats.cpp index a3ade6e..10a60b1 100644 --- a/PugMod/PugStats.cpp +++ b/PugMod/PugStats.cpp @@ -13,8 +13,6 @@ void CPugStats::ServerActivate() // Round events this->m_RoundEvent.clear(); - // Register Say Text messages - gPugEngine.RegisterHook("SayText", this->SayText); } void CPugStats::SetState() @@ -912,86 +910,37 @@ void CPugStats::ExplodeBomb(CGrenade* pThis, TraceResult* ptr, int bitsDamageTyp } } -bool CPugStats::SayText(int msg_dest, int msg_type, const float* pOrigin, edict_t* pEntity) +void CPugStats::LogChat(CBasePlayer* Player, const char* Text) { - // If has entity target - if (!FNullEnt(pEntity)) - { - // Get CBasePlayer data - auto Player = UTIL_PlayerByIndexSafe(ENTINDEX(pEntity)); + if (!Player || !Text || Text[0] == '\0') + return; - // If is not null - if (Player) - { - // If is in game - if ((Player->m_iTeam == TERRORIST) || (Player->m_iTeam == CT)) - { - // Get argument 1 - auto Format = gPugEngine.GetString(1); + // Only log while a match is active + auto State = gPugMod.GetState(); - // If is not empty - if (Format) - { - // Get argument 3 - auto TextMsg = gPugEngine.GetString(3); + if (State == STATE_DEAD) + return; - // If is not empty - if (TextMsg) - { - // If is chat for all or for all dead - if (!Q_stricmp("#Cstrike_Chat_All", Format) || !Q_stricmp("#Cstrike_Chat_AllDead", Format)) - { - // Get State - auto State = gPugMod.GetState(); - - // If match is running - if (State != STATE_DEAD) - { - // If player is not null - if (Player) - { - // If text is not null - if (TextMsg) - { - // Get player auth - auto Auth = gPugStats.GetAuthId(Player); - - // If is not null - if (Auth) - { - // Chat struct - P_PLAYER_CHAT Chat = { }; - - // Set time - Chat.Time = time(NULL); - - // Set match state - Chat.State = State; - - // Set team - Chat.Team = static_cast(Player->m_iTeam); - - // Player is alive - Chat.Alive = Player->IsAlive() ? 1 : 0; - - // Set message - Chat.Message = TextMsg; - - // Push to vector - gPugStats.m_Player[Auth].ChatLog.push_back(Chat); - } - } - } - } - } - } - } - } - } - } + // Only log players in a team + if ((Player->m_iTeam != TERRORIST) && (Player->m_iTeam != CT)) + return; + + // Get player auth + auto Auth = gPugStats.GetAuthId(Player); + + if (!Auth) + return; + + // Build chat entry + P_PLAYER_CHAT Chat = { }; + + Chat.Time = time(NULL); + Chat.State = State; + Chat.Team = static_cast(Player->m_iTeam); + Chat.Alive = Player->IsAlive() ? 1 : 0; + Chat.Message = Text; - // Do not block original message call - return false; + gPugStats.m_Player[Auth].ChatLog.push_back(Chat); } void CPugStats::OnEvent(GameEventType event, int ScenarioEvent, CBaseEntity* pEntity, class CBaseEntity* pEntityOther) diff --git a/PugMod/PugStats.h b/PugMod/PugStats.h index 6839c05..f276e29 100644 --- a/PugMod/PugStats.h +++ b/PugMod/PugStats.h @@ -372,7 +372,7 @@ class CPugStats void DefuseBombStart(CBasePlayer* Player); void DefuseBombEnd(CBasePlayer* Player, bool Defused); void ExplodeBomb(CGrenade* pThis, TraceResult* ptr, int bitsDamageType); - static bool SayText(int msg_dest, int msg_type, const float* pOrigin, edict_t* pEntity); + void LogChat(CBasePlayer* Player, const char* Text); void OnEvent(GameEventType event, int ScenarioEvent, CBaseEntity* pEntity, CBaseEntity* pEntityOther); void DumpData(); void SaveData(nlohmann::json Data);