|
darope@0
|
1 |
// vi: set ts=4 sw=4 : |
|
darope@0
|
2 |
// vim: set tw=75 : |
|
darope@0
|
3 |
|
|
darope@0
|
4 |
// mplugin.cpp - functions for individual plugin (class MPlugin) |
|
darope@0
|
5 |
|
|
darope@0
|
6 |
/* |
|
darope@0
|
7 |
* Copyright (c) 2001-2003 Will Day <[email protected]> |
|
darope@0
|
8 |
* |
|
darope@0
|
9 |
* This file is part of Metamod. |
|
darope@0
|
10 |
* |
|
darope@0
|
11 |
* Metamod is free software; you can redistribute it and/or modify it |
|
darope@0
|
12 |
* under the terms of the GNU General Public License as published by the |
|
darope@0
|
13 |
* Free Software Foundation; either version 2 of the License, or (at |
|
darope@0
|
14 |
* your option) any later version. |
|
darope@0
|
15 |
* |
|
darope@0
|
16 |
* Metamod is distributed in the hope that it will be useful, but |
|
darope@0
|
17 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
|
darope@0
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
darope@0
|
19 |
* General Public License for more details. |
|
darope@0
|
20 |
* |
|
darope@0
|
21 |
* You should have received a copy of the GNU General Public License |
|
darope@0
|
22 |
* along with Metamod; if not, write to the Free Software Foundation, |
|
darope@0
|
23 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
darope@0
|
24 |
* |
|
darope@0
|
25 |
* In addition, as a special exception, the author gives permission to |
|
darope@0
|
26 |
* link the code of this program with the Half-Life Game Engine ("HL |
|
darope@0
|
27 |
* Engine") and Modified Game Libraries ("MODs") developed by Valve, |
|
darope@0
|
28 |
* L.L.C ("Valve"). You must obey the GNU General Public License in all |
|
darope@0
|
29 |
* respects for all of the code used other than the HL Engine and MODs |
|
darope@0
|
30 |
* from Valve. If you modify this file, you may extend this exception |
|
darope@0
|
31 |
* to your version of the file, but you are not obligated to do so. If |
|
darope@0
|
32 |
* you do not wish to do so, delete this exception statement from your |
|
darope@0
|
33 |
* version. |
|
darope@0
|
34 |
* |
|
darope@0
|
35 |
*/ |
|
darope@0
|
36 |
|
|
darope@0
|
37 |
#include <errno.h> // errno, etc |
|
darope@0
|
38 |
#include <malloc.h> // malloc, etc |
|
darope@0
|
39 |
#include <sys/types.h> // stat |
|
darope@0
|
40 |
#include <sys/stat.h> // stat |
|
darope@0
|
41 |
|
|
darope@0
|
42 |
#include <extdll.h> // always |
|
darope@0
|
43 |
|
|
darope@0
|
44 |
#include "mplugin.h" // me |
|
darope@0
|
45 |
#include "metamod.h" // GameDLL, etc |
|
darope@0
|
46 |
#include "mreg.h" // MRegCmdList::show(int), etc |
|
darope@0
|
47 |
#include "mhook.h" // class MHook |
|
darope@0
|
48 |
#include "h_export.h" // GIVE_ENGINE_FUNCTIONS_FN, etc |
|
darope@0
|
49 |
#include "dllapi.h" // FN_GAMEINIT, etc |
|
darope@0
|
50 |
#include "support_meta.h" // full_gamedir_path, |
|
darope@0
|
51 |
#include "types_meta.h" // mBOOL |
|
darope@0
|
52 |
#include "log_meta.h" // logging functions, etc |
|
darope@0
|
53 |
#include "osdep.h" // win32 snprintf, is_absolute_path, |
|
darope@0
|
54 |
|
|
darope@0
|
55 |
|
|
darope@0
|
56 |
// Parse a line from plugins.ini into a plugin. |
|
darope@0
|
57 |
// meta_errno values: |
|
darope@0
|
58 |
// - ME_COMMENT ignored commented line |
|
darope@0
|
59 |
// - ME_FORMAT invalid line format |
|
darope@0
|
60 |
// - ME_OSNOTSUP plugin is not for this OS |
|
darope@0
|
61 |
mBOOL MPlugin::ini_parseline(char *line) { |
|
darope@0
|
62 |
char *token; |
|
darope@0
|
63 |
char *ptr_token; |
|
darope@0
|
64 |
char *cp; |
|
darope@0
|
65 |
|
|
darope@244
|
66 |
// skip whitespace at start of line |
|
darope@244
|
67 |
while(*line==' ' || *line=='\t' ) line++; |
|
darope@244
|
68 |
|
|
darope@245
|
69 |
// remove whitespace at end of line |
|
darope@245
|
70 |
cp = line + strlen(line) -1; |
|
darope@245
|
71 |
while(*cp==' ' || *cp=='\t') *cp--='\0'; |
|
darope@245
|
72 |
|
|
darope@244
|
73 |
// skip empty lines |
|
darope@244
|
74 |
if(line[0]=='\0') { |
|
darope@244
|
75 |
META_DEBUG(7, ("ini: Ignoring empty line: %s", line)); |
|
darope@244
|
76 |
RETURN_ERRNO(mFALSE, ME_BLANK); |
|
darope@244
|
77 |
} |
|
darope@244
|
78 |
|
|
darope@0
|
79 |
if(line[0]=='#' || line[0]==';' || strstr(line, "//")==line) { |
|
darope@0
|
80 |
META_DEBUG(7, ("ini: Ignoring commented line: %s", line)); |
|
darope@0
|
81 |
RETURN_ERRNO(mFALSE, ME_COMMENT); |
|
darope@0
|
82 |
} |
|
darope@0
|
83 |
|
|
darope@0
|
84 |
// grab platform ("win32" or "linux") |
|
darope@0
|
85 |
token=strtok_r(line, " \t", &ptr_token); |
|
darope@0
|
86 |
if(!token) |
|
darope@0
|
87 |
RETURN_ERRNO(mFALSE, ME_FORMAT); |
|
darope@244
|
88 |
if(strcasecmp(token, PLATFORM) == 0) { |
|
darope@244
|
89 |
pfspecific=0; |
|
darope@244
|
90 |
} else if(strcasecmp(token, PLATFORM_SPC) == 0) { |
|
darope@244
|
91 |
pfspecific=1; |
|
darope@244
|
92 |
} else { |
|
darope@0
|
93 |
// plugin is not for this OS |
|
darope@0
|
94 |
META_DEBUG(7, ("ini: Ignoring entry for %s", token)); |
|
darope@0
|
95 |
RETURN_ERRNO(mFALSE, ME_OSNOTSUP); |
|
darope@0
|
96 |
} |
|
darope@0
|
97 |
|
|
darope@0
|
98 |
// grab filename |
|
darope@0
|
99 |
token=strtok_r(NULL, " \t\r\n", &ptr_token); |
|
darope@0
|
100 |
if(!token) |
|
darope@0
|
101 |
RETURN_ERRNO(mFALSE, ME_FORMAT); |
|
darope@0
|
102 |
STRNCPY(filename, token, sizeof(filename)); |
|
darope@0
|
103 |
normalize_pathname(filename); |
|
darope@0
|
104 |
// Store name of just the actual _file_, without dir components. |
|
darope@0
|
105 |
cp=strrchr(filename, '/'); |
|
darope@0
|
106 |
if(cp) |
|
darope@0
|
107 |
file=cp+1; |
|
darope@0
|
108 |
else |
|
darope@0
|
109 |
file=filename; |
|
darope@0
|
110 |
|
|
darope@0
|
111 |
// Grab description. |
|
darope@0
|
112 |
// Just get the the rest of the line, minus line-termination. |
|
darope@0
|
113 |
token=strtok_r(NULL, "\n\r", &ptr_token); |
|
darope@0
|
114 |
if(token) { |
|
darope@0
|
115 |
token=token+strspn(token, " \t"); // skip whitespace |
|
darope@0
|
116 |
STRNCPY(desc, token, sizeof(desc)); |
|
darope@0
|
117 |
} |
|
darope@0
|
118 |
else { |
|
darope@0
|
119 |
// If no description is specified, temporarily use plugin file, |
|
darope@0
|
120 |
// until plugin can be queried, and desc replaced with info->name. |
|
darope@0
|
121 |
snprintf(desc, sizeof(desc), "<%s>", file); |
|
darope@0
|
122 |
} |
|
darope@0
|
123 |
|
|
darope@0
|
124 |
// Make full pathname (from gamedir if relative, remove "..", |
|
darope@0
|
125 |
// backslashes, etc). |
|
darope@0
|
126 |
full_gamedir_path(filename, pathname); |
|
darope@0
|
127 |
|
|
darope@0
|
128 |
source=PS_INI; |
|
darope@0
|
129 |
status=PL_VALID; |
|
darope@0
|
130 |
return(mTRUE); |
|
darope@0
|
131 |
} |
|
darope@0
|
132 |
|
|
darope@0
|
133 |
// Parse a line from console "load" command into a plugin. |
|
darope@0
|
134 |
// meta_errno values: |
|
darope@0
|
135 |
// - ME_FORMAT invalid line format |
|
darope@0
|
136 |
mBOOL MPlugin::cmd_parseline(const char *line) { |
|
darope@0
|
137 |
char buf[NAME_MAX + PATH_MAX + MAX_DESC_LEN]; |
|
darope@0
|
138 |
char *token; |
|
darope@0
|
139 |
char *ptr_token; |
|
darope@0
|
140 |
char *cp; |
|
darope@0
|
141 |
|
|
darope@0
|
142 |
STRNCPY(buf, line, sizeof(buf)); |
|
darope@0
|
143 |
|
|
darope@0
|
144 |
// remove "load" |
|
darope@0
|
145 |
token=strtok_r(buf, " \t", &ptr_token); |
|
darope@0
|
146 |
if(!token) |
|
darope@0
|
147 |
RETURN_ERRNO(mFALSE, ME_FORMAT); |
|
darope@0
|
148 |
|
|
darope@0
|
149 |
// grab filename |
|
darope@0
|
150 |
token=strtok_r(NULL, " \t", &ptr_token); |
|
darope@0
|
151 |
if(!token) |
|
darope@0
|
152 |
RETURN_ERRNO(mFALSE, ME_FORMAT); |
|
darope@0
|
153 |
STRNCPY(filename, token, sizeof(filename)); |
|
darope@0
|
154 |
normalize_pathname(filename); |
|
darope@0
|
155 |
// store name of just the actual _file_, without dir components |
|
darope@0
|
156 |
cp=strrchr(filename, '/'); |
|
darope@0
|
157 |
if(cp) |
|
darope@0
|
158 |
file=cp+1; |
|
darope@0
|
159 |
else |
|
darope@0
|
160 |
file=filename; |
|
darope@0
|
161 |
|
|
darope@0
|
162 |
// Grab description. |
|
darope@0
|
163 |
// Specify no delimiter chars, as we just want the rest of the line. |
|
darope@0
|
164 |
token=strtok_r(NULL, "", &ptr_token); |
|
darope@0
|
165 |
if(token) { |
|
darope@0
|
166 |
token=token+strspn(token, " \t"); // skip whitespace |
|
darope@0
|
167 |
STRNCPY(desc, token, sizeof(desc)); |
|
darope@0
|
168 |
} |
|
darope@0
|
169 |
else { |
|
darope@0
|
170 |
// if no description is specified, temporarily use plugin file, |
|
darope@0
|
171 |
// until plugin can be queried, and desc replaced with info->name. |
|
darope@0
|
172 |
snprintf(desc, sizeof(desc), "<%s>", file); |
|
darope@0
|
173 |
} |
|
darope@0
|
174 |
|
|
darope@0
|
175 |
// Make full pathname (from gamedir if relative, remove "..", |
|
darope@0
|
176 |
// backslashes, etc). |
|
darope@0
|
177 |
full_gamedir_path(filename, pathname); |
|
darope@0
|
178 |
|
|
darope@0
|
179 |
source=PS_CMD; |
|
darope@0
|
180 |
status=PL_VALID; |
|
darope@0
|
181 |
return(mTRUE); |
|
darope@0
|
182 |
} |
|
darope@0
|
183 |
|
|
darope@0
|
184 |
// Make sure this plugin has the necessary minimal information. |
|
darope@0
|
185 |
// meta_errno values: |
|
darope@0
|
186 |
// - ME_ARGUMENT missing necessary fields in plugin |
|
darope@0
|
187 |
mBOOL MPlugin::check_input(void) { |
|
darope@0
|
188 |
// doublecheck our input/state |
|
darope@0
|
189 |
if(status < PL_VALID) { |
|
darope@0
|
190 |
META_ERROR("dll: Tried to operate on plugin[%d] with a non-valid status (%d)", index, str_status()); |
|
darope@0
|
191 |
RETURN_ERRNO(mFALSE, ME_ARGUMENT); |
|
darope@0
|
192 |
} |
|
darope@0
|
193 |
if(!file || !file[0]) { |
|
darope@0
|
194 |
META_ERROR("dll: Tried to operate on plugin[%d] with an empty file", |
|
darope@0
|
195 |
index); |
|
darope@0
|
196 |
RETURN_ERRNO(mFALSE, ME_ARGUMENT); |
|
darope@0
|
197 |
} |
|
darope@0
|
198 |
if(!filename[0]) { |
|
darope@0
|
199 |
META_ERROR("dll: Tried to operate on plugin[%d] with an empty filename", |
|
darope@0
|
200 |
index); |
|
darope@0
|
201 |
RETURN_ERRNO(mFALSE, ME_ARGUMENT); |
|
darope@0
|
202 |
} |
|
darope@0
|
203 |
if(!pathname[0]) { |
|
darope@0
|
204 |
META_ERROR("dll: Tried to operate on plugin[%d] with an empty pathname", |
|
darope@0
|
205 |
index); |
|
darope@0
|
206 |
RETURN_ERRNO(mFALSE, ME_ARGUMENT); |
|
darope@0
|
207 |
} |
|
darope@0
|
208 |
if(!desc[0]) { |
|
darope@0
|
209 |
// if no description is specified, temporarily use plugin file, |
|
darope@0
|
210 |
// until plugin can be queried, and desc replaced with info->name. |
|
darope@0
|
211 |
snprintf(desc, sizeof(desc), "<%s>", file); |
|
darope@0
|
212 |
} |
|
darope@0
|
213 |
return(mTRUE); |
|
darope@0
|
214 |
} |
|
darope@0
|
215 |
|
|
darope@0
|
216 |
// Try to resolve a plugin's filename as a (possibly partial) path to an |
|
darope@0
|
217 |
// actual filename on disk, to facilitate easier console load-command |
|
darope@0
|
218 |
// arguments. Uses resolve_dirs, resolve_prefix, and resolve_suffix below. |
|
darope@0
|
219 |
// Example paths that it tries: |
|
darope@0
|
220 |
// filename |
|
darope@0
|
221 |
// Gamedir/filename.dll, Gamedir/filename.so |
|
darope@0
|
222 |
// Gamedir/filename_i386.so |
|
darope@0
|
223 |
// Gamedir/dlls/mm_filename_i386.so |
|
darope@0
|
224 |
// Gamedir/dlls/filename_mm_i386.so |
|
darope@0
|
225 |
// Gamedir/dlls/filename_MM_i386.so |
|
darope@0
|
226 |
// meta_errno values: |
|
darope@0
|
227 |
// - ME_NOTFOUND couldn't find a matching file for the partial name |
|
darope@0
|
228 |
// - errno's from check_input() |
|
darope@0
|
229 |
mBOOL MPlugin::resolve(void) { |
|
darope@0
|
230 |
char *found; |
|
darope@0
|
231 |
char *cp; |
|
darope@0
|
232 |
int len; |
|
darope@0
|
233 |
if(!check_input()) { |
|
darope@0
|
234 |
// details logged, meta_errno set in check_input() |
|
darope@0
|
235 |
return(mFALSE); |
|
darope@0
|
236 |
} |
|
darope@0
|
237 |
if(is_absolute_path(filename)) |
|
darope@0
|
238 |
found=resolve_prefix(filename); |
|
darope@0
|
239 |
else |
|
darope@0
|
240 |
found=resolve_dirs(filename); |
|
darope@0
|
241 |
|
|
darope@0
|
242 |
if(!found) { |
|
darope@0
|
243 |
META_DEBUG(2, ("Couldn't resolve '%s' to file", filename)); |
|
darope@0
|
244 |
RETURN_ERRNO(mFALSE, ME_NOTFOUND); |
|
darope@0
|
245 |
} |
|
darope@0
|
246 |
META_DEBUG(2, ("Resolved '%s' to file '%s'", filename, found)); |
|
darope@0
|
247 |
// store pathname: the resolved path (should be absolute) |
|
darope@0
|
248 |
STRNCPY(pathname, found, sizeof(pathname)); |
|
darope@0
|
249 |
// store file: the name of the file (without dir) |
|
darope@0
|
250 |
cp=strrchr(pathname, '/'); |
|
darope@0
|
251 |
if(cp) |
|
darope@0
|
252 |
file=cp+1; |
|
darope@0
|
253 |
else |
|
darope@0
|
254 |
file=pathname; |
|
darope@0
|
255 |
// store pathname: the gamedir relative path, or an absolute path |
|
darope@0
|
256 |
len=strlen(GameDLL.gamedir); |
|
darope@0
|
257 |
if(strncasecmp(pathname, GameDLL.gamedir, len) == 0) |
|
darope@0
|
258 |
STRNCPY(filename, pathname+len+1, sizeof(filename)); |
|
darope@0
|
259 |
else |
|
darope@0
|
260 |
STRNCPY(filename, pathname, sizeof(filename)); |
|
darope@0
|
261 |
|
|
darope@0
|
262 |
return(mTRUE); |
|
darope@0
|
263 |
} |
|
darope@0
|
264 |
|
|
darope@0
|
265 |
// For the given path, tries to find file in several possible |
|
darope@0
|
266 |
// directories. |
|
darope@0
|
267 |
// Try: |
|
darope@0
|
268 |
// GAMEDIR/filename |
|
darope@0
|
269 |
// GAMEDIR/dlls/filename |
|
darope@0
|
270 |
// meta_errno values: |
|
darope@0
|
271 |
// - none |
|
darope@0
|
272 |
char *MPlugin::resolve_dirs(char *path) { |
|
darope@0
|
273 |
struct stat st; |
|
darope@0
|
274 |
static char buf[PATH_MAX]; |
|
darope@0
|
275 |
char *found; |
|
darope@0
|
276 |
|
|
darope@0
|
277 |
snprintf(buf, sizeof(buf), "%s/%s", GameDLL.gamedir, path); |
|
darope@0
|
278 |
// try this path |
|
darope@0
|
279 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
280 |
return(buf); |
|
darope@0
|
281 |
// try other file prefixes in this path |
|
darope@0
|
282 |
if((found=resolve_prefix(buf))) |
|
darope@0
|
283 |
return(found); |
|
darope@0
|
284 |
|
|
darope@0
|
285 |
snprintf(buf, sizeof(buf), "%s/dlls/%s", GameDLL.gamedir, path); |
|
darope@0
|
286 |
// try this path |
|
darope@0
|
287 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
288 |
return(buf); |
|
darope@0
|
289 |
// try other file prefixes for this path |
|
darope@0
|
290 |
if((found=resolve_prefix(buf))) |
|
darope@0
|
291 |
return(found); |
|
darope@0
|
292 |
|
|
darope@0
|
293 |
return(NULL); |
|
darope@0
|
294 |
} |
|
darope@0
|
295 |
|
|
darope@0
|
296 |
// For the given path, tries several possible filename prefixes. |
|
darope@0
|
297 |
// Try: |
|
darope@0
|
298 |
// dir/mm_file |
|
darope@0
|
299 |
// dir/file |
|
darope@0
|
300 |
// meta_errno values: |
|
darope@0
|
301 |
// - none |
|
darope@0
|
302 |
char *MPlugin::resolve_prefix(char *path) { |
|
darope@0
|
303 |
struct stat st; |
|
darope@0
|
304 |
char *cp, *fname; |
|
darope@0
|
305 |
char dname[PATH_MAX]; |
|
darope@0
|
306 |
static char buf[PATH_MAX]; |
|
darope@0
|
307 |
char *found; |
|
darope@0
|
308 |
|
|
darope@0
|
309 |
// try "mm_" prefix FIRST. |
|
darope@0
|
310 |
// split into dirname and filename |
|
darope@0
|
311 |
STRNCPY(dname, path, sizeof(dname)); |
|
darope@0
|
312 |
cp=strrchr(dname, '/'); |
|
darope@0
|
313 |
if(cp) { |
|
darope@0
|
314 |
*cp='\0'; |
|
darope@0
|
315 |
fname=cp+1; |
|
darope@0
|
316 |
snprintf(buf, sizeof(buf), "%s/mm_%s", dname, fname); |
|
darope@0
|
317 |
} |
|
darope@0
|
318 |
else { |
|
darope@0
|
319 |
// no directory in given path |
|
darope@0
|
320 |
snprintf(buf, sizeof(buf), "mm_%s", path); |
|
darope@0
|
321 |
} |
|
darope@0
|
322 |
// try this path |
|
darope@0
|
323 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
324 |
return(buf); |
|
darope@0
|
325 |
// try other suffixes for this path |
|
darope@0
|
326 |
if((found=resolve_suffix(buf))) |
|
darope@0
|
327 |
return(found); |
|
darope@0
|
328 |
|
|
darope@0
|
329 |
// try other suffixes for the original path |
|
darope@0
|
330 |
if((found=resolve_suffix(path))) |
|
darope@0
|
331 |
return(found); |
|
darope@0
|
332 |
|
|
darope@0
|
333 |
return(NULL); |
|
darope@0
|
334 |
} |
|
darope@0
|
335 |
|
|
darope@0
|
336 |
// For the given path, tries several different filename suffixes. |
|
darope@0
|
337 |
// Try: |
|
darope@0
|
338 |
// path |
|
darope@0
|
339 |
// path_mm |
|
darope@0
|
340 |
// path_MM |
|
darope@0
|
341 |
// path.so (linux), path.dll (win32) |
|
darope@0
|
342 |
// path_i386.so, path_i486.so, etc (if linux) |
|
darope@0
|
343 |
// meta_errno values: |
|
darope@0
|
344 |
// - none |
|
darope@0
|
345 |
char *MPlugin::resolve_suffix(char *path) { |
|
darope@0
|
346 |
struct stat st; |
|
darope@0
|
347 |
static char buf[PATH_MAX]; |
|
darope@0
|
348 |
char *found; |
|
darope@0
|
349 |
|
|
darope@0
|
350 |
// Hmm, recursion. |
|
darope@0
|
351 |
if(!strstr(path, "_mm")) { |
|
darope@0
|
352 |
char *tmpbuf; |
|
darope@0
|
353 |
snprintf(buf, sizeof(buf), "%s_mm", path); |
|
darope@0
|
354 |
tmpbuf=strdup(buf); |
|
darope@0
|
355 |
found=resolve_suffix(tmpbuf); |
|
darope@0
|
356 |
free(tmpbuf); |
|
darope@0
|
357 |
if(found) return(found); |
|
darope@0
|
358 |
} |
|
darope@0
|
359 |
if(!strstr(path, "_MM")) { |
|
darope@0
|
360 |
char *tmpbuf; |
|
darope@0
|
361 |
snprintf(buf, sizeof(buf), "%s_MM", path); |
|
darope@0
|
362 |
tmpbuf=strdup(buf); |
|
darope@0
|
363 |
found=resolve_suffix(tmpbuf); |
|
darope@0
|
364 |
free(tmpbuf); |
|
darope@0
|
365 |
if(found) return(found); |
|
darope@0
|
366 |
} |
|
darope@0
|
367 |
|
|
darope@0
|
368 |
#ifdef _WIN32 |
|
darope@0
|
369 |
snprintf(buf, sizeof(buf), "%s.dll", path); |
|
darope@0
|
370 |
#elif defined(linux) |
|
darope@0
|
371 |
snprintf(buf, sizeof(buf), "%s.so", path); |
|
darope@0
|
372 |
#else |
|
darope@0
|
373 |
#error "OS unrecognized" |
|
darope@0
|
374 |
#endif /* _WIN32 */ |
|
darope@0
|
375 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
376 |
return(buf); |
|
darope@0
|
377 |
|
|
darope@0
|
378 |
#ifdef linux |
|
darope@0
|
379 |
snprintf(buf, sizeof(buf), "%s_i386.so", path); |
|
darope@0
|
380 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
381 |
return(buf); |
|
darope@0
|
382 |
snprintf(buf, sizeof(buf), "%s_i486.so", path); |
|
darope@0
|
383 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
384 |
return(buf); |
|
darope@0
|
385 |
snprintf(buf, sizeof(buf), "%s_i586.so", path); |
|
darope@0
|
386 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
387 |
return(buf); |
|
darope@0
|
388 |
snprintf(buf, sizeof(buf), "%s_i686.so", path); |
|
darope@0
|
389 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@0
|
390 |
return(buf); |
|
darope@244
|
391 |
snprintf(buf, sizeof(buf), "%s_amd64.so", path); |
|
darope@244
|
392 |
if(stat(buf, &st) == 0 && S_ISREG(st.st_mode)) |
|
darope@244
|
393 |
return(buf); |
|
darope@0
|
394 |
#endif /* linux */ |
|
darope@0
|
395 |
|
|
darope@0
|
396 |
return(NULL); |
|
darope@0
|
397 |
} |
|
darope@0
|
398 |
|
|
darope@246
|
399 |
|
|
darope@246
|
400 |
// Check if a passed string starts with a known platform postfix. |
|
darope@246
|
401 |
// It does not check beyond the period in order to work for both |
|
darope@246
|
402 |
// Linux and Win32. |
|
darope@246
|
403 |
static mBOOL is_platform_postfix(char* pf) |
|
darope@246
|
404 |
{ |
|
darope@246
|
405 |
if ( NULL == pf ) return mFALSE; |
|
darope@246
|
406 |
|
|
darope@246
|
407 |
if ( 0 == strncmp(pf, "_i386.", 6) ) return mTRUE; |
|
darope@246
|
408 |
if ( 0 == strncmp(pf, "_i486.", 6) ) return mTRUE; |
|
darope@246
|
409 |
if ( 0 == strncmp(pf, "_i586.", 6) ) return mTRUE; |
|
darope@246
|
410 |
if ( 0 == strncmp(pf, "_i686.", 6) ) return mTRUE; |
|
darope@246
|
411 |
if ( 0 == strncmp(pf, "_amd64.", 7) ) return mTRUE; |
|
darope@246
|
412 |
|
|
darope@246
|
413 |
return mFALSE; |
|
darope@246
|
414 |
} |
|
darope@246
|
415 |
|
|
darope@246
|
416 |
|
|
darope@244
|
417 |
// Check if a given plugin is the same but possibly for a |
|
darope@244
|
418 |
// different platform. A match is considered to be found if |
|
darope@244
|
419 |
// 1. the filename without the path is the same, or |
|
darope@244
|
420 |
// 2a. for an attached plugin the logtag is the same, or |
|
darope@244
|
421 |
// 2b. the description is the same, or |
|
darope@244
|
422 |
// 3. a significant part of the filename is the same. |
|
darope@246
|
423 |
// A significant part of a plugin name is currently defined to: |
|
darope@246
|
424 |
// the part up to a known platform postfix as determined by |
|
darope@246
|
425 |
// the is_platform_postfix() function (see above), or |
|
darope@246
|
426 |
// the part up to the last dot, if one exists. |
|
darope@244
|
427 |
// meta_errno values: |
|
darope@244
|
428 |
// - none |
|
darope@244
|
429 |
mBOOL MPlugin::platform_match(MPlugin* other) { |
|
darope@244
|
430 |
char *end, *other_end; |
|
darope@244
|
431 |
int prefixlen; |
|
darope@244
|
432 |
|
|
darope@244
|
433 |
if(status == PL_EMPTY || other->status == PL_EMPTY) return mFALSE; |
|
darope@244
|
434 |
|
|
darope@244
|
435 |
if(strcmp(file, other->file) == 0) return mTRUE; |
|
darope@244
|
436 |
|
|
darope@244
|
437 |
if(status >= PL_OPENED && other->status >= PL_OPENED && |
|
darope@244
|
438 |
strcmp(info->logtag, other->info->logtag) == 0 ) return mTRUE; |
|
darope@244
|
439 |
if(*desc != '\0' && strcasecmp(desc,other->desc) == 0) return mTRUE; |
|
darope@244
|
440 |
|
|
darope@244
|
441 |
end=strrchr(file, '_'); |
|
darope@246
|
442 |
if(end == NULL || !is_platform_postfix(end)) end=strrchr(file, '.'); |
|
darope@244
|
443 |
other_end=strrchr(other->file, '_'); |
|
darope@246
|
444 |
if(other_end == NULL || !is_platform_postfix(other_end)) other_end=strrchr(other->file, '.'); |
|
darope@244
|
445 |
|
|
darope@244
|
446 |
if(end == NULL || other_end == NULL) return mFALSE; |
|
darope@244
|
447 |
|
|
darope@244
|
448 |
prefixlen=end-file; |
|
darope@244
|
449 |
if((other_end-other->file) != prefixlen) return mFALSE; |
|
darope@244
|
450 |
|
|
darope@244
|
451 |
if(strncmp(file,other->file, prefixlen) == 0) return mTRUE; |
|
darope@244
|
452 |
|
|
darope@244
|
453 |
return mFALSE; |
|
darope@244
|
454 |
} |
|
darope@244
|
455 |
|
|
darope@244
|
456 |
|
|
darope@0
|
457 |
// Load a plugin; query, check allowed time, attach. |
|
darope@0
|
458 |
// meta_errno values: |
|
darope@0
|
459 |
// - ME_ARGUMENT missing necessary fields in plugin |
|
darope@0
|
460 |
// - ME_ALREADY this plugin already loaded |
|
darope@0
|
461 |
// - ME_BADREQ plugin not marked for load |
|
darope@0
|
462 |
// - ME_DELAYED load request is delayed (till changelevel?) |
|
darope@0
|
463 |
// - ME_NOTALLOWED plugin not loadable after startup |
|
darope@0
|
464 |
// - errno's from query() |
|
darope@0
|
465 |
// - errno's from attach() |
|
darope@0
|
466 |
// - errno's from check_input() |
|
darope@0
|
467 |
mBOOL MPlugin::load(PLUG_LOADTIME now) { |
|
darope@0
|
468 |
if(!check_input()) { |
|
darope@0
|
469 |
// details logged, meta_errno set in check_input() |
|
darope@0
|
470 |
RETURN_ERRNO(mFALSE, ME_ARGUMENT); |
|
darope@0
|
471 |
} |
|
darope@0
|
472 |
if(status >= PL_RUNNING) { |
|
darope@0
|
473 |
META_ERROR("dll: Not loading plugin '%s'; already loaded (status=%s)", |
|
darope@0
|
474 |
desc, str_status()); |
|
darope@0
|
475 |
RETURN_ERRNO(mFALSE, ME_ALREADY); |
|
darope@0
|
476 |
} |
|
darope@0
|
477 |
if(action != PA_LOAD && action != PA_ATTACH) { |
|
darope@0
|
478 |
META_ERROR("dll: Not loading plugin '%s'; not marked for load (action=%s)", desc, str_action()); |
|
darope@0
|
479 |
RETURN_ERRNO(mFALSE, ME_BADREQ); |
|
darope@0
|
480 |
} |
|
darope@0
|
481 |
|
|
darope@0
|
482 |
if(status != PL_OPENED) { |
|
darope@0
|
483 |
// query plugin; open file and get info about it |
|
darope@0
|
484 |
if(!query()) { |
|
darope@0
|
485 |
META_ERROR("dll: Skipping plugin '%s'; couldn't query", desc); |
|
darope@0
|
486 |
if(meta_errno != ME_DLOPEN) { |
|
darope@0
|
487 |
if(DLCLOSE(handle) != 0) { |
|
darope@0
|
488 |
META_ERROR("dll: Couldn't close plugin file '%s': %s", |
|
darope@0
|
489 |
file, DLERROR()); |
|
darope@0
|
490 |
} |
|
darope@0
|
491 |
else |
|
darope@0
|
492 |
handle=NULL; |
|
darope@0
|
493 |
} |
|
darope@0
|
494 |
status=PL_BADFILE; |
|
darope@0
|
495 |
// meta_errno should be already set in query() |
|
darope@0
|
496 |
return(mFALSE); |
|
darope@0
|
497 |
} |
|
darope@0
|
498 |
status=PL_OPENED; |
|
darope@0
|
499 |
} |
|
darope@0
|
500 |
|
|
darope@0
|
501 |
// are we allowed to attach this plugin at this time? |
|
darope@0
|
502 |
if(info->loadable < now) { |
|
darope@0
|
503 |
if(info->loadable > PT_STARTUP) { |
|
darope@0
|
504 |
// will try to attach again at next opportunity |
|
darope@0
|
505 |
META_DEBUG(2, ("dll: Delaying load plugin '%s'; can't attach now: allowed=%s; now=%s", |
|
darope@0
|
506 |
desc, str_loadable(), str_loadtime(now, SL_SIMPLE))); |
|
darope@0
|
507 |
RETURN_ERRNO(mFALSE, ME_DELAYED); |
|
darope@0
|
508 |
} |
|
darope@0
|
509 |
else { |
|
darope@0
|
510 |
META_DEBUG(2, ("dll: Failed load plugin '%s'; can't attach now: allowed=%s; now=%s", |
|
darope@0
|
511 |
desc, str_loadable(), str_loadtime(now, SL_SIMPLE))); |
|
darope@0
|
512 |
// don't try to attach again later |
|
darope@0
|
513 |
action=PA_NONE; |
|
darope@0
|
514 |
RETURN_ERRNO(mFALSE, ME_NOTALLOWED); |
|
darope@0
|
515 |
} |
|
darope@0
|
516 |
} |
|
darope@0
|
517 |
|
|
darope@0
|
518 |
// attach plugin; get function tables |
|
darope@0
|
519 |
if(attach(now) != mTRUE) { |
|
darope@0
|
520 |
META_ERROR("dll: Failed to attach plugin '%s'", desc); |
|
darope@0
|
521 |
// Note we don't dlclose() here, since we're returning PL_FAILED, |
|
darope@0
|
522 |
// which implies that it's been dlopened and queried successfully. |
|
darope@0
|
523 |
// Doing so causes crashes, because things like "meta list" try to |
|
darope@0
|
524 |
// look at *info, which is in the DLL memory space and unaccessible |
|
darope@0
|
525 |
// (segfault) after dlclosed. |
|
darope@0
|
526 |
status=PL_FAILED; |
|
darope@0
|
527 |
// meta_errno should be already set in attach() |
|
darope@0
|
528 |
return(mFALSE); |
|
darope@0
|
529 |
} |
|
darope@0
|
530 |
status=PL_RUNNING; |
|
darope@0
|
531 |
action=PA_NONE; |
|
darope@0
|
532 |
|
|
darope@0
|
533 |
// If not loading at server startup, then need to call plugin's |
|
darope@0
|
534 |
// GameInit, since we've passed that. |
|
darope@0
|
535 |
if(now != PT_STARTUP) { |
|
darope@0
|
536 |
FN_GAMEINIT pfn_gameinit=NULL; |
|
darope@0
|
537 |
if(dllapi_table && (pfn_gameinit=dllapi_table->pfnGameInit)) |
|
darope@0
|
538 |
pfn_gameinit(); |
|
darope@0
|
539 |
} |
|
darope@0
|
540 |
// If loading during map, then I'd like to call plugin's |
|
darope@0
|
541 |
// ServerActivate, since we've passed that. However, I'm not sure what |
|
darope@0
|
542 |
// arguments to give it... So, we'll just have to say for the |
|
darope@0
|
543 |
// moment that plugins that are loadable during a map can't need to |
|
darope@0
|
544 |
// hook ServerActivate. |
|
darope@0
|
545 |
|
|
darope@0
|
546 |
META_LOG("dll: Loaded plugin '%s': %s v%s %s, %s", desc, info->name, |
|
darope@0
|
547 |
info->version, info->date, info->author); |
|
darope@0
|
548 |
return(mTRUE); |
|
darope@0
|
549 |
} |
|
darope@0
|
550 |
|
|
darope@0
|
551 |
// Query a plugin: |
|
darope@0
|
552 |
// - dlopen() the file, store the handle |
|
darope@0
|
553 |
// - dlsym() and call: |
|
darope@0
|
554 |
// Meta_Init (if present) - tell dll it'll be used as a metamod plugin |
|
darope@0
|
555 |
// GiveFnptrsToDll - give engine function ptrs |
|
darope@0
|
556 |
// Meta_Query - say "hi" and get info about plugin |
|
darope@0
|
557 |
// meta_errno values: |
|
darope@0
|
558 |
// - ME_DLOPEN dlopen/loadlibrary failed; see dlerror() for details |
|
darope@0
|
559 |
// - ME_DLMISSING couldn't find a query() or giveFuncs() in plugin |
|
darope@0
|
560 |
// - ME_DLERROR plugin query() returned error |
|
darope@0
|
561 |
// - ME_NULLDATA info struct from query() was null |
|
darope@0
|
562 |
mBOOL MPlugin::query(void) { |
|
darope@0
|
563 |
META_INIT_FN pfn_init; |
|
darope@0
|
564 |
GIVE_ENGINE_FUNCTIONS_FN pfn_give_engfuncs; |
|
darope@0
|
565 |
META_QUERY_FN pfn_query; |
|
darope@0
|
566 |
|
|
darope@0
|
567 |
// open the plugin DLL |
|
darope@0
|
568 |
if(!(handle=DLOPEN(pathname))) { |
|
darope@0
|
569 |
META_ERROR("dll: Failed query plugin '%s'; Couldn't open file '%s': %s", |
|
darope@0
|
570 |
desc, pathname, DLERROR()); |
|
darope@0
|
571 |
RETURN_ERRNO(mFALSE, ME_DLOPEN); |
|
darope@0
|
572 |
} |
|
darope@0
|
573 |
|
|
darope@0
|
574 |
// First, we check to see if they have a Meta_Query. We would normally |
|
darope@0
|
575 |
// dlsym this just prior to calling it, after having called |
|
darope@0
|
576 |
// GiveFnptrsToDll, but things like standalone-DLL bots do all their |
|
darope@0
|
577 |
// startup in GiveFnptrsToDll, and trying to load them as metamod |
|
darope@0
|
578 |
// plugins creates all sorts of crashes. So, we do a trivial check |
|
darope@0
|
579 |
// first to see if the DLL looks like a metamod plugin before |
|
darope@0
|
580 |
// proceeding with the normal order. Note that we still have to call |
|
darope@0
|
581 |
// GiveFnptrsToDll before Meta_Query, because the latter typically uses |
|
darope@0
|
582 |
// engine functions like AlertMessage, which have to be passed along via |
|
darope@0
|
583 |
// GiveFnptrsToDll. |
|
darope@0
|
584 |
pfn_query = (META_QUERY_FN) DLSYM(handle, "Meta_Query"); |
|
darope@0
|
585 |
if(!pfn_query) { |
|
darope@0
|
586 |
META_ERROR("dll: Failed query plugin '%s'; Couldn't find Meta_Query(): %s", desc, DLERROR()); |
|
darope@0
|
587 |
// caller will dlclose() |
|
darope@0
|
588 |
RETURN_ERRNO(mFALSE, ME_DLMISSING); |
|
darope@0
|
589 |
} |
|
darope@0
|
590 |
|
|
darope@0
|
591 |
// Call Meta_Init, if present. This is an optional plugin routine to |
|
darope@0
|
592 |
// allow plugin to do any special initializing or other processing |
|
darope@0
|
593 |
// prior to the standard query/attach procedure. |
|
darope@0
|
594 |
// |
|
darope@0
|
595 |
// In particular, this should allow for DLL's that can operate as both |
|
darope@0
|
596 |
// a standalone dll AND a metamod plugin. This routine has to be |
|
darope@0
|
597 |
// called _before_ GiveFnptrsToDll, since the dll will usually do all |
|
darope@0
|
598 |
// its startup processing in GiveFn, and has to know at that point |
|
darope@0
|
599 |
// whether it needs to do just mm plugin startup, or all the extra |
|
darope@0
|
600 |
// startup needed for a standalone DLL. |
|
darope@0
|
601 |
// |
|
darope@0
|
602 |
// This passes nothing and returns nothing, and the routine in the |
|
darope@0
|
603 |
// plugin can NOT use any Engine functions, as they haven't been |
|
darope@0
|
604 |
// provided yet (done next, in GiveFnptrsToDll). |
|
darope@0
|
605 |
pfn_init = (META_INIT_FN) DLSYM(handle, "Meta_Init"); |
|
darope@0
|
606 |
if(pfn_init) { |
|
darope@0
|
607 |
pfn_init(); |
|
darope@0
|
608 |
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Init()", desc)); |
|
darope@0
|
609 |
} |
|
darope@0
|
610 |
else { |
|
darope@0
|
611 |
META_DEBUG(5, ("dll: no Meta_Init present in plugin '%s'", desc)); |
|
darope@0
|
612 |
// don't return; not an error |
|
darope@0
|
613 |
} |
|
darope@0
|
614 |
|
|
darope@0
|
615 |
// pass on engine function table and globals to plugin |
|
darope@0
|
616 |
if(!(pfn_give_engfuncs = (GIVE_ENGINE_FUNCTIONS_FN) DLSYM(handle, "GiveFnptrsToDll"))) { |
|
darope@0
|
617 |
// META_ERROR("dll: Couldn't find GiveFnptrsToDll() in plugin '%s': %s", desc, DLERROR()); |
|
darope@0
|
618 |
META_ERROR("dll: Failed query plugin '%s'; Couldn't find GiveFnptrsToDll(): %s", desc, DLERROR()); |
|
darope@0
|
619 |
// caller will dlclose() |
|
darope@0
|
620 |
RETURN_ERRNO(mFALSE, ME_DLMISSING); |
|
darope@0
|
621 |
} |
|
darope@0
|
622 |
pfn_give_engfuncs(Engine.pl_funcs, Engine.globals); |
|
darope@0
|
623 |
META_DEBUG(6, ("dll: Plugin '%s': Called GiveFnptrsToDll()", desc)); |
|
darope@0
|
624 |
|
|
darope@0
|
625 |
// Call plugin's Meta_Query(), to pass our meta interface version, and get |
|
darope@0
|
626 |
// plugin's info structure. |
|
darope@0
|
627 |
meta_errno=ME_NOERROR; |
|
darope@0
|
628 |
info=NULL; |
|
darope@0
|
629 |
// Make a copy of the meta_util function table for each plugin, for the |
|
darope@0
|
630 |
// same reason. |
|
darope@0
|
631 |
memcpy(&mutil_funcs, &MetaUtilFunctions, sizeof(mutil_funcs)); |
|
darope@0
|
632 |
|
|
darope@0
|
633 |
if(pfn_query(META_INTERFACE_VERSION, &info, &mutil_funcs) != TRUE) { |
|
darope@0
|
634 |
META_ERROR("dll: Failed query plugin '%s'; Meta_Query returned error", |
|
darope@0
|
635 |
desc); |
|
darope@0
|
636 |
meta_errno=ME_DLERROR; |
|
darope@0
|
637 |
} |
|
darope@0
|
638 |
else { |
|
darope@0
|
639 |
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Query() successfully", |
|
darope@0
|
640 |
desc)); |
|
darope@0
|
641 |
} |
|
darope@0
|
642 |
|
|
darope@0
|
643 |
// Check for interface differences... Generally, a difference in major |
|
darope@0
|
644 |
// version will be incompatible, and a plugin that expects a later |
|
darope@0
|
645 |
// minor version will be incompatible (it's expecting things that this |
|
darope@0
|
646 |
// Metamod won't be supplying). Plugins that use an older minor |
|
darope@0
|
647 |
// version will still work, as backward-compability within major |
|
darope@0
|
648 |
// version is expected (forward-compatibility is not). |
|
darope@0
|
649 |
// |
|
darope@0
|
650 |
// Note, this check is done regardless of whether meta_query returns an |
|
darope@0
|
651 |
// error. |
|
darope@0
|
652 |
if(info && !FStrEq(info->ifvers, META_INTERFACE_VERSION)) { |
|
darope@0
|
653 |
int mmajor=0, mminor=0, pmajor=0, pminor=0; |
|
darope@0
|
654 |
META_DEBUG(3, ("dll: Note: Plugin '%s' interface version didn't match; expected %s, found %s", desc, META_INTERFACE_VERSION, info->ifvers)); |
|
darope@0
|
655 |
sscanf(META_INTERFACE_VERSION, "%d:%d", &mmajor, &mminor); |
|
darope@0
|
656 |
sscanf(info->ifvers, "%d:%d", &pmajor, &pminor); |
|
darope@0
|
657 |
// If plugin has later interface version, it's incompatible |
|
darope@0
|
658 |
// (update metamod). |
|
darope@0
|
659 |
if(pmajor > mmajor || (pmajor==mmajor && pminor > mminor)) { |
|
darope@0
|
660 |
META_ERROR("dll: Plugin '%s' requires a newer version of Metamod (Metamod needs at least interface %s not the current %s)", desc, info->ifvers, META_INTERFACE_VERSION); |
|
darope@0
|
661 |
meta_errno=ME_IFVERSION; |
|
darope@0
|
662 |
} |
|
darope@0
|
663 |
// If plugin has older major interface version, it's incompatible |
|
darope@0
|
664 |
// (update plugin). |
|
darope@0
|
665 |
else if(pmajor < mmajor) { |
|
darope@0
|
666 |
META_ERROR("dll: Plugin '%s' is out of date and incompatible with this version of Metamod; please find a newer version of the plugin (plugin needs at least interface %s not the current %s)", desc, META_INTERFACE_VERSION, info->ifvers); |
|
darope@0
|
667 |
meta_errno=ME_IFVERSION; |
|
darope@0
|
668 |
} |
|
darope@0
|
669 |
// Plugin has identical major, with older minor. This is supposed to be |
|
darope@0
|
670 |
// backwards compatible, so we warn, but we still accept it. |
|
darope@0
|
671 |
else if(pmajor==mmajor && pminor < mminor) |
|
darope@0
|
672 |
META_LOG("dll: Note: plugin '%s' is using an older interface version (%s), not the latest interface version (%s); there might be an updated version of the plugin", desc, info->ifvers, META_INTERFACE_VERSION); |
|
darope@0
|
673 |
else |
|
darope@0
|
674 |
META_LOG("dll: Plugin '%s': unexpected version comparision; metavers=%s, mmajor=%d, mminor=%d; plugvers=%s, pmajor=%d, pminor=%d", |
|
darope@0
|
675 |
desc, META_INTERFACE_VERSION, mmajor, mminor, info->ifvers, pmajor, pminor); |
|
darope@0
|
676 |
} |
|
darope@0
|
677 |
|
|
darope@0
|
678 |
if(meta_errno == ME_IFVERSION) { |
|
darope@0
|
679 |
META_ERROR("dll: Rejected plugin '%s' due to interface version incompatibility (mm=%s, pl=%s)", desc, META_INTERFACE_VERSION, info->ifvers); |
|
darope@0
|
680 |
// meta_errno is set already above |
|
darope@0
|
681 |
// caller will dlclose() |
|
darope@0
|
682 |
return(mFALSE); |
|
darope@0
|
683 |
} |
|
darope@0
|
684 |
else if(meta_errno != ME_NOERROR) |
|
darope@0
|
685 |
// some other error, already logged |
|
darope@0
|
686 |
return(mFALSE); |
|
darope@0
|
687 |
|
|
darope@0
|
688 |
if(!info) { |
|
darope@0
|
689 |
META_ERROR("dll: Failed query plugin '%s'; Empty info structure", desc); |
|
darope@0
|
690 |
// caller will dlclose() |
|
darope@0
|
691 |
RETURN_ERRNO(mFALSE, ME_NULLRESULT); |
|
darope@0
|
692 |
} |
|
darope@0
|
693 |
// Replace temporary desc with plugin's internal name. |
|
darope@0
|
694 |
if(desc[0] == '<') |
|
darope@0
|
695 |
STRNCPY(desc, info->name, sizeof(desc)); |
|
darope@0
|
696 |
META_DEBUG(6, ("dll: Plugin '%s': Query successful", desc)); |
|
darope@0
|
697 |
return(mTRUE); |
|
darope@0
|
698 |
} |
|
darope@0
|
699 |
|
|
darope@0
|
700 |
// Attach a plugin: |
|
darope@0
|
701 |
// - dlsym() and call: |
|
darope@0
|
702 |
// Meta_Attach - get table of api tables, give meta_globals |
|
darope@0
|
703 |
// - if provided by plugin, call various "Get" function pointers, |
|
darope@0
|
704 |
// and store resulting function tables: |
|
darope@0
|
705 |
// GetEntityAPI (std) |
|
darope@0
|
706 |
// GetEntityAPI2 (std sdk2) |
|
darope@0
|
707 |
// GetNewDLLFunctions (std sdk2) |
|
darope@0
|
708 |
// |
|
darope@0
|
709 |
// GetEntityAPI_Post (meta) |
|
darope@0
|
710 |
// GetEntityAPI2_Post (meta) |
|
darope@0
|
711 |
// GetNewDLLFunctions_Post (meta) |
|
darope@0
|
712 |
// |
|
darope@0
|
713 |
// GetEngineFunctions (meta) |
|
darope@0
|
714 |
// GetEngineFunctions_Post (meta) |
|
darope@0
|
715 |
// meta_errno values: |
|
darope@0
|
716 |
// - ME_DLMISSING couldn't find meta_attach() in plugin |
|
darope@0
|
717 |
// - ME_DLERROR plugin attach() returned error |
|
darope@0
|
718 |
// - ME_NOMEM failed malloc |
|
darope@0
|
719 |
mBOOL MPlugin::attach(PLUG_LOADTIME now) { |
|
darope@0
|
720 |
int ret; |
|
darope@0
|
721 |
int iface_vers; |
|
darope@0
|
722 |
|
|
darope@0
|
723 |
META_ATTACH_FN pfn_attach; |
|
darope@0
|
724 |
META_FUNCTIONS meta_table; |
|
darope@0
|
725 |
|
|
darope@0
|
726 |
// Make copy of gameDLL's function tables for each plugin, so we don't |
|
darope@0
|
727 |
// risk the plugins screwing with the tables everyone uses. |
|
darope@0
|
728 |
if(GameDLL.funcs.dllapi_table && !gamedll_funcs.dllapi_table) { |
|
darope@247
|
729 |
gamedll_funcs.dllapi_table = (DLL_FUNCTIONS *) calloc(1, sizeof(DLL_FUNCTIONS)); |
|
darope@0
|
730 |
if(!gamedll_funcs.dllapi_table) { |
|
darope@0
|
731 |
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for dllapi_table"); |
|
darope@0
|
732 |
RETURN_ERRNO(mFALSE, ME_NOMEM); |
|
darope@0
|
733 |
} |
|
darope@0
|
734 |
memcpy(gamedll_funcs.dllapi_table, GameDLL.funcs.dllapi_table, |
|
darope@0
|
735 |
sizeof(DLL_FUNCTIONS)); |
|
darope@0
|
736 |
} |
|
darope@0
|
737 |
if(GameDLL.funcs.newapi_table && !gamedll_funcs.newapi_table) { |
|
darope@0
|
738 |
gamedll_funcs.newapi_table = (NEW_DLL_FUNCTIONS *) malloc(sizeof(NEW_DLL_FUNCTIONS)); |
|
darope@0
|
739 |
if(!gamedll_funcs.newapi_table) { |
|
darope@0
|
740 |
META_ERROR("dll: Failed attach plugin '%s': Failed malloc() for newapi_table"); |
|
darope@0
|
741 |
RETURN_ERRNO(mFALSE, ME_NOMEM); |
|
darope@0
|
742 |
} |
|
darope@0
|
743 |
memcpy(gamedll_funcs.newapi_table, GameDLL.funcs.newapi_table, |
|
darope@0
|
744 |
sizeof(NEW_DLL_FUNCTIONS)); |
|
darope@0
|
745 |
} |
|
darope@0
|
746 |
if(!(pfn_attach = (META_ATTACH_FN) DLSYM(handle, "Meta_Attach"))) { |
|
darope@0
|
747 |
META_ERROR("dll: Failed attach plugin '%s': Couldn't find Meta_Attach(): %s", desc, DLERROR()); |
|
darope@0
|
748 |
// caller will dlclose() |
|
darope@0
|
749 |
RETURN_ERRNO(mFALSE, ME_DLMISSING); |
|
darope@0
|
750 |
} |
|
darope@0
|
751 |
|
|
darope@0
|
752 |
memset(&meta_table, 0, sizeof(meta_table)); |
|
darope@0
|
753 |
// get table of function tables, |
|
darope@0
|
754 |
// give public meta globals |
|
darope@0
|
755 |
ret=pfn_attach(now, &meta_table, &PublicMetaGlobals, &gamedll_funcs); |
|
darope@0
|
756 |
if(ret != TRUE) { |
|
darope@0
|
757 |
META_ERROR("dll: Failed attach plugin '%s': Error from Meta_Attach(): %d", desc, ret); |
|
darope@0
|
758 |
// caller will dlclose() |
|
darope@0
|
759 |
RETURN_ERRNO(mFALSE, ME_DLERROR); |
|
darope@0
|
760 |
} |
|
darope@0
|
761 |
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Attach() successfully", desc)); |
|
darope@0
|
762 |
|
|
darope@0
|
763 |
// Rather than duplicate code, we use another ugly macro. Again, |
|
darope@0
|
764 |
// a function isn't an option since we have varying types. |
|
darope@0
|
765 |
#define GET_FUNC_TABLE_FROM_PLUGIN(pfnGetFuncs, STR_GetFuncs, struct_field, API_TYPE, TABLE_TYPE, vers_pass, vers_int, vers_want) \ |
|
darope@0
|
766 |
if(meta_table.pfnGetFuncs) { \ |
|
darope@247
|
767 |
if (!struct_field) \ |
|
darope@247
|
768 |
struct_field = (TABLE_TYPE*) calloc(1, sizeof(TABLE_TYPE)); \ |
|
darope@0
|
769 |
if(meta_table.pfnGetFuncs(struct_field, vers_pass)) { \ |
|
darope@0
|
770 |
META_DEBUG(3, ("dll: Plugin '%s': Found %s", desc, STR_GetFuncs)); \ |
|
darope@0
|
771 |
} \ |
|
darope@0
|
772 |
else { \ |
|
darope@0
|
773 |
META_ERROR("dll: Failure calling %s in plugin '%s'", STR_GetFuncs, desc); \ |
|
darope@0
|
774 |
if(vers_int != vers_want) \ |
|
darope@0
|
775 |
META_ERROR("dll: Interface version didn't match; expected %d, found %d", vers_want, vers_int); \ |
|
darope@0
|
776 |
} \ |
|
darope@0
|
777 |
} \ |
|
darope@0
|
778 |
else { \ |
|
darope@0
|
779 |
META_DEBUG(5, ("dll: Plugin '%s': No %s", desc, STR_GetFuncs)); \ |
|
darope@247
|
780 |
if (struct_field) \ |
|
darope@247
|
781 |
free(struct_field); \ |
|
darope@0
|
782 |
struct_field=NULL; \ |
|
darope@0
|
783 |
} |
|
darope@0
|
784 |
|
|
darope@0
|
785 |
// Look for API-NEW interface in plugin. We do this before API2/API, because |
|
darope@0
|
786 |
// that's what the engine appears to do.. |
|
darope@0
|
787 |
// But we only do this if the gamedll provides these, so that we don't |
|
darope@0
|
788 |
// give a plugin the idea that we'll call them, when in fact we won't |
|
darope@0
|
789 |
// (since we don't export them to the engine when the gamedll doesn't |
|
darope@0
|
790 |
// provide them). |
|
darope@0
|
791 |
if(GameDLL.funcs.newapi_table) { |
|
darope@0
|
792 |
iface_vers=NEW_DLL_FUNCTIONS_VERSION; |
|
darope@0
|
793 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetNewDLLFunctions, |
|
darope@0
|
794 |
"GetNewDLLFunctions", newapi_table, |
|
darope@0
|
795 |
NEW_DLL_FUNCTIONS_FN, NEW_DLL_FUNCTIONS, |
|
darope@0
|
796 |
&iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION); |
|
darope@0
|
797 |
iface_vers=NEW_DLL_FUNCTIONS_VERSION; |
|
darope@0
|
798 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetNewDLLFunctions_Post, |
|
darope@0
|
799 |
"GetNewDLLFunctions_Post", newapi_post_table, |
|
darope@0
|
800 |
NEW_DLL_FUNCTIONS_FN, NEW_DLL_FUNCTIONS, |
|
darope@0
|
801 |
&iface_vers, iface_vers, NEW_DLL_FUNCTIONS_VERSION); |
|
darope@0
|
802 |
} |
|
darope@0
|
803 |
|
|
darope@0
|
804 |
// Look for API2 interface in plugin; preferred over API-1. |
|
darope@0
|
805 |
iface_vers=INTERFACE_VERSION; |
|
darope@0
|
806 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI2, |
|
darope@0
|
807 |
"GetEntityAPI2", dllapi_table, |
|
darope@0
|
808 |
APIFUNCTION2, DLL_FUNCTIONS, |
|
darope@0
|
809 |
&iface_vers, iface_vers, INTERFACE_VERSION); |
|
darope@0
|
810 |
iface_vers=INTERFACE_VERSION; |
|
darope@0
|
811 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI2_Post, |
|
darope@0
|
812 |
"GetEntityAPI2_Post", dllapi_post_table, |
|
darope@0
|
813 |
APIFUNCTION2, DLL_FUNCTIONS, |
|
darope@0
|
814 |
&iface_vers, iface_vers, INTERFACE_VERSION); |
|
darope@0
|
815 |
|
|
darope@0
|
816 |
// Look for old-style API in plugin, if API2 interface wasn't found. |
|
darope@0
|
817 |
if(!dllapi_table && !dllapi_post_table) { |
|
darope@0
|
818 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI, |
|
darope@0
|
819 |
"GetEntityAPI", dllapi_table, |
|
darope@0
|
820 |
APIFUNCTION, DLL_FUNCTIONS, |
|
darope@0
|
821 |
INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION); |
|
darope@0
|
822 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEntityAPI_Post, |
|
darope@0
|
823 |
"GetEntityAPI_Post", dllapi_post_table, |
|
darope@0
|
824 |
APIFUNCTION, DLL_FUNCTIONS, |
|
darope@0
|
825 |
INTERFACE_VERSION, INTERFACE_VERSION, INTERFACE_VERSION); |
|
darope@0
|
826 |
} |
|
darope@0
|
827 |
|
|
darope@0
|
828 |
// Look for Engine interface. |
|
darope@0
|
829 |
iface_vers=ENGINE_INTERFACE_VERSION; |
|
darope@0
|
830 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEngineFunctions, |
|
darope@0
|
831 |
"GetEngineFunctions", engine_table, |
|
darope@0
|
832 |
GET_ENGINE_FUNCTIONS_FN, enginefuncs_t, |
|
darope@0
|
833 |
&iface_vers, iface_vers, ENGINE_INTERFACE_VERSION); |
|
darope@0
|
834 |
iface_vers=ENGINE_INTERFACE_VERSION; |
|
darope@0
|
835 |
GET_FUNC_TABLE_FROM_PLUGIN(pfnGetEngineFunctions_Post, |
|
darope@0
|
836 |
"GetEngineFunctions_Post", engine_post_table, |
|
darope@0
|
837 |
GET_ENGINE_FUNCTIONS_FN, enginefuncs_t, |
|
darope@0
|
838 |
&iface_vers, iface_vers, ENGINE_INTERFACE_VERSION); |
|
darope@0
|
839 |
|
|
darope@0
|
840 |
if(!dllapi_table && !dllapi_post_table |
|
darope@0
|
841 |
&& !newapi_table && !newapi_post_table |
|
darope@0
|
842 |
&& !engine_table && !engine_post_table) |
|
darope@0
|
843 |
{ |
|
darope@0
|
844 |
META_LOG("dll: Plugin '%s' isn't catching _any_ functions ??", desc); |
|
darope@0
|
845 |
} |
|
darope@0
|
846 |
|
|
darope@0
|
847 |
time_loaded=time(NULL); |
|
darope@0
|
848 |
return(mTRUE); |
|
darope@0
|
849 |
} |
|
darope@0
|
850 |
|
|
darope@0
|
851 |
// Unload a plugin. Check time, detach. |
|
darope@0
|
852 |
// meta_errno values: |
|
darope@0
|
853 |
// - ME_ARGUMENT missing necessary fields in plugin |
|
darope@0
|
854 |
// - ME_ALREADY this plugin already unloaded |
|
darope@0
|
855 |
// - ME_BADREQ plugin not marked for unload |
|
darope@0
|
856 |
// - ME_DELAYED unload request is delayed (till changelevel?) |
|
darope@0
|
857 |
// - ME_NOTALLOWED plugin not unloadable after startup |
|
darope@0
|
858 |
// - errno's from check_input() |
|
darope@0
|
859 |
mBOOL MPlugin::unload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { |
|
darope@0
|
860 |
if(!check_input()) { |
|
darope@0
|
861 |
// details logged, meta_errno set in check_input() |
|
darope@0
|
862 |
RETURN_ERRNO(mFALSE, ME_ARGUMENT); |
|
darope@0
|
863 |
} |
|
darope@0
|
864 |
if(status < PL_RUNNING) { |
|
darope@0
|
865 |
META_ERROR("dll: Not unloading plugin '%s'; already unloaded (status=%s)", desc, str_status()); |
|
darope@0
|
866 |
RETURN_ERRNO(mFALSE, ME_ALREADY); |
|
darope@0
|
867 |
} |
|
darope@0
|
868 |
if(action != PA_UNLOAD && action != PA_RELOAD) { |
|
darope@0
|
869 |
META_ERROR("dll: Not unloading plugin '%s'; not marked for unload (action=%s)", desc, str_action()); |
|
darope@0
|
870 |
RETURN_ERRNO(mFALSE, ME_BADREQ); |
|
darope@0
|
871 |
} |
|
darope@0
|
872 |
|
|
darope@0
|
873 |
// Are we allowed to detach this plugin at this time? |
|
darope@0
|
874 |
// If forcing unload, we disregard when plugin wants to be unloaded. |
|
darope@0
|
875 |
if(info->unloadable < now) { |
|
darope@0
|
876 |
if(reason == PNL_CMD_FORCED) { |
|
darope@0
|
877 |
META_DEBUG(2, ("dll: Forced unload plugin '%s' overriding allowed times: allowed=%s; now=%s", desc, str_unloadable(), str_loadtime(now, SL_SIMPLE))); |
|
darope@0
|
878 |
} |
|
darope@0
|
879 |
else { |
|
darope@0
|
880 |
if(info->unloadable > PT_STARTUP) { |
|
darope@0
|
881 |
META_DEBUG(2, ("dll: Delaying unload plugin '%s'; can't detach now: allowed=%s; now=%s", desc, str_unloadable(), str_loadtime(now, SL_SIMPLE))); |
|
darope@0
|
882 |
// caller should give message to user |
|
darope@0
|
883 |
// try to unload again at next opportunity |
|
darope@0
|
884 |
RETURN_ERRNO(mFALSE, ME_DELAYED); |
|
darope@0
|
885 |
} |
|
darope@0
|
886 |
else { |
|
darope@0
|
887 |
META_DEBUG(2, ("dll: Failed unload plugin '%s'; can't detach now: allowed=%s; now=%s", desc, str_unloadable(), str_loadtime(now, SL_SIMPLE))); |
|
darope@0
|
888 |
// don't try to unload again later |
|
darope@0
|
889 |
action=PA_NONE; |
|
darope@0
|
890 |
RETURN_ERRNO(mFALSE, ME_NOTALLOWED); |
|
darope@0
|
891 |
} |
|
darope@0
|
892 |
} |
|
darope@0
|
893 |
} |
|
darope@0
|
894 |
|
|
darope@0
|
895 |
// If unloading during map, then I'd like to call plugin's |
|
darope@0
|
896 |
// ServerDeactivate. However, I don't want to do this until I start |
|
darope@0
|
897 |
// calling ServerActivate when loading during map, since the SDK |
|
darope@0
|
898 |
// indicates these two routines should match call for call. |
|
darope@0
|
899 |
|
|
darope@0
|
900 |
// detach plugin |
|
darope@0
|
901 |
if(!detach(now, reason)) { |
|
darope@0
|
902 |
if(reason == PNL_CMD_FORCED) { |
|
darope@0
|
903 |
META_DEBUG(2, ("dll: Forced unload plugin '%s' overriding failed detach")); |
|
darope@0
|
904 |
} |
|
darope@0
|
905 |
else { |
|
darope@0
|
906 |
META_ERROR("dll: Failed to detach plugin '%s'; ", desc); |
|
darope@0
|
907 |
// meta_errno should be already set in detach() |
|
darope@0
|
908 |
return(mFALSE); |
|
darope@0
|
909 |
} |
|
darope@0
|
910 |
} |
|
darope@0
|
911 |
|
|
darope@0
|
912 |
// successful detach, or forced unload |
|
darope@0
|
913 |
|
|
darope@0
|
914 |
// Unmark registered commands for this plugin (by index number). |
|
darope@0
|
915 |
RegCmds->disable(index); |
|
darope@0
|
916 |
// Unmark registered cvars for this plugin (by index number). |
|
darope@0
|
917 |
RegCvars->disable(index); |
|
darope@0
|
918 |
|
|
darope@0
|
919 |
#ifdef UNFINISHED |
|
darope@0
|
920 |
// Remove all requested hooks from this plugin (by index number). |
|
darope@0
|
921 |
Hooks->remove_all(info); |
|
darope@0
|
922 |
#endif /* UNFINISHED */ |
|
darope@0
|
923 |
|
|
darope@0
|
924 |
// Close the file. Note: after this, attempts to reference any memory |
|
darope@0
|
925 |
// locations in the file will produce a segfault. |
|
darope@0
|
926 |
if(DLCLOSE(handle) != 0) { |
|
darope@0
|
927 |
META_ERROR("dll: Couldn't close plugin file '%s': %s", file, DLERROR()); |
|
darope@0
|
928 |
status=PL_FAILED; |
|
darope@0
|
929 |
RETURN_ERRNO(mFALSE, ME_DLERROR); |
|
darope@0
|
930 |
} |
|
darope@0
|
931 |
handle=NULL; |
|
darope@0
|
932 |
|
|
darope@0
|
933 |
if(action==PA_UNLOAD) { |
|
darope@0
|
934 |
status=PL_EMPTY; |
|
darope@0
|
935 |
clear(); |
|
darope@0
|
936 |
} |
|
darope@0
|
937 |
else if(action==PA_RELOAD) { |
|
darope@0
|
938 |
status=PL_VALID; |
|
darope@0
|
939 |
action=PA_LOAD; |
|
darope@247
|
940 |
clear(); |
|
darope@0
|
941 |
} |
|
darope@0
|
942 |
META_LOG("dll: Unloaded plugin '%s' for reason '%s'", desc, str_reason(reason)); |
|
darope@0
|
943 |
return(mTRUE); |
|
darope@0
|
944 |
} |
|
darope@0
|
945 |
|
|
darope@0
|
946 |
// Inform plugin we're going to unload it. |
|
darope@0
|
947 |
// meta_errno values: |
|
darope@0
|
948 |
// - ME_DLMISSING couldn't find meta_detach() in plugin |
|
darope@0
|
949 |
// - ME_DLERROR plugin detach() returned error |
|
darope@0
|
950 |
mBOOL MPlugin::detach(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { |
|
darope@0
|
951 |
int ret; |
|
darope@0
|
952 |
META_DETACH_FN pfn_detach; |
|
darope@0
|
953 |
|
|
darope@0
|
954 |
if(!(pfn_detach = (META_DETACH_FN) DLSYM(handle, "Meta_Detach"))) { |
|
darope@0
|
955 |
META_ERROR("dll: Error detach plugin '%s': Couldn't find Meta_detach(): %s", desc, DLERROR()); |
|
darope@0
|
956 |
// caller will dlclose() |
|
darope@0
|
957 |
RETURN_ERRNO(mFALSE, ME_DLMISSING); |
|
darope@0
|
958 |
} |
|
darope@0
|
959 |
|
|
darope@0
|
960 |
ret=pfn_detach(now, reason); |
|
darope@0
|
961 |
if(ret != TRUE) { |
|
darope@0
|
962 |
META_ERROR("dll: Failed detach plugin '%s': Error from Meta_Detach(): %d", desc, ret); |
|
darope@0
|
963 |
RETURN_ERRNO(mFALSE, ME_DLERROR); |
|
darope@0
|
964 |
} |
|
darope@0
|
965 |
META_DEBUG(6, ("dll: Plugin '%s': Called Meta_Detach() successfully", desc)); |
|
darope@0
|
966 |
return(mTRUE); |
|
darope@0
|
967 |
} |
|
darope@0
|
968 |
|
|
darope@0
|
969 |
// Reload a plugin; unload and load again. |
|
darope@0
|
970 |
// meta_errno values: |
|
darope@246
|
971 |
// - ME_NOTALLOWED plugin not loadable after startup |
|
darope@246
|
972 |
// - errno's from check_input() |
|
darope@0
|
973 |
// - errno's from unload() |
|
darope@0
|
974 |
// - errno's from load() |
|
darope@0
|
975 |
mBOOL MPlugin::reload(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { |
|
darope@246
|
976 |
if(!check_input()) { |
|
darope@246
|
977 |
// details logged, meta_errno set in check_input() |
|
darope@246
|
978 |
RETURN_ERRNO(mFALSE, ME_ARGUMENT); |
|
darope@246
|
979 |
} |
|
darope@246
|
980 |
// Are we allowed to load this plugin at this time? |
|
darope@246
|
981 |
// If we cannot load the plugin after unloading it, we keep it. |
|
darope@246
|
982 |
if(info->loadable < now) { |
|
darope@246
|
983 |
if(info->loadable > PT_STARTUP) { |
|
darope@246
|
984 |
META_DEBUG(2, ("dll: Delaying reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE))); |
|
darope@246
|
985 |
// caller should give message to user |
|
darope@246
|
986 |
// try to reload again at next opportunity |
|
darope@246
|
987 |
RETURN_ERRNO(mFALSE, ME_DELAYED); |
|
darope@246
|
988 |
} |
|
darope@246
|
989 |
else { |
|
darope@246
|
990 |
META_DEBUG(2, ("dll: Failed reload plugin '%s'; would not be able to reattach now: allowed=%s; now=%s", desc, str_loadable(), str_loadtime(now, SL_SIMPLE))); |
|
darope@246
|
991 |
// don't try to reload again later |
|
darope@246
|
992 |
action=PA_NONE; |
|
darope@246
|
993 |
RETURN_ERRNO(mFALSE, ME_NOTALLOWED); |
|
darope@246
|
994 |
} |
|
darope@246
|
995 |
} |
|
darope@246
|
996 |
|
|
darope@0
|
997 |
if(!unload(now, reason)) { |
|
darope@0
|
998 |
META_ERROR("dll: Failed to unload plugin '%s' for reloading", desc); |
|
darope@0
|
999 |
// meta_errno should be set already in unload() |
|
darope@0
|
1000 |
return(mFALSE); |
|
darope@0
|
1001 |
} |
|
darope@0
|
1002 |
if(!load(now)) { |
|
darope@0
|
1003 |
META_ERROR("dll: Failed to reload plugin '%s' after unloading", desc); |
|
darope@0
|
1004 |
// meta_errno should be set already in load() |
|
darope@0
|
1005 |
return(mFALSE); |
|
darope@0
|
1006 |
} |
|
darope@0
|
1007 |
return(mTRUE); |
|
darope@0
|
1008 |
} |
|
darope@0
|
1009 |
|
|
darope@0
|
1010 |
// Pause a plugin; temporarily disabled for API routines. |
|
darope@0
|
1011 |
// meta_errno values: |
|
darope@0
|
1012 |
// - ME_ALREADY this plugin already paused |
|
darope@0
|
1013 |
// - ME_BADREQ can't pause; not running |
|
darope@0
|
1014 |
// - ME_NOTALLOWED plugin doesn't want to be paused |
|
darope@0
|
1015 |
mBOOL MPlugin::pause(void) { |
|
darope@0
|
1016 |
if(status == PL_PAUSED) { |
|
darope@0
|
1017 |
META_ERROR("Not pausing plugin '%s'; already paused", desc); |
|
darope@0
|
1018 |
RETURN_ERRNO(mFALSE, ME_ALREADY); |
|
darope@0
|
1019 |
} |
|
darope@0
|
1020 |
if(status != PL_RUNNING) { |
|
darope@0
|
1021 |
META_ERROR("Cannot pause plugin '%s'; not currently running (status=%s)", desc, str_status()); |
|
darope@0
|
1022 |
RETURN_ERRNO(mFALSE, ME_BADREQ); |
|
darope@0
|
1023 |
} |
|
darope@0
|
1024 |
|
|
darope@0
|
1025 |
// are we allowed to pause this plugin? |
|
darope@0
|
1026 |
if(info->unloadable < PT_ANYPAUSE) { |
|
darope@0
|
1027 |
META_ERROR("Cannot pause plugin '%s'; not allowed by plugin (allowed=%s)", desc, str_unloadable()); |
|
darope@0
|
1028 |
action=PA_NONE; |
|
darope@0
|
1029 |
RETURN_ERRNO(mFALSE, ME_NOTALLOWED); |
|
darope@0
|
1030 |
} |
|
darope@0
|
1031 |
|
|
darope@0
|
1032 |
status=PL_PAUSED; |
|
darope@0
|
1033 |
META_LOG("Paused plugin '%s'", desc); |
|
darope@0
|
1034 |
return(mTRUE); |
|
darope@0
|
1035 |
} |
|
darope@0
|
1036 |
|
|
darope@0
|
1037 |
// Unpause a plugin. |
|
darope@0
|
1038 |
// meta_errno values: |
|
darope@0
|
1039 |
// - ME_BADREQ can't unpause; not paused |
|
darope@0
|
1040 |
mBOOL MPlugin::unpause(void) { |
|
darope@0
|
1041 |
if(status != PL_PAUSED) { |
|
darope@0
|
1042 |
META_ERROR("Cannot unpause plugin '%s'; not currently paused (status=%s)", desc, str_status()); |
|
darope@0
|
1043 |
RETURN_ERRNO(mFALSE, ME_BADREQ); |
|
darope@0
|
1044 |
} |
|
darope@0
|
1045 |
status=PL_RUNNING; |
|
darope@0
|
1046 |
META_LOG("Unpaused plugin '%s'", desc); |
|
darope@0
|
1047 |
return(mTRUE); |
|
darope@0
|
1048 |
} |
|
darope@0
|
1049 |
|
|
darope@0
|
1050 |
// Retry pending action, presumably from a previous failure. |
|
darope@0
|
1051 |
// meta_errno values: |
|
darope@0
|
1052 |
// - ME_BADREQ no pending action |
|
darope@0
|
1053 |
// - errno's from load() |
|
darope@0
|
1054 |
// - errno's from unload() |
|
darope@0
|
1055 |
// - errno's from reload() |
|
darope@0
|
1056 |
mBOOL MPlugin::retry(PLUG_LOADTIME now, PL_UNLOAD_REASON reason) { |
|
darope@0
|
1057 |
if(action==PA_LOAD) |
|
darope@0
|
1058 |
return(load(now)); |
|
darope@0
|
1059 |
else if(action==PA_ATTACH) |
|
darope@0
|
1060 |
return(load(now)); |
|
darope@0
|
1061 |
else if(action==PA_UNLOAD) |
|
darope@0
|
1062 |
return(unload(now, reason)); |
|
darope@0
|
1063 |
else if(action==PA_RELOAD) |
|
darope@0
|
1064 |
return(reload(now, reason)); |
|
darope@0
|
1065 |
else { |
|
darope@0
|
1066 |
META_ERROR("No pending action to retry for plugin '%s'; (status=%s, action=%s)", desc, str_status(), str_action()); |
|
darope@0
|
1067 |
RETURN_ERRNO(mFALSE, ME_BADREQ); |
|
darope@0
|
1068 |
} |
|
darope@0
|
1069 |
} |
|
darope@0
|
1070 |
|
|
darope@0
|
1071 |
// Clear a plugin (it failed a previous action and should be |
|
darope@0
|
1072 |
// removed from the list, or it's being unloaded). |
|
darope@0
|
1073 |
// meta_errno values: |
|
darope@0
|
1074 |
// - ME_BADREQ not marked for clearing |
|
darope@0
|
1075 |
// - ME_DLERROR failed to dlclose |
|
darope@0
|
1076 |
mBOOL MPlugin::clear(void) { |
|
darope@0
|
1077 |
if(status != PL_FAILED && status != PL_BADFILE |
|
darope@0
|
1078 |
&& status != PL_EMPTY && status != PL_OPENED) { |
|
darope@0
|
1079 |
META_ERROR("Cannot clear plugin '%s'; not marked as failed, empty, or open (status=%s)", desc, str_status()); |
|
darope@0
|
1080 |
RETURN_ERRNO(mFALSE, ME_BADREQ); |
|
darope@0
|
1081 |
} |
|
darope@0
|
1082 |
// If file is open, close the file. Note: after this, attempts to |
|
darope@0
|
1083 |
// reference any memory locations in the file will produce a segfault. |
|
darope@0
|
1084 |
if(handle && DLCLOSE(handle) != 0) { |
|
darope@0
|
1085 |
META_ERROR("dll: Couldn't close plugin file '%s': %s", file, DLERROR()); |
|
darope@0
|
1086 |
status=PL_FAILED; |
|
darope@0
|
1087 |
RETURN_ERRNO(mFALSE, ME_DLERROR); |
|
darope@0
|
1088 |
} |
|
darope@0
|
1089 |
handle=NULL; |
|
darope@0
|
1090 |
|
|
darope@0
|
1091 |
if(gamedll_funcs.dllapi_table) free(gamedll_funcs.dllapi_table); |
|
darope@0
|
1092 |
if(gamedll_funcs.newapi_table) free(gamedll_funcs.newapi_table); |
|
darope@246
|
1093 |
if(dllapi_table) free(dllapi_table); |
|
darope@246
|
1094 |
if(dllapi_post_table) free(dllapi_post_table); |
|
darope@246
|
1095 |
if(newapi_table) free(newapi_table); |
|
darope@246
|
1096 |
if(newapi_post_table) free(newapi_post_table); |
|
darope@246
|
1097 |
if(engine_table) free(engine_table); |
|
darope@246
|
1098 |
if(engine_post_table) free(engine_post_table); |
|
darope@0
|
1099 |
|
|
darope@0
|
1100 |
status=PL_EMPTY; |
|
darope@0
|
1101 |
action=PA_NULL; |
|
darope@0
|
1102 |
handle=NULL; |
|
darope@0
|
1103 |
info=NULL; |
|
darope@0
|
1104 |
time_loaded=0; |
|
darope@0
|
1105 |
dllapi_table=NULL; |
|
darope@0
|
1106 |
dllapi_post_table=NULL; |
|
darope@0
|
1107 |
newapi_table=NULL; |
|
darope@0
|
1108 |
newapi_post_table=NULL; |
|
darope@0
|
1109 |
engine_table=NULL; |
|
darope@0
|
1110 |
engine_post_table=NULL; |
|
darope@246
|
1111 |
gamedll_funcs.dllapi_table = NULL; |
|
darope@246
|
1112 |
gamedll_funcs.newapi_table = NULL; |
|
darope@0
|
1113 |
return(mTRUE); |
|
darope@0
|
1114 |
} |
|
darope@0
|
1115 |
|
|
darope@0
|
1116 |
// List information about plugin to console. |
|
darope@0
|
1117 |
void MPlugin::show(void) { |
|
darope@0
|
1118 |
char *cp, *tstr; |
|
darope@0
|
1119 |
int n, width; |
|
darope@0
|
1120 |
width=13; |
|
darope@0
|
1121 |
META_CONS("%*s: %s", width, "name", info ? info->name : "(nil)"); |
|
darope@0
|
1122 |
META_CONS("%*s: %s", width, "desc", desc); |
|
darope@0
|
1123 |
META_CONS("%*s: %s", width, "status", str_status()); |
|
darope@0
|
1124 |
META_CONS("%*s: %s", width, "action", str_action()); |
|
darope@0
|
1125 |
META_CONS("%*s: %s", width, "filename", filename); |
|
darope@0
|
1126 |
META_CONS("%*s: %s", width, "file", file); |
|
darope@0
|
1127 |
META_CONS("%*s: %s", width, "pathname", pathname); |
|
darope@0
|
1128 |
META_CONS("%*s: %d", width, "index", index); |
|
darope@0
|
1129 |
META_CONS("%*s: %s", width, "source", str_source()); |
|
darope@0
|
1130 |
META_CONS("%*s: %s", width, "loadable", str_loadable(SL_ALLOWED)); |
|
darope@0
|
1131 |
META_CONS("%*s: %s", width, "unloadable", str_unloadable(SL_ALLOWED)); |
|
darope@0
|
1132 |
META_CONS("%*s: %s", width, "version", info ? info->version : "(nil)"); |
|
darope@0
|
1133 |
META_CONS("%*s: %s", width, "date", info ? info->date : "(nil)"); |
|
darope@0
|
1134 |
META_CONS("%*s: %s", width, "author", info ? info->author : "(nil)"); |
|
darope@0
|
1135 |
META_CONS("%*s: %s", width, "url", info ? info->url : "(nil)"); |
|
darope@0
|
1136 |
META_CONS("%*s: %s", width, "logtag", info ? info->logtag : "(nil)"); |
|
darope@0
|
1137 |
// ctime() includes newline at EOL |
|
darope@0
|
1138 |
tstr=ctime(&time_loaded); |
|
darope@0
|
1139 |
if((cp=strchr(tstr, '\n'))) |
|
darope@0
|
1140 |
*cp='\0'; |
|
darope@0
|
1141 |
META_CONS("%*s: %s", width, "last loaded", tstr); |
|
darope@0
|
1142 |
// XXX show file time ? |
|
darope@0
|
1143 |
|
|
darope@0
|
1144 |
if(dllapi_table) { |
|
darope@0
|
1145 |
META_CONS("DLLAPI functions:"); |
|
darope@0
|
1146 |
SHOW_DEF_DLLAPI(dllapi_table, " ", ""); |
|
darope@0
|
1147 |
META_CONS("%d functions (dllapi)", n); |
|
darope@0
|
1148 |
} |
|
darope@0
|
1149 |
else |
|
darope@0
|
1150 |
META_CONS("No DLLAPI functions."); |
|
darope@0
|
1151 |
if(dllapi_post_table) { |
|
darope@0
|
1152 |
META_CONS("DLLAPI-Post functions:"); |
|
darope@0
|
1153 |
SHOW_DEF_DLLAPI(dllapi_post_table, " ", "_Post"); |
|
darope@0
|
1154 |
META_CONS("%d functions (dllapi post)", n); |
|
darope@0
|
1155 |
} |
|
darope@0
|
1156 |
else |
|
darope@0
|
1157 |
META_CONS("No DLLAPI-Post functions."); |
|
darope@0
|
1158 |
|
|
darope@0
|
1159 |
if(newapi_table) { |
|
darope@0
|
1160 |
META_CONS("NEWAPI functions:"); |
|
darope@0
|
1161 |
SHOW_DEF_NEWAPI(newapi_table, " ", ""); |
|
darope@0
|
1162 |
META_CONS("%d functions (newapi)", n); |
|
darope@0
|
1163 |
} |
|
darope@0
|
1164 |
else |
|
darope@0
|
1165 |
META_CONS("No NEWAPI functions."); |
|
darope@0
|
1166 |
if(newapi_post_table) { |
|
darope@0
|
1167 |
META_CONS("NEWAPI-Post functions:"); |
|
darope@0
|
1168 |
SHOW_DEF_NEWAPI(newapi_post_table, " ", "_Post"); |
|
darope@0
|
1169 |
META_CONS("%d functions (newapi post)", n); |
|
darope@0
|
1170 |
} |
|
darope@0
|
1171 |
else |
|
darope@0
|
1172 |
META_CONS("No NEWAPI-Post functions."); |
|
darope@0
|
1173 |
|
|
darope@0
|
1174 |
if(engine_table) { |
|
darope@0
|
1175 |
META_CONS("Engine functions:"); |
|
darope@0
|
1176 |
SHOW_DEF_ENGINE(engine_table, " ", ""); |
|
darope@0
|
1177 |
META_CONS("%d functions (engine)", n); |
|
darope@0
|
1178 |
} |
|
darope@0
|
1179 |
else |
|
darope@0
|
1180 |
META_CONS("No Engine functions."); |
|
darope@0
|
1181 |
if(engine_post_table) { |
|
darope@0
|
1182 |
META_CONS("Engine-Post functions:"); |
|
darope@0
|
1183 |
SHOW_DEF_ENGINE(engine_post_table, " ", "_Post"); |
|
darope@0
|
1184 |
META_CONS("%d functions (engine post)", n); |
|
darope@0
|
1185 |
} |
|
darope@0
|
1186 |
else |
|
darope@0
|
1187 |
META_CONS("No Engine-Post functions."); |
|
darope@0
|
1188 |
RegCmds->show(index); |
|
darope@0
|
1189 |
RegCvars->show(index); |
|
darope@0
|
1190 |
} |
|
darope@0
|
1191 |
|
|
darope@0
|
1192 |
// Check whether the file on disk looks like it's been updated since we |
|
darope@0
|
1193 |
// last loaded the plugin. |
|
darope@0
|
1194 |
// meta_errno values: |
|
darope@0
|
1195 |
// - ME_NOFILE couldn't find file |
|
darope@0
|
1196 |
// - ME_NOERROR no error; false indicates file not newer |
|
darope@0
|
1197 |
mBOOL MPlugin::newer_file(void) { |
|
darope@0
|
1198 |
struct stat st; |
|
darope@0
|
1199 |
time_t file_time; |
|
darope@0
|
1200 |
|
|
darope@0
|
1201 |
if(stat(pathname, &st) != 0) |
|
darope@0
|
1202 |
RETURN_ERRNO(mFALSE, ME_NOFILE); |
|
darope@0
|
1203 |
file_time=max(st.st_ctime, st.st_mtime); |
|
darope@0
|
1204 |
META_DEBUG(5, ("newer_file? file=%s; load=%d, file=%d; ctime=%d, mtime=%d", |
|
darope@0
|
1205 |
file, time_loaded, file_time, st.st_ctime, st.st_mtime)); |
|
darope@0
|
1206 |
if(file_time > time_loaded) |
|
darope@0
|
1207 |
return(mTRUE); |
|
darope@0
|
1208 |
else |
|
darope@0
|
1209 |
RETURN_ERRNO(mFALSE, ME_NOERROR); |
|
darope@0
|
1210 |
} |
|
darope@0
|
1211 |
|
|
darope@0
|
1212 |
// Return a string describing status of plugin. |
|
darope@0
|
1213 |
// SIMPLE is the default. |
|
darope@0
|
1214 |
// SHOW is max 4 chars, for "show" output. |
|
darope@0
|
1215 |
// meta_errno values: |
|
darope@0
|
1216 |
// - none |
|
darope@0
|
1217 |
char *MPlugin::str_status(STR_STATUS fmt) { |
|
darope@0
|
1218 |
switch(status) { |
|
darope@0
|
1219 |
case PL_EMPTY: |
|
darope@0
|
1220 |
if(fmt==ST_SHOW) return("empt"); |
|
darope@0
|
1221 |
else return("empty"); |
|
darope@0
|
1222 |
case PL_VALID: |
|
darope@0
|
1223 |
if(fmt==ST_SHOW) return("info"); |
|
darope@0
|
1224 |
else return("valid"); |
|
darope@0
|
1225 |
case PL_BADFILE: |
|
darope@0
|
1226 |
if(fmt==ST_SHOW) return("badf"); |
|
darope@0
|
1227 |
else return("badfile"); |
|
darope@0
|
1228 |
case PL_OPENED: |
|
darope@0
|
1229 |
if(fmt==ST_SHOW) return("open"); |
|
darope@0
|
1230 |
else return("opened"); |
|
darope@0
|
1231 |
case PL_FAILED: |
|
darope@0
|
1232 |
if(fmt==ST_SHOW) return("fail"); |
|
darope@0
|
1233 |
else return("failed"); |
|
darope@0
|
1234 |
case PL_RUNNING: |
|
darope@0
|
1235 |
if(fmt==ST_SHOW) return("RUN"); |
|
darope@0
|
1236 |
else return("running"); |
|
darope@0
|
1237 |
case PL_PAUSED: |
|
darope@0
|
1238 |
if(fmt==ST_SHOW) return("PAUS"); |
|
darope@0
|
1239 |
else return("paused"); |
|
darope@0
|
1240 |
default: |
|
darope@0
|
1241 |
if(fmt==ST_SHOW) return(UTIL_VarArgs("UNK%d", status)); |
|
darope@0
|
1242 |
return(UTIL_VarArgs("unknown (%d)", status)); |
|
darope@0
|
1243 |
} |
|
darope@0
|
1244 |
} |
|
darope@0
|
1245 |
|
|
darope@0
|
1246 |
// Return a string (one word) describing requested action for plugin. |
|
darope@0
|
1247 |
// SIMPLE is the default. |
|
darope@0
|
1248 |
// SHOW is max 4 chars, for "show" output. |
|
darope@0
|
1249 |
// meta_errno values: |
|
darope@0
|
1250 |
// - none |
|
darope@0
|
1251 |
char *MPlugin::str_action(STR_ACTION fmt) { |
|
darope@0
|
1252 |
switch(action) { |
|
darope@0
|
1253 |
case PA_NULL: |
|
darope@0
|
1254 |
if(fmt==SA_SHOW) return("NULL"); |
|
darope@0
|
1255 |
else return("null"); |
|
darope@0
|
1256 |
case PA_NONE: |
|
darope@0
|
1257 |
if(fmt==SA_SHOW) return(" - "); |
|
darope@0
|
1258 |
else return("none"); |
|
darope@0
|
1259 |
case PA_KEEP: |
|
darope@0
|
1260 |
if(fmt==SA_SHOW) return("keep"); |
|
darope@0
|
1261 |
else return("keep"); |
|
darope@0
|
1262 |
case PA_LOAD: |
|
darope@0
|
1263 |
if(fmt==SA_SHOW) return("load"); |
|
darope@0
|
1264 |
else return("load"); |
|
darope@0
|
1265 |
case PA_ATTACH: |
|
darope@0
|
1266 |
if(fmt==SA_SHOW) return("atch"); |
|
darope@0
|
1267 |
else return("attach"); |
|
darope@0
|
1268 |
case PA_UNLOAD: |
|
darope@0
|
1269 |
if(fmt==SA_SHOW) return("unld"); |
|
darope@0
|
1270 |
else return("unload"); |
|
darope@0
|
1271 |
case PA_RELOAD: |
|
darope@0
|
1272 |
if(fmt==SA_SHOW) return("relo"); |
|
darope@0
|
1273 |
else return("reload"); |
|
darope@0
|
1274 |
default: |
|
darope@0
|
1275 |
if(fmt==SA_SHOW) return(UTIL_VarArgs("UNK%d", action)); |
|
darope@0
|
1276 |
else return(UTIL_VarArgs("unknown (%d)", action)); |
|
darope@0
|
1277 |
} |
|
darope@0
|
1278 |
} |
|
darope@0
|
1279 |
|
|
darope@0
|
1280 |
// Return a string describing given plugin loadtime. |
|
darope@0
|
1281 |
// SIMPLE is the default. |
|
darope@0
|
1282 |
// SHOW is max 3 chars, for "show" output. |
|
darope@0
|
1283 |
// ALLOWED is in terms of when it's allowed to load/unload. |
|
darope@0
|
1284 |
// NOW is to describe current situation of load/unload attempt. |
|
darope@0
|
1285 |
// meta_errno values: |
|
darope@0
|
1286 |
// - none |
|
darope@0
|
1287 |
char *MPlugin::str_loadtime(PLUG_LOADTIME ptime, STR_LOADTIME fmt) { |
|
darope@0
|
1288 |
switch(ptime) { |
|
darope@0
|
1289 |
case PT_NEVER: |
|
darope@0
|
1290 |
if(fmt==SL_SHOW) return("Never"); |
|
darope@0
|
1291 |
else return("never"); |
|
darope@0
|
1292 |
case PT_STARTUP: |
|
darope@0
|
1293 |
if(fmt==SL_SHOW) return("Start"); |
|
darope@0
|
1294 |
else if(fmt==SL_ALLOWED) return("at server startup"); |
|
darope@0
|
1295 |
else if(fmt==SL_NOW) return("during server startup"); |
|
darope@0
|
1296 |
else return("startup"); |
|
darope@0
|
1297 |
case PT_CHANGELEVEL: |
|
darope@0
|
1298 |
if(fmt==SL_SHOW) return("Chlvl"); |
|
darope@0
|
1299 |
else if(fmt==SL_ALLOWED) return("at changelevel"); |
|
darope@0
|
1300 |
else if(fmt==SL_NOW) return("during changelevel"); |
|
darope@0
|
1301 |
else return("changelevel"); |
|
darope@0
|
1302 |
case PT_ANYTIME: |
|
darope@0
|
1303 |
if(fmt==SL_SHOW) return("ANY"); |
|
darope@0
|
1304 |
else if(fmt==SL_ALLOWED) return("at any time"); |
|
darope@0
|
1305 |
else if(fmt==SL_NOW) return("during map"); |
|
darope@0
|
1306 |
else return("anytime"); |
|
darope@0
|
1307 |
case PT_ANYPAUSE: |
|
darope@0
|
1308 |
if(fmt==SL_SHOW) return("Pause"); |
|
darope@0
|
1309 |
else if(fmt==SL_ALLOWED) return("at any time, and pausable"); |
|
darope@0
|
1310 |
else if(fmt==SL_NOW) return("for requested pause"); |
|
darope@0
|
1311 |
else return("pausable"); |
|
darope@0
|
1312 |
default: |
|
darope@0
|
1313 |
if(fmt==SL_SHOW) return(UTIL_VarArgs("UNK-%d", ptime)); |
|
darope@0
|
1314 |
else return(UTIL_VarArgs("unknown (%d)", ptime)); |
|
darope@0
|
1315 |
} |
|
darope@0
|
1316 |
} |
|
darope@0
|
1317 |
|
|
darope@0
|
1318 |
// Return a string describing why a plugin is to be unloaded. |
|
darope@0
|
1319 |
// meta_errno values: |
|
darope@0
|
1320 |
// - none |
|
darope@0
|
1321 |
char *MPlugin::str_reason(PL_UNLOAD_REASON preason) { |
|
darope@0
|
1322 |
switch(preason) { |
|
darope@0
|
1323 |
case PNL_NULL: |
|
darope@0
|
1324 |
return("null"); |
|
darope@0
|
1325 |
case PNL_INI_DELETED: |
|
darope@0
|
1326 |
return("deleted from ini file"); |
|
darope@0
|
1327 |
case PNL_FILE_NEWER: |
|
darope@0
|
1328 |
return("file on disk is newer"); |
|
darope@0
|
1329 |
case PNL_COMMAND: |
|
darope@0
|
1330 |
return("server command"); |
|
darope@0
|
1331 |
case PNL_CMD_FORCED: |
|
darope@0
|
1332 |
return("forced by server command"); |
|
darope@0
|
1333 |
default: |
|
darope@0
|
1334 |
return(UTIL_VarArgs("unknown (%d)", preason)); |
|
darope@0
|
1335 |
} |
|
darope@0
|
1336 |
} |
|
darope@0
|
1337 |
|
|
darope@0
|
1338 |
// Return a string describing how the plugin was loaded. |
|
darope@0
|
1339 |
// meta_errno values: |
|
darope@0
|
1340 |
// - none |
|
darope@0
|
1341 |
char *MPlugin::str_source(STR_SOURCE fmt) { |
|
darope@0
|
1342 |
switch(source) { |
|
darope@0
|
1343 |
case PS_INI: |
|
darope@0
|
1344 |
if(fmt==SO_SHOW) return("ini"); |
|
darope@0
|
1345 |
else return("ini file"); |
|
darope@0
|
1346 |
case PS_CMD: |
|
darope@0
|
1347 |
if(fmt==SO_SHOW) return("cmd"); |
|
darope@0
|
1348 |
else return("console command"); |
|
darope@0
|
1349 |
default: |
|
darope@0
|
1350 |
if(fmt==SO_SHOW) return(UTIL_VarArgs("UNK%d", source)); |
|
darope@0
|
1351 |
else return(UTIL_VarArgs("unknown (%d)", source)); |
|
darope@0
|
1352 |
} |
|
darope@0
|
1353 |
} |