core/sm_globals.h
author David Anderson <dvander@alliedmods.net>
Wed Aug 01 02:12:47 2007 +0000 (2007-08-01)
changeset 1231 17badaf66ce4
parent 1157 61c7092246c6
child 1330 ab94316bb52b
permissions -rw-r--r--
updated more header files (mostly internal now)
     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 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_GLOBALS_H_
    34 #define _INCLUDE_SOURCEMOD_GLOBALS_H_
    35 
    36 /**
    37  * @file Contains global headers that most files in SourceMod will need.
    38  */
    39 
    40 #include <sp_vm_types.h>
    41 #include <sp_vm_api.h>
    42 #include "sm_platform.h"
    43 #include <IShareSys.h>
    44 
    45 using namespace SourcePawn;
    46 using namespace SourceMod;
    47 
    48 class IServerPluginCallbacks;
    49 
    50 /**
    51  * @brief Lists result codes possible from attempting to set a core configuration option.
    52  */
    53 enum ConfigResult
    54 {
    55 	ConfigResult_Accept = 0,	/**< Config option was successfully set */
    56 	ConfigResult_Reject = 1,	/**< Config option was given an invalid value and was rejected */
    57 	ConfigResult_Ignore = 2		/**< Config option was invalid, but ignored */
    58 };
    59 
    60 /**
    61  * @brief Lists possible sources of a config option change
    62  */
    63 enum ConfigSource
    64 {
    65 	ConfigSource_File = 0,		/**< Config option was set from config file (core.cfg) */
    66 	ConfigSource_Console = 1,	/**< Config option was set from console command (sm config) */
    67 };
    68 
    69 /** 
    70  * @brief Any class deriving from this will be automatically initiated/shutdown by SourceMod
    71  */
    72 class SMGlobalClass
    73 {
    74 	friend class SourceMod_Core;
    75 	friend class SourceModBase;
    76 	friend class CoreConfig;
    77 	friend class CExtensionManager;
    78 public:
    79 	SMGlobalClass();
    80 public:
    81 	/**
    82 	 * @brief Called when SourceMod is initially loading
    83 	 */
    84 	virtual void OnSourceModStartup(bool late)
    85 	{
    86 	}
    87 
    88 	/**
    89 	 * @brief Called after all global classes have initialized
    90 	 */
    91 	virtual void OnSourceModAllInitialized()
    92 	{
    93 	}
    94 
    95 	/**
    96 	 * @brief Called when SourceMod is shutting down
    97 	 */
    98 	virtual void OnSourceModShutdown()
    99 	{
   100 	}
   101 
   102 	/**
   103 	 * @brief Called after SourceMod is completely shut down
   104 	 */
   105 	virtual void OnSourceModAllShutdown()
   106 	{
   107 	}
   108 
   109 	/**
   110 	 * @brief Called when a core config option is changed.
   111 	 * @note This is called once BEFORE OnSourceModStartup() when SourceMod is loading
   112 	 * @note It can then be called again when the 'sm config' command is used
   113 	 */
   114 	virtual ConfigResult OnSourceModConfigChanged(const char *key, 
   115 												  const char *value, 
   116 												  ConfigSource source,
   117 												  char *error, 
   118 												  size_t maxlength)
   119 	{
   120 		return ConfigResult_Ignore;
   121 	}
   122 
   123 	/**
   124 	 * @brief Called when the level changes.
   125 	 */
   126 	virtual void OnSourceModLevelChange(const char *mapName)
   127 	{
   128 	}
   129 
   130 	/**
   131 	 * @brief Called when the level ends.
   132 	 */
   133 	virtual void OnSourceModLevelEnd()
   134 	{
   135 	}
   136 
   137 	/**
   138 	 * @brief Called after plugins are loaded on mapchange.
   139 	 */
   140 	virtual void OnSourceModPluginsLoaded()
   141 	{
   142 	}
   143 
   144 	/**
   145 	 * @brief Called when SourceMod receives a pointer to IServerPluginCallbacks from SourceMM
   146 	 */
   147 	virtual void OnSourceModVSPReceived(IServerPluginCallbacks *iface)
   148 	{
   149 	}
   150 
   151 	/**
   152 	 * @brief Called once all MM:S plugins are loaded.
   153 	 */
   154 	virtual void OnSourceModGameInitialized()
   155 	{
   156 	}
   157 
   158 	/**
   159 	 * @brief Called when an identity is dropped (right now, extensions only)
   160 	 */
   161 	virtual void OnSourceModIdentityDropped(IdentityToken_t *pToken)
   162 	{
   163 	}
   164 private:
   165 	SMGlobalClass *m_pGlobalClassNext;
   166 	static SMGlobalClass *head;
   167 };
   168 
   169 extern ISourcePawnEngine *g_pSourcePawn;
   170 extern IVirtualMachine *g_pVM;
   171 extern IdentityToken_t *g_pCoreIdent;
   172 
   173 #include "sm_autonatives.h"
   174 
   175 #endif //_INCLUDE_SOURCEMOD_GLOBALS_H_