core/sourcemm_api.cpp
author David Anderson <dvander@alliedmods.net>
Mon Oct 15 00:38:25 2007 +0000 (2007-10-15)
changeset 1568 ecbaee393b0b
parent 1541 e46ad208b9b4
child 1581 2562512b4a44
permissions -rw-r--r--
extensions can now be built for multiple engines, and will autoload from auto.X.Y folders
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #include "sourcemod.h"
    33 #include "sourcemm_api.h"
    34 #include "sm_version.h"
    35 #include "Logger.h"
    36 #include "ConVarManager.h"
    37 
    38 SourceMod_Core g_SourceMod_Core;
    39 IVEngineServer *engine = NULL;
    40 IServerGameDLL *gamedll = NULL;
    41 IServerGameClients *serverClients = NULL;
    42 ISmmPluginManager *g_pMMPlugins = NULL;
    43 CGlobalVars *gpGlobals = NULL;
    44 ICvar *icvar = NULL;
    45 IGameEventManager2 *gameevents = NULL;
    46 IUniformRandomStream *engrandom = NULL;
    47 CallClass<IVEngineServer> *enginePatch = NULL;
    48 CallClass<IServerGameDLL> *gamedllPatch = NULL;
    49 IPlayerInfoManager *playerinfo = NULL;
    50 IBaseFileSystem *basefilesystem = NULL;
    51 IEngineSound *enginesound = NULL;
    52 IServerPluginHelpers *serverpluginhelpers = NULL;
    53 
    54 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
    55 
    56 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    57 {
    58 	PLUGIN_SAVEVARS();
    59 
    60 	GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
    61 	GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
    62 	GET_V_IFACE_CURRENT(GetServerFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
    63 	GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
    64 	GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
    65 	GET_V_IFACE_CURRENT(GetEngineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
    66 	GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
    67 	GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
    68 	GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
    69 
    70 	/* :TODO: Make this optional and... make it find earlier versions [?] */
    71 	GET_V_IFACE_CURRENT(GetServerFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    72 
    73 	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
    74 	{
    75 		if (error)
    76 		{
    77 			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
    78 		}
    79 		return false;
    80 	}
    81 
    82 	gpGlobals = ismm->GetCGlobals();
    83 	
    84 	ismm->AddListener(this, this);
    85 	ismm->EnableVSPListener();
    86 
    87 	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
    88 }
    89 
    90 bool SourceMod_Core::Unload(char *error, size_t maxlen)
    91 {
    92 	g_SourceMod.CloseSourceMod();
    93 	return true;
    94 }
    95 
    96 bool SourceMod_Core::Pause(char *error, size_t maxlen)
    97 {
    98 	return true;
    99 }
   100 
   101 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
   102 {
   103 	return true;
   104 }
   105 
   106 void SourceMod_Core::AllPluginsLoaded()
   107 {
   108 	g_SourceMod.AllPluginsLoaded();
   109 }
   110 
   111 const char *SourceMod_Core::GetAuthor()
   112 {
   113 	return "AlliedModders LLC";
   114 }
   115 
   116 const char *SourceMod_Core::GetName()
   117 {
   118 	return "SourceMod";
   119 }
   120 
   121 const char *SourceMod_Core::GetDescription()
   122 {
   123 	return "Extensible administration and scripting system";
   124 }
   125 
   126 const char *SourceMod_Core::GetURL()
   127 {
   128 	return "http://www.sourcemod.net/";
   129 }
   130 
   131 const char *SourceMod_Core::GetLicense()
   132 {
   133 	return "See LICENSE.txt";
   134 }
   135 
   136 const char *SourceMod_Core::GetVersion()
   137 {
   138 	return SVN_FULL_VERSION;
   139 }
   140 
   141 const char *SourceMod_Core::GetDate()
   142 {
   143 	return __DATE__;
   144 }
   145 
   146 const char *SourceMod_Core::GetLogTag()
   147 {
   148 	return "SM";
   149 }
   150 
   151 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
   152 {
   153 	/* This shouldn't happen */
   154 	if (!iface)
   155 	{
   156 		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
   157 		return;
   158 	}
   159 
   160 	/* Notify! */
   161 	SMGlobalClass *pBase = SMGlobalClass::head;
   162 	while (pBase)
   163 	{
   164 		pBase->OnSourceModVSPReceived(iface);
   165 		pBase = pBase->m_pGlobalClassNext;
   166 	}
   167 }
   168 
   169 #if PLAPI_VERSION >= 12
   170 void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
   171 {
   172 	g_ConVarManager.OnUnlinkConCommandBase(id, pCommand);
   173 }
   174 #else
   175 void SourceMod_Core::OnPluginUnload(PluginId id)
   176 {
   177 	g_ConVarManager.OnMetamodPluginUnloaded(id);
   178 }
   179 #endif