Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PugMod/PugClientCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
103 changes: 26 additions & 77 deletions PugMod/PugStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<int>(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<int>(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)
Expand Down
2 changes: 1 addition & 1 deletion PugMod/PugStats.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down