core/sourcemm_api.cpp
author Scott Ehlert <ds@alliedmods.net>
Mon Jul 23 19:38:02 2007 +0000 (2007-07-23)
changeset 1149 70d171906c7e
parent 1145 f12e19245c7a
child 1231 17badaf66ce4
permissions -rw-r--r--
No comment worth mentioning for this one :x
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #include <oslink.h>
    16 #include "sourcemm_api.h"
    17 #include "sm_version.h"
    18 #include "sourcemod.h"
    19 #include "Logger.h"
    20 #include "ConVarManager.h"
    21 
    22 SourceMod_Core g_SourceMod_Core;
    23 IVEngineServer *engine = NULL;
    24 IServerGameDLL *gamedll = NULL;
    25 IServerGameClients *serverClients = NULL;
    26 ISmmPluginManager *g_pMMPlugins = NULL;
    27 CGlobalVars *gpGlobals = NULL;
    28 ICvar *icvar = NULL;
    29 IGameEventManager2 *gameevents = NULL;
    30 IUniformRandomStream *engrandom = NULL;
    31 CallClass<IVEngineServer> *enginePatch = NULL;
    32 CallClass<IServerGameDLL> *gamedllPatch = NULL;
    33 IPlayerInfoManager *playerinfo = NULL;
    34 IBaseFileSystem *basefilesystem = NULL;
    35 IEngineSound *enginesound = NULL;
    36 IServerPluginHelpers *serverpluginhelpers = NULL;
    37 
    38 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
    39 
    40 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    41 {
    42 	PLUGIN_SAVEVARS();
    43 
    44 	GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
    45 	GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
    46 	GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
    47 	GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
    48 	GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
    49 	GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
    50 	GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
    51 	GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
    52 	GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
    53 
    54 	/* :TODO: Make this optional and... make it find earlier versions [?] */
    55 	GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    56 
    57 	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
    58 	{
    59 		if (error)
    60 		{
    61 			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
    62 		}
    63 		return false;
    64 	}
    65 
    66 	gpGlobals = ismm->pGlobals();
    67 	
    68 	ismm->AddListener(this, this);
    69 	ismm->EnableVSPListener();
    70 
    71 	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
    72 }
    73 
    74 bool SourceMod_Core::Unload(char *error, size_t maxlen)
    75 {
    76 	g_SourceMod.CloseSourceMod();
    77 	return true;
    78 }
    79 
    80 bool SourceMod_Core::Pause(char *error, size_t maxlen)
    81 {
    82 	return true;
    83 }
    84 
    85 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
    86 {
    87 	return true;
    88 }
    89 
    90 void SourceMod_Core::AllPluginsLoaded()
    91 {
    92 	g_SourceMod.AllPluginsLoaded();
    93 }
    94 
    95 const char *SourceMod_Core::GetAuthor()
    96 {
    97 	return "AlliedModders, LLC";
    98 }
    99 
   100 const char *SourceMod_Core::GetName()
   101 {
   102 	return "SourceMod";
   103 }
   104 
   105 const char *SourceMod_Core::GetDescription()
   106 {
   107 	return "Extensible administration and scripting system";
   108 }
   109 
   110 const char *SourceMod_Core::GetURL()
   111 {
   112 	return "http://www.sourcemod.net/";
   113 }
   114 
   115 const char *SourceMod_Core::GetLicense()
   116 {
   117 	return "See LICENSE.txt";
   118 }
   119 
   120 const char *SourceMod_Core::GetVersion()
   121 {
   122 	return SVN_FULL_VERSION;
   123 }
   124 
   125 const char *SourceMod_Core::GetDate()
   126 {
   127 	return __DATE__;
   128 }
   129 
   130 const char *SourceMod_Core::GetLogTag()
   131 {
   132 	return "SM";
   133 }
   134 
   135 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
   136 {
   137 	/* This shouldn't happen */
   138 	if (!iface)
   139 	{
   140 		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
   141 		return;
   142 	}
   143 
   144 	/* Notify! */
   145 	SMGlobalClass *pBase = SMGlobalClass::head;
   146 	while (pBase)
   147 	{
   148 		pBase->OnSourceModVSPReceived(iface);
   149 		pBase = pBase->m_pGlobalClassNext;
   150 	}
   151 }
   152 
   153 #if PLAPI_VERSION >= 12
   154 void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
   155 {
   156 	g_ConVarManager.OnUnlinkConCommandBase(id, pCommand);
   157 }
   158 #else
   159 void SourceMod_Core::OnPluginUnload(PluginId id)
   160 {
   161 	g_ConVarManager.OnMetamodPluginUnloaded(id);
   162 }
   163 #endif