3 * ================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * ================================================================
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License,
10 * version 3.0, as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to
21 * link the code of this program (as well as its derivative works) to
22 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any
23 * Game MODs that run on software by the Valve Corporation. You must
24 * obey the GNU General Public License in all respects for all other
25 * code used. Additionally, AlliedModders LLC grants this exception
26 * to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version
28 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
34 #include "sourcemm_api.h"
35 #include "sm_version.h"
36 #include "sourcemod.h"
38 #include "ConVarManager.h"
40 SourceMod_Core g_SourceMod_Core;
41 IVEngineServer *engine = NULL;
42 IServerGameDLL *gamedll = NULL;
43 IServerGameClients *serverClients = NULL;
44 ISmmPluginManager *g_pMMPlugins = NULL;
45 CGlobalVars *gpGlobals = NULL;
47 IGameEventManager2 *gameevents = NULL;
48 IUniformRandomStream *engrandom = NULL;
49 CallClass<IVEngineServer> *enginePatch = NULL;
50 CallClass<IServerGameDLL> *gamedllPatch = NULL;
51 IPlayerInfoManager *playerinfo = NULL;
52 IBaseFileSystem *basefilesystem = NULL;
53 IEngineSound *enginesound = NULL;
54 IServerPluginHelpers *serverpluginhelpers = NULL;
56 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
58 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
62 GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
63 GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
64 GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
65 GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
66 GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
67 GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
68 GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
69 GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
70 GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
72 /* :TODO: Make this optional and... make it find earlier versions [?] */
73 GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
75 if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
79 snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
84 gpGlobals = ismm->pGlobals();
86 ismm->AddListener(this, this);
87 ismm->EnableVSPListener();
89 return g_SourceMod.InitializeSourceMod(error, maxlen, late);
92 bool SourceMod_Core::Unload(char *error, size_t maxlen)
94 g_SourceMod.CloseSourceMod();
98 bool SourceMod_Core::Pause(char *error, size_t maxlen)
103 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
108 void SourceMod_Core::AllPluginsLoaded()
110 g_SourceMod.AllPluginsLoaded();
113 const char *SourceMod_Core::GetAuthor()
115 return "AlliedModders, LLC";
118 const char *SourceMod_Core::GetName()
123 const char *SourceMod_Core::GetDescription()
125 return "Extensible administration and scripting system";
128 const char *SourceMod_Core::GetURL()
130 return "http://www.sourcemod.net/";
133 const char *SourceMod_Core::GetLicense()
135 return "See LICENSE.txt";
138 const char *SourceMod_Core::GetVersion()
140 return SVN_FULL_VERSION;
143 const char *SourceMod_Core::GetDate()
148 const char *SourceMod_Core::GetLogTag()
153 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
155 /* This shouldn't happen */
158 g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
163 SMGlobalClass *pBase = SMGlobalClass::head;
166 pBase->OnSourceModVSPReceived(iface);
167 pBase = pBase->m_pGlobalClassNext;
171 #if PLAPI_VERSION >= 12
172 void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
174 g_ConVarManager.OnUnlinkConCommandBase(id, pCommand);
177 void SourceMod_Core::OnPluginUnload(PluginId id)
179 g_ConVarManager.OnMetamodPluginUnloaded(id);