2 * vim: set ts=4 sw=4 tw=99 noet :
3 * ======================================================
5 * Copyright (C) 2004-2009 AlliedModders LLC and authors.
7 * ======================================================
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.
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:
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.
26 #ifndef _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
27 #define _INCLUDE_METAMOD_SOURCE_SUPPORT_H_
34 ConVarFlag_Notify = 1,
35 ConVarFlag_SpOnly = 2,
40 ProvidedHook_LevelInit = 0, /**< IServerGameDLL::LevelInit */
41 ProvidedHook_LevelShutdown = 1, /**< IServerGameDLL::LevelShutdown */
42 ProvidedHook_GameInit = 4, /**< IServerGameDLL::GameInit */
46 * @brief Abstracts command information, since the new engine fixes the
47 * re-entrancy problems in the tokenization system.
49 class IMetamodSourceCommandInfo
53 * @brief Returns the argument count such that arguments
54 * 1 to N are valid arguments, and 0 is the command name.
56 * @return Argument count.
58 virtual unsigned int GetArgCount() =0;
61 * @brief Returns the string of an argument number.
63 * @param num Argument number.
64 * @return Argument text.
66 virtual const char *GetArg(unsigned int num) =0;
69 * @brief Returns the entire command argument string.
71 * @return Argument string.
73 virtual const char *GetArgString() =0;
76 class IMetamodSourceProvider
80 * @brief Returns whether source engine build is compatible.
82 * @param build Source engine build.
83 * @return True if compatible, false otherwise.
85 virtual bool IsSourceEngineBuildCompatible(int build) =0;
88 * @brief Retrieves hook information for each callback. Each hook
89 * must be implemented.
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.
97 virtual bool GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo) =0;
100 * @brief Logs a message via IVEngineServer::LogPrint.
102 * @param buffer Buffer to print.
103 * @return True on success, false if not supported,
104 * or IVEngineServer is not yet known.
106 virtual bool LogMessage(const char *buffer) =0;
109 * @brief Returns the command line value of a parameter. If ICvar
110 * is not yet loaded, this uses an equivalent function.
112 * @param key Parameter to look up.
113 * @param val Default string to return if none found.
114 * @return Parameter value.
116 virtual const char *GetCommandLineValue(const char *key, const char *defval=NULL) =0;
119 * @brief Prints a string to the remote server console.
121 * Note: new lines are not appended.
123 * @param msg Message string.
125 virtual void ConsolePrint(const char *msg) =0;
128 * @brief Returns whether remote printing is available.
130 * @return True if remote printing is available,
131 * otherwise returns false.
133 virtual bool IsRemotePrintingAvailable() =0;
136 * @brief Prints text in the specified client's console.
138 * @param client Client edict pointer.
139 * @param msg Message string.
141 virtual void ClientConsolePrint(edict_t *client, const char *msg) =0;
144 * @brief Halts the server with a fatal error message.
146 * No newline is appended.
148 * @param fmt Formatted message string.
149 * @param ... Format parameters.
151 virtual void DisplayError(const char *fmt, ...) =0;
154 * @brief Sends the server a warning message.
156 * No newline is appended.
158 * @param fmt Formatted message string.
159 * @param ... Format parameters.
161 virtual void DisplayWarning(const char *fmt, ...) =0;
164 * @brief Attempts to notify the provider of the gamedll version being
167 * @param iface Interface string.
168 * @return Version number on success, 0 otherwise.
170 virtual int TryServerGameDLL(const char *iface) =0;
173 * @brief Notifies the provider that the DLLInit pre-hook is almost done.
175 virtual void Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, CreateInterfaceFn serverFactory) =0;
177 virtual void Notify_DLLShutdown_Pre() =0;
180 * @brief Wrapper around IVEngineServer::ServerCommand()
182 * @param cmd Command string.
184 virtual void ServerCommand(const char *cmd) =0;
187 * @brief Creates a ConVar pointer.
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.
195 virtual ConVar *CreateConVar(const char *name,
201 * @brief Returns the string value of a ConVar.
203 * @param convar ConVar pointer.
204 * @return String value.
206 virtual const char *GetConVarString(ConVar *convar) =0;
209 * @brief Sets a ConVar string.
211 * @param convar ConVar pointer.
212 * @param str String pointer.
214 virtual void SetConVarString(ConVar *convar, const char *str) =0;
217 * @brief Retrieves the game description.
219 * @return Game description.
221 virtual const char *GetGameDescription() =0;
224 * @brief Returns the ConCommandBase accessor.
226 * @return An IConCommandBaseAccessor pointer.
228 virtual IConCommandBaseAccessor *GetConCommandBaseAccessor() =0;
231 * @brief Registers a ConCommandBase.
233 * @param pCommand ConCommandBase to register.
234 * @return True if successful, false otherwise.
236 virtual bool RegisterConCommandBase(ConCommandBase *pCommand) =0;
239 * @brief Unregisters a ConCommandBase.
241 * @param pCommand ConCommandBase to unlink.
243 virtual void UnregisterConCommandBase(ConCommandBase *pCommand) =0;
246 * @brief Returns whether a ConCommandBase is a command or not.
248 * @param pCommand ConCommandBase pointer.
249 * @return True if a command, false otherwise.
251 virtual bool IsConCommandBaseACommand(ConCommandBase *pCommand) =0;
254 * @brief Returns the number of user messages in the GameDLL.
256 * @return Number of user messages, or -1 if SourceMM has
257 * failed to get user message list.
259 virtual int GetUserMessageCount() =0;
262 * @brief Returns the index of the specified user message.
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.
268 virtual int FindUserMessage(const char *name, int *size=NULL) =0;
271 * @brief Returns the name of the specified user message.
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.
277 virtual const char *GetUserMessage(int index, int *size=NULL) =0;
280 * @brief Returns the Source Engine build.
282 * @param game Game folder.
283 * @return SOURCE_ENGINE constant.
285 virtual int DetermineSourceEngine(const char *game) =0;
288 * @brief Processes a VDF plugin file.
291 virtual bool ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len) =0;
295 extern PluginId g_PLID;
296 extern SourceHook::ISourceHook *g_SHPtr;
297 extern SourceMM::IMetamodSourceProvider *provider;
298 extern SourceMM::ISmmAPI *g_pMetamod;
300 #endif //_INCLUDE_METAMOD_SOURCE_SUPPORT_H_