Atrinik Server 2.5
include/plugin.h
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00032 #ifndef PLUGIN_H
00033 #define PLUGIN_H
00034 
00035 #ifndef WIN32
00036 #   include <dlfcn.h>
00037 #endif
00038 
00039 #undef MODULEAPI
00040 
00041 #ifdef WIN32
00042 #   ifdef PYTHON_PLUGIN_EXPORTS
00043 #       define MODULEAPI __declspec(dllexport)
00044 #   else
00045 #       define MODULEAPI __declspec(dllimport)
00046 #   endif
00047 #else
00048 #   define MODULEAPI
00049 #endif
00050 
00051 #include <global.h>
00052 
00060 #define PLUGIN_EVENT_NORMAL 1
00061 
00062 #define PLUGIN_EVENT_MAP 2
00063 
00064 #define PLUGIN_EVENT_GLOBAL 3
00065 
00072 #define EVENT_NONE 0
00073 
00074 #define EVENT_APPLY 1
00075 
00076 #define EVENT_ATTACK 2
00077 
00078 #define EVENT_DEATH 3
00079 
00080 #define EVENT_DROP 4
00081 
00082 #define EVENT_PICKUP 5
00083 
00084 #define EVENT_SAY 6
00085 
00086 #define EVENT_STOP 7
00087 
00088 #define EVENT_TIME 8
00089 
00090 #define EVENT_THROW 9
00091 
00092 #define EVENT_TRIGGER 10
00093 
00094 #define EVENT_CLOSE 11
00095 
00096 #define EVENT_TIMER 12
00097 
00098 #define EVENT_QUEST 13
00099 
00100 #define EVENT_ASK_SHOW 14
00101 
00102 #define EVENT_AI 15
00103 
00110 #define EVENT_AI_RANDOM_MOVE 1
00111 
00118 #define MEVENT_ENTER 1
00119 
00120 #define MEVENT_LEAVE 2
00121 
00122 #define MEVENT_RESET 3
00123 
00124 #define MEVENT_SPELL_CAST 4
00125 
00126 #define MEVENT_SKILL_USED 5
00127 
00128 #define MEVENT_DROP 6
00129 
00130 #define MEVENT_PICK 7
00131 
00132 #define MEVENT_PUT 8
00133 
00134 #define MEVENT_APPLY 9
00135 
00136 #define MEVENT_LOGIN 10
00137 
00138 #define MEVENT_CMD_DROP 11
00139 
00140 #define MEVENT_CMD_TAKE 12
00141 
00142 #define MEVENT_EXAMINE 13
00143 
00150 #define GEVENT_BORN 0
00151 
00152 #define GEVENT_LOGIN 1
00153 
00154 #define GEVENT_LOGOUT 2
00155 
00156 #define GEVENT_PLAYER_DEATH 3
00157 
00158 #define GEVENT_CACHE_REMOVED 4
00159 
00160 #define GEVENT_NUM 5
00161 
00166 #define EVENT_FLAG(x) (1U << (x - 1))
00167 
00172 #define HAS_EVENT(ob, event) (ob->event_flags & EVENT_FLAG(event))
00173 
00179 struct plugin_hooklist
00180 {
00181     char *(*query_name)(object *, object *);
00182     const char *(*re_cmp)(const char *, const char *);
00183     object *(*present_in_ob)(unsigned char, object *);
00184     int (*players_on_map)(mapstruct *);
00185     char *(*create_pathname)(const char *);
00186     char *(*normalize_path)(const char *, const char *, char *);
00187     void (*LOG)(LogLevel, const char *, ...);
00188     void (*free_string_shared)(const char *);
00189     const char *(*add_string)(const char *);
00190     void (*remove_ob)(object *);
00191     void (*fix_player)(object *);
00192     object *(*insert_ob_in_ob)(object *, object *);
00193     void (*new_info_map)(int, const char *color, mapstruct *, int, int, int, const char *);
00194     void (*new_info_map_except)(int , const char *color, mapstruct *, int, int, int, object *, object *, const char *);
00195     void (*spring_trap)(object *, object *);
00196     int (*cast_spell)(object *, object *, int, int, int, int, const char *);
00197     void (*update_ob_speed)(object *);
00198     int (*command_rskill)(object *, char *);
00199     void (*become_follower)(object *, object *);
00200     void (*pick_up)(object *, object *, int);
00201     mapstruct *(*get_map_from_coord)(mapstruct *, int *, int *);
00202     void (*esrv_send_item)(object *, object *);
00203     player *(*find_player)(const char *);
00204     int (*manual_apply)(object *, object *, int);
00205     int (*command_drop)(object *, char *);
00206     int (*transfer_ob)(object *, int, int, int, object *, object *);
00207     int (*kill_object)(object *, int, object *, int);
00208     void (*do_learn_spell)(object *, int, int);
00209     void (*do_forget_spell)(object *, int);
00210     int (*look_up_spell_name)(const char *);
00211     int (*check_spell_known)(object *, int);
00212     void (*esrv_send_inventory)(object *, object *);
00213     object *(*get_archetype)(const char *);
00214     mapstruct *(*ready_map_name)(const char *, int);
00215     sint64 (*add_exp)(object *, sint64, int, int);
00216     const char *(*determine_god)(object *);
00217     object *(*find_god)(const char *);
00218     void (*register_global_event)(const char *, int);
00219     void (*unregister_global_event)(const char *, int);
00220     object *(*load_object_str)(char *);
00221     sint64 (*query_cost)(object *, object *, int);
00222     sint64 (*query_money)(object *);
00223     int (*pay_for_item)(object *, object *);
00224     int (*pay_for_amount)(sint64, object *);
00225     void (*new_draw_info)(int, const char *, object *, const char *);
00226     void (*communicate)(object *, char *);
00227     object *(*object_create_clone)(object *);
00228     object *(*get_object)();
00229     void (*copy_object)(object *, object *, int);
00230     void (*enter_exit)(object *, object *);
00231     void (*play_sound_map)(mapstruct *, int, const char *, int, int, int, int);
00232     int (*learn_skill)(object *, object *, char *, int, int);
00233     object *(*find_marked_object)(object *);
00234     int (*cast_identify)(object *, int, object *, int);
00235     int (*lookup_skill_by_name)(const char *);
00236     int (*check_skill_known)(object *, int);
00237     archetype *(*find_archetype)(const char *);
00238     object *(*arch_to_object)(archetype *);
00239     object *(*insert_ob_in_map)(object *, mapstruct *, object *, int);
00240     char *(*cost_string_from_value)(sint64);
00241     int (*bank_deposit)(object *, const char *, sint64 *value);
00242     int (*bank_withdraw)(object *, const char *, sint64 *value);
00243     sint64 (*bank_get_balance)(object *);
00244     int (*swap_apartments)(const char *, const char *, int, int, object *);
00245     int (*player_exists)(char *);
00246     void (*get_tod)(timeofday_t *);
00247     const char *(*object_get_value)(const object *, const char *const);
00248     int (*object_set_value)(object *, const char *, const char *, int);
00249     void (*drop)(object *, object *, int);
00250     char *(*query_short_name)(object *, object *);
00251     object *(*beacon_locate)(const char *);
00252     char *(*strdup_local)(const char *);
00253     void (*adjust_player_name)(char *);
00254     party_struct *(*find_party)(const char *);
00255     void (*add_party_member)(party_struct *, object *);
00256     void (*remove_party_member)(party_struct *, object *);
00257     void (*send_party_message)(party_struct *, const char *, int, object *);
00258     void (*Write_String_To_Socket)(socket_struct *, char, const char *, int);
00259     void (*dump_object)(object *, StringBuffer *);
00260     StringBuffer *(*stringbuffer_new)();
00261     char *(*stringbuffer_finish)(StringBuffer *);
00262     char *(*cleanup_chat_string)(char *);
00263     int (*cftimer_find_free_id)();
00264     int (*cftimer_create)(int, long, object *, int);
00265     int (*cftimer_destroy)(int);
00266     int (*find_face)(char *, int);
00267     int (*find_animation)(char *);
00268     void (*play_sound_player_only)(player *, int, const char *, int, int, int, int);
00269     void (*new_draw_info_format)(int, const char *, object *, char *, ...);
00270     int (*was_destroyed)(object *, tag_t);
00271     int (*object_get_gender)(object *);
00272     int (*change_abil)(object *, object *);
00273     object *(*decrease_ob_nr)(object *, uint32);
00274     int (*check_walk_off)(object *, object *, int);
00275     int (*wall)(mapstruct *, int, int);
00276     int (*blocked)(object *, mapstruct *, int, int, int);
00277     int (*get_rangevector)(object *, object *, rv_vector *, int);
00278     int (*get_rangevector_from_mapcoords)(mapstruct *, int, int, mapstruct *, int, int, rv_vector *, int);
00279     int (*player_can_carry)(object *, uint32);
00280     cache_struct *(*cache_find)(shstr *);
00281     int (*cache_add)(const char *, void *, uint32);
00282     int (*cache_remove)(shstr *);
00283     void (*cache_remove_by_flags)(uint32);
00284     shstr *(*find_string)(const char *);
00285     int (*command_take)(object *, char *);
00286     object *(*object_need_esrv_update)(object *);
00287     void (*object_remove_esrv_update)(object *);
00288     void (*esrv_update_item)(int, object *, object *);
00289     int (*execute_newserver_command)(object *, char *);
00290     treasurelist *(*find_treasurelist)(const char *);
00291     void (*create_treasure)(treasurelist *, object *, int, int, int, int, int, struct _change_arch *);
00292     void (*dump_object_rec)(object *, StringBuffer *);
00293     int (*hit_player)(object *, int, object *, int);
00294     int (*move_ob)(object *, int, object *);
00295     int (*move_player)(object *, int);
00296     mapstruct *(*get_empty_map)(int, int);
00297     void (*set_map_darkness)(mapstruct *, int);
00298     int (*find_free_spot)(archetype *, object *, mapstruct *, int, int, int, int);
00299     void (*send_target_command)(player *);
00300     void (*examine)(object *, object *);
00301     void (*push_button)(object *);
00302 
00303     const char **season_name;
00304     const char **weekdays;
00305     const char **month_name;
00306     const char **periodsofday;
00307     spell_struct *spells;
00308     struct shstr_constants *shstr_cons;
00309     const char **gender_noun;
00310     const char **gender_subjective;
00311     const char **gender_subjective_upper;
00312     const char **gender_objective;
00313     const char **gender_possessive;
00314     const char **gender_reflexive;
00315     const char **object_flag_names;
00316     int *freearr_x;
00317     int *freearr_y;
00318     player **first_player;
00319     New_Face **new_faces;
00320     int *nrofpixmaps;
00321     Animations **animations;
00322     int *num_animations;
00323     archetype **first_archetype;
00324     mapstruct **first_map;
00325     party_struct **first_party;
00326     region **first_region;
00327     FILE **logfile;
00328 };
00329 
00331 typedef void *(*f_plug_api) (int *type, ...);
00333 typedef void *(*f_plug_init) (struct plugin_hooklist *hooklist);
00335 typedef void *(*f_plug_pinit) ();
00336 
00337 #ifndef WIN32
00338 
00339 #   define LIBPTRTYPE void *
00340 
00341 #   define plugins_dlopen(fname) dlopen(fname, RTLD_NOW | RTLD_GLOBAL)
00342 
00343 #   define plugins_dlclose(lib) dlclose(lib)
00344 
00345 #   define plugins_dlsym(lib, name) dlsym(lib, name)
00346 
00347 #   define plugins_dlerror() dlerror()
00348 #else
00349 #   define LIBPTRTYPE HMODULE
00350 #   define plugins_dlopen(fname) LoadLibrary(fname)
00351 #   define plugins_dlclose(lib) FreeLibrary(lib)
00352 #   define plugins_dlsym(lib, name) GetProcAddress(lib, name)
00353 #endif
00354 
00356 #define FILENAME_IS_PLUGIN(_path) (strstr((_path), "plugin_") && !strcmp((_path) + strlen((_path)) - strlen(PLUGIN_SUFFIX), PLUGIN_SUFFIX))
00357 
00359 typedef struct atrinik_plugin
00360 {
00362     f_plug_api eventfunc;
00363 
00365     f_plug_api propfunc;
00366 
00368     f_plug_pinit closefunc;
00369 
00371     LIBPTRTYPE libptr;
00372 
00374     char id[MAX_BUF];
00375 
00377     char fullname[MAX_BUF];
00378 
00380     sint8 gevent[GEVENT_NUM];
00381 
00383     struct atrinik_plugin *next;
00384 } atrinik_plugin;
00385 
00393 extern MODULEAPI void initPlugin(struct plugin_hooklist *hooklist);
00394 
00400 extern MODULEAPI void *getPluginProperty(int *type, ...);
00401 
00406 extern MODULEAPI void *triggerEvent(int *type, ...);
00407 
00410 extern MODULEAPI void postinitPlugin();
00411 
00414 extern MODULEAPI void closePlugin();
00417 #endif