core/sourcemm_api.cpp
author Michael McKoy <ferret99gt@gmail.com>
Wed Aug 08 23:26:42 2007 +0000 (2007-08-08)
changeset 1280 13c62962a9ef
parent 1231 17badaf66ce4
child 1330 ab94316bb52b
permissions -rw-r--r--
Corrected filename in header of basefuncommands.sp
dvander@370
     1
/**
ds@653
     2
 * vim: set ts=4 :
dvander@1231
     3
 * ================================================================
dvander@1231
     4
 * SourceMod
dvander@1231
     5
 * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
dvander@1231
     6
 * ================================================================
dvander@370
     7
 *
dvander@1231
     8
 * This program is free software; you can redistribute it and/or 
dvander@1231
     9
 * modify it under the terms of the GNU General Public License, 
dvander@1231
    10
 * version 3.0, as published by the Free Software Foundation.
dvander@1231
    11
 * 
dvander@1231
    12
 * This program is distributed in the hope that it will be useful,
dvander@1231
    13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dvander@1231
    14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dvander@1231
    15
 * GNU General Public License for more details.
dvander@1231
    16
 *
dvander@1231
    17
 * You should have received a copy of the GNU General Public License
dvander@1231
    18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
dvander@1231
    20
 * As a special exception, AlliedModders LLC gives you permission to 
dvander@1231
    21
 * link the code of this program (as well as its derivative works) to 
dvander@1231
    22
 * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
dvander@1231
    23
 * Game MODs that run on software by the Valve Corporation.  You must 
dvander@1231
    24
 * obey the GNU General Public License in all respects for all other 
dvander@1231
    25
 * code used. Additionally, AlliedModders LLC grants this exception 
dvander@1231
    26
 * to all derivative works. AlliedModders LLC defines further 
dvander@1231
    27
 * exceptions, found in LICENSE.txt (as of this writing, version 
dvander@1231
    28
 * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
dvander@370
    29
 *
dvander@370
    30
 * Version: $Id$
dvander@370
    31
 */
dvander@370
    32
dvander@145
    33
#include <oslink.h>
dvander@145
    34
#include "sourcemm_api.h"
dvander@145
    35
#include "sm_version.h"
dvander@160
    36
#include "sourcemod.h"
ds@675
    37
#include "Logger.h"
ds@1145
    38
#include "ConVarManager.h"
dvander@145
    39
dvander@160
    40
SourceMod_Core g_SourceMod_Core;
dvander@209
    41
IVEngineServer *engine = NULL;
dvander@209
    42
IServerGameDLL *gamedll = NULL;
faluco@226
    43
IServerGameClients *serverClients = NULL;
dvander@304
    44
ISmmPluginManager *g_pMMPlugins = NULL;
dvander@448
    45
CGlobalVars *gpGlobals = NULL;
ds@457
    46
ICvar *icvar = NULL;
dvander@453
    47
IGameEventManager2 *gameevents = NULL;
dvander@530
    48
IUniformRandomStream *engrandom = NULL;
dvander@496
    49
CallClass<IVEngineServer> *enginePatch = NULL;
dvander@532
    50
CallClass<IServerGameDLL> *gamedllPatch = NULL;
dvander@644
    51
IPlayerInfoManager *playerinfo = NULL;
faluco@656
    52
IBaseFileSystem *basefilesystem = NULL;
faluco@656
    53
IEngineSound *enginesound = NULL;
faluco@659
    54
IServerPluginHelpers *serverpluginhelpers = NULL;
dvander@145
    55
dvander@160
    56
PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
dvander@145
    57
dvander@145
    58
bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
dvander@145
    59
{
dvander@145
    60
	PLUGIN_SAVEVARS();
dvander@145
    61
dvander@209
    62
	GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
faluco@216
    63
	GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
faluco@226
    64
	GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
ds@457
    65
	GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
dvander@453
    66
	GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
dvander@530
    67
	GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
faluco@654
    68
	GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
faluco@656
    69
	GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
faluco@659
    70
	GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
dvander@209
    71
dvander@644
    72
	/* :TODO: Make this optional and... make it find earlier versions [?] */
dvander@644
    73
	GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
dvander@644
    74
dvander@304
    75
	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
dvander@304
    76
	{
dvander@304
    77
		if (error)
dvander@304
    78
		{
dvander@304
    79
			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
dvander@304
    80
		}
dvander@304
    81
		return false;
dvander@304
    82
	}
dvander@304
    83
dvander@448
    84
	gpGlobals = ismm->pGlobals();
ds@675
    85
	
ds@675
    86
	ismm->AddListener(this, this);
ds@675
    87
	ismm->EnableVSPListener();
dvander@448
    88
dvander@160
    89
	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
dvander@145
    90
}
dvander@145
    91
faluco@226
    92
bool SourceMod_Core::Unload(char *error, size_t maxlen)
dvander@145
    93
{
faluco@289
    94
	g_SourceMod.CloseSourceMod();
dvander@145
    95
	return true;
dvander@145
    96
}
dvander@145
    97
dvander@145
    98
bool SourceMod_Core::Pause(char *error, size_t maxlen)
dvander@145
    99
{
dvander@145
   100
	return true;
dvander@145
   101
}
dvander@145
   102
dvander@145
   103
bool SourceMod_Core::Unpause(char *error, size_t maxlen)
dvander@145
   104
{
dvander@145
   105
	return true;
dvander@145
   106
}
dvander@145
   107
dvander@145
   108
void SourceMod_Core::AllPluginsLoaded()
dvander@145
   109
{
dvander@893
   110
	g_SourceMod.AllPluginsLoaded();
dvander@145
   111
}
dvander@145
   112
dvander@145
   113
const char *SourceMod_Core::GetAuthor()
dvander@145
   114
{
dvander@145
   115
	return "AlliedModders, LLC";
dvander@145
   116
}
dvander@145
   117
dvander@145
   118
const char *SourceMod_Core::GetName()
dvander@145
   119
{
dvander@145
   120
	return "SourceMod";
dvander@145
   121
}
dvander@145
   122
dvander@145
   123
const char *SourceMod_Core::GetDescription()
dvander@145
   124
{
dvander@145
   125
	return "Extensible administration and scripting system";
dvander@145
   126
}
dvander@145
   127
dvander@145
   128
const char *SourceMod_Core::GetURL()
dvander@145
   129
{
dvander@145
   130
	return "http://www.sourcemod.net/";
dvander@145
   131
}
dvander@145
   132
dvander@145
   133
const char *SourceMod_Core::GetLicense()
dvander@145
   134
{
dvander@145
   135
	return "See LICENSE.txt";
dvander@145
   136
}
dvander@145
   137
dvander@145
   138
const char *SourceMod_Core::GetVersion()
dvander@145
   139
{
dvander@566
   140
	return SVN_FULL_VERSION;
dvander@145
   141
}
dvander@145
   142
dvander@145
   143
const char *SourceMod_Core::GetDate()
dvander@145
   144
{
dvander@145
   145
	return __DATE__;
dvander@145
   146
}
dvander@145
   147
dvander@145
   148
const char *SourceMod_Core::GetLogTag()
dvander@145
   149
{
ds@657
   150
	return "SM";
dvander@145
   151
}
ds@675
   152
ds@675
   153
void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
ds@675
   154
{
ds@675
   155
	/* This shouldn't happen */
ds@675
   156
	if (!iface)
ds@675
   157
	{
ds@675
   158
		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
ds@675
   159
		return;
ds@675
   160
	}
ds@675
   161
ds@675
   162
	/* Notify! */
ds@675
   163
	SMGlobalClass *pBase = SMGlobalClass::head;
ds@675
   164
	while (pBase)
ds@675
   165
	{
ds@675
   166
		pBase->OnSourceModVSPReceived(iface);
ds@675
   167
		pBase = pBase->m_pGlobalClassNext;
ds@675
   168
	}
ds@675
   169
}
ds@1145
   170
ds@1145
   171
#if PLAPI_VERSION >= 12
ds@1145
   172
void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
ds@1145
   173
{
ds@1145
   174
	g_ConVarManager.OnUnlinkConCommandBase(id, pCommand);
ds@1145
   175
}
ds@1145
   176
#else
ds@1145
   177
void SourceMod_Core::OnPluginUnload(PluginId id)
ds@1145
   178
{
ds@1145
   179
	g_ConVarManager.OnMetamodPluginUnloaded(id);
ds@1145
   180
}
ds@1145
   181
#endif