Fixed warning when building stub_mm plugin.
4 // plugin.cpp - generic plugin operation
9 * This file is part of Metamod.
11 * Metamod is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
16 * Metamod is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with Metamod; if not, write to the Free Software Foundation,
23 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * In addition, as a special exception, the author gives permission to
26 * link the code of this program with the Half-Life Game Engine ("HL
27 * Engine") and Modified Game Libraries ("MODs") developed by Valve,
28 * L.L.C ("Valve"). You must obey the GNU General Public License in all
29 * respects for all of the code used other than the HL Engine and MODs
30 * from Valve. If you modify this file, you may extend this exception
31 * to your version of the file, but you are not obligated to do so. If
32 * you do not wish to do so, delete this exception statement from your
37 #include <extdll.h> // always
39 #include <meta_api.h> //
40 #include <vdate.h> // COMPILE_TIME,
41 #include <support_meta.h> // STRNCPY,
43 #include "wdmisc.h" // me
44 #include "plugin.h" // generic routines
45 #include "log_plugin.h" // MAX_LOGMSG_LEN
48 // Must provide at least one of these..
49 META_FUNCTIONS gMetaFunctionTable = {
50 NULL, // pfnGetEntityAPI HL SDK; called before game DLL
51 NULL, // pfnGetEntityAPI_Post META; called after game DLL
52 GetEntityAPI2, // pfnGetEntityAPI2 HL SDK2; called before game DLL
53 NULL, // pfnGetEntityAPI2_Post META; called after game DLL
54 NULL, // pfnGetNewDLLFunctions HL SDK2; called before game DLL
55 NULL, // pfnGetNewDLLFunctions_Post META; called after game DLL
56 GetEngineFunctions, // pfnGetEngineFunctions META; called before HL engine
57 NULL, // pfnGetEngineFunctions_Post META; called after HL engine
61 cvar_t init_plugin_debug = {"wd_debug", "0", FCVAR_EXTDLL, 0, NULL};
62 cvar_t bounce = {"bounce", "0", FCVAR_EXTDLL, 0, NULL};
65 // Meta_Query, any desired checks for valid use.
66 int plugin_query(void) {
70 // Meta_Attach. Plugin startup. Register commands and cvars.
71 int plugin_attach(void) {
76 REG_SVR_COMMAND("msglist", &wd_msglist);
77 REG_SVR_COMMAND("msgid", &wd_msgid);
78 REG_SVR_COMMAND("testit", &wd_testit);
83 // Meta_Detach. Cleaning up.
84 int plugin_detach(void) {
89 void bounce_init(void) {
90 CVAR_REGISTER(&bounce);
93 void bounce_check(void) {
94 if((int)CVAR_GET_FLOAT("bounce")==1) {
95 LOG_MESSAGE(PLID, "Exiting server at end of map (bounce==1)");
96 SERVER_COMMAND("quit\n");
100 void do_my_getengfuncs(void) {
101 memset(&meta_engfuncs, 0, sizeof(meta_engfuncs));
102 meta_engfuncs.pfnAlertMessage = wd_AlertMessage;
105 // The below was done basically as a proof-of-concept for catching certain
106 // game-events that aren't otherwise triggered by the HL API. It works only
107 // by examining every log message that the server generates, and checking
108 // to see if it includes the string indicating the particular event in
109 // question (in this case "Planted_The_Bomb").
111 // Although this works, it is really a rather poor solution to the problem,
112 // as it assumes a lot of string-compares, which can seriously degrade the
113 // performance of the server. I did try to take as many short-cuts as
114 // reasonable in the code, to decrease the amount of string-comparing going
115 // on, which makes the code a bit less readable than doing just a "strstr"
118 void wd_AlertMessage(ALERT_TYPE atype, const char *szFmt, ...) {
120 static char buf[MAX_LOGMSG_LEN];
125 if(atype != at_logged)
126 RETURN_META(MRES_IGNORED);
129 vsnprintf(buf, sizeof(buf), szFmt, ap);
132 // Team "...." triggered ...
133 if((cp=buf) && (cp[0]=='T')
134 && (cp=strchr(cp+1, '"'))
135 && (cp=strchr(cp+1, '"'))
136 && !strncmp(cp+2, "triggered", 9))
141 // World triggered ...
142 else if((cp=buf) && (cp[0]=='W')
143 && !strncmp(cp+6, "triggered", 9))
148 // "player<444><44444><...>" triggered ...
149 else if((cp=buf) && (cp[0]=='"')
150 && (cp=strchr(cp+1, '"'))
151 && !strncmp(cp+2, "triggered", 9))
158 // past 'triggered "'
160 if((ep=strchr(cp, '"')))
164 if(len && !strncmp(cp, "Planted_The_Bomb", len)) {
168 end=strchr(buf, '<') + 1;
170 RETURN_META(MRES_IGNORED);
172 if(len > sizeof(name))
174 STRNCPY(name, beg, len);
175 CENTER_SAY(PLID, "%s set up us the bomb!", name);
177 RETURN_META(MRES_HANDLED);
180 void wd_msglist(void) {
183 LOG_CONSOLE(PLID, "registered user msgs:");
184 for(i=0; i < MAX_REG_MSGS; i++) {
185 cp=GET_USER_MSG_NAME(PLID, i, &size);
187 LOG_CONSOLE(PLID, "%d %s %d", i, cp, size);
191 void wd_msgid(void) {
195 id=GET_USER_MSG_ID(PLID, msgname, NULL);
197 LOG_CONSOLE(PLID, "%s = %d", msgname, id);
199 LOG_CONSOLE(PLID, "msg not found: %s", msgname);
202 void wd_testit(void) {
204 cv=CVAR_GET_POINTER("csguard_version");
206 LOG_CONSOLE(PLID, "csguard_version found!: %d", cv);
208 LOG_CONSOLE(PLID, "csguard_version not found!");