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