core/sourcemm_api.cpp
author David Anderson <dvander@alliedmods.net>
Mon Oct 22 16:48:54 2007 +0000 (2007-10-22)
changeset 1639 5c7fffd146ae
parent 1583 1b92a3e4b962
child 1655 b401b28e186a
permissions -rw-r--r--
fixed linux build
     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 "concmd_cleaner.h"
    37 #include "compat_wrappers.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 IServerPluginCallbacks *vsp_interface = NULL;
    55 int vsp_version = 0;
    56 
    57 PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
    58 
    59 bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
    60 {
    61 	PLUGIN_SAVEVARS();
    62 
    63 	GET_V_IFACE_ANY(GetServerFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
    64 	GET_V_IFACE_CURRENT(GetEngineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
    65 	GET_V_IFACE_CURRENT(GetServerFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
    66 	GET_V_IFACE_CURRENT(GetEngineFactory, icvar, ICvar, CVAR_INTERFACE_VERSION);
    67 	GET_V_IFACE_CURRENT(GetEngineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
    68 	GET_V_IFACE_CURRENT(GetEngineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
    69 	GET_V_IFACE_CURRENT(GetFileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
    70 	GET_V_IFACE_CURRENT(GetEngineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
    71 	GET_V_IFACE_CURRENT(GetEngineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
    72 
    73 	/* :TODO: Make this optional and... make it find earlier versions [?] */
    74 	GET_V_IFACE_CURRENT(GetServerFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
    75 
    76 	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
    77 	{
    78 		if (error)
    79 		{
    80 			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
    81 		}
    82 		return false;
    83 	}
    84 
    85 	gpGlobals = ismm->GetCGlobals();
    86 	
    87 	ismm->AddListener(this, this);
    88 
    89 #if defined METAMOD_PLAPI_VERSION
    90 	if ((vsp_interface = g_SMAPI->GetVSPInfo(&vsp_version)) == NULL)
    91 #endif
    92 	{
    93 		g_SMAPI->EnableVSPListener();
    94 	}
    95 
    96 	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
    97 }
    98 
    99 bool SourceMod_Core::Unload(char *error, size_t maxlen)
   100 {
   101 	g_SourceMod.CloseSourceMod();
   102 	return true;
   103 }
   104 
   105 bool SourceMod_Core::Pause(char *error, size_t maxlen)
   106 {
   107 	return true;
   108 }
   109 
   110 bool SourceMod_Core::Unpause(char *error, size_t maxlen)
   111 {
   112 	return true;
   113 }
   114 
   115 void SourceMod_Core::AllPluginsLoaded()
   116 {
   117 	g_SourceMod.AllPluginsLoaded();
   118 }
   119 
   120 const char *SourceMod_Core::GetAuthor()
   121 {
   122 	return "AlliedModders LLC";
   123 }
   124 
   125 const char *SourceMod_Core::GetName()
   126 {
   127 	return "SourceMod";
   128 }
   129 
   130 const char *SourceMod_Core::GetDescription()
   131 {
   132 	return "Extensible administration and scripting system";
   133 }
   134 
   135 const char *SourceMod_Core::GetURL()
   136 {
   137 	return "http://www.sourcemod.net/";
   138 }
   139 
   140 const char *SourceMod_Core::GetLicense()
   141 {
   142 	return "See LICENSE.txt";
   143 }
   144 
   145 const char *SourceMod_Core::GetVersion()
   146 {
   147 	return SVN_FULL_VERSION;
   148 }
   149 
   150 const char *SourceMod_Core::GetDate()
   151 {
   152 	return __DATE__;
   153 }
   154 
   155 const char *SourceMod_Core::GetLogTag()
   156 {
   157 	return "SM";
   158 }
   159 
   160 void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
   161 {
   162 	/* This shouldn't happen */
   163 	if (!iface)
   164 	{
   165 		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4.2 or greater.");
   166 		return;
   167 	}
   168 
   169 	if (vsp_interface == NULL)
   170 	{
   171 		vsp_interface = iface;
   172 	}
   173 
   174 	if (!g_Loaded)
   175 	{
   176 		return;
   177 	}
   178 
   179 #if defined METAMOD_PLAPI_VERSION
   180 	if (vsp_version == 0)
   181 	{
   182 		g_SMAPI->GetVSPInfo(&vsp_version);
   183 	}
   184 #else
   185 	if (vsp_version == 0)
   186 	{
   187 		if (strcmp(g_SourceMod.GetGameFolderName(), "ship") == 0)
   188 		{
   189 			vsp_version = 1;
   190 		}
   191 		else
   192 		{
   193 			vsp_version = 2;
   194 		}
   195 	}
   196 #endif
   197 
   198 	/* Notify! */
   199 	SMGlobalClass *pBase = SMGlobalClass::head;
   200 	while (pBase)
   201 	{
   202 		pBase->OnSourceModVSPReceived();
   203 		pBase = pBase->m_pGlobalClassNext;
   204 	}
   205 }
   206 
   207 #if defined METAMOD_PLAPI_VERSION
   208 
   209 void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
   210 {
   211 	Global_OnUnlinkConCommandBase(pCommand);
   212 }
   213 
   214 #else
   215 
   216 void SourceMod_Core::OnPluginUnload(PluginId id)
   217 {
   218 	Global_OnUnlinkConCommandBase(NULL);
   219 }
   220 
   221 #endif