1 | /*****************************************************************************/ |
1 | /* |
2 | /* Crossfire plugin support - (C) 2001 by Yann Chachkoff. */ |
2 | * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. |
3 | /* This code is placed under the GPL. */ |
3 | * |
4 | /*****************************************************************************/ |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
|
|
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
|
|
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
|
|
7 | * |
|
|
8 | * Crossfire TRT is free software; you can redistribute it and/or modify it |
|
|
9 | * under the terms of the GNU General Public License as published by the Free |
|
|
10 | * Software Foundation; either version 2 of the License, or (at your option) |
|
|
11 | * any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, but |
|
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
|
|
15 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
|
16 | * for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License along |
|
|
19 | * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 |
|
|
20 | * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
|
21 | * |
|
|
22 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
|
|
23 | */ |
5 | |
24 | |
6 | /*****************************************************************************/ |
25 | /*****************************************************************************/ |
7 | /* Headers needed. */ |
26 | /* Headers needed. */ |
8 | /*****************************************************************************/ |
27 | /*****************************************************************************/ |
9 | |
28 | |
… | |
… | |
11 | #define PLUGIN_H_ |
30 | #define PLUGIN_H_ |
12 | |
31 | |
13 | /*****************************************************************************/ |
32 | /*****************************************************************************/ |
14 | /* This one does not exist under Win32. */ |
33 | /* This one does not exist under Win32. */ |
15 | /*****************************************************************************/ |
34 | /*****************************************************************************/ |
16 | #ifndef WIN32 |
|
|
17 | #include <dlfcn.h> |
35 | #include <dlfcn.h> |
18 | #endif |
|
|
19 | |
36 | |
20 | #undef MODULEAPI |
|
|
21 | #ifdef WIN32 |
|
|
22 | #ifdef PYTHON_PLUGIN_EXPORTS |
|
|
23 | #define MODULEAPI __declspec(dllexport) |
|
|
24 | #else |
|
|
25 | #define MODULEAPI __declspec(dllimport) |
|
|
26 | #endif |
|
|
27 | #else |
|
|
28 | #define MODULEAPI |
37 | #define MODULEAPI |
29 | #endif |
|
|
30 | |
38 | |
31 | #include <global.h> |
39 | #include <global.h> |
32 | #include <object.h> |
40 | #include <object.h> |
33 | |
41 | |
34 | #ifdef HAVE_TIME_H |
42 | #ifdef HAVE_TIME_H |
… | |
… | |
39 | |
47 | |
40 | |
48 | |
41 | /*****************************************************************************/ |
49 | /*****************************************************************************/ |
42 | /* This one does not exist under Win32. */ |
50 | /* This one does not exist under Win32. */ |
43 | /*****************************************************************************/ |
51 | /*****************************************************************************/ |
44 | #ifndef WIN32 |
|
|
45 | #include <dirent.h> |
52 | #include <dirent.h> |
46 | #endif |
|
|
47 | |
53 | |
48 | /*****************************************************************************/ |
|
|
49 | /* Event ID codes. I sorted them to present local events first, but it is */ |
|
|
50 | /* just a 'cosmetic' thing. */ |
|
|
51 | /*****************************************************************************/ |
|
|
52 | /*****************************************************************************/ |
|
|
53 | /* Local events. Those are always linked to a specific object. */ |
|
|
54 | /*****************************************************************************/ |
|
|
55 | // how about making this an enum |
|
|
56 | #define EVENT_NONE 0 /* No event. This exists only to reserve the "0". */ |
|
|
57 | #define EVENT_APPLY 1 /* Object applied-unapplied. */ |
|
|
58 | #define EVENT_ATTACK 2 /* Monster attacked or Scripted Weapon used. */ |
|
|
59 | #define EVENT_DEATH 3 /* Player or monster dead. */ |
|
|
60 | #define EVENT_DROP 4 /* Object dropped on the floor. */ |
|
|
61 | #define EVENT_PICKUP 5 /* Object picked up. */ |
|
|
62 | #define EVENT_SAY 6 /* Someone speaks. */ |
|
|
63 | #define EVENT_STOP 7 /* Thrown object stopped. */ |
|
|
64 | #define EVENT_TIME 8 /* Triggered each time the object can react/move. */ |
|
|
65 | #define EVENT_THROW 9 /* Object is thrown. */ |
|
|
66 | #define EVENT_TRIGGER 10 /* Button pushed, lever pulled, etc. */ |
|
|
67 | #define EVENT_CLOSE 11 /* Container closed. */ |
|
|
68 | #define EVENT_TIMER 12 /* Timer connected triggered it. */ |
|
|
69 | #define EVENT_MOVE 28 /* Monster move */ |
|
|
70 | /*****************************************************************************/ |
|
|
71 | /* Global events. Those are never linked to a specific object. */ |
|
|
72 | /*****************************************************************************/ |
|
|
73 | #define EVENT_BORN 13 /* A new character has been created. */ |
|
|
74 | #define EVENT_CLOCK 14 /* Global time event. */ |
|
|
75 | #define EVENT_CRASH 15 /* Triggered when the server crashes. Not recursive*/ |
|
|
76 | #define EVENT_PLAYER_DEATH 16 /* Global Death event */ |
|
|
77 | #define EVENT_GKILL 17 /* Triggered when anything got killed by anyone. */ |
|
|
78 | #define EVENT_LOGIN 18 /* Player login. */ |
|
|
79 | #define EVENT_LOGOUT 19 /* Player logout. */ |
|
|
80 | #define EVENT_MAPENTER 20 /* A player entered a map. */ |
|
|
81 | #define EVENT_MAPLEAVE 21 /* A player left a map. */ |
|
|
82 | #define EVENT_MAPRESET 22 /* A map is resetting. */ |
|
|
83 | #define EVENT_REMOVE 23 /* A Player character has been removed. */ |
|
|
84 | #define EVENT_SHOUT 24 /* A player 'shout' something. */ |
|
|
85 | #define EVENT_TELL 25 /* A player 'tell' something. */ |
|
|
86 | #define EVENT_MUZZLE 26 /* A player was Muzzled (no_shout set). */ |
|
|
87 | #define EVENT_KICK 27 /* A player was Kicked by a DM */ |
|
|
88 | #define EVENT_FREE_OB 29 /* Object destroyed */ |
|
|
89 | /* should add FREE_MAP, FREE_PLAYER */ |
|
|
90 | |
|
|
91 | #define NR_EVENTS 30 |
54 | #define NR_EVENTS 42 |
92 | |
55 | |
93 | #include <stdarg.h> |
56 | #include <stdarg.h> |
94 | |
57 | |
95 | #define CFAPI_NONE 0 |
58 | #define CFAPI_NONE 0 |
96 | #define CFAPI_INT 1 |
59 | #define CFAPI_INT 1 |
… | |
… | |
104 | #define CFAPI_PARCH 9 |
67 | #define CFAPI_PARCH 9 |
105 | #define CFAPI_FUNC 10 |
68 | #define CFAPI_FUNC 10 |
106 | #define CFAPI_PPLAYER 11 |
69 | #define CFAPI_PPLAYER 11 |
107 | #define CFAPI_PPARTY 12 |
70 | #define CFAPI_PPARTY 12 |
108 | #define CFAPI_PREGION 13 |
71 | #define CFAPI_PREGION 13 |
|
|
72 | #define CFAPI_INT16 14 |
109 | |
73 | |
110 | typedef void* (*f_plug_api) (int* type, ...); |
74 | typedef void* (*f_plug_api) (int* type, ...); |
111 | typedef int (*f_plug_postinit) (void); |
75 | typedef int (*f_plug_postinit) (void); |
112 | typedef int (*f_plug_init)(const char* iversion, f_plug_api gethooksptr); |
76 | typedef int (*f_plug_init)(const char* iversion, f_plug_api gethooksptr); |
113 | |
77 | |
114 | #ifndef WIN32 |
|
|
115 | #define LIBPTRTYPE void* |
78 | #define LIBPTRTYPE void* |
116 | #else |
|
|
117 | #define LIBPTRTYPE HMODULE |
|
|
118 | #endif |
|
|
119 | |
79 | |
120 | typedef struct _crossfire_plugin |
80 | typedef struct _crossfire_plugin |
121 | { |
81 | { |
122 | f_plug_api eventfunc; /* Event Handler function */ |
82 | f_plug_api eventfunc; /* Event Handler function */ |
123 | f_plug_api propfunc; /* Plugin getProperty function */ |
83 | f_plug_api propfunc; /* Plugin getProperty function */ |
… | |
… | |
131 | } crossfire_plugin; |
91 | } crossfire_plugin; |
132 | |
92 | |
133 | extern int plugin_number; |
93 | extern int plugin_number; |
134 | extern crossfire_plugin* plugins_list; |
94 | extern crossfire_plugin* plugins_list; |
135 | |
95 | |
136 | #ifdef WIN32 |
|
|
137 | |
|
|
138 | #define plugins_dlopen(fname) LoadLibrary(fname) |
|
|
139 | #define plugins_dlclose(lib) FreeLibrary(lib) |
|
|
140 | #define plugins_dlsym(lib,name) GetProcAddress(lib,name) |
|
|
141 | |
|
|
142 | #else /*WIN32 */ |
|
|
143 | |
|
|
144 | #define plugins_dlopen(fname) dlopen(fname,RTLD_NOW|RTLD_GLOBAL) |
96 | #define plugins_dlopen(fname) dlopen(fname,RTLD_NOW|RTLD_GLOBAL) |
145 | #define plugins_dlclose(lib) dlclose(lib) |
97 | #define plugins_dlclose(lib) dlclose(lib) |
146 | #define plugins_dlsym(lib,name) dlsym(lib,name) |
98 | #define plugins_dlsym(lib,name) dlsym(lib,name) |
147 | #define plugins_dlerror() dlerror() |
99 | #define plugins_dlerror() dlerror() |
148 | #endif /* WIN32 */ |
|
|
149 | |
100 | |
150 | |
101 | |
151 | /* OBJECT-RELATED HOOKS */ |
102 | /* OBJECT-RELATED HOOKS */ |
152 | |
103 | |
153 | #define CFAPI_OBJECT_PROP_OB_ABOVE 1 |
104 | #define CFAPI_OBJECT_PROP_OB_ABOVE 1 |