Fixed warning when building stub_mm plugin.
4 // meta_api.cpp - common implementation of Metamod's plugin interface
6 // This file is intended to provide a decent common codebase for the
7 // Metamod plugins that I maintain, so everything is set up to be very
8 // generalized, with the things specific for each plugin handled in
9 // plugin.{h,cpp} and elsewhere.
14 * This file is part of Metamod.
16 * Metamod is free software; you can redistribute it and/or modify it
17 * under the terms of the GNU General Public License as published by the
18 * Free Software Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * Metamod is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with Metamod; if not, write to the Free Software Foundation,
28 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 * In addition, as a special exception, the author gives permission to
31 * link the code of this program with the Half-Life Game Engine ("HL
32 * Engine") and Modified Game Libraries ("MODs") developed by Valve,
33 * L.L.C ("Valve"). You must obey the GNU General Public License in all
34 * respects for all of the code used other than the HL Engine and MODs
35 * from Valve. If you modify this file, you may extend this exception
36 * to your version of the file, but you are not obligated to do so. If
37 * you do not wish to do so, delete this exception statement from your
49 #include "info_name.h"
50 #include "log_plugin.h"
52 extern META_FUNCTIONS gMetaFunctionTable;
54 // Description of plugin.
55 // (V* info from info_name.h)
56 plugin_info_t Plugin_info = {
57 META_INTERFACE_VERSION, // ifvers
64 PT_ANYTIME, // loadable
65 PT_ANYPAUSE, // unloadable
68 // Global variables from metamod. These variable names are referenced by
70 meta_globals_t *gpMetaGlobals; // metamod globals
71 gamedll_funcs_t *gpGamedllFuncs; // gameDLL function tables
72 mutil_funcs_t *gpMetaUtilFuncs; // metamod utility functions
74 // Metamod requesting info about this plugin
75 // ifvers (given) interface_version metamod is using
76 // pPlugInfo (requested) struct with info about plugin
77 // pMetaUtilFuncs (given) table of utility functions provided by metamod
78 C_DLLEXPORT int Meta_Query(const char *ifvers, plugin_info_t **pPlugInfo,
79 mutil_funcs_t *pMetaUtilFuncs)
81 if ((int) CVAR_GET_FLOAT("developer") != 0)
82 UTIL_LogPrintf("[%s] dev: called: Meta_Query; version=%s, ours=%s\n",
83 Plugin_info.logtag, ifvers, Plugin_info.ifvers);
85 // Check for valid pMetaUtilFuncs before we continue.
87 UTIL_LogPrintf("[%s] ERROR: Meta_Query called with null pMetaUtilFuncs\n", Plugin_info.logtag);
90 gpMetaUtilFuncs=pMetaUtilFuncs;
92 // Give metamod our plugin_info struct.
93 *pPlugInfo=&Plugin_info;
95 // Check for interface version compatibility.
96 if(!FStrEq(ifvers, Plugin_info.ifvers)) {
97 int mmajor=0, mminor=0, pmajor=0, pminor=0;
98 LOG_MESSAGE(PLID, "WARNING: meta-interface version mismatch; requested=%s ours=%s",
99 Plugin_info.logtag, ifvers);
100 // If plugin has later interface version, it's incompatible (update
102 sscanf(ifvers, "%d:%d", &mmajor, &mminor);
103 sscanf(META_INTERFACE_VERSION, "%d:%d", &pmajor, &pminor);
104 if(pmajor > mmajor || (pmajor==mmajor && pminor > mminor)) {
105 LOG_ERROR(PLID, "metamod version is too old for this plugin; update metamod");
108 // If plugin has older major interface version, it's incompatible
110 else if(pmajor < mmajor) {
111 LOG_ERROR(PLID, "metamod version is incompatible with this plugin; please find a newer version of this plugin");
114 // Minor interface is older, but this is guaranteed to be backwards
115 // compatible, so we warn, but we still accept it.
116 else if(pmajor==mmajor && pminor < mminor)
117 LOG_MESSAGE(PLID, "WARNING: metamod version is newer than expected; consider finding a newer version of this plugin");
119 LOG_ERROR(PLID, "unexpected version comparison; metavers=%s, mmajor=%d, mminor=%d; plugvers=%s, pmajor=%d, pminor=%d", ifvers, mmajor, mminor, META_INTERFACE_VERSION, pmajor, pminor);
122 return (plugin_query());
125 // Metamod attaching plugin to the server.
126 // now (given) current phase, ie during map, during changelevel, or at startup
127 // pFunctionTable (requested) table of function tables this plugin catches
128 // pMGlobals (given) global vars from metamod
129 // pGamedllFuncs (given) copy of function tables from game dll
130 C_DLLEXPORT int Meta_Attach(PLUG_LOADTIME now, META_FUNCTIONS *pFunctionTable,
131 meta_globals_t *pMGlobals, gamedll_funcs_t *pGamedllFuncs)
133 if(now > Plugin_info.loadable) {
134 LOG_ERROR(PLID, "Can't load plugin right now");
138 LOG_ERROR(PLID, "Meta_Attach called with null pMGlobals");
141 gpMetaGlobals=pMGlobals;
142 if(!pFunctionTable) {
143 LOG_ERROR(PLID, "Meta_Attach called with null pFunctionTable");
146 memcpy(pFunctionTable, &gMetaFunctionTable, sizeof(META_FUNCTIONS));
147 gpGamedllFuncs=pGamedllFuncs;
149 LOG_MESSAGE(PLID, "%s v%s %s", Plugin_info.name, Plugin_info.version,
151 LOG_MESSAGE(PLID, "by %s", Plugin_info.author);
152 LOG_MESSAGE(PLID, " %s", Plugin_info.url);
153 LOG_MESSAGE(PLID, "compiled: %s Eastern (%s)", COMPILE_TIME, OPT_TYPE);
156 return(plugin_attach());
159 // Metamod detaching plugin from the server.
160 // now (given) current phase, ie during map, etc
161 // reason (given) why detaching (refresh, console unload, forced unload, etc)
162 C_DLLEXPORT int Meta_Detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) {
163 if(now > Plugin_info.unloadable && reason != PNL_CMD_FORCED) {
164 LOG_ERROR(PLID, "Can't unload plugin right now");
168 return(plugin_detach());