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