diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index b41b6bfd..f177dd54 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -379,14 +379,14 @@ void ConCmdManager::InternalDispatch(const CCommand &command) /* On a listen server, sometimes the server host's client index can be set as 0. * So index 1 is passed to the command callback to correct this potential problem. */ - if (client == 0 && !engine->IsDedicatedServer()) + if (!engine->IsDedicatedServer()) { - pHook->pf->PushCell(1); - } else { - pHook->pf->PushCell(client); + client = g_Players.ListenClient(); } + pHook->pf->PushCell(client); pHook->pf->PushCell(args); + if (pHook->pf->Execute(&tempres) == SP_ERROR_NONE) { if (tempres > result) diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 87d80e8e..9e0ecc58 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -134,6 +134,9 @@ void PlayerManager::OnSourceModAllInitialized() PreAdminCheck = g_Forwards.CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1); PostAdminCheck = g_Forwards.CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1); PostAdminFilter = g_Forwards.CreateForward("OnClientPostAdminFilter", ET_Ignore, 1, p1); + + m_bIsListenServer = !engine->IsDedicatedServer(); + m_ListenClient = 0; } void PlayerManager::OnSourceModShutdown() @@ -385,7 +388,9 @@ bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const { m_AuthQueue[++m_AuthQueue[0]] = client; } - } else { + } + else + { RETURN_META_VALUE(MRES_SUPERCEDE, false); } @@ -415,6 +420,13 @@ bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName, } } + if (!pPlayer->IsFakeClient() + && m_bIsListenServer + && strncmp(pszAddress, "127.0.0.1", 9) == 0) + { + m_ListenClient = client; + } + return true; } @@ -524,7 +536,9 @@ void PlayerManager::OnClientDisconnect(edict_t *pEntity) { m_cldisconnect->PushCell(client); m_cldisconnect->Execute(&res, NULL); - } else { + } + else + { /* We don't care, prevent a double call */ return; } @@ -565,6 +579,11 @@ void PlayerManager::OnClientDisconnect(edict_t *pEntity) m_Players[client].Disconnect(); m_UserIdLookUp[engine->GetPlayerUserId(pEntity)] = 0; + + if (m_ListenClient == client) + { + m_ListenClient = 0; + } } void PlayerManager::OnClientDisconnect_Post(edict_t *pEntity) diff --git a/core/PlayerManager.h b/core/PlayerManager.h index e4930099..9d235c49 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -161,6 +161,10 @@ public: { return m_PlayerCount; } + inline int ListenClient() + { + return m_ListenClient; + } bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id); bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id); const char *GetPassInfoVar(); @@ -188,6 +192,8 @@ private: unsigned int *m_AuthQueue; String m_PassInfoVar; bool m_QueryLang; + bool m_bIsListenServer; + int m_ListenClient; }; extern PlayerManager g_Players;