Crossfire Server, Trunk  R20513
plugin.h
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* Crossfire plugin support - (C) 2001 by Yann Chachkoff. */
3 /* This code is placed under the GPL. */
4 /*****************************************************************************/
5 
12 /*****************************************************************************/
13 /* Headers needed. */
14 /*****************************************************************************/
15 
16 #ifndef PLUGIN_H
17 #define PLUGIN_H
18 
19 /*****************************************************************************/
20 /* This one does not exist under Win32. */
21 /*****************************************************************************/
22 #ifndef WIN32
23 #include <dlfcn.h>
24 #endif
25 
26 #undef MODULEAPI
27 #ifdef WIN32
28 # ifdef PYTHON_PLUGIN_EXPORTS
29 # define MODULEAPI __declspec(dllexport)
30 # else
31 # define MODULEAPI __declspec(dllimport)
32 # endif
33 #else
34 #ifdef HAVE_VISIBILITY
35 # define MODULEAPI __attribute__((visibility("default")))
36 #else
37 # define MODULEAPI
38 #endif
39 #endif
40 
41 #include <global.h>
42 #include <object.h>
43 #include <logger.h>
44 
45 #include <time.h>
46 #include "random_maps/random_map.h"
47 #include "random_maps/rproto.h"
48 
49 /*******************************************************************************/
50 /* This one does not exist under Win32. */
51 /*******************************************************************************/
52 #ifndef WIN32
53 #include <dirent.h>
54 #endif
55 
56 /*******************************************************************************/
57 /* Event ID codes. I sorted them to present local events first, but it is */
58 /* just a 'cosmetic' thing. */
59 /*******************************************************************************/
60 /*******************************************************************************/
61 /* Local events. Those are always linked to a specific object. */
62 /*******************************************************************************/
63 #define EVENT_NONE 0
64 #define EVENT_APPLY 1
65 #define EVENT_ATTACKED 2
66 #define EVENT_ATTACKS 33
67 #define EVENT_DEATH 3
68 #define EVENT_DROP 4
69 #define EVENT_PICKUP 5
70 #define EVENT_SAY 6
71 #define EVENT_STOP 7
72 #define EVENT_TIME 8
73 #define EVENT_THROW 9
74 #define EVENT_TRIGGER 10
75 #define EVENT_CLOSE 11
76 #define EVENT_TIMER 12
77 #define EVENT_DESTROY 13
78 #define EVENT_USER 31
79 #define EVENT_SELLING 32
80 /*******************************************************************************/
81 /* Global events. Those are never linked to a specific object. */
82 /*******************************************************************************/
83 #define EVENT_BORN 14
84 #define EVENT_CLOCK 15
85 #define EVENT_CRASH 16
86 #define EVENT_PLAYER_DEATH 17
87 #define EVENT_GKILL 18
88 #define EVENT_LOGIN 19
89 #define EVENT_LOGOUT 20
90 #define EVENT_MAPENTER 21
91 #define EVENT_MAPLEAVE 22
92 #define EVENT_MAPRESET 23
93 #define EVENT_REMOVE 24
94 #define EVENT_SHOUT 25
95 #define EVENT_TELL 26
96 #define EVENT_MUZZLE 27
97 #define EVENT_KICK 28
98 #define EVENT_MAPUNLOAD 29
99 #define EVENT_MAPLOAD 30
100 #define NR_EVENTS 34
101 
102 #include <stdarg.h>
103 
104 #define CFAPI_NONE 0
105 #define CFAPI_INT 1
106 #define CFAPI_LONG 2
107 #define CFAPI_CHAR 3
108 #define CFAPI_STRING 4 /* String with a length that must be given too. */
109 #define CFAPI_POBJECT 5
110 #define CFAPI_PMAP 6
111 #define CFAPI_FLOAT 7
112 #define CFAPI_DOUBLE 8
113 #define CFAPI_PARCH 9
114 #define CFAPI_FUNC 10
115 #define CFAPI_PPLAYER 11
116 #define CFAPI_PPARTY 12
117 #define CFAPI_PREGION 13
118 #define CFAPI_INT16 14
119 #define CFAPI_TIME 15
120 #define CFAPI_SINT64 16
121 #define CFAPI_SSTRING 17 /* Shared string that shouldn't be changed, or const char* */
122 #define CFAPI_MOVETYPE 18 /* MoveType */
123 
125 typedef void (*f_plug_api)(int *type, ...);
127 typedef int (*f_plug_postinit)(void);
129 typedef int (*f_plug_init)(const char *iversion, f_plug_api gethooksptr);
131 typedef int (*f_plug_event)(int *type, ...);
133 typedef void *(*f_plug_property)(int *type, ...);
134 
135 #ifndef WIN32
136 #define LIBPTRTYPE void *
137 #else
138 
139 #define LIBPTRTYPE HMODULE
140 #endif
141 
143 typedef struct _crossfire_plugin {
148  char id[MAX_BUF];
154 
155 #ifdef WIN32
156 
157 #define plugins_dlopen(fname) LoadLibrary(fname)
158 #define plugins_dlclose(lib) FreeLibrary(lib)
159 #define plugins_dlsym(lib, name) GetProcAddress(lib, name)
160 
161 #else /*WIN32 */
162 
163 #define plugins_dlopen(fname) dlopen(fname, RTLD_NOW|RTLD_GLOBAL)
164 #define plugins_dlclose(lib) dlclose(lib)
165 #define plugins_dlsym(lib, name) dlsym(lib, name)
166 #define plugins_dlerror() dlerror()
167 #endif /* WIN32 */
168 
169 /* OBJECT-RELATED HOOKS */
170 
171 #define CFAPI_OBJECT_PROP_OB_ABOVE 1
172 #define CFAPI_OBJECT_PROP_OB_BELOW 2
173 #define CFAPI_OBJECT_PROP_NEXT_ACTIVE_OB 3
174 #define CFAPI_OBJECT_PROP_PREV_ACTIVE_OB 4
175 #define CFAPI_OBJECT_PROP_INVENTORY 5
176 #define CFAPI_OBJECT_PROP_ENVIRONMENT 6
177 #define CFAPI_OBJECT_PROP_HEAD 7
178 #define CFAPI_OBJECT_PROP_CONTAINER 8
179 #define CFAPI_OBJECT_PROP_MAP 9
180 #define CFAPI_OBJECT_PROP_COUNT 10
181 #define CFAPI_OBJECT_PROP_NAME 12
182 #define CFAPI_OBJECT_PROP_NAME_PLURAL 13
183 #define CFAPI_OBJECT_PROP_TITLE 14
184 #define CFAPI_OBJECT_PROP_RACE 15
185 #define CFAPI_OBJECT_PROP_SLAYING 16
186 #define CFAPI_OBJECT_PROP_SKILL 17
187 #define CFAPI_OBJECT_PROP_MESSAGE 18
188 #define CFAPI_OBJECT_PROP_LORE 19
189 #define CFAPI_OBJECT_PROP_X 20
190 #define CFAPI_OBJECT_PROP_Y 21
191 #define CFAPI_OBJECT_PROP_SPEED 22
192 #define CFAPI_OBJECT_PROP_SPEED_LEFT 23
193 #define CFAPI_OBJECT_PROP_NROF 24
194 #define CFAPI_OBJECT_PROP_DIRECTION 25
195 #define CFAPI_OBJECT_PROP_FACING 26
196 #define CFAPI_OBJECT_PROP_TYPE 27
197 #define CFAPI_OBJECT_PROP_SUBTYPE 28
198 #define CFAPI_OBJECT_PROP_CLIENT_TYPE 29
199 #define CFAPI_OBJECT_PROP_RESIST 30
200 #define CFAPI_OBJECT_PROP_ATTACK_TYPE 31
201 #define CFAPI_OBJECT_PROP_PATH_ATTUNED 32
202 #define CFAPI_OBJECT_PROP_PATH_REPELLED 33
203 #define CFAPI_OBJECT_PROP_PATH_DENIED 34
204 #define CFAPI_OBJECT_PROP_MATERIAL 35
205 #define CFAPI_OBJECT_PROP_MATERIAL_NAME 36
206 #define CFAPI_OBJECT_PROP_MAGIC 37
207 #define CFAPI_OBJECT_PROP_VALUE 38
208 #define CFAPI_OBJECT_PROP_LEVEL 39
209 #define CFAPI_OBJECT_PROP_LAST_HEAL 40
210 #define CFAPI_OBJECT_PROP_LAST_SP 41
211 #define CFAPI_OBJECT_PROP_LAST_GRACE 42
212 #define CFAPI_OBJECT_PROP_LAST_EAT 43
213 #define CFAPI_OBJECT_PROP_INVISIBLE_TIME 44
214 #define CFAPI_OBJECT_PROP_PICK_UP 45
215 #define CFAPI_OBJECT_PROP_ITEM_POWER 46
216 #define CFAPI_OBJECT_PROP_GEN_SP_ARMOUR 47
217 #define CFAPI_OBJECT_PROP_WEIGHT 48
218 #define CFAPI_OBJECT_PROP_WEIGHT_LIMIT 49
219 #define CFAPI_OBJECT_PROP_CARRYING 50
220 #define CFAPI_OBJECT_PROP_GLOW_RADIUS 51
221 #define CFAPI_OBJECT_PROP_PERM_EXP 52
222 #define CFAPI_OBJECT_PROP_CURRENT_WEAPON 53
223 #define CFAPI_OBJECT_PROP_ENEMY 54
224 #define CFAPI_OBJECT_PROP_ATTACKED_BY 55
225 #define CFAPI_OBJECT_PROP_RUN_AWAY 56
226 #define CFAPI_OBJECT_PROP_CHOSEN_SKILL 57
227 #define CFAPI_OBJECT_PROP_HIDDEN 58
228 #define CFAPI_OBJECT_PROP_MOVE_STATUS 59
229 #define CFAPI_OBJECT_PROP_ATTACK_MOVEMENT 60
230 #define CFAPI_OBJECT_PROP_SPELL_ITEM 61
231 #define CFAPI_OBJECT_PROP_EXP_MULTIPLIER 62
232 #define CFAPI_OBJECT_PROP_ARCHETYPE 63
233 #define CFAPI_OBJECT_PROP_OTHER_ARCH 64
234 #define CFAPI_OBJECT_PROP_CUSTOM_NAME 65
235 #define CFAPI_OBJECT_PROP_ANIM_SPEED 66
236 #define CFAPI_OBJECT_PROP_FRIENDLY 67
237 #define CFAPI_OBJECT_PROP_SHORT_NAME 68
238 #define CFAPI_OBJECT_PROP_BASE_NAME 69
239 #define CFAPI_OBJECT_PROP_MAGICAL 70
240 #define CFAPI_OBJECT_PROP_LUCK 71
241 #define CFAPI_OBJECT_PROP_EXP 72
242 #define CFAPI_OBJECT_PROP_OWNER 73
243 #define CFAPI_OBJECT_PROP_PRESENT 74
244 #define CFAPI_OBJECT_PROP_CHEATER 75
245 #define CFAPI_OBJECT_PROP_MERGEABLE 76
246 #define CFAPI_OBJECT_PROP_PICKABLE 77
247 #define CFAPI_OBJECT_PROP_FLAGS 78
248 #define CFAPI_OBJECT_PROP_STR 79
249 #define CFAPI_OBJECT_PROP_DEX 80
250 #define CFAPI_OBJECT_PROP_CON 81
251 #define CFAPI_OBJECT_PROP_WIS 82
252 #define CFAPI_OBJECT_PROP_INT 83
253 #define CFAPI_OBJECT_PROP_POW 84
254 #define CFAPI_OBJECT_PROP_CHA 85
255 #define CFAPI_OBJECT_PROP_WC 86
256 #define CFAPI_OBJECT_PROP_AC 87
257 #define CFAPI_OBJECT_PROP_HP 88
258 #define CFAPI_OBJECT_PROP_SP 89
259 #define CFAPI_OBJECT_PROP_GP 90
260 #define CFAPI_OBJECT_PROP_FP 91
261 #define CFAPI_OBJECT_PROP_MAXHP 92
262 #define CFAPI_OBJECT_PROP_MAXSP 93
263 #define CFAPI_OBJECT_PROP_MAXGP 94
264 #define CFAPI_OBJECT_PROP_DAM 95
265 #define CFAPI_OBJECT_PROP_GOD 96
266 #define CFAPI_OBJECT_PROP_ARCH_NAME 97
267 #define CFAPI_OBJECT_PROP_INVISIBLE 98
268 #define CFAPI_OBJECT_PROP_FACE 99
269 #define CFAPI_OBJECT_PROP_ANIMATION 100
270 /*#define CFAPI_OBJECT_PROP_NO_SAVE 101*/
271 #define CFAPI_OBJECT_PROP_MOVE_TYPE 102
272 #define CFAPI_OBJECT_PROP_MOVE_BLOCK 103
273 #define CFAPI_OBJECT_PROP_MOVE_ALLOW 104
274 #define CFAPI_OBJECT_PROP_MOVE_ON 105
275 #define CFAPI_OBJECT_PROP_MOVE_OFF 106
276 #define CFAPI_OBJECT_PROP_MOVE_SLOW 107
277 #define CFAPI_OBJECT_PROP_MOVE_SLOW_PENALTY 108
278 #define CFAPI_OBJECT_PROP_DURATION 109
279 #define CFAPI_OBJECT_PROP_RAW_NAME 110
280 
281 #define CFAPI_PLAYER_PROP_IP 150
282 #define CFAPI_PLAYER_PROP_MARKED_ITEM 151
283 #define CFAPI_PLAYER_PROP_PARTY 152
284 #define CFAPI_PLAYER_PROP_BED_MAP 153
285 #define CFAPI_PLAYER_PROP_BED_X 154
286 #define CFAPI_PLAYER_PROP_BED_Y 155
287 #define CFAPI_PLAYER_PROP_NEXT 156
288 #define CFAPI_PLAYER_PROP_TITLE 157
289 
290 #define CFAPI_PLAYER_QUEST_START 0
291 #define CFAPI_PLAYER_QUEST_GET_STATE 1
292 #define CFAPI_PLAYER_QUEST_SET_STATE 2
293 #define CFAPI_PLAYER_QUEST_WAS_COMPLETED 3
294 
295 #define CFAPI_MAP_PROP_FLAGS 0
296 #define CFAPI_MAP_PROP_DIFFICULTY 1
297 #define CFAPI_MAP_PROP_PATH 2
298 #define CFAPI_MAP_PROP_TMPNAME 3
299 #define CFAPI_MAP_PROP_NAME 4
300 #define CFAPI_MAP_PROP_RESET_TIME 5
301 #define CFAPI_MAP_PROP_RESET_TIMEOUT 6
302 #define CFAPI_MAP_PROP_PLAYERS 7
303 #define CFAPI_MAP_PROP_LIGHT 8
304 #define CFAPI_MAP_PROP_DARKNESS 9
305 #define CFAPI_MAP_PROP_WIDTH 10
306 #define CFAPI_MAP_PROP_HEIGHT 11
307 #define CFAPI_MAP_PROP_ENTER_X 12
308 #define CFAPI_MAP_PROP_ENTER_Y 13
309 #define CFAPI_MAP_PROP_MESSAGE 22
310 #define CFAPI_MAP_PROP_NEXT 23
311 #define CFAPI_MAP_PROP_REGION 24
312 #define CFAPI_MAP_PROP_UNIQUE 25
313 
314 #define CFAPI_ARCH_PROP_NAME 0
315 #define CFAPI_ARCH_PROP_NEXT 1
316 #define CFAPI_ARCH_PROP_HEAD 2
317 #define CFAPI_ARCH_PROP_MORE 3
318 #define CFAPI_ARCH_PROP_CLONE 4
319 
320 #define CFAPI_PARTY_PROP_NAME 0
321 #define CFAPI_PARTY_PROP_NEXT 1
322 #define CFAPI_PARTY_PROP_PASSWORD 2
323 #define CFAPI_PARTY_PROP_PLAYER 3
324 
325 #define CFAPI_REGION_PROP_NAME 0
326 #define CFAPI_REGION_PROP_NEXT 1
327 #define CFAPI_REGION_PROP_PARENT 2
328 #define CFAPI_REGION_PROP_LONGNAME 3
329 #define CFAPI_REGION_PROP_MESSAGE 4
330 #define CFAPI_REGION_PROP_JAIL_X 5
331 #define CFAPI_REGION_PROP_JAIL_Y 6
332 #define CFAPI_REGION_PROP_JAIL_PATH 7
333 
334 /*****************************************************************************/
335 /* Exportable functions. Any plugin should define all those. */
336 /* initPlugin is called when the plugin initialization process starts.*/
337 /* endPlugin is called before the plugin gets unloaded from memory. */
338 /* getPluginProperty is currently unused. */
339 /* registerHook is used to transmit hook pointers from server to plugin.*/
340 /* triggerEvent is called whenever an event occurs. */
341 /*****************************************************************************/
342 /*extern MODULEAPI CFParm *initPlugin(CFParm *PParm);
343 extern MODULEAPI CFParm *endPlugin(CFParm *PParm);
344 extern MODULEAPI CFParm *getPluginProperty(CFParm *PParm);
345 extern MODULEAPI CFParm *registerHook(CFParm *PParm);
346 extern MODULEAPI CFParm *triggerEvent(CFParm *PParm);
347 */
348 
350 typedef struct _hook_entry {
352  int fid;
353  const char fname[256];
354 } hook_entry;
355 
356 #endif /* PLUGIN_H */
struct _crossfire_plugin crossfire_plugin
One loaded plugin.
#define NR_EVENTS
Definition: plugin.h:100
f_plug_api func
Function itself.
Definition: plugin.h:351
Random map related variables.
struct _hook_entry hook_entry
One function the server exposes to plugins.
Global type definitions and header inclusions.
int fid
Function identifier.
Definition: plugin.h:352
One function the server exposes to plugins.
Definition: plugin.h:350
struct _crossfire_plugin * next
Next plugin in list.
Definition: plugin.h:151
LIBPTRTYPE libptr
Pointer to the plugin library.
Definition: plugin.h:147
void *(* f_plug_property)(int *type,...)
Get various plugin properties.
Definition: plugin.h:133
f_plug_postinit closefunc
Plugin Termination function.
Definition: plugin.h:146
int(* f_plug_postinit)(void)
Function called after the plugin was initialized.
Definition: plugin.h:127
#define LIBPTRTYPE
Definition: plugin.h:136
char fullname[MAX_BUF]
Plugin full name.
Definition: plugin.h:149
f_plug_property propfunc
Plugin getProperty function.
Definition: plugin.h:145
#define MAX_BUF
Used for all kinds of things.
Definition: define.h:35
int(* f_plug_event)(int *type,...)
Function to call to handle global or object-related events.
Definition: plugin.h:131
Object structure, the core of Crossfire.
Log levels.
f_plug_event eventfunc
Event Handler function.
Definition: plugin.h:144
struct _crossfire_plugin * prev
Previous plugin in list.
Definition: plugin.h:152
int(* f_plug_init)(const char *iversion, f_plug_api gethooksptr)
First function called in a plugin.
Definition: plugin.h:129
f_plug_event gevent[NR_EVENTS]
Global events registered.
Definition: plugin.h:150
void(* f_plug_api)(int *type,...)
General API function.
Definition: plugin.h:125
One loaded plugin.
Definition: plugin.h:143