core/sourcemm_api.cpp
author David Anderson <dvander@alliedmods.net>
Wed Jun 06 22:16:15 2007 +0000 (2007-06-06)
changeset 893 a3bc816549a8
parent 675 40b8bc6ac247
child 1145 f12e19245c7a
permissions -rw-r--r--
- added experimental (so far) support for SourceMod chat triggers
- added ReplyToCommand() for replying to triggers nicely
     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 
    21 SourceMod_Core g_SourceMod_Core;
    22 IVEngineServer *engine = NULL;
    23 IServerGameDLL *gamedll = NULL;
    24 IServerGameClients *serverClients = NULL;
    25 ISmmPluginManager *g_pMMPlugins = NULL;
    26 CGlobalVars *gpGlobals = NULL;
    27 ICvar *icvar = NULL;
    28 IGameEventManager2 *gameevents = NULL;
    29 IUniformRandomStream *engrandom = NULL;
    30 CallClass<IVEngineServer> *enginePatch = NULL;
    31 CallClass<IServerGameDLL> *gamedllPatch = NULL;
    32 IPlayerInfoManager *playerinfo = NULL;
    33 IBaseFileSystem *basefilesystem = NULL;
    34 IEngineSound *enginesound = NULL;
    35 IServerPluginHelpers *serverpluginhelpers = NULL;
    36 
    37 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
    38 
    39 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    40 {
    41 	PLUGIN_SAVEVARS();
    42 
    43 	GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
    44 	GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
    45 	GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
    46 	GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
    47 	GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
    48 	GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
    49 	GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
    50 	GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
    51 	GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
    52 
    53 	/* :TODO: Make this optional and... make it find earlier versions [?] */
    54 	GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    55 
    56 	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
    57 	{
    58 		if (error)
    59 		{
    60 			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
    61 		}
    62 		return false;
    63 	}
    64 
    65 	gpGlobals = ismm->pGlobals();
    66 	
    67 	ismm->AddListener(this, this);
    68 	ismm->EnableVSPListener();
    69 
    70 	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
    71 }
    72 
    73 bool SourceMod_Core::Unload(char *error, size_t maxlen)
    74 {
    75 	g_SourceMod.CloseSourceMod();
    76 	return true;
    77 }
    78 
    79 bool SourceMod_Core::Pause(char *error, size_t maxlen)
    80 {
    81 	return true;
    82 }
    83 
    84 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
    85 {
    86 	return true;
    87 }
    88 
    89 void SourceMod_Core::AllPluginsLoaded()
    90 {
    91 	g_SourceMod.AllPluginsLoaded();
    92 }
    93 
    94 const char *SourceMod_Core::GetAuthor()
    95 {
    96 	return "AlliedModders, LLC";
    97 }
    98 
    99 const char *SourceMod_Core::GetName()
   100 {
   101 	return "SourceMod";
   102 }
   103 
   104 const char *SourceMod_Core::GetDescription()
   105 {
   106 	return "Extensible administration and scripting system";
   107 }
   108 
   109 const char *SourceMod_Core::GetURL()
   110 {
   111 	return "http://www.sourcemod.net/";
   112 }
   113 
   114 const char *SourceMod_Core::GetLicense()
   115 {
   116 	return "See LICENSE.txt";
   117 }
   118 
   119 const char *SourceMod_Core::GetVersion()
   120 {
   121 	return SVN_FULL_VERSION;
   122 }
   123 
   124 const char *SourceMod_Core::GetDate()
   125 {
   126 	return __DATE__;
   127 }
   128 
   129 const char *SourceMod_Core::GetLogTag()
   130 {
   131 	return "SM";
   132 }
   133 
   134 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
   135 {
   136 	/* This shouldn't happen */
   137 	if (!iface)
   138 	{
   139 		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
   140 		return;
   141 	}
   142 
   143 	/* Notify! */
   144 	SMGlobalClass *pBase = SMGlobalClass::head;
   145 	while (pBase)
   146 	{
   147 		pBase->OnSourceModVSPReceived(iface);
   148 		pBase = pBase->m_pGlobalClassNext;
   149 	}
   150 }