core/sourcemm_api.cpp
author David Anderson <dvander@alliedmods.net>
Wed Aug 01 02:12:47 2007 +0000 (2007-08-01)
changeset 1231 17badaf66ce4
parent 1145 f12e19245c7a
child 1330 ab94316bb52b
permissions -rw-r--r--
updated more header files (mostly internal now)
     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 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    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.
    16  *
    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/>.
    19  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #include <oslink.h>
    34 #include "sourcemm_api.h"
    35 #include "sm_version.h"
    36 #include "sourcemod.h"
    37 #include "Logger.h"
    38 #include "ConVarManager.h"
    39 
    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;
    46 ICvar *icvar = 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;
    55 
    56 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
    57 
    58 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    59 {
    60 	PLUGIN_SAVEVARS();
    61 
    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);
    71 
    72 	/* :TODO: Make this optional and... make it find earlier versions [?] */
    73 	GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    74 
    75 	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
    76 	{
    77 		if (error)
    78 		{
    79 			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
    80 		}
    81 		return false;
    82 	}
    83 
    84 	gpGlobals = ismm->pGlobals();
    85 	
    86 	ismm->AddListener(this, this);
    87 	ismm->EnableVSPListener();
    88 
    89 	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
    90 }
    91 
    92 bool SourceMod_Core::Unload(char *error, size_t maxlen)
    93 {
    94 	g_SourceMod.CloseSourceMod();
    95 	return true;
    96 }
    97 
    98 bool SourceMod_Core::Pause(char *error, size_t maxlen)
    99 {
   100 	return true;
   101 }
   102 
   103 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
   104 {
   105 	return true;
   106 }
   107 
   108 void SourceMod_Core::AllPluginsLoaded()
   109 {
   110 	g_SourceMod.AllPluginsLoaded();
   111 }
   112 
   113 const char *SourceMod_Core::GetAuthor()
   114 {
   115 	return "AlliedModders, LLC";
   116 }
   117 
   118 const char *SourceMod_Core::GetName()
   119 {
   120 	return "SourceMod";
   121 }
   122 
   123 const char *SourceMod_Core::GetDescription()
   124 {
   125 	return "Extensible administration and scripting system";
   126 }
   127 
   128 const char *SourceMod_Core::GetURL()
   129 {
   130 	return "http://www.sourcemod.net/";
   131 }
   132 
   133 const char *SourceMod_Core::GetLicense()
   134 {
   135 	return "See LICENSE.txt";
   136 }
   137 
   138 const char *SourceMod_Core::GetVersion()
   139 {
   140 	return SVN_FULL_VERSION;
   141 }
   142 
   143 const char *SourceMod_Core::GetDate()
   144 {
   145 	return __DATE__;
   146 }
   147 
   148 const char *SourceMod_Core::GetLogTag()
   149 {
   150 	return "SM";
   151 }
   152 
   153 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
   154 {
   155 	/* This shouldn't happen */
   156 	if (!iface)
   157 	{
   158 		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
   159 		return;
   160 	}
   161 
   162 	/* Notify! */
   163 	SMGlobalClass *pBase = SMGlobalClass::head;
   164 	while (pBase)
   165 	{
   166 		pBase->OnSourceModVSPReceived(iface);
   167 		pBase = pBase->m_pGlobalClassNext;
   168 	}
   169 }
   170 
   171 #if PLAPI_VERSION >= 12
   172 void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
   173 {
   174 	g_ConVarManager.OnUnlinkConCommandBase(id, pCommand);
   175 }
   176 #else
   177 void SourceMod_Core::OnPluginUnload(PluginId id)
   178 {
   179 	g_ConVarManager.OnMetamodPluginUnloaded(id);
   180 }
   181 #endif