core/sourcemm_api.cpp
author Scott Ehlert <ds@alliedmods.net>
Wed Aug 15 06:19:30 2007 +0000 (2007-08-15)
changeset 1330 ab94316bb52b
parent 1231 17badaf66ce4
child 1541 e46ad208b9b4
permissions -rw-r--r--
Updated license headers on virtually all files with extremely minor changes in the name of some sort of strange consistency.
All plugin and include file headers also have been changed to say about GPL3 instead of GPL2.

(This day shall henceforth be known as the Eighty Column Massacre of '07)
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
dvander@145
    32
#include <oslink.h>
dvander@145
    33
#include "sourcemm_api.h"
dvander@145
    34
#include "sm_version.h"
dvander@160
    35
#include "sourcemod.h"
ds@675
    36
#include "Logger.h"
ds@1145
    37
#include "ConVarManager.h"
dvander@145
    38
dvander@160
    39
SourceMod_Core g_SourceMod_Core;
dvander@209
    40
IVEngineServer *engine = NULL;
dvander@209
    41
IServerGameDLL *gamedll = NULL;
faluco@226
    42
IServerGameClients *serverClients = NULL;
dvander@304
    43
ISmmPluginManager *g_pMMPlugins = NULL;
dvander@448
    44
CGlobalVars *gpGlobals = NULL;
ds@457
    45
ICvar *icvar = NULL;
dvander@453
    46
IGameEventManager2 *gameevents = NULL;
dvander@530
    47
IUniformRandomStream *engrandom = NULL;
dvander@496
    48
CallClass<IVEngineServer> *enginePatch = NULL;
dvander@532
    49
CallClass<IServerGameDLL> *gamedllPatch = NULL;
dvander@644
    50
IPlayerInfoManager *playerinfo = NULL;
faluco@656
    51
IBaseFileSystem *basefilesystem = NULL;
faluco@656
    52
IEngineSound *enginesound = NULL;
faluco@659
    53
IServerPluginHelpers *serverpluginhelpers = NULL;
dvander@145
    54
dvander@160
    55
PLUGIN_EXPOSE(SourceMod, g_SourceMod_Core);
dvander@145
    56
dvander@145
    57
bool SourceMod_Core::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool late)
dvander@145
    58
{
dvander@145
    59
	PLUGIN_SAVEVARS();
dvander@145
    60
dvander@209
    61
	GET_V_IFACE_ANY(serverFactory, gamedll, IServerGameDLL, INTERFACEVERSION_SERVERGAMEDLL);
faluco@216
    62
	GET_V_IFACE_CURRENT(engineFactory, engine, IVEngineServer, INTERFACEVERSION_VENGINESERVER);
faluco@226
    63
	GET_V_IFACE_CURRENT(serverFactory, serverClients, IServerGameClients, INTERFACEVERSION_SERVERGAMECLIENTS);
ds@457
    64
	GET_V_IFACE_CURRENT(engineFactory, icvar, ICvar, VENGINE_CVAR_INTERFACE_VERSION);
dvander@453
    65
	GET_V_IFACE_CURRENT(engineFactory, gameevents, IGameEventManager2, INTERFACEVERSION_GAMEEVENTSMANAGER2);
dvander@530
    66
	GET_V_IFACE_CURRENT(engineFactory, engrandom, IUniformRandomStream, VENGINE_SERVER_RANDOM_INTERFACE_VERSION);
faluco@654
    67
	GET_V_IFACE_CURRENT(fileSystemFactory, basefilesystem, IBaseFileSystem, BASEFILESYSTEM_INTERFACE_VERSION);
faluco@656
    68
	GET_V_IFACE_CURRENT(engineFactory, enginesound, IEngineSound, IENGINESOUND_SERVER_INTERFACE_VERSION);
faluco@659
    69
	GET_V_IFACE_CURRENT(engineFactory, serverpluginhelpers, IServerPluginHelpers, INTERFACEVERSION_ISERVERPLUGINHELPERS);
dvander@209
    70
dvander@644
    71
	/* :TODO: Make this optional and... make it find earlier versions [?] */
dvander@644
    72
	GET_V_IFACE_CURRENT(serverFactory, playerinfo, IPlayerInfoManager, INTERFACEVERSION_PLAYERINFOMANAGER);
dvander@644
    73
dvander@304
    74
	if ((g_pMMPlugins = (ISmmPluginManager *)g_SMAPI->MetaFactory(MMIFACE_PLMANAGER, NULL, NULL)) == NULL)
dvander@304
    75
	{
dvander@304
    76
		if (error)
dvander@304
    77
		{
dvander@304
    78
			snprintf(error, maxlen, "Unable to find interface %s", MMIFACE_PLMANAGER);
dvander@304
    79
		}
dvander@304
    80
		return false;
dvander@304
    81
	}
dvander@304
    82
dvander@448
    83
	gpGlobals = ismm->pGlobals();
ds@675
    84
	
ds@675
    85
	ismm->AddListener(this, this);
ds@675
    86
	ismm->EnableVSPListener();
dvander@448
    87
dvander@160
    88
	return g_SourceMod.InitializeSourceMod(error, maxlen, late);
dvander@145
    89
}
dvander@145
    90
faluco@226
    91
bool SourceMod_Core::Unload(char *error, size_t maxlen)
dvander@145
    92
{
faluco@289
    93
	g_SourceMod.CloseSourceMod();
dvander@145
    94
	return true;
dvander@145
    95
}
dvander@145
    96
dvander@145
    97
bool SourceMod_Core::Pause(char *error, size_t maxlen)
dvander@145
    98
{
dvander@145
    99
	return true;
dvander@145
   100
}
dvander@145
   101
dvander@145
   102
bool SourceMod_Core::Unpause(char *error, size_t maxlen)
dvander@145
   103
{
dvander@145
   104
	return true;
dvander@145
   105
}
dvander@145
   106
dvander@145
   107
void SourceMod_Core::AllPluginsLoaded()
dvander@145
   108
{
dvander@893
   109
	g_SourceMod.AllPluginsLoaded();
dvander@145
   110
}
dvander@145
   111
dvander@145
   112
const char *SourceMod_Core::GetAuthor()
dvander@145
   113
{
ds@1330
   114
	return "AlliedModders LLC";
dvander@145
   115
}
dvander@145
   116
dvander@145
   117
const char *SourceMod_Core::GetName()
dvander@145
   118
{
dvander@145
   119
	return "SourceMod";
dvander@145
   120
}
dvander@145
   121
dvander@145
   122
const char *SourceMod_Core::GetDescription()
dvander@145
   123
{
dvander@145
   124
	return "Extensible administration and scripting system";
dvander@145
   125
}
dvander@145
   126
dvander@145
   127
const char *SourceMod_Core::GetURL()
dvander@145
   128
{
dvander@145
   129
	return "http://www.sourcemod.net/";
dvander@145
   130
}
dvander@145
   131
dvander@145
   132
const char *SourceMod_Core::GetLicense()
dvander@145
   133
{
dvander@145
   134
	return "See LICENSE.txt";
dvander@145
   135
}
dvander@145
   136
dvander@145
   137
const char *SourceMod_Core::GetVersion()
dvander@145
   138
{
dvander@566
   139
	return SVN_FULL_VERSION;
dvander@145
   140
}
dvander@145
   141
dvander@145
   142
const char *SourceMod_Core::GetDate()
dvander@145
   143
{
dvander@145
   144
	return __DATE__;
dvander@145
   145
}
dvander@145
   146
dvander@145
   147
const char *SourceMod_Core::GetLogTag()
dvander@145
   148
{
ds@657
   149
	return "SM";
dvander@145
   150
}
ds@675
   151
ds@675
   152
void SourceMod_Core::OnVSPListening(IServerPluginCallbacks *iface)
ds@675
   153
{
ds@675
   154
	/* This shouldn't happen */
ds@675
   155
	if (!iface)
ds@675
   156
	{
ds@675
   157
		g_Logger.LogFatal("Metamod:Source version is out of date. SourceMod requires 1.4 or greater.");
ds@675
   158
		return;
ds@675
   159
	}
ds@675
   160
ds@675
   161
	/* Notify! */
ds@675
   162
	SMGlobalClass *pBase = SMGlobalClass::head;
ds@675
   163
	while (pBase)
ds@675
   164
	{
ds@675
   165
		pBase->OnSourceModVSPReceived(iface);
ds@675
   166
		pBase = pBase->m_pGlobalClassNext;
ds@675
   167
	}
ds@675
   168
}
ds@1145
   169
ds@1145
   170
#if PLAPI_VERSION >= 12
ds@1145
   171
void SourceMod_Core::OnUnlinkConCommandBase(PluginId id, ConCommandBase *pCommand)
ds@1145
   172
{
ds@1145
   173
	g_ConVarManager.OnUnlinkConCommandBase(id, pCommand);
ds@1145
   174
}
ds@1145
   175
#else
ds@1145
   176
void SourceMod_Core::OnPluginUnload(PluginId id)
ds@1145
   177
{
ds@1145
   178
	g_ConVarManager.OnMetamodPluginUnloaded(id);
ds@1145
   179
}
ds@1145
   180
#endif