2007-01-25 23:36:38 +01:00
|
|
|
/**
|
2007-03-22 22:50:20 +01:00
|
|
|
* vim: set ts=4 :
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-08-01 04:12:47 +02:00
|
|
|
* SourceMod
|
|
|
|
* Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-08-01 04:12:47 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
2007-08-01 04:12:47 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
2007-08-01 04:12:47 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-01 04:12:47 +02:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
2007-01-25 23:36:38 +01:00
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2007-10-14 02:04:21 +02:00
|
|
|
#include "sourcemod.h"
|
2006-11-06 11:57:37 +01:00
|
|
|
#include "sourcemm_api.h"
|
2006-11-04 20:27:20 +01:00
|
|
|
#include "sm_version.h"
|
2007-04-08 20:19:06 +02:00
|
|
|
#include "Logger.h"
|
2007-10-30 21:43:59 +01:00
|
|
|
#include "ExtensionSys.h"
|
2007-10-16 03:17:08 +02:00
|
|
|
#include "concmd_cleaner.h"
|
2007-10-16 03:29:28 +02:00
|
|
|
#include "compat_wrappers.h"
|
2006-11-04 20:27:20 +01:00
|
|
|
|
2006-11-08 08:32:44 +01:00
|
|
|
SourceMod_Core g_SourceMod_Core;
|
2006-12-13 12:16:20 +01:00
|
|
|
IVEngineServer *engine = NULL;
|
|
|
|
IServerGameDLL *gamedll = NULL;
|
2006-12-28 01:48:09 +01:00
|
|
|
IServerGameClients *serverClients = NULL;
|
2007-01-17 04:01:38 +01:00
|
|
|
ISmmPluginManager *g_pMMPlugins = NULL;
|
2007-02-07 09:44:48 +01:00
|
|
|
CGlobalVars *gpGlobals = NULL;
|
2007-02-08 22:41:28 +01:00
|
|
|
ICvar *icvar = NULL;
|
2007-02-08 02:11:45 +01:00
|
|
|
IGameEventManager2 *gameevents = NULL;
|
2007-02-26 05:24:06 +01:00
|
|
|
IUniformRandomStream *engrandom = NULL;
|
2007-02-15 21:35:17 +01:00
|
|
|
CallClass<IVEngineServer> *enginePatch = NULL;
|
2007-02-26 06:26:54 +01:00
|
|
|
CallClass<IServerGameDLL> *gamedllPatch = NULL;
|
2007-03-18 00:03:44 +01:00
|
|
|
IPlayerInfoManager *playerinfo = NULL;
|
2007-03-26 00:25:45 +02:00
|
|
|
IBaseFileSystem *basefilesystem = NULL;
|
|
|
|
IEngineSound *enginesound = NULL;
|
2007-03-29 21:48:54 +02:00
|
|
|
IServerPluginHelpers *serverpluginhelpers = NULL;
|
2007-10-16 00:15:22 +02:00
|
|
|
IServerPluginCallbacks *vsp_interface = NULL;
|
|
|
|
int vsp_version = 0;
|
2006-11-04 20:27:20 +01:00
|
|
|
|
2006-11-08 08:32:44 +01:00
|
|
|
PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
|
2006-11-04 20:27:20 +01:00
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
PLUGIN_SAVEVARS();
|
|
|
|
|
2007-10-14 02:04:21 +02:00
|
|
|
GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
|
|
|
|
GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
|
|
|
|
GET_V_IFACE_CURRENT(GetServerFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
|
|
|
|
GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
|
|
|
|
GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
|
|
|
|
GET_V_IFACE_CURRENT(GetEngineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
|
|
|
|
GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
|
|
|
|
GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
|
|
|
|
GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
|
2006-12-13 12:16:20 +01:00
|
|
|
|
2007-03-18 00:03:44 +01:00
|
|
|
/* :TODO: Make this optional and... make it find earlier versions [?] */
|
2007-10-14 02:04:21 +02:00
|
|
|
GET_V_IFACE_CURRENT(GetServerFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
|
2007-03-18 00:03:44 +01:00
|
|
|
|
2007-01-17 04:01:38 +01:00
|
|
|
if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
|
|
|
|
{
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-10-14 02:04:21 +02:00
|
|
|
gpGlobals = ismm->GetCGlobals();
|
2007-04-08 20:19:06 +02:00
|
|
|
|
|
|
|
ismm->AddListener(this, this);
|
2007-10-16 00:15:22 +02:00
|
|
|
|
|
|
|
#if defined METAMOD_PLAPI_VERSION
|
|
|
|
if ((vsp_interface = g_SMAPI->GetVSPInfo(&vsp_version)) == NULL)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
g_SMAPI->EnableVSPListener();
|
|
|
|
}
|
2007-02-07 09:44:48 +01:00
|
|
|
|
2006-11-08 08:32:44 +01:00
|
|
|
return g_SourceMod.InitializeSourceMod(error, maxlen, late);
|
2006-11-04 20:27:20 +01:00
|
|
|
}
|
|
|
|
|
2006-12-28 01:48:09 +01:00
|
|
|
bool SourceMod_Core::Unload(char *error, size_t maxlen)
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
2007-01-13 05:28:13 +01:00
|
|
|
g_SourceMod.CloseSourceMod();
|
2006-11-04 20:27:20 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
bool SourceMod_Core::Pause(char *error, size_t maxlen)
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
bool SourceMod_Core::Unpause(char *error, size_t maxlen)
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
void SourceMod_Core::AllPluginsLoaded()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
2007-06-07 00:16:15 +02:00
|
|
|
g_SourceMod.AllPluginsLoaded();
|
2006-11-04 20:27:20 +01:00
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetAuthor()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
2007-08-15 08:19:30 +02:00
|
|
|
return "AlliedModders LLC";
|
2006-11-04 20:27:20 +01:00
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetName()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
return "SourceMod";
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetDescription()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
return "Extensible administration and scripting system";
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetURL()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
return "http://www.sourcemod.net/";
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetLicense()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
return "See LICENSE.txt";
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetVersion()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
2007-03-03 08:50:01 +01:00
|
|
|
return SVN_FULL_VERSION;
|
2006-11-04 20:27:20 +01:00
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetDate()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
|
|
|
return __DATE__;
|
|
|
|
}
|
|
|
|
|
2006-11-05 01:29:44 +01:00
|
|
|
const char *SourceMod_Core::GetLogTag()
|
2006-11-04 20:27:20 +01:00
|
|
|
{
|
2007-03-28 22:28:42 +02:00
|
|
|
return "SM";
|
2006-11-04 20:27:20 +01:00
|
|
|
}
|
2007-04-08 20:19:06 +02:00
|
|
|
|
|
|
|
void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
|
|
|
|
{
|
|
|
|
/* This shouldn't happen */
|
|
|
|
if (!iface)
|
|
|
|
{
|
2007-10-16 00:15:22 +02:00
|
|
|
g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4.2 or greater.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vsp_interface == NULL)
|
|
|
|
{
|
|
|
|
vsp_interface = iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_Loaded)
|
|
|
|
{
|
2007-04-08 20:19:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-10-16 00:15:22 +02:00
|
|
|
#if defined METAMOD_PLAPI_VERSION
|
|
|
|
if (vsp_version == 0)
|
|
|
|
{
|
|
|
|
g_SMAPI->GetVSPInfo(&vsp_version);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if (vsp_version == 0)
|
|
|
|
{
|
|
|
|
if (strcmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
|
|
|
|
{
|
|
|
|
vsp_version = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vsp_version = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-04-08 20:19:06 +02:00
|
|
|
/* Notify! */
|
|
|
|
SMGlobalClass *pBase = SMGlobalClass::head;
|
|
|
|
while (pBase)
|
|
|
|
{
|
2007-10-16 00:15:22 +02:00
|
|
|
pBase->OnSourceModVSPReceived();
|
2007-04-08 20:19:06 +02:00
|
|
|
pBase = pBase->m_pGlobalClassNext;
|
|
|
|
}
|
|
|
|
}
|
2007-07-23 20:30:02 +02:00
|
|
|
|
2007-10-16 03:17:08 +02:00
|
|
|
#if defined METAMOD_PLAPI_VERSION
|
|
|
|
|
2007-07-23 20:30:02 +02:00
|
|
|
void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
|
|
|
|
{
|
2007-10-16 03:17:08 +02:00
|
|
|
Global_OnUnlinkConCommandBase(pCommand);
|
2007-07-23 20:30:02 +02:00
|
|
|
}
|
2007-10-16 03:17:08 +02:00
|
|
|
|
2007-07-23 20:30:02 +02:00
|
|
|
#else
|
2007-10-16 03:17:08 +02:00
|
|
|
|
2007-07-23 20:30:02 +02:00
|
|
|
void SourceMod_Core::OnPluginUnload(PluginId id)
|
|
|
|
{
|
2007-10-16 03:17:08 +02:00
|
|
|
Global_OnUnlinkConCommandBase(NULL);
|
2007-07-23 20:30:02 +02:00
|
|
|
}
|
2007-10-16 03:17:08 +02:00
|
|
|
|
2007-07-23 20:30:02 +02:00
|
|
|
#endif
|
2007-10-30 21:43:59 +01:00
|
|
|
|
|
|
|
void *SourceMod_Core::OnMetamodQuery(const char *iface, int *ret)
|
|
|
|
{
|
|
|
|
void *ptr = NULL;
|
|
|
|
|
|
|
|
if (strcmp(iface, SOURCEMOD_INTERFACE_EXTENSIONS) == 0)
|
|
|
|
{
|
|
|
|
ptr = (IExtensionManager *)&g_Extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret != NULL)
|
|
|
|
{
|
|
|
|
*ret = (ptr == NULL) ? IFACE_FAILED : IFACE_OK;
|
|
|
|
}
|
|
|
|
|
2007-11-10 06:46:09 +01:00
|
|
|
return ptr;
|
2007-10-30 21:43:59 +01:00
|
|
|
}
|
|
|
|
|