core/sm_globals.h
author Erik Minekus <erik@minekus.com>
Thu Aug 01 09:26:34 2013 -0400 (2013-08-01)
changeset 3967 ceafb87d38a7
parent 3010 8ea042c00c80
permissions -rw-r--r--
Numerous code documentation fixups (bug 5720, r=psychonic).
     1 /**
     2  * vim: set ts=4 sw=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2009 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 #ifndef _INCLUDE_SOURCEMOD_GLOBALS_H_
    33 #define _INCLUDE_SOURCEMOD_GLOBALS_H_
    34 
    35 /**
    36  * @file Contains global headers that most files in SourceMod will need.
    37  */
    38 
    39 #include <sp_vm_types.h>
    40 #include <sp_vm_api.h>
    41 #include "sm_platform.h"
    42 #include <IShareSys.h>
    43 
    44 using namespace SourcePawn;
    45 using namespace SourceMod;
    46 
    47 class IServerPluginCallbacks;
    48 
    49 /**
    50  * @brief Lists result codes possible from attempting to set a core configuration option.
    51  */
    52 enum ConfigResult
    53 {
    54 	ConfigResult_Accept = 0,	/**< Config option was successfully set */
    55 	ConfigResult_Reject = 1,	/**< Config option was given an invalid value and was rejected */
    56 	ConfigResult_Ignore = 2		/**< Config option was invalid, but ignored */
    57 };
    58 
    59 /**
    60  * @brief Lists possible sources of a config option change
    61  */
    62 enum ConfigSource
    63 {
    64 	ConfigSource_File = 0,		/**< Config option was set from config file (core.cfg) */
    65 	ConfigSource_Console = 1,	/**< Config option was set from console command (sm config) */
    66 };
    67 
    68 /** 
    69  * @brief Any class deriving from this will be automatically initiated/shutdown by SourceMod
    70  */
    71 class SMGlobalClass
    72 {
    73 	friend class SourceMod_Core;
    74 	friend class SourceModBase;
    75 	friend class CoreConfig;
    76 	friend class CExtensionManager;
    77 	friend class PlayerManager;
    78 public:
    79 	SMGlobalClass()
    80 	{
    81 		m_pGlobalClassNext = SMGlobalClass::head;
    82 		SMGlobalClass::head = this;
    83 	}
    84 public:
    85 	/**
    86 	 * @brief Called when SourceMod is initially loading
    87 	 */
    88 	virtual void OnSourceModStartup(bool late)
    89 	{
    90 	}
    91 
    92 	/**
    93 	 * @brief Called after all global classes have been started up
    94 	 */
    95 	virtual void OnSourceModAllInitialized()
    96 	{
    97 	}
    98 
    99 	/**
   100 	 * @brief Called after all global classes have initialized
   101 	 */
   102 	virtual void OnSourceModAllInitialized_Post()
   103 	{
   104 	}
   105 
   106 	/**
   107 	 * @brief Called when SourceMod is shutting down
   108 	 */
   109 	virtual void OnSourceModShutdown()
   110 	{
   111 	}
   112 
   113 	/**
   114 	 * @brief Called after SourceMod is completely shut down
   115 	 */
   116 	virtual void OnSourceModAllShutdown()
   117 	{
   118 	}
   119 
   120 	/**
   121 	 * @brief Called when a core config option is changed.
   122 	 * @note This is called once BEFORE OnSourceModStartup() when SourceMod is loading
   123 	 * @note It can then be called again when the 'sm config' command is used
   124 	 */
   125 	virtual ConfigResult OnSourceModConfigChanged(const char *key, 
   126 												  const char *value, 
   127 												  ConfigSource source,
   128 												  char *error, 
   129 												  size_t maxlength)
   130 	{
   131 		return ConfigResult_Ignore;
   132 	}
   133 
   134 	/**
   135 	 * @brief Called when the level changes.
   136 	 */
   137 	virtual void OnSourceModLevelChange(const char *mapName)
   138 	{
   139 	}
   140 
   141 	/**
   142 	 * @brief Called when the level has activated.
   143 	 */
   144 	virtual void OnSourceModLevelActivated()
   145 	{
   146 	}
   147 
   148 	/**
   149 	 * @brief Called when the level ends.
   150 	 */
   151 	virtual void OnSourceModLevelEnd()
   152 	{
   153 	}
   154 
   155 	/**
   156 	 * @brief Called after plugins are loaded on mapchange.
   157 	 */
   158 	virtual void OnSourceModPluginsLoaded()
   159 	{
   160 	}
   161 
   162 	/**
   163 	 * @brief Called when SourceMod receives a pointer to IServerPluginCallbacks from SourceMM
   164 	 */
   165 	virtual void OnSourceModVSPReceived()
   166 	{
   167 	}
   168 
   169 	/**
   170 	 * @brief Called once all MM:S plugins are loaded.
   171 	 */
   172 	virtual void OnSourceModGameInitialized()
   173 	{
   174 	}
   175 
   176 	/**
   177 	 * @brief Called when an identity is dropped (right now, extensions only)
   178 	 */
   179 	virtual void OnSourceModIdentityDropped(IdentityToken_t *pToken)
   180 	{
   181 	}
   182 
   183 	/**
   184 	 * @brief Called when the server maxplayers changes
   185 	 *
   186 	 * @param newvalue		New maxplayers value.
   187 	 */
   188 	virtual void OnSourceModMaxPlayersChanged(int newvalue)
   189 	{
   190 	}
   191 public:
   192 	SMGlobalClass *m_pGlobalClassNext;
   193 	static SMGlobalClass *head;
   194 };
   195 
   196 extern ISourcePawnEngine *g_pSourcePawn;
   197 extern ISourcePawnEngine2 *g_pSourcePawn2;
   198 extern IdentityToken_t *g_pCoreIdent;
   199 
   200 namespace SourceMod
   201 {
   202 	class IThreader;
   203 	class ITextParsers;
   204 }
   205 
   206 extern IThreader *g_pThreader;
   207 extern ITextParsers *textparsers;
   208 
   209 #include "sm_autonatives.h"
   210 
   211 #endif //_INCLUDE_SOURCEMOD_GLOBALS_H_
   212