1 | /* |
1 | /* |
2 | * static char *rcsid_plugins_c = |
2 | * static char *rcsid_plugins_c = |
3 | * "$Id: plugins.c,v 1.1.1.2 2006/02/22 18:03:23 elmex Exp $"; |
3 | * "$Id: plugins.c,v 1.3 2006/02/08 03:46:15 root Exp $"; |
4 | */ |
4 | */ |
5 | |
5 | |
6 | /*****************************************************************************/ |
6 | /*****************************************************************************/ |
7 | /* CrossFire, A Multiplayer game for X-windows */ |
7 | /* CrossFire, A Multiplayer game for X-windows */ |
8 | /* */ |
8 | /* */ |
… | |
… | |
127 | |
127 | |
128 | /*****************************************************************************/ |
128 | /*****************************************************************************/ |
129 | /* NEW PLUGIN STUFF STARTS HERE */ |
129 | /* NEW PLUGIN STUFF STARTS HERE */ |
130 | /*****************************************************************************/ |
130 | /*****************************************************************************/ |
131 | |
131 | |
|
|
132 | static void plugin_object_free(object *ob) |
|
|
133 | { |
|
|
134 | execute_global_event (EVENT_FREE_OB, ob); |
|
|
135 | } |
|
|
136 | |
132 | #ifdef WIN32 |
137 | #ifdef WIN32 |
133 | static const char *plugins_dlerror(void) |
138 | static const char *plugins_dlerror(void) |
134 | { |
139 | { |
135 | static char buf[256]; |
140 | static char buf[256]; |
136 | DWORD err; |
141 | DWORD err; |
… | |
… | |
242 | free_object(tmp); |
247 | free_object(tmp); |
243 | } else { |
248 | } else { |
244 | plugin = plugins_find_plugin(tmp->title); |
249 | plugin = plugins_find_plugin(tmp->title); |
245 | if (plugin == NULL) { |
250 | if (plugin == NULL) { |
246 | object *env = object_get_env_recursive(tmp); |
251 | object *env = object_get_env_recursive(tmp); |
247 | LOG(llevError, "The requested plugin doesn't exit: %s at %d/%d in map %s\n", tmp->title, env->x, env->y, env->map->name); |
252 | LOG(llevError, "The requested plugin doesn't exist: %s at %d/%d in map %s\n", tmp->title, env->x, env->y, env->map->name); |
248 | send_removed_object(tmp); |
253 | send_removed_object(tmp); |
249 | remove_ob(tmp); |
254 | remove_ob(tmp); |
250 | free_object(tmp); |
255 | free_object(tmp); |
251 | } else { |
256 | } else { |
252 | int rvt = 0; |
257 | int rvt = 0; |
… | |
… | |
274 | return -1; |
279 | return -1; |
275 | |
280 | |
276 | va_start(args, eventcode); |
281 | va_start(args, eventcode); |
277 | |
282 | |
278 | switch (eventcode) { |
283 | switch (eventcode) { |
279 | case EVENT_BORN: |
|
|
280 | /*BORN: op*/ |
|
|
281 | op = va_arg(args, object*); |
|
|
282 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
283 | if (cp->gevent[eventcode] != NULL) |
|
|
284 | cp->gevent[eventcode](&rt, eventcode, op); |
|
|
285 | } |
|
|
286 | break; |
|
|
287 | |
284 | |
288 | case EVENT_CLOCK: |
285 | case EVENT_CLOCK: |
289 | /*CLOCK: -*/ |
286 | case EVENT_CRASH: |
|
|
287 | case EVENT_TELL: |
|
|
288 | /* no additional arguments */ |
290 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
289 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
291 | if (cp->gevent[eventcode] != NULL) |
290 | if (cp->gevent[eventcode] != NULL) |
292 | cp->gevent[eventcode](&rt, eventcode); |
291 | cp->gevent[eventcode](&rt, eventcode); |
293 | } |
292 | } |
294 | break; |
293 | break; |
295 | |
294 | |
|
|
295 | case EVENT_REMOVE: |
|
|
296 | case EVENT_MAPENTER: |
|
|
297 | case EVENT_MAPLEAVE: |
296 | case EVENT_CRASH: |
298 | case EVENT_BORN: |
297 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
298 | if (cp->gevent[eventcode] != NULL) |
|
|
299 | cp->gevent[eventcode](&rt, eventcode); |
|
|
300 | } |
|
|
301 | break; |
|
|
302 | |
|
|
303 | case EVENT_PLAYER_DEATH: |
299 | case EVENT_PLAYER_DEATH: |
304 | /*PLAYER_DEATH: op*/ |
300 | case EVENT_FREE_OB: |
|
|
301 | /* op argument */ |
305 | op = va_arg(args, object*); |
302 | op = va_arg(args, object*); |
306 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
303 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
307 | if (cp->gevent[eventcode] != NULL) |
304 | if (cp->gevent[eventcode] != NULL) |
308 | cp->gevent[eventcode](&rt, eventcode, op); |
305 | cp->gevent[eventcode](&rt, eventcode, op); |
309 | } |
306 | } |
… | |
… | |
337 | if (cp->gevent[eventcode] != NULL) |
334 | if (cp->gevent[eventcode] != NULL) |
338 | cp->gevent[eventcode](&rt, eventcode, pl, buf); |
335 | cp->gevent[eventcode](&rt, eventcode, pl, buf); |
339 | } |
336 | } |
340 | break; |
337 | break; |
341 | |
338 | |
342 | case EVENT_MAPENTER: |
|
|
343 | /*MAPENTER: op*/ |
|
|
344 | op = va_arg(args, object*); |
|
|
345 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
346 | if (cp->gevent[eventcode] != NULL) |
|
|
347 | cp->gevent[eventcode](&rt, eventcode, op); |
|
|
348 | } |
|
|
349 | break; |
|
|
350 | |
|
|
351 | case EVENT_MAPLEAVE: |
|
|
352 | /*MAPLEAVE: op*/ |
|
|
353 | op = va_arg(args, object*); |
|
|
354 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
355 | if (cp->gevent[eventcode] != NULL) |
|
|
356 | cp->gevent[eventcode](&rt, eventcode, op); |
|
|
357 | } |
|
|
358 | break; |
|
|
359 | |
|
|
360 | case EVENT_MAPRESET: |
339 | case EVENT_MAPRESET: |
361 | /*MAPRESET: map->path*/ |
340 | /*MAPRESET: map->path*/ |
362 | buf = va_arg(args, char*); |
341 | buf = va_arg(args, char*); |
363 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
342 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
364 | if (cp->gevent[eventcode] != NULL) |
343 | if (cp->gevent[eventcode] != NULL) |
365 | cp->gevent[eventcode](&rt, eventcode, buf); |
344 | cp->gevent[eventcode](&rt, eventcode, buf); |
366 | } |
|
|
367 | break; |
|
|
368 | |
|
|
369 | case EVENT_REMOVE: |
|
|
370 | /*REMOVE: op*/ |
|
|
371 | op = va_arg(args, object*); |
|
|
372 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
373 | if (cp->gevent[eventcode] != NULL) |
|
|
374 | cp->gevent[eventcode](&rt, eventcode, op); |
|
|
375 | } |
345 | } |
376 | break; |
346 | break; |
377 | |
347 | |
378 | case EVENT_SHOUT: |
348 | case EVENT_SHOUT: |
379 | /*SHOUT: op, parms, priority*/ |
349 | /*SHOUT: op, parms, priority*/ |
… | |
… | |
384 | if (cp->gevent[eventcode] != NULL) |
354 | if (cp->gevent[eventcode] != NULL) |
385 | cp->gevent[eventcode](&rt, eventcode, op, buf, i); |
355 | cp->gevent[eventcode](&rt, eventcode, op, buf, i); |
386 | } |
356 | } |
387 | break; |
357 | break; |
388 | |
358 | |
389 | case EVENT_TELL: |
|
|
390 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
391 | if (cp->gevent[eventcode] != NULL) |
|
|
392 | cp->gevent[eventcode](&rt, eventcode); |
|
|
393 | } |
|
|
394 | break; |
|
|
395 | |
|
|
396 | case EVENT_MUZZLE: |
359 | case EVENT_MUZZLE: |
397 | /*MUZZLE: op, parms*/ |
360 | /*MUZZLE: op, parms*/ |
398 | op = va_arg(args, object*); |
361 | op = va_arg(args, object*); |
399 | buf = va_arg(args, char*); |
362 | buf = va_arg(args, char*); |
400 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
363 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
… | |
… | |
426 | f_plug_postinit postfunc; |
389 | f_plug_postinit postfunc; |
427 | f_plug_postinit closefunc; |
390 | f_plug_postinit closefunc; |
428 | int i; |
391 | int i; |
429 | crossfire_plugin* cp; |
392 | crossfire_plugin* cp; |
430 | crossfire_plugin* ccp; |
393 | crossfire_plugin* ccp; |
|
|
394 | |
|
|
395 | object_free_callback = plugin_object_free; |
431 | |
396 | |
432 | /* Open the plugin lib and load the required functions */ |
397 | /* Open the plugin lib and load the required functions */ |
433 | ptr = plugins_dlopen(libfile); |
398 | ptr = plugins_dlopen(libfile); |
434 | if (ptr == NULL) { |
399 | if (ptr == NULL) { |
435 | LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror()); |
400 | LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror()); |
… | |
… | |
1506 | { |
1471 | { |
1507 | int idx; |
1472 | int idx; |
1508 | idx = va_arg(args, int); |
1473 | idx = va_arg(args, int); |
1509 | rv = &op->resist[idx]; |
1474 | rv = &op->resist[idx]; |
1510 | } |
1475 | } |
1511 | *type = CFAPI_INT16; |
1476 | *type = CFAPI_INT; |
1512 | break; |
1477 | break; |
1513 | |
1478 | |
1514 | case CFAPI_OBJECT_PROP_ATTACK_TYPE: |
1479 | case CFAPI_OBJECT_PROP_ATTACK_TYPE: |
1515 | rv = &op->attacktype; |
1480 | rv = &op->attacktype; |
1516 | *type = CFAPI_INT; |
1481 | *type = CFAPI_INT; |