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