core/metamod_provider.h
author David Anderson <dvander@alliedmods.net>
Sat Mar 12 20:18:10 2011 -0800 (2011-03-12)
changeset 742 f38fc2289fa5
parent 683 b507295429f9
permissions -rw-r--r--
Updated symstore logic.
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2009 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     9  * This software is provided 'as-is', without any express or implied warranty.
    10  * In no event will the authors be held liable for any damages arising from 
    11  * the use of this software.
    12  * 
    13  * Permission is granted to anyone to use this software for any purpose, 
    14  * including commercial applications, and to alter it and redistribute it 
    15  * freely, subject to the following restrictions:
    16  *
    17  * 1. The origin of this software must not be misrepresented; you must not 
    18  * claim that you wrote the original software. If you use this software in a 
    19  * product, an acknowledgment in the product documentation would be 
    20  * appreciated but is not required.
    21  * 2. Altered source versions must be plainly marked as such, and must not be
    22  * misrepresented as being the original software.
    23  * 3. This notice may not be removed or altered from any source distribution.
    24  */
    25 
    26 #ifndef _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
    27 #define _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
    28 
    29 namespace SourceMM
    30 {
    31 	enum
    32 	{
    33 		ConVarFlag_None = 0,
    34 		ConVarFlag_Notify = 1,
    35 		ConVarFlag_SpOnly = 2,
    36 	};
    37 
    38 	enum ProvidedHooks
    39 	{
    40 		ProvidedHook_LevelInit = 0,			/**< IServerGameDLL::LevelInit */
    41 		ProvidedHook_LevelShutdown = 1,		/**< IServerGameDLL::LevelShutdown */
    42 		ProvidedHook_GameInit = 4,			/**< IServerGameDLL::GameInit */
    43 	};
    44 
    45 	/**
    46 	 * @brief Abstracts command information, since the new engine fixes the 
    47 	 * re-entrancy problems in the tokenization system.
    48 	 */
    49 	class IMetamodSourceCommandInfo
    50 	{
    51 	public:
    52 		/**
    53 		 * @brief Returns the argument count such that arguments 
    54 		 * 1 to N are valid arguments, and 0 is the command name.
    55 		 *
    56 		 * @return					Argument count.
    57 		 */
    58 		virtual unsigned int GetArgCount() =0;
    59 
    60 		/**
    61 		 * @brief Returns the string of an argument number.
    62 		 *
    63 		 * @param num				Argument number.
    64 		 * @return					Argument text.
    65 		 */
    66 		virtual const char *GetArg(unsigned int num) =0;
    67 
    68 		/**
    69 		 * @brief Returns the entire command argument string.
    70 		 *
    71 		 * @return					Argument string.
    72 		 */
    73 		virtual const char *GetArgString() =0;
    74 	};
    75 
    76 	class IMetamodSourceProvider
    77 	{
    78 	public:
    79 		/**
    80 		 * @brief Returns whether source engine build is compatible.
    81 		 *
    82 		 * @param build				Source engine build.
    83 		 * @return					True if compatible, false otherwise.
    84 		 */
    85 		virtual bool IsSourceEngineBuildCompatible(int build) =0;
    86 
    87 		/**
    88 		 * @brief Retrieves hook information for each callback.  Each hook 
    89 		 * must be implemented.
    90 		 *
    91 		 * @param hook				Hook information to provide.
    92 		 * @param pInfo				Non-NULL pointer to fill with information 
    93 		 * 							about the hook's virtual location.
    94 		 * @return					True if supported, false to fail, which 
    95 		 * 							will cause Metamod:Source to fail.
    96 		 */
    97 		virtual bool GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo) =0;
    98 
    99 		/**
   100 		 * @brief Logs a message via IVEngineServer::LogPrint.
   101 		 * 
   102 		 * @param buffer			Buffer to print.
   103 		 * @return					True on success, false if not supported, 
   104 		 * 							or IVEngineServer is not yet known.
   105 		 */
   106 		virtual bool LogMessage(const char *buffer) =0;
   107 
   108 		/**
   109 		 * @brief Returns the command line value of a parameter.  If ICvar 
   110 		 * is not yet loaded, this uses an equivalent function.
   111 		 *
   112 		 * @param key				Parameter to look up.
   113 		 * @param val				Default string to return if none found.
   114 		 * @return					Parameter value.
   115 		 */
   116 		virtual const char *GetCommandLineValue(const char *key, const char *defval=NULL) =0;
   117 
   118 		/**
   119 		 * @brief Prints a string to the remote server console. 
   120 		 * 
   121 		 * Note: new lines are not appended.
   122 		 *
   123 		 * @param msg			 	Message string.
   124 		 */
   125 		virtual void ConsolePrint(const char *msg) =0;
   126 
   127 		/**
   128 		 * @brief Returns whether remote printing is available.
   129 		 *
   130 		 * @return					True if remote printing is available, 
   131 		 * 							otherwise returns false.
   132 		 */
   133 		virtual bool IsRemotePrintingAvailable() =0;
   134 
   135 		/**
   136 		 * @brief Prints text in the specified client's console.
   137 		 *
   138 		 * @param client			Client edict pointer.
   139 		 * @param msg				Message string.
   140 		 */
   141 		virtual void ClientConsolePrint(edict_t *client, const char *msg) =0;
   142 
   143 		/**
   144 		 * @brief Halts the server with a fatal error message.
   145 		 *
   146 		 * No newline is appended.
   147 		 *
   148 		 * @param fmt				Formatted message string.
   149 		 * @param ...				Format parameters.
   150 		 */
   151 		virtual void DisplayError(const char *fmt, ...) =0;
   152 
   153 		/**
   154 		 * @brief Sends the server a warning message.
   155 		 *
   156 		 * No newline is appended.
   157 		 *
   158 		 * @param fmt				Formatted message string.
   159 		 * @param ...				Format parameters.
   160 		 */
   161 		virtual void DisplayWarning(const char *fmt, ...) =0;
   162 
   163 		/**
   164 		 * @brief Attempts to notify the provider of the gamedll version being 
   165 		 * used.
   166 		 *
   167 		 * @param iface				Interface string.
   168 		 * @return					Version number on success, 0 otherwise.
   169 		 */
   170 		virtual int TryServerGameDLL(const char *iface) =0;
   171 
   172 		/**
   173 		 * @brief Notifies the provider that the DLLInit pre-hook is almost done.
   174 		 */
   175 		virtual void Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, CreateInterfaceFn serverFactory) =0;
   176 
   177 		virtual void Notify_DLLShutdown_Pre() =0;
   178 
   179 		/**
   180 		 * @brief Wrapper around IVEngineServer::ServerCommand()
   181 		 *
   182 		 * @param cmd				Command string.
   183 		 */
   184 		virtual void ServerCommand(const char *cmd) =0;
   185 
   186 		/**
   187 		 * @brief Creates a ConVar pointer.
   188 		 *
   189 		 * @param name				ConVar name.
   190 		 * @param defval			Default value string.
   191 		 * @param flags				ConVar flags.
   192 		 * @param help				Help text.
   193 		 * @return					ConVar pointer.
   194 		 */
   195 		virtual ConVar *CreateConVar(const char *name, 
   196 			const char *defval, 
   197 			const char *help,
   198 			int flags) =0;
   199 
   200 		/**
   201 		 * @brief Returns the string value of a ConVar.
   202 		 *
   203 		 * @param convar			ConVar pointer.
   204 		 * @return					String value.
   205 		 */
   206 		virtual const char *GetConVarString(ConVar *convar) =0;
   207 
   208 		/**
   209 		 * @brief Sets a ConVar string.
   210 		 *
   211 		 * @param convar			ConVar pointer.
   212 		 * @param str				String pointer.
   213 		 */
   214 		virtual void SetConVarString(ConVar *convar, const char *str) =0;
   215 
   216 		/**
   217 		 * @brief Retrieves the game description.
   218 		 *
   219 		 * @return					Game description.
   220 		 */
   221 		virtual const char *GetGameDescription() =0;
   222 
   223 		/**
   224 		 * @brief Returns the ConCommandBase accessor.
   225 		 *
   226 		 * @return				An IConCommandBaseAccessor pointer.
   227 		 */
   228 		virtual IConCommandBaseAccessor *GetConCommandBaseAccessor() =0;
   229 
   230 		/**
   231 		 * @brief Registers a ConCommandBase.
   232 		 *
   233 		 * @param pCommand		ConCommandBase to register.
   234 		 * @return				True if successful, false otherwise.
   235 		 */
   236 		virtual bool RegisterConCommandBase(ConCommandBase *pCommand) =0;
   237 
   238 		/**
   239 		 * @brief Unregisters a ConCommandBase.
   240 		 *
   241 		 * @param pCommand		ConCommandBase to unlink.
   242 		 */
   243 		virtual void UnregisterConCommandBase(ConCommandBase *pCommand) =0;
   244 
   245 		/**
   246 		 * @brief Returns whether a ConCommandBase is a command or not.
   247 		 *
   248 		 * @param pCommand		ConCommandBase pointer.
   249 		 * @return				True if a command, false otherwise.
   250 		 */
   251 		virtual bool IsConCommandBaseACommand(ConCommandBase *pCommand) =0;
   252 
   253 		/**
   254 		 * @brief Returns the number of user messages in the GameDLL.
   255 		 *
   256 		 * @return				Number of user messages, or -1 if SourceMM has 
   257 		 *						failed to get user message list.
   258 		 */
   259 		virtual int GetUserMessageCount() =0;
   260 
   261 		/**
   262 		 * @brief Returns the index of the specified user message.
   263 		 *
   264 		 * @param name			User message name.
   265 		 * @param size			Optional pointer to store size of user message.
   266 		 * @return				Message index, or -1 on failure.
   267 		 */
   268 		virtual int FindUserMessage(const char *name, int *size=NULL) =0;
   269 
   270 		/**
   271 		 * @brief Returns the name of the specified user message.
   272 		 *
   273 		 * @param index			User message index.
   274 		 * @param size			Optional pointer to store size of user message.
   275 		 * @return				Message name, or NULL on failure.
   276 		 */
   277 		virtual const char *GetUserMessage(int index, int *size=NULL) =0;
   278 
   279 		/**
   280 		 * @brief Returns the Source Engine build.
   281 		 *
   282 		 * @param game			Game folder.
   283 		 * @return				SOURCE_ENGINE constant.
   284 		 */
   285 		virtual int DetermineSourceEngine(const char *game) =0;
   286 
   287 		/**
   288 		 * @brief Processes a VDF plugin file.
   289 		 *
   290 		 */
   291 		virtual bool ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len) =0;
   292 	};
   293 };
   294 
   295 extern PluginId g_PLID;
   296 extern SourceHook::ISourceHook *g_SHPtr;
   297 extern SourceMM::IMetamodSourceProvider *provider;
   298 extern SourceMM::ISmmAPI *g_pMetamod;
   299 
   300 #endif //_INCLUDE_METAMOD_SOURCE_SUPPORT_H_
   301