Skip to content

Commit 38bebf3

Browse files
committed
Include recent VC users in !voicechat as well
1 parent 5516223 commit 38bebf3

3 files changed

Lines changed: 58 additions & 34 deletions

File tree

src/commands.cpp

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -750,48 +750,76 @@ CON_COMMAND_F(cs2f_fullupdate, "- Force a full update for all clients.", FCVAR_L
750750
g_playerManager->FullUpdateAllClients();
751751
}
752752

753+
void VoiceChatPrintPlayer(CCSPlayerController* player, int slot)
754+
{
755+
CCSPlayerController* pController = CCSPlayerController::FromSlot(slot);
756+
ZEPlayer* pPlayer = g_playerManager->GetPlayer(slot);
757+
758+
bool bSteamIDAuthed = pPlayer->IsAuthenticated();
759+
uint64 uSteamID = bSteamIDAuthed ? pPlayer->GetSteamId64() : pPlayer->GetUnauthenticatedSteamId64();
760+
std::string strPlayerName = pController->GetPlayerName();
761+
CPlayerUserId userId = g_pEngineServer2->GetPlayerUserId(slot);
762+
763+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "\x04%s \x06[#%hu] \x05[%llu%s\x05]", strPlayerName.c_str(), userId, uSteamID, bSteamIDAuthed ? "" : " \x02(No Auth)");
764+
765+
if (player)
766+
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "%s [#%hu] [%llu%s]", strPlayerName.c_str(), userId, uSteamID, bSteamIDAuthed ? "" : " (No Auth)");
767+
}
768+
753769
void VoiceChatPrintCmd(const CCommand& args, CCSPlayerController* player)
754770
{
755771
if (!GetGlobals()) return;
756772

757773
std::vector<int> vecActivePlayers;
774+
std::vector<std::pair<int, float>> vecRecentPlayers;
775+
758776
for (int i = 0; i < GetGlobals()->maxClients; i++)
759777
{
760778
ZEPlayer* pPlayer = g_playerManager->GetPlayer(i);
761779

762-
if (pPlayer && !pPlayer->GetVoiceTimer().expired())
780+
if (!pPlayer)
781+
continue;
782+
783+
float flLastVoiceTime = pPlayer->GetLastVoiceTime();
784+
785+
if (flLastVoiceTime + 0.3f > GetGlobals()->curtime)
786+
{
763787
vecActivePlayers.push_back(i);
788+
}
789+
else if (flLastVoiceTime + 15.0f > GetGlobals()->curtime)
790+
{
791+
auto iter = std::lower_bound(vecRecentPlayers.begin(), vecRecentPlayers.end(), flLastVoiceTime, [](const std::pair<int, float>& recentPlayer, float flCompareVoiceTime) {
792+
return recentPlayer.second < flCompareVoiceTime;
793+
});
794+
795+
vecRecentPlayers.insert(iter, {i, flLastVoiceTime});
796+
}
764797
}
765798

766-
if (vecActivePlayers.empty())
799+
if (vecActivePlayers.empty() && vecRecentPlayers.empty())
767800
{
768-
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "There are no players currently using voice chat.");
801+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "No players have recently used the voice chat.");
769802
return;
770803
}
771804

772-
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "List of players using voice chat:");
773-
if (player)
774-
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "List of players using voice chat:");
805+
if (!vecRecentPlayers.empty())
806+
{
807+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Players who recently used voice chat:");
808+
if (player)
809+
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "Players who recently used voice chat:");
810+
811+
for (const auto& recentPlayer : vecRecentPlayers)
812+
VoiceChatPrintPlayer(player, recentPlayer.first);
813+
}
775814

776-
for (const auto& slot : vecActivePlayers)
815+
if (!vecActivePlayers.empty())
777816
{
778-
CCSPlayerController* pController = CCSPlayerController::FromSlot(slot);
779-
ZEPlayer* pPlayer = g_playerManager->GetPlayer(slot);
780-
781-
bool bSteamIDAuthed = pPlayer->IsAuthenticated();
782-
uint64 uSteamID = bSteamIDAuthed ? pPlayer->GetSteamId64() : pPlayer->GetUnauthenticatedSteamId64();
783-
784-
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "\x04%s \x06[#%hu] \x05[%llu%s\x05]",
785-
pController->GetPlayerName().c_str(),
786-
g_pEngineServer2->GetPlayerUserId(slot),
787-
uSteamID,
788-
bSteamIDAuthed ? "" : " \x02(No Auth)");
789-
if (!player) continue;
790-
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "%s [#%hu] [%llu%s]",
791-
pController->GetPlayerName().c_str(),
792-
g_pEngineServer2->GetPlayerUserId(slot),
793-
uSteamID,
794-
bSteamIDAuthed ? "" : " (No Auth)");
817+
ClientPrint(player, HUD_PRINTTALK, CHAT_PREFIX "Players using voice chat:");
818+
if (player)
819+
ClientPrint(player, HUD_PRINTCONSOLE, CHAT_PREFIX "Players using voice chat:");
820+
821+
for (int slot : vecActivePlayers)
822+
VoiceChatPrintPlayer(player, slot);
795823
}
796824
}
797825

src/cs2fixes.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,19 +1235,15 @@ bool CS2Fixes::Hook_ProcessVoiceData(const CCLCMsg_VoiceData_t& msg)
12351235
{
12361236
CServerSideClient* client = META_IFACEPTR(CServerSideClient);
12371237

1238-
if (!client)
1238+
if (!client || !GetGlobals())
12391239
RETURN_META_VALUE(MRES_IGNORED, true);
12401240

12411241
ZEPlayer* pPlayer = g_playerManager->GetPlayer(client->GetPlayerSlot());
12421242

12431243
if (!pPlayer)
12441244
RETURN_META_VALUE(MRES_IGNORED, true);
12451245

1246-
// logic following sourcemod's implementation of OnClientSpeaking
1247-
if (auto timer = pPlayer->GetVoiceTimer().lock())
1248-
timer->Cancel();
1249-
1250-
pPlayer->SetVoiceTimer(CTimer::Create(0.3f, TIMERFLAG_NONE, []() { return -1.0f; }));
1246+
pPlayer->SetLastVoiceTime(GetGlobals()->curtime);
12511247

12521248
RETURN_META_VALUE(MRES_IGNORED, true);
12531249
}

src/playermanager.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#pragma once
2121
#include "bitvec.h"
2222
#include "common.h"
23-
#include "ctimer.h"
2423
#include "entity/cparticlesystem.h"
2524
#include "entity/cpointorient.h"
2625
#include "entity/cpointworldtext.h"
@@ -200,6 +199,7 @@ class ZEPlayer
200199
m_flEntwatchHudY = -2.0f;
201200
m_flEntwatchHudSize = 60.0f;
202201
m_bTopDefender = false;
202+
m_flLastVoiceTime = -15.0f;
203203
m_flBeaconEnabledTime = -2.0f;
204204
}
205205

@@ -272,7 +272,7 @@ class ZEPlayer
272272
void SetEntwatchHudPos(float x, float y);
273273
void SetEntwatchHudSize(float flSize);
274274
void SetTopDefenderStatus(bool bStatus) { m_bTopDefender = bStatus; }
275-
void SetVoiceTimer(std::weak_ptr<CTimer> timer) { m_pVoiceTimer = timer; }
275+
void SetLastVoiceTime(float flTime) { m_flLastVoiceTime = flTime; }
276276
void SetBeaconEnabledTime(float flTime) { m_flBeaconEnabledTime = flTime; }
277277

278278
uint64 GetAdminFlags() { return m_iAdminFlags; }
@@ -324,7 +324,7 @@ class ZEPlayer
324324
float GetEntwatchHudY() { return m_flEntwatchHudY; }
325325
float GetEntwatchHudSize() { return m_flEntwatchHudSize; }
326326
bool GetTopDefenderStatus() { return m_bTopDefender; }
327-
std::weak_ptr<CTimer> GetVoiceTimer() { return m_pVoiceTimer; }
327+
float GetLastVoiceTime() { return m_flLastVoiceTime; }
328328
float GetBeaconEnabledTime() { return m_flBeaconEnabledTime; }
329329

330330
void OnSpawn();
@@ -400,7 +400,7 @@ class ZEPlayer
400400
float m_flEntwatchHudY;
401401
float m_flEntwatchHudSize;
402402
bool m_bTopDefender;
403-
std::weak_ptr<CTimer> m_pVoiceTimer;
403+
float m_flLastVoiceTime;
404404
float m_flBeaconEnabledTime;
405405
};
406406

0 commit comments

Comments
 (0)