sourcemm/metamod_provider.h
changeset 371 751179604513
child 408 a0f99231cf3b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sourcemm/metamod_provider.h	Thu Oct 04 20:15:25 2007 +0000
     1.3 @@ -0,0 +1,294 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * ======================================================
     1.7 + * Metamod:Source
     1.8 + * Copyright (C) 2004-2007 AlliedModders LLC and authors.
     1.9 + * All rights reserved.
    1.10 + * ======================================================
    1.11 + *
    1.12 + * This software is provided 'as-is', without any express or implied warranty.
    1.13 + * In no event will the authors be held liable for any damages arising from 
    1.14 + * the use of this software.
    1.15 + * 
    1.16 + * Permission is granted to anyone to use this software for any purpose, 
    1.17 + * including commercial applications, and to alter it and redistribute it 
    1.18 + * freely, subject to the following restrictions:
    1.19 + *
    1.20 + * 1. The origin of this software must not be misrepresented; you must not 
    1.21 + * claim that you wrote the original software. If you use this software in a 
    1.22 + * product, an acknowledgment in the product documentation would be 
    1.23 + * appreciated but is not required.
    1.24 + * 2. Altered source versions must be plainly marked as such, and must not be
    1.25 + * misrepresented as being the original software.
    1.26 + * 3. This notice may not be removed or altered from any source distribution.
    1.27 + *
    1.28 + * Version: $Id$
    1.29 + */
    1.30 +
    1.31 +#ifndef _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
    1.32 +#define _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
    1.33 +
    1.34 +namespace SourceMM
    1.35 +{
    1.36 +	enum
    1.37 +	{
    1.38 +		ConVarFlag_None,
    1.39 +		ConVarFlag_Notify,
    1.40 +		ConVarFlag_Replicated,
    1.41 +		ConVarFlag_SpOnly
    1.42 +	};
    1.43 +
    1.44 +	enum ProvidedHooks
    1.45 +	{
    1.46 +		ProvidedHook_LevelInit = 0,			/**< IServerGameDLL::LevelInit */
    1.47 +		ProvidedHook_LevelShutdown = 1,		/**< IServerGameDLL::LevelShutdown */
    1.48 +		ProvidedHook_DLLInit = 2,			/**< IServerGameDLL::DLLInit */
    1.49 +		ProvidedHook_DLLShutdown = 3,		/**< IServerGameDLL::DLLShutdown */
    1.50 +		ProvidedHook_GameInit = 4,			/**< IServerGameDLL::GameInit */
    1.51 +	};
    1.52 +
    1.53 +	/**
    1.54 +	 * @brief Abstracts command information, since the new engine fixes the 
    1.55 +	 * re-entrancy problems in the tokenization system.
    1.56 +	 */
    1.57 +	class IMetamodSourceCommandInfo
    1.58 +	{
    1.59 +	public:
    1.60 +		/**
    1.61 +		 * @brief Returns the argument count such that arguments 
    1.62 +		 * 1 to N are valid arguments, and 0 is the command name.
    1.63 +		 *
    1.64 +		 * @return					Argument count.
    1.65 +		 */
    1.66 +		virtual unsigned int GetArgCount() =0;
    1.67 +
    1.68 +		/**
    1.69 +		 * @brief Returns the string of an argument number.
    1.70 +		 *
    1.71 +		 * @param num				Argument number.
    1.72 +		 * @return					Argument text.
    1.73 +		 */
    1.74 +		virtual const char *GetArg(unsigned int num) =0;
    1.75 +
    1.76 +		/**
    1.77 +		 * @brief Returns the entire command argument string.
    1.78 +		 *
    1.79 +		 * @return					Argument string.
    1.80 +		 */
    1.81 +		virtual const char *GetArgString() =0;
    1.82 +	};
    1.83 +
    1.84 +	class IMetamodSourceProvider
    1.85 +	{
    1.86 +	public:
    1.87 +		/**
    1.88 +		 * @brief Returns whether source engine build is compatible.
    1.89 +		 *
    1.90 +		 * @param build				Source engine build.
    1.91 +		 * @return					True if compatible, false otherwise.
    1.92 +		 */
    1.93 +		virtual bool IsSourceEngineBuildCompatible(int build) =0;
    1.94 +
    1.95 +		/**
    1.96 +		 * @brief Retrieves hook information for each callback.  Each hook 
    1.97 +		 * must be implemented.
    1.98 +		 *
    1.99 +		 * @param hook				Hook information to provide.
   1.100 +		 * @param pInfo				Non-NULL pointer to fill with information 
   1.101 +		 * 							about the hook's virtual location.
   1.102 +		 * @return					True if supported, false to fail, which 
   1.103 +		 * 							will cause Metamod:Source to fail.
   1.104 +		 */
   1.105 +		virtual bool GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo) =0;
   1.106 +
   1.107 +		/**
   1.108 +		 * @brief Logs a message via IVEngineServer::LogPrint.
   1.109 +		 * 
   1.110 +		 * @param buffer			Buffer to print.
   1.111 +		 * @return					True on success, false if not supported, 
   1.112 +		 * 							or IVEngineServer is not yet known.
   1.113 +		 */
   1.114 +		virtual bool LogMessage(const char *buffer) =0;
   1.115 +
   1.116 +		/**
   1.117 +		 * @brief Returns the command line value of a parameter.  If ICvar 
   1.118 +		 * is not yet loaded, this uses an equivalent function.
   1.119 +		 *
   1.120 +		 * @param key				Parameter to look up.
   1.121 +		 * @param val				Default string to return if none found.
   1.122 +		 * @return					Parameter value.
   1.123 +		 */
   1.124 +		virtual const char *GetCommandLineValue(const char *key, const char *defval) =0;
   1.125 +
   1.126 +		/**
   1.127 +		 * @brief Prints a string to the remote server console. 
   1.128 +		 * 
   1.129 +		 * Note: new lines are not appended.
   1.130 +		 *
   1.131 +		 * @param msg			 	Message string.
   1.132 +		 */
   1.133 +		virtual void ConsolePrint(const char *msg) =0;
   1.134 +
   1.135 +		/**
   1.136 +		 * @brief Returns whether remote printing is available.
   1.137 +		 *
   1.138 +		 * @return					True if remote printing is available, 
   1.139 +		 * 							otherwise returns false.
   1.140 +		 */
   1.141 +		virtual bool IsRemotePrintingAvailable() =0;
   1.142 +
   1.143 +		/**
   1.144 +		 * @brief Prints text in the specified client's console.
   1.145 +		 *
   1.146 +		 * @param client			Client edict pointer.
   1.147 +		 * @param msg				Message string.
   1.148 +		 */
   1.149 +		virtual void ClientConsolePrint(edict_t *client, const char *msg) =0;
   1.150 +
   1.151 +		/**
   1.152 +		 * @brief Returns a server plugin helper for the given interface 
   1.153 +		 * string.
   1.154 +		 *
   1.155 +		 * @param iface				Interface version
   1.156 +		 * @return					IServerPluginCallbacks pointer.
   1.157 +		 */
   1.158 +		virtual IServerPluginCallbacks *GetVSPCallbacks(const char *iface) =0;
   1.159 +
   1.160 +		/**
   1.161 +		 * @brief Halts the server with a fatal error message.
   1.162 +		 *
   1.163 +		 * No newline is appended.
   1.164 +		 *
   1.165 +		 * @param fmt				Formatted message string.
   1.166 +		 * @param ...				Format parameters.
   1.167 +		 */
   1.168 +		virtual void DisplayError(const char *fmt, ...) =0;
   1.169 +
   1.170 +		/**
   1.171 +		 * @brief Sends the server a warning message.
   1.172 +		 *
   1.173 +		 * No newline is appended.
   1.174 +		 *
   1.175 +		 * @param fmt				Formatted message string.
   1.176 +		 * @param ...				Format parameters.
   1.177 +		 */
   1.178 +		virtual void DisplayWarning(const char *fmt, ...) =0;
   1.179 +
   1.180 +		/**
   1.181 +		 * @brief Attempts to notify the provider of the gamedll version being 
   1.182 +		 * used.
   1.183 +		 *
   1.184 +		 * @param iface				Interface string.
   1.185 +		 * @return					Version number on success, 0 otherwise.
   1.186 +		 */
   1.187 +		virtual int TryServerGameDLL(const char *iface) =0;
   1.188 +
   1.189 +		/**
   1.190 +		 * @brief Notifies the provider that the DLLInit pre-hook is almost done.
   1.191 +		 */
   1.192 +		virtual void Notify_DLLInit_Pre(void *gamedll,
   1.193 +			CreateInterfaceFn engineFactory, 
   1.194 +			CreateInterfaceFn serverFactory) =0;
   1.195 +
   1.196 +		virtual void Notify_DLLShutdown_Pre() =0;
   1.197 +
   1.198 +		/**
   1.199 +		 * @brief Wrapper around IVEngineServer::ServerCommand()
   1.200 +		 *
   1.201 +		 * @param cmd				Command string.
   1.202 +		 */
   1.203 +		virtual void ServerCommand(const char *cmd) =0;
   1.204 +
   1.205 +		/**
   1.206 +		 * @brief Creates a ConVar pointer.
   1.207 +		 *
   1.208 +		 * @param name				ConVar name.
   1.209 +		 * @param defval			Default value string.
   1.210 +		 * @param flags				ConVar flags.
   1.211 +		 * @param help				Help text.
   1.212 +		 * @return					ConVar pointer.
   1.213 +		 */
   1.214 +		virtual ConVar *CreateConVar(const char *name, 
   1.215 +			const char *defval, 
   1.216 +			const char *help,
   1.217 +			int flags) =0;
   1.218 +
   1.219 +		/**
   1.220 +		 * @brief Returns the string value of a ConVar.
   1.221 +		 *
   1.222 +		 * @param convar			ConVar pointer.
   1.223 +		 * @return					String value.
   1.224 +		 */
   1.225 +		virtual const char *GetConVarString(ConVar *convar) =0;
   1.226 +
   1.227 +		/**
   1.228 +		 * @brief Retrieves the game description.
   1.229 +		 *
   1.230 +		 * @return					Game description.
   1.231 +		 */
   1.232 +		virtual const char *GetGameDescription() =0;
   1.233 +
   1.234 +		/**
   1.235 +		 * @brief Returns the ConCommandBase accessor.
   1.236 +		 *
   1.237 +		 * @return				An IConCommandBaseAccessor pointer.
   1.238 +		 */
   1.239 +		virtual IConCommandBaseAccessor *GetConCommandBaseAccessor() =0;
   1.240 +
   1.241 +		/**
   1.242 +		 * @brief Registers a ConCommandBase.
   1.243 +		 *
   1.244 +		 * @param pCommand		ConCommandBase to register.
   1.245 +		 * @return				True if successful, false otherwise.
   1.246 +		 */
   1.247 +		virtual bool RegisterConCommandBase(ConCommandBase *pCommand) =0;
   1.248 +
   1.249 +		/**
   1.250 +		 * @brief Unregisters a ConCommandBase.
   1.251 +		 *
   1.252 +		 * @param pCommand		ConCommandBase to unlink.
   1.253 +		 */
   1.254 +		virtual void UnregisterConCommandBase(ConCommandBase *pCommand) =0;
   1.255 +
   1.256 +		/**
   1.257 +		 * @brief Returns whether a ConCommandBase is a command or not.
   1.258 +		 *
   1.259 +		 * @param pCommand		ConCommandBase pointer.
   1.260 +		 * @return				True if a command, false otherwise.
   1.261 +		 */
   1.262 +		virtual bool IsConCommandBaseACommand(ConCommandBase *pCommand) =0;
   1.263 +
   1.264 +		/**
   1.265 +		 * @brief Returns the number of user messages in the GameDLL.
   1.266 +		 *
   1.267 +		 * @return				Number of user messages, or -1 if SourceMM has 
   1.268 +		 *						failed to get user message list.
   1.269 +		 */
   1.270 +		virtual int GetUserMessageCount() =0;
   1.271 +
   1.272 +		/**
   1.273 +		 * @brief Returns the index of the specified user message.
   1.274 +		 *
   1.275 +		 * @param name			User message name.
   1.276 +		 * @param size			Optional pointer to store size of user message.
   1.277 +		 * @return				Message index, or -1 on failure.
   1.278 +		 */
   1.279 +		virtual int FindUserMessage(const char *name, int *size=NULL) =0;
   1.280 +
   1.281 +		/**
   1.282 +		 * @brief Returns the name of the specified user message.
   1.283 +		 *
   1.284 +		 * @param index			User message index.
   1.285 +		 * @param size			Optional pointer to store size of user message.
   1.286 +		 * @return				Message name, or NULL on failure.
   1.287 +		 */
   1.288 +		virtual const char *GetUserMessage(int index, int *size=NULL) =0;
   1.289 +	};
   1.290 +};
   1.291 +
   1.292 +extern PluginId g_PLID;
   1.293 +extern SourceHook::ISourceHook *g_SHPtr;
   1.294 +extern SourceMM::IMetamodSourceProvider *provider;
   1.295 +
   1.296 +#endif //_INCLUDE_METAMOD_SOURCE_SUPPORT_H_
   1.297 +