core/logic/intercom.h
author David Anderson <dvander@alliedmods.net>
Thu Aug 08 22:02:42 2013 -0700 (2013-08-08)
changeset 3980 dc7dfcd855dc
parent 3929 0bc0ffdb2eba
child 4029 cf8bdfcf6503
permissions -rw-r--r--
More Windows build fix.
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet:
     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_INTERCOM_H_
    33 #define _INCLUDE_SOURCEMOD_INTERCOM_H_
    34 
    35 #include <sp_vm_api.h>
    36 #include <IHandleSys.h>
    37 #include <IShareSys.h>
    38 #include <IPluginSys.h>
    39 #include <sh_string.h>
    40 #include <sp_vm_api.h>
    41 #include <sh_vector.h>
    42 #include <IExtensionSys.h>
    43 
    44 using namespace SourceMod;
    45 using namespace SourcePawn;
    46 using namespace SourceHook;
    47 
    48 /**
    49  * Add 1 to the RHS of this expression to bump the intercom file
    50  * This is to prevent mismatching core/logic binaries
    51  */
    52 #define SM_LOGIC_MAGIC		(0x0F47C0DE - 22)
    53 
    54 #if defined SM_LOGIC
    55 class IVEngineServer
    56 #else
    57 class IVEngineServer_Logic
    58 #endif
    59 {
    60 public:
    61 	virtual bool IsMapValid(const char *map) = 0;
    62 	virtual void ServerCommand(const char *cmd) = 0;
    63 };
    64 
    65 typedef int FileFindHandle_t; 
    66 
    67 #if defined SM_LOGIC
    68 class IFileSystem
    69 #else
    70 class IFileSystem_Logic
    71 #endif
    72 {
    73 public:
    74 	virtual const char *FindFirstEx(const char *pWildCard, const char *pPathID, FileFindHandle_t *pHandle) = 0;
    75 	virtual const char *FindNext(FileFindHandle_t handle) = 0;
    76 	virtual void FindClose(FileFindHandle_t handle) = 0;
    77 };
    78 
    79 namespace SourceMod
    80 {
    81 	class ISourceMod;
    82 	class ILibrarySys;
    83 	class ITextParsers;
    84 	class IThreader;
    85 	class IRootConsole;
    86 	class IPluginManager;
    87 	class IForwardManager;
    88 	class ITimerSystem;
    89 	class IPlayerManager;
    90 	class IAdminSystem;
    91 	class IGameHelpers;
    92 	class IPhraseCollection;
    93 	class ITranslator;
    94 	class IGameConfig;
    95 }
    96 
    97 class IVEngineServer;
    98 class IFileSystem;
    99 class ConVar;
   100 class SMGlobalClass;
   101 
   102 namespace SourceMod
   103 {
   104 	class IChangeableForward;
   105 }
   106 
   107 struct ServerGlobals
   108 {
   109 	const double *universalTime;
   110 	float *interval_per_tick;
   111 	float *frametime;
   112 };
   113 
   114 struct AutoConfig
   115 {
   116 	SourceHook::String autocfg;
   117 	SourceHook::String folder;
   118 	bool create;
   119 };
   120 
   121 enum LibraryAction
   122 {
   123 	LibraryAction_Removed,
   124 	LibraryAction_Added
   125 };
   126 
   127 class CNativeOwner;
   128 
   129 class SMPlugin : public IPlugin
   130 {
   131 public:
   132 	virtual size_t GetConfigCount() = 0;
   133 	virtual AutoConfig *GetConfig(size_t i) = 0;
   134 	virtual void AddLibrary(const char *name) = 0;
   135 	virtual void AddConfig(bool create, const char *cfg, const char *folder) = 0;
   136 	virtual void SetErrorState(PluginStatus status, const char *fmt, ...) = 0;
   137 };
   138 
   139 class IScriptManager
   140 {
   141 public:
   142 	virtual void LoadAll(const char *config_path, const char *plugins_path) = 0;
   143 	virtual void RefreshAll() = 0;
   144 	virtual void Shutdown() = 0;
   145 	virtual IdentityToken_t *GetIdentity() = 0;
   146 	virtual void SyncMaxClients(int maxClients) = 0;
   147 	virtual void AddPluginsListener(IPluginsListener *listener) = 0;
   148 	virtual void RemovePluginsListener(IPluginsListener *listener) = 0;
   149 	virtual IPluginIterator *GetPluginIterator() = 0;
   150 	virtual void OnLibraryAction(const char *name, LibraryAction action) = 0;
   151 	virtual bool LibraryExists(const char *name) = 0;
   152 	virtual SMPlugin *FindPluginByOrder(unsigned num) = 0;
   153 	virtual SMPlugin *FindPluginByIdentity(IdentityToken_t *ident) = 0;
   154 	virtual SMPlugin *FindPluginByContext(IPluginContext *ctx) = 0;
   155 	virtual SMPlugin *FindPluginByContext(sp_context_t *ctx) = 0;
   156 	virtual SMPlugin *FindPluginByConsoleArg(const char *text) = 0;
   157 	virtual SMPlugin *FindPluginByHandle(Handle_t hndl, HandleError *errp) = 0;
   158 	virtual bool UnloadPlugin(IPlugin *plugin) = 0;
   159 	virtual const CVector<SMPlugin *> *ListPlugins() = 0;
   160 	virtual void FreePluginList(const CVector<SMPlugin *> *list) = 0;
   161 	virtual void AddFunctionsToForward(const char *name, IChangeableForward *fwd) = 0;
   162 };
   163 
   164 class IExtensionSys : public IExtensionManager
   165 {
   166 public:
   167 	virtual IExtension *LoadAutoExtension(const char *name) = 0;
   168 	virtual void TryAutoload() = 0;
   169 	virtual void Shutdown() = 0;
   170 	virtual IExtension *FindExtensionByFile(const char *name) = 0;
   171 	virtual bool LibraryExists(const char *name) = 0;
   172 	virtual void CallOnCoreMapStart(edict_t *edictList, int edictCount, int maxClients) = 0;
   173 	virtual IExtension *GetExtensionFromIdent(IdentityToken_t *token) = 0;
   174 	virtual void BindChildPlugin(IExtension *ext, SMPlugin *plugin) = 0;
   175 	virtual void AddRawDependency(IExtension *myself, IdentityToken_t *token, void *iface) = 0;
   176 	virtual const CVector<IExtension *> *ListExtensions() = 0;
   177 	virtual void FreeExtensionList(const CVector<IExtension *> *list) = 0;
   178 };
   179 
   180 class AutoPluginList
   181 {
   182 public:
   183 	AutoPluginList(IScriptManager *scripts)
   184 		: scripts_(scripts), list_(scripts->ListPlugins())
   185 	{
   186 	}
   187 	~AutoPluginList()
   188 	{
   189 		scripts_->FreePluginList(list_);
   190 	}
   191 	const CVector<SMPlugin *> *operator ->()
   192 	{
   193 		return list_;
   194 	}
   195 private:
   196 	IScriptManager *scripts_;
   197 	const CVector<SMPlugin *> *list_;
   198 };
   199 
   200 class AutoExtensionList
   201 {
   202 public:
   203 	AutoExtensionList(IExtensionSys *extensions)
   204 		: extensions_(extensions), list_(extensions_->ListExtensions())
   205 	{
   206 	}
   207 	~AutoExtensionList()
   208 	{
   209 		extensions_->FreeExtensionList(list_);
   210 	}
   211 	const CVector<IExtension *> *operator ->()
   212 	{
   213 		return list_;
   214 	}
   215 private:
   216 	IExtensionSys *extensions_;
   217 	const CVector<IExtension *> *list_;
   218 };
   219 
   220 class CCommand;
   221 
   222 struct sm_core_t
   223 {
   224 	/* Objects */
   225 	ISourceMod		*sm;
   226 	ILibrarySys		*libsys;
   227 	IVEngineServer	*engine;
   228 	IFileSystem		*filesystem;
   229 	IRootConsole	*rootmenu;
   230 	IForwardManager	*forwardsys;
   231 	ITimerSystem    *timersys;
   232 	IPlayerManager  *playerhelpers;
   233 	IAdminSystem	*adminsys;
   234 	IGameHelpers    *gamehelpers;
   235 	ISourcePawnEngine **spe1;
   236 	ISourcePawnEngine2 **spe2;
   237 	/* Functions */
   238 	ConVar *		(*FindConVar)(const char*);
   239 	unsigned int	(*strncopy)(char*, const char*, size_t);
   240 	char *			(*TrimWhitespace)(char *, size_t &);
   241 	void			(*LogError)(const char*, ...);
   242 	void			(*LogFatal)(const char*, ...);
   243 	void			(*Log)(const char*, ...);
   244 	void			(*LogToFile)(FILE *fp, const char*, ...);
   245 	void			(*LogToGame)(const char *message);
   246 	bool			(*FileExists)(const char *path);
   247 	const char *	(*GetCvarString)(ConVar*);
   248 	size_t			(*Format)(char*, size_t, const char*, ...);
   249 	size_t			(*FormatArgs)(char*, size_t, const char*,va_list ap);
   250 	bool			(*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **,
   251 	                            unsigned int, unsigned int &, size_t *, const char **);
   252 	size_t			(*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *);
   253 	bool            (*GetGameName)(char *buffer, size_t maxlength);
   254 	const char *    (*GetGameDescription)();
   255 	const char *    (*GetSourceEngineName)();
   256 	bool            (*SymbolsAreHidden)();
   257 	const char *	(*GetCoreConfigValue)(const char*);
   258 	bool			(*IsMapLoading)();
   259 	bool			(*IsMapRunning)();
   260 	int				(*Argc)(const CCommand &args);
   261 	const char *	(*Arg)(const CCommand &args, int arg);
   262 	int				(*LoadMMSPlugin)(const char *file, bool *ok, char *error, size_t maxlength);
   263 	void			(*UnloadMMSPlugin)(int id);
   264 	void			(*DoGlobalPluginLoads)();
   265 	bool			(*AreConfigsExecuted)();
   266 	void			(*ExecuteConfigs)(IPluginContext *ctx);
   267 	const char		*gamesuffix;
   268 	/* Data */
   269 	ServerGlobals   *serverGlobals;
   270 	void *          serverFactory;
   271 	void *          engineFactory;
   272 	void *          matchmakingDSFactory;
   273 };
   274 
   275 struct sm_logic_t
   276 {
   277 	SMGlobalClass	*head;
   278 	IThreader		*threader;
   279 	IProfiler		*profiler;
   280 	ITranslator		*translator;
   281 	const char      *(*stristr)(const char *, const char *);
   282 	bool			(*CoreTranslate)(char *,  size_t, const char *, unsigned int, size_t *, ...);
   283 	void            (*AddCorePhraseFile)(const char *filename);
   284 	unsigned int	(*ReplaceAll)(char*, size_t, const char *, const char *, bool);
   285 	char            *(*ReplaceEx)(char *, size_t, const char *, size_t, const char *, size_t, bool);
   286 	size_t          (*DecodeHexString)(unsigned char *, size_t, const char *);
   287 	IGameConfig *   (*GetCoreGameConfig)();
   288 	bool			(*OnLogPrint)(const char *msg);	// true to supercede
   289 	IDebugListener   *debugger;
   290 	void			(*GenerateError)(IPluginContext *, cell_t, int, const char *, ...);
   291 	void			(*AddNatives)(sp_nativeinfo_t *natives);
   292 	void			(*DumpHandles)(void (*dumpfn)(const char *fmt, ...));
   293 	IScriptManager	*scripts;
   294 	IShareSys		*sharesys;
   295 	IExtensionSys	*extsys;
   296 	IHandleSys		*handlesys;
   297 	IdentityToken_t *core_ident;
   298 	float			sentinel;
   299 };
   300 
   301 typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic);
   302 typedef LogicInitFunction (*LogicLoadFunction)(uint32_t magic);
   303 typedef ITextParsers *(*GetITextParsers)();
   304 
   305 #endif /* _INCLUDE_SOURCEMOD_INTERCOM_H_ */