core/sourcemm_api.cpp
author David Anderson <dvander@alliedmods.net>
Wed Sep 26 14:38:40 2007 +0000 (2007-09-26)
changeset 1488 5562086c65c8
parent 1330 ab94316bb52b
child 1541 e46ad208b9b4
permissions -rw-r--r--
initial import of UNTESTED, UNFINISHED topmenus extension
     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 <oslink.h>
    33 #include "sourcemm_api.h"
    34 #include "sm_version.h"
    35 #include "sourcemod.h"
    36 #include "Logger.h"
    37 #include "ConVarManager.h"
    38 
    39 SourceMod_Core g_SourceMod_Core;
    40 IVEngineServer *engine = NULL;
    41 IServerGameDLL *gamedll = NULL;
    42 IServerGameClients *serverClients = NULL;
    43 ISmmPluginManager *g_pMMPlugins = NULL;
    44 CGlobalVars *gpGlobals = NULL;
    45 ICvar *icvar = NULL;
    46 IGameEventManager2 *gameevents = NULL;
    47 IUniformRandomStream *engrandom = NULL;
    48 CallClass<IVEngineServer> *enginePatch = NULL;
    49 CallClass<IServerGameDLL> *gamedllPatch = NULL;
    50 IPlayerInfoManager *playerinfo = NULL;
    51 IBaseFileSystem *basefilesystem = NULL;
    52 IEngineSound *enginesound = NULL;
    53 IServerPluginHelpers *serverpluginhelpers = NULL;
    54 
    55 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
    56 
    57 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    58 {
    59 	PLUGIN_SAVEVARS();
    60 
    61 	GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
    62 	GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
    63 	GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
    64 	GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
    65 	GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
    66 	GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
    67 	GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
    68 	GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
    69 	GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
    70 
    71 	/* :TODO: Make this optional and... make it find earlier versions [?] */
    72 	GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    73 
    74 	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
    75 	{
    76 		if (error)
    77 		{
    78 			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
    79 		}
    80 		return false;
    81 	}
    82 
    83 	gpGlobals = ismm->pGlobals();
    84 	
    85 	ismm->AddListener(this, this);
    86 	ismm->EnableVSPListener();
    87 
    88 	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
    89 }
    90 
    91 bool SourceMod_Core::Unload(char *error, size_t maxlen)
    92 {
    93 	g_SourceMod.CloseSourceMod();
    94 	return true;
    95 }
    96 
    97 bool SourceMod_Core::Pause(char *error, size_t maxlen)
    98 {
    99 	return true;
   100 }
   101 
   102 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
   103 {
   104 	return true;
   105 }
   106 
   107 void SourceMod_Core::AllPluginsLoaded()
   108 {
   109 	g_SourceMod.AllPluginsLoaded();
   110 }
   111 
   112 const char *SourceMod_Core::GetAuthor()
   113 {
   114 	return "AlliedModders LLC";
   115 }
   116 
   117 const char *SourceMod_Core::GetName()
   118 {
   119 	return "SourceMod";
   120 }
   121 
   122 const char *SourceMod_Core::GetDescription()
   123 {
   124 	return "Extensible administration and scripting system";
   125 }
   126 
   127 const char *SourceMod_Core::GetURL()
   128 {
   129 	return "http://www.sourcemod.net/";
   130 }
   131 
   132 const char *SourceMod_Core::GetLicense()
   133 {
   134 	return "See LICENSE.txt";
   135 }
   136 
   137 const char *SourceMod_Core::GetVersion()
   138 {
   139 	return SVN_FULL_VERSION;
   140 }
   141 
   142 const char *SourceMod_Core::GetDate()
   143 {
   144 	return __DATE__;
   145 }
   146 
   147 const char *SourceMod_Core::GetLogTag()
   148 {
   149 	return "SM";
   150 }
   151 
   152 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
   153 {
   154 	/* This shouldn't happen */
   155 	if (!iface)
   156 	{
   157 		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
   158 		return;
   159 	}
   160 
   161 	/* Notify! */
   162 	SMGlobalClass *pBase = SMGlobalClass::head;
   163 	while (pBase)
   164 	{
   165 		pBase->OnSourceModVSPReceived(iface);
   166 		pBase = pBase->m_pGlobalClassNext;
   167 	}
   168 }
   169 
   170 #if PLAPI_VERSION >= 12
   171 void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
   172 {
   173 	g_ConVarManager.OnUnlinkConCommandBase(id, pCommand);
   174 }
   175 #else
   176 void SourceMod_Core::OnPluginUnload(PluginId id)
   177 {
   178 	g_ConVarManager.OnMetamodPluginUnloaded(id);
   179 }
   180 #endif