From d140bfa8af77c8bb4d93b549789490e8ed7ddeb8 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Thu, 1 May 2008 04:49:06 +0000 Subject: [PATCH] Merged bug fixes from 1.0.x branch. --HG-- branch : sourcemod-1.0.1 extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/sourcemod-1.0.1%402117 --- core/ConCmdManager.cpp | 9 ++++----- core/PlayerManager.cpp | 23 +++++++++++++++++++++-- core/PlayerManager.h | 6 ++++++ core/systems/ExtensionSys.cpp | 17 +++++++++++++++++ core/systems/ExtensionSys.h | 1 + extensions/sdktools/extension.h | 1 + extensions/sdktools/teamnatives.cpp | 18 +++++++++--------- plugins/include/sdktools_functions.inc | 5 +++++ public/IExtensionSys.h | 10 ++++++++++ 9 files changed, 74 insertions(+), 16 deletions(-) diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index ec112f78..eb7edbaa 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -2,7 +2,7 @@ * vim: set ts=4 : * ============================================================================= * SourceMod - * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved. + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. * ============================================================================= * * This program is free software; you can redistribute it and/or modify it under @@ -379,13 +379,12 @@ 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) { diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index b6f37ca5..1051fbff 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -46,6 +46,7 @@ #include #include #include "GameConfigs.h" +#include "systems/ExtensionSys.h" PlayerManager g_Players; bool g_OnMapStarted = false; @@ -133,6 +134,8 @@ 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() @@ -206,6 +209,7 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl g_NumPlayersToAuth = &m_AuthQueue[0]; } + g_Extensions.CallOnCoreMapStart(pEdictList, edictCount, clientMax); m_onActivate->Execute(NULL); m_onActivate2->Execute(NULL); @@ -383,7 +387,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); } @@ -413,6 +419,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; } @@ -522,7 +535,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; } @@ -563,6 +578,10 @@ 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 767a90dd..e34084b4 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; diff --git a/core/systems/ExtensionSys.cpp b/core/systems/ExtensionSys.cpp index 8209b3ce..e8daca49 100644 --- a/core/systems/ExtensionSys.cpp +++ b/core/systems/ExtensionSys.cpp @@ -1369,3 +1369,20 @@ IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface, return pExt; } +void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax) +{ + IExtensionInterface *pAPI; + List::iterator iter; + + for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + { + if ((pAPI = (*iter)->GetAPI()) == NULL) + { + continue; + } + if (pAPI->GetExtensionVersion() > 3) + { + pAPI->OnCoreMapStart(pEdictList, edictCount, clientMax); + } + } +} diff --git a/core/systems/ExtensionSys.h b/core/systems/ExtensionSys.h index dbba34e6..0b070c2e 100644 --- a/core/systems/ExtensionSys.h +++ b/core/systems/ExtensionSys.h @@ -178,6 +178,7 @@ public: void AddLibrary(IExtension *pSource, const char *library); bool LibraryExists(const char *library); void OverrideNatives(IExtension *myself, const sp_nativeinfo_t *natives); + void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax); public: CExtension *GetExtensionFromIdent(IdentityToken_t *ptr); void Shutdown(); diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index c13343a9..663497d2 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -71,6 +71,7 @@ public: //public SDKExtension virtual bool QueryRunning(char *error, size_t maxlength); virtual bool QueryInterfaceDrop(SMInterface *pInterface); virtual void NotifyInterfaceDrop(SMInterface *pInterface); + virtual void OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax); public: #if defined SMEXT_CONF_METAMOD virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late); diff --git a/extensions/sdktools/teamnatives.cpp b/extensions/sdktools/teamnatives.cpp index 3eac3c68..7002cdf6 100644 --- a/extensions/sdktools/teamnatives.cpp +++ b/extensions/sdktools/teamnatives.cpp @@ -42,6 +42,10 @@ SourceHook::CVector g_Teams; bool FindTeamEntities(SendTable *pTable, const char *name) { + if (strcmp(pTable->GetName(), name) == 0) + { + return true; + } int props = pTable->GetNumProps(); SendProp *prop; @@ -50,10 +54,6 @@ bool FindTeamEntities(SendTable *pTable, const char *name) prop = pTable->GetProp(i); if (prop->GetDataTable()) { - if (strcmp(prop->GetDataTable()->GetName(), name) == 0) - { - return true; - } if (FindTeamEntities(prop->GetDataTable(), name)) { return true; @@ -64,7 +64,7 @@ bool FindTeamEntities(SendTable *pTable, const char *name) return false; } -void SDKTools::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax) +void SDKTools::OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax) { g_Teams.clear(); g_Teams.resize(1); @@ -111,7 +111,7 @@ static cell_t GetTeamCount(IPluginContext *pContext, const cell_t *params) static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (teamindex > (int)g_Teams.size()) + if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) { pContext->ThrowNativeError("Team index %d is invalid", teamindex); } @@ -127,7 +127,7 @@ static cell_t GetTeamName(IPluginContext *pContext, const cell_t *params) static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (teamindex > (int)g_Teams.size()) + if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) { pContext->ThrowNativeError("Team index %d is invalid", teamindex); } @@ -140,7 +140,7 @@ static cell_t GetTeamScore(IPluginContext *pContext, const cell_t *params) static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (teamindex > (int)g_Teams.size()) + if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) { pContext->ThrowNativeError("Team index %d is invalid", teamindex); } @@ -154,7 +154,7 @@ static cell_t SetTeamScore(IPluginContext *pContext, const cell_t *params) static cell_t GetTeamClientCount(IPluginContext *pContext, const cell_t *params) { int teamindex = params[1]; - if (teamindex > (int)g_Teams.size()) + if (!g_Teams[teamindex].ClassName || (teamindex > (int)g_Teams.size())) { pContext->ThrowNativeError("Team index %d is invalid", teamindex); } diff --git a/plugins/include/sdktools_functions.inc b/plugins/include/sdktools_functions.inc index 1765878c..1694e8de 100644 --- a/plugins/include/sdktools_functions.inc +++ b/plugins/include/sdktools_functions.inc @@ -210,6 +210,7 @@ native GetClientAimTarget(client, bool:only_clients=true); /** * Returns the total number of teams in a game. + * Note: This native should not be called before OnMapStart. * * @return Total number of teams. */ @@ -217,6 +218,7 @@ native GetTeamCount(); /** * Retrieves the team name based on a team index. + * Note: This native should not be called before OnMapStart. * * @param index Team index. * @param name Buffer to store string in. @@ -228,6 +230,7 @@ native GetTeamName(index, String:name[], maxlength); /** * Returns the score of a team based on a team index. + * Note: This native should not be called before OnMapStart. * * @param index Team index. * @return Score. @@ -237,6 +240,7 @@ native GetTeamScore(index); /** * Sets the score of a team based on a team index. + * Note: This native should not be called before OnMapStart. * * @param index Team index. * @param value New score value. @@ -247,6 +251,7 @@ native SetTeamScore(index, value); /** * Retrieves the number of players in a certain team. + * Note: This native should not be called before OnMapStart. * * @param index Team index. * @return Number of players in the team. diff --git a/public/IExtensionSys.h b/public/IExtensionSys.h index 3f4989a2..ab913087 100644 --- a/public/IExtensionSys.h +++ b/public/IExtensionSys.h @@ -289,6 +289,16 @@ namespace SourceMod * @return String containing the compilation date. */ virtual const char *GetExtensionDateString() =0; + /** + * @brief Called on server activation before plugins receive the OnServerLoad forward. + * + * @param pEdictList Edicts list. + * @param edictCount Number of edicts in the list. + * @param clientMax Maximum number of clients allowed in the server. + */ + virtual void OnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax) + { + } }; /**