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
This commit is contained in:
Matt Woodrow 2008-05-01 04:49:06 +00:00
parent a41c004d1c
commit d140bfa8af
9 changed files with 74 additions and 16 deletions

View File

@ -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)
{

View File

@ -46,6 +46,7 @@
#include <inetchannel.h>
#include <iclient.h>
#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)

View File

@ -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;

View File

@ -1369,3 +1369,20 @@ IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface,
return pExt;
}
void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax)
{
IExtensionInterface *pAPI;
List<CExtension *>::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);
}
}
}

View File

@ -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();

View File

@ -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);

View File

@ -42,6 +42,10 @@ SourceHook::CVector<TeamInfo> 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);
}

View File

@ -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.

View File

@ -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)
{
}
};
/**