diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index 3e6144a0..b54bd47a 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -413,10 +413,12 @@ bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmi return true; } -#if SOURCE_ENGINE != SE_DOTA - edict_t *pEdict = PEntityOfEntIndex(client); -#endif - + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); + if (!pPlayer) + { + return false; + } + /* If we got here, the command failed... */ char buffer[128]; if (!logicore.CoreTranslate(buffer, sizeof(buffer), "%T", 2, NULL, "No Access", &client)) @@ -429,11 +431,7 @@ bool ConCmdManager::CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmi { char fullbuffer[192]; UTIL_Format(fullbuffer, sizeof(fullbuffer), "[SM] %s.\n", buffer); -#if SOURCE_ENGINE == SE_DOTA - engine->ClientPrintf(client, fullbuffer); -#else - engine->ClientPrintf(pEdict, fullbuffer); -#endif + pPlayer->PrintToConsole(fullbuffer); } else if (replyto == SM_REPLY_CHAT) { diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index ede00bfa..476747cc 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -843,11 +843,13 @@ void ClientConsolePrint(edict_t *e, const char *fmt, ...) buffer[len] = '\0'; } -#if SOURCE_ENGINE == SE_DOTA - engine->ClientPrintf(CEntityIndex(IndexOfEdict(e)), buffer); -#else - engine->ClientPrintf(e, buffer); -#endif + CPlayer *pPlayer = g_Players.GetPlayerByIndex(IndexOfEdict(e)); + if (!pPlayer) + { + return; + } + + pPlayer->PrintToConsole(buffer); } void ListExtensionsToClient(CPlayer *player, const CCommand &args) @@ -2323,3 +2325,23 @@ unsigned int CPlayer::GetSerial() { return m_Serial.value; } + +void CPlayer::PrintToConsole(const char *pMsg) +{ + if (m_IsConnected == false || m_bFakeClient == true) + { + return; + } + + INetChannel *pNetChan = static_cast(engine->GetPlayerNetInfo(m_iIndex)); + if (pNetChan == NULL) + { + return; + } + +#if SOURCE_ENGINE == SE_DOTA + engine->ClientPrintf(m_iIndex, pMsg); +#else + engine->ClientPrintf(m_pEdict, pMsg); +#endif +} diff --git a/core/PlayerManager.h b/core/PlayerManager.h index f88f080d..acb92d91 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -91,6 +91,7 @@ public: void NotifyPostAdminChecks(); unsigned int GetSerial(); int GetIndex() const; + void PrintToConsole(const char *pMsg); public: void DoBasicAdminChecks(); void MarkAsBeingKicked(); diff --git a/core/smn_console.cpp b/core/smn_console.cpp index 1ec22b2f..d90a58bf 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -884,11 +884,7 @@ static cell_t sm_PrintToConsole(IPluginContext *pCtx, const cell_t *params) if (index != 0) { -#if SOURCE_ENGINE == SE_DOTA - engine->ClientPrintf(pPlayer->GetIndex(), buffer); -#else - engine->ClientPrintf(pPlayer->GetEdict(), buffer); -#endif + pPlayer->PrintToConsole(buffer); } else { META_CONPRINT(buffer); } @@ -1200,11 +1196,7 @@ static cell_t ReplyToCommand(IPluginContext *pContext, const cell_t *params) { buffer[len++] = '\n'; buffer[len] = '\0'; -#if SOURCE_ENGINE == SE_DOTA - engine->ClientPrintf(pPlayer->GetIndex(), buffer); -#else - engine->ClientPrintf(pPlayer->GetEdict(), buffer); -#endif + pPlayer->PrintToConsole(buffer); } else if (replyto == SM_REPLY_CHAT) { if (len >= 191) { diff --git a/core/smn_player.cpp b/core/smn_player.cpp index d803c1d0..14c447e4 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -1118,11 +1118,7 @@ static cell_t _ShowActivity(IPluginContext *pContext, } UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); -#if SOURCE_ENGINE == SE_DOTA - engine->ClientPrintf(pPlayer->GetIndex(), message); -#else - engine->ClientPrintf(pPlayer->GetEdict(), message); -#endif + pPlayer->PrintToConsole(message); display_in_chat = true; } } @@ -1248,20 +1244,8 @@ static cell_t _ShowActivity2(IPluginContext *pContext, * simply gets added to the console, so we don't want it to print * twice. */ - if (replyto == SM_REPLY_CONSOLE) - { -#if 0 - UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); - engine->ClientPrintf(pPlayer->GetEdict(), message); -#endif - UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); - g_HL2.TextMsg(client, HUD_PRINTTALK, message); - } - else - { - UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); - g_HL2.TextMsg(client, HUD_PRINTTALK, message); - } + UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); + g_HL2.TextMsg(client, HUD_PRINTTALK, message); } else { diff --git a/public/IPlayerHelpers.h b/public/IPlayerHelpers.h index ec4ce5de..95d9904f 100644 --- a/public/IPlayerHelpers.h +++ b/public/IPlayerHelpers.h @@ -41,7 +41,7 @@ #include #define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager" -#define SMINTERFACE_PLAYERMANAGER_VERSION 18 +#define SMINTERFACE_PLAYERMANAGER_VERSION 19 struct edict_t; class IPlayerInfo; @@ -253,6 +253,13 @@ namespace SourceMod * @return Client's index. */ virtual int GetIndex() const =0; + + /** + * @brief Prints a string to the client console. + * + * @param pMsg String to print. + */ + virtual void PrintToConsole(const char *pMsg) =0; }; /**