1 | /* |
1 | /* |
2 | * static char *rcsid_plugins_c = |
2 | * static char *rcsid_plugins_c = |
3 | * "$Id: plugins.C,v 1.2 2006/08/15 17:10:46 root Exp $"; |
3 | * "$Id: plugins.C,v 1.4 2006/08/25 17:11:53 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_load_original_map(mapstruct *map) |
|
|
133 | { |
|
|
134 | execute_global_event (EVENT_MAPLOAD, map); |
|
|
135 | } |
|
|
136 | |
|
|
137 | static void plugin_load_temporary_map(mapstruct *map) |
|
|
138 | { |
|
|
139 | execute_global_event (EVENT_MAPIN, map); |
|
|
140 | } |
|
|
141 | |
|
|
142 | static void plugin_clean_temporary_map(mapstruct *map) |
|
|
143 | { |
|
|
144 | execute_global_event (EVENT_MAPCLEAN, map); |
|
|
145 | } |
|
|
146 | |
|
|
147 | static void plugin_object_free(object *ob) |
|
|
148 | { |
|
|
149 | execute_global_event (EVENT_FREE_OB, ob); |
|
|
150 | } |
|
|
151 | |
|
|
152 | #ifdef WIN32 |
132 | #ifdef WIN32 |
153 | static const char *plugins_dlerror(void) |
133 | static const char *plugins_dlerror(void) |
154 | { |
134 | { |
155 | static char buf[256]; |
135 | static char buf[256]; |
156 | DWORD err; |
136 | DWORD err; |
… | |
… | |
309 | if (cp->gevent[eventcode] != NULL) |
289 | if (cp->gevent[eventcode] != NULL) |
310 | cp->gevent[eventcode](&rt, eventcode); |
290 | cp->gevent[eventcode](&rt, eventcode); |
311 | } |
291 | } |
312 | break; |
292 | break; |
313 | |
293 | |
314 | case EVENT_PLAYER_LOAD: |
|
|
315 | case EVENT_PLAYER_SAVE: |
|
|
316 | /* object, filename */ |
|
|
317 | op = va_arg(args, object*); |
|
|
318 | buf = va_arg(args, char*); |
|
|
319 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
320 | if (cp->gevent[eventcode] != NULL) |
|
|
321 | cp->gevent[eventcode](&rt, eventcode, op, buf); |
|
|
322 | } |
|
|
323 | break; |
|
|
324 | |
|
|
325 | case EVENT_MAPLOAD: |
|
|
326 | case EVENT_MAPOUT: |
|
|
327 | case EVENT_MAPIN: |
|
|
328 | case EVENT_MAPCLEAN: |
|
|
329 | /* map argument */ |
|
|
330 | map = va_arg(args, mapstruct*); |
|
|
331 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
332 | if (cp->gevent[eventcode] != NULL) |
|
|
333 | cp->gevent[eventcode](&rt, eventcode, map); |
|
|
334 | } |
|
|
335 | break; |
|
|
336 | |
|
|
337 | case EVENT_REMOVE: |
|
|
338 | case EVENT_MAPENTER: |
|
|
339 | case EVENT_MAPLEAVE: |
|
|
340 | case EVENT_BORN: |
|
|
341 | case EVENT_PLAYER_DEATH: |
|
|
342 | case EVENT_FREE_OB: |
|
|
343 | /* op argument */ |
|
|
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_GKILL: |
|
|
352 | /*GKILL: op, hitter*/ |
|
|
353 | op = va_arg(args, object*); |
|
|
354 | op2 = va_arg(args, object*); |
|
|
355 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
356 | if (cp->gevent[eventcode] != NULL) |
|
|
357 | cp->gevent[eventcode](&rt, eventcode, op, op2); |
|
|
358 | } |
|
|
359 | break; |
|
|
360 | |
|
|
361 | case EVENT_LOGIN: |
|
|
362 | /*LOGIN: pl, pl->socket.host*/ |
|
|
363 | pl = va_arg(args, player*); |
|
|
364 | buf = va_arg(args, char*); |
|
|
365 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
366 | if (cp->gevent[eventcode] != NULL) |
|
|
367 | cp->gevent[eventcode](&rt, eventcode, pl, buf); |
|
|
368 | } |
|
|
369 | break; |
|
|
370 | |
|
|
371 | case EVENT_LOGOUT: |
|
|
372 | /*LOGOUT: pl, pl->socket.host*/ |
|
|
373 | pl = va_arg(args, player*); |
|
|
374 | buf = va_arg(args, char*); |
|
|
375 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
376 | if (cp->gevent[eventcode] != NULL) |
|
|
377 | cp->gevent[eventcode](&rt, eventcode, pl, buf); |
|
|
378 | } |
|
|
379 | break; |
|
|
380 | |
|
|
381 | case EVENT_MAPRESET: |
|
|
382 | /*MAPRESET: map->path*/ |
|
|
383 | buf = va_arg(args, char*); |
|
|
384 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
385 | if (cp->gevent[eventcode] != NULL) |
|
|
386 | cp->gevent[eventcode](&rt, eventcode, buf); |
|
|
387 | } |
|
|
388 | break; |
|
|
389 | |
|
|
390 | case EVENT_SHOUT: |
294 | case EVENT_SHOUT: |
391 | /*SHOUT: op, parms, priority*/ |
295 | /*SHOUT: op, parms, priority*/ |
392 | op = va_arg(args, object*); |
296 | op = va_arg(args, object*); |
393 | buf = va_arg(args, char*); |
297 | buf = va_arg(args, char*); |
394 | i = va_arg(args, int); |
298 | i = va_arg(args, int); |
… | |
… | |
425 | if ((tmpretval = (int*) cp->gevent[eventcode](&rt, eventcode, op)) && *tmpretval > 0) { |
329 | if ((tmpretval = (int*) cp->gevent[eventcode](&rt, eventcode, op)) && *tmpretval > 0) { |
426 | retval = *tmpretval; |
330 | retval = *tmpretval; |
427 | } |
331 | } |
428 | } |
332 | } |
429 | break; |
333 | break; |
430 | |
|
|
431 | case EVENT_PLAYER_USE_SKILL: |
|
|
432 | case EVENT_MONSTER_USE_SKILL: |
|
|
433 | op = va_arg(args, object*); |
|
|
434 | op2 = va_arg(args, object*); |
|
|
435 | op3 = va_arg(args, object*); |
|
|
436 | fix = va_arg(args, int); |
|
|
437 | buf = va_arg(args, char*); |
|
|
438 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
439 | if (cp->gevent[eventcode] != NULL) |
|
|
440 | if ((tmpretval = (int*) cp->gevent[eventcode](&rt, eventcode, op, op2, op3, fix, buf)) && *tmpretval != 0) { |
|
|
441 | retval = *tmpretval; |
|
|
442 | } |
|
|
443 | } |
|
|
444 | break; |
|
|
445 | |
|
|
446 | case EVENT_CAST_SPELL: |
|
|
447 | op = va_arg(args, object*); |
|
|
448 | op2 = va_arg(args, object*); |
|
|
449 | op3 = va_arg(args, object*); |
|
|
450 | fix = va_arg(args, int); |
|
|
451 | buf = va_arg(args, char*); |
|
|
452 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
453 | if (cp->gevent[eventcode] != NULL) |
|
|
454 | if ((tmpretval = (int*) cp->gevent[eventcode](&rt, eventcode, op, op2, op3, fix, buf)) && *tmpretval != 0) { |
|
|
455 | retval = *tmpretval; |
|
|
456 | break; /* The first who did something wins! */ |
|
|
457 | } |
|
|
458 | } |
|
|
459 | break; |
|
|
460 | |
|
|
461 | case EVENT_EXTCMD: |
|
|
462 | /*KICK: op, parms*/ |
|
|
463 | pl = va_arg (args, player *); |
|
|
464 | buf = va_arg (args, char *); |
|
|
465 | i = va_arg (args, int); |
|
|
466 | for (cp = plugins_list; cp != NULL; cp = cp->next) { |
|
|
467 | if (cp->gevent[eventcode] != NULL) |
|
|
468 | cp->gevent[eventcode](&rt, eventcode, pl, buf, i, buf); |
|
|
469 | } |
|
|
470 | break; |
|
|
471 | } |
334 | } |
472 | va_end(args); |
335 | va_end(args); |
473 | |
336 | |
474 | return retval; |
337 | return retval; |
475 | } |
338 | } |
… | |
… | |
478 | extern "C" void *cfperl_getPluginProperty (int *type, ...); |
341 | extern "C" void *cfperl_getPluginProperty (int *type, ...); |
479 | extern "C" int cfperl_postInitPlugin (); |
342 | extern "C" int cfperl_postInitPlugin (); |
480 | extern "C" void *cfperl_eventListener (int *type, ...); |
343 | extern "C" void *cfperl_eventListener (int *type, ...); |
481 | extern "C" int cfperl_closePlugin (); |
344 | extern "C" int cfperl_closePlugin (); |
482 | |
345 | |
|
|
346 | // this is a temporary hack till the old plugin stuff is removed |
483 | int plugins_init_perl() |
347 | int plugins_init_perl() |
484 | { |
348 | { |
485 | f_plug_init initfunc; |
349 | f_plug_init initfunc; |
486 | f_plug_api propfunc; |
350 | f_plug_api propfunc; |
487 | f_plug_api eventfunc; |
351 | f_plug_api eventfunc; |
488 | f_plug_postinit postfunc; |
352 | f_plug_postinit postfunc; |
489 | f_plug_postinit closefunc; |
353 | f_plug_postinit closefunc; |
490 | int i; |
354 | int i; |
491 | crossfire_plugin* cp; |
355 | crossfire_plugin* cp; |
492 | crossfire_plugin* ccp; |
356 | crossfire_plugin* ccp; |
493 | |
|
|
494 | load_original_map_callback = plugin_load_original_map; |
|
|
495 | load_temporary_map_callback = plugin_load_temporary_map; |
|
|
496 | clean_temporary_map_callback = plugin_clean_temporary_map; |
|
|
497 | object_free_callback = plugin_object_free; |
|
|
498 | |
357 | |
499 | initfunc = (f_plug_init)cfperl_initPlugin; |
358 | initfunc = (f_plug_init)cfperl_initPlugin; |
500 | propfunc = (f_plug_api)cfperl_getPluginProperty; |
359 | propfunc = (f_plug_api)cfperl_getPluginProperty; |
501 | eventfunc = (f_plug_api)cfperl_eventListener; |
360 | eventfunc = (f_plug_api)cfperl_eventListener; |
502 | postfunc = (f_plug_postinit)cfperl_postInitPlugin; |
361 | postfunc = (f_plug_postinit)cfperl_postInitPlugin; |
… | |
… | |
535 | f_plug_postinit postfunc; |
394 | f_plug_postinit postfunc; |
536 | f_plug_postinit closefunc; |
395 | f_plug_postinit closefunc; |
537 | int i; |
396 | int i; |
538 | crossfire_plugin* cp; |
397 | crossfire_plugin* cp; |
539 | crossfire_plugin* ccp; |
398 | crossfire_plugin* ccp; |
540 | |
|
|
541 | load_original_map_callback = plugin_load_original_map; |
|
|
542 | load_temporary_map_callback = plugin_load_temporary_map; |
|
|
543 | clean_temporary_map_callback = plugin_clean_temporary_map; |
|
|
544 | object_free_callback = plugin_object_free; |
|
|
545 | |
399 | |
546 | /* Open the plugin lib and load the required functions */ |
400 | /* Open the plugin lib and load the required functions */ |
547 | ptr = plugins_dlopen(libfile); |
401 | ptr = plugins_dlopen(libfile); |
548 | if (ptr == NULL) { |
402 | if (ptr == NULL) { |
549 | LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror()); |
403 | LOG(llevError, "Error trying to load %s: %s\n", libfile, plugins_dlerror()); |