core/sourcemod.h
author David Anderson <dvander@alliedmods.net>
Sun Aug 26 17:41:02 2007 +0000 (2007-08-26)
changeset 1369 bd9ccced1b1a
parent 1330 ab94316bb52b
child 1371 d207f0e17532
permissions -rw-r--r--
fixed amb834 - command callbacks could potentially occur on invalid clients in very rare cases
     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 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_GLOBALHEADER_H_
    33 #define _INCLUDE_SOURCEMOD_GLOBALHEADER_H_
    34 
    35 #include "sm_globals.h"
    36 #include <ISourceMod.h>
    37 #include <sh_stack.h>
    38 #include "CDataPack.h"
    39 
    40 using namespace SourceHook;
    41 
    42 /**
    43  * @brief Implements SourceMod's global overall management, API, and logic
    44  */
    45 
    46 class SourceModBase : 
    47 	public ISourceMod,
    48 	public SMGlobalClass
    49 {
    50 public:
    51 	SourceModBase();
    52 public:
    53 	/**
    54 	 * @brief Initializes SourceMod, or returns an error on failure.
    55 	 */
    56 	bool InitializeSourceMod(char *error, size_t maxlength, bool late);
    57 
    58 	/** 
    59 	 * @brief Starts everything SourceMod needs to run
    60 	 */
    61 	void StartSourceMod(bool late);
    62 
    63 	/** 
    64 	 * @brief Shuts down all SourceMod components
    65 	 */
    66 	void CloseSourceMod();
    67 
    68 	/**
    69 	 * @brief Map change hook
    70 	 */
    71 	bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
    72 
    73 	/**
    74 	 * @brief Level shutdown hook
    75 	 */
    76 	void LevelShutdown();
    77 
    78 	/** 
    79 	 * @brief Returns whether or not a map load is in progress
    80 	 */
    81 	bool IsMapLoading() const;
    82 
    83 	/** 
    84 	 * @brief Stores the global target index.
    85 	 */
    86 	void SetGlobalTarget(unsigned int index);
    87 
    88 	/** 
    89 	 * @brief Returns the global target index.
    90 	 */
    91 	unsigned int GetGlobalTarget() const;
    92 	
    93 	/** 
    94 	 * @brief Sets whether if SoureMod needs to check player auths.
    95 	 */
    96 	void SetAuthChecking(bool set);
    97 public: // SMGlobalClass
    98 	ConfigResult OnSourceModConfigChanged(const char *key, 
    99 										  const char *value, 
   100 										  ConfigSource source, 
   101 										  char *error, 
   102 										  size_t maxlength);
   103 public: // ISourceMod
   104 	const char *GetGamePath() const;
   105 	const char *GetSourceModPath() const;
   106 	size_t BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...);
   107 	void LogMessage(IExtension *pExt, const char *format, ...);
   108 	void LogError(IExtension *pExt, const char *format, ...);
   109 	size_t FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param);
   110 	IDataPack *CreateDataPack();
   111 	void FreeDataPack(IDataPack *pack);
   112 	HandleType_t GetDataPackHandleType(bool readonly=false);
   113 	KeyValues *ReadKeyValuesHandle(Handle_t hndl, HandleError *err=NULL, bool root=false);
   114 	const char *GetGameFolderName() const;
   115 	ISourcePawnEngine *GetScriptingEngine();
   116 	IVirtualMachine *GetScriptingVM();
   117 	void AllPluginsLoaded();
   118 private:
   119 	/**
   120 	 * @brief Loading plugins
   121 	 */
   122 	void DoGlobalPluginLoads();
   123 
   124 	/**
   125 	 * @brief GameFrame hook
   126 	 */
   127 	void GameFrame(bool simulating);
   128 private:
   129 	CStack<CDataPack *> m_freepacks;
   130 	char m_SMBaseDir[PLATFORM_MAX_PATH];
   131 	char m_SMRelDir[PLATFORM_MAX_PATH];
   132 	char m_ModDir[32];
   133 	bool m_IsMapLoading;
   134 	bool m_ExecPluginReload;
   135 	bool m_ExecOnMapEnd;
   136 	unsigned int m_target;
   137 	bool m_CheckingAuth;
   138 	bool m_GotBasePath;
   139 };
   140 
   141 extern SourceModBase g_SourceMod;
   142 extern HandleType_t g_WrBitBufType;		//:TODO: find a better place for this
   143 extern HandleType_t g_RdBitBufType;		//:TODO: find a better place for this
   144 
   145 #endif //_INCLUDE_SOURCEMOD_GLOBALHEADER_H_