1 | /*****************************************************************************/ |
1 | /* |
2 | /* Crossfire plugin support - (C) 2001 by Yann Chachkoff. */ |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
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 |
|
|
9 | * it under the terms of the GNU General Public License as published by |
|
|
10 | * the Free Software Foundation, either version 3 of the License, or |
|
|
11 | * (at your option) any later version. |
|
|
12 | * |
|
|
13 | * This program is distributed in the hope that it will be useful, |
|
|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
16 | * GNU General Public License for more details. |
|
|
17 | * |
|
|
18 | * You should have received a copy of the GNU General Public License |
|
|
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
20 | * |
|
|
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
|
|
22 | */ |
5 | |
23 | |
6 | /*****************************************************************************/ |
24 | /*****************************************************************************/ |
7 | /* Headers needed. */ |
25 | /* Headers needed. */ |
8 | /*****************************************************************************/ |
26 | /*****************************************************************************/ |
9 | |
27 | |
… | |
… | |
11 | #define PLUGIN_H_ |
29 | #define PLUGIN_H_ |
12 | |
30 | |
13 | /*****************************************************************************/ |
31 | /*****************************************************************************/ |
14 | /* This one does not exist under Win32. */ |
32 | /* This one does not exist under Win32. */ |
15 | /*****************************************************************************/ |
33 | /*****************************************************************************/ |
16 | #ifndef WIN32 |
|
|
17 | #include <dlfcn.h> |
34 | #include <dlfcn.h> |
18 | #endif |
|
|
19 | |
35 | |
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 |
36 | #define MODULEAPI |
29 | #endif |
|
|
30 | |
37 | |
31 | #include <global.h> |
38 | #include <global.h> |
32 | #include <object.h> |
39 | #include <object.h> |
33 | |
40 | |
34 | #ifdef HAVE_TIME_H |
41 | #ifdef HAVE_TIME_H |
… | |
… | |
39 | |
46 | |
40 | |
47 | |
41 | /*****************************************************************************/ |
48 | /*****************************************************************************/ |
42 | /* This one does not exist under Win32. */ |
49 | /* This one does not exist under Win32. */ |
43 | /*****************************************************************************/ |
50 | /*****************************************************************************/ |
44 | #ifndef WIN32 |
|
|
45 | #include <dirent.h> |
51 | #include <dirent.h> |
46 | #endif |
|
|
47 | |
52 | |
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 | #define EVENT_NONE 0 /* No event. This exists only to reserve the "0". */ |
|
|
56 | #define EVENT_APPLY 1 /* Object applied-unapplied. */ |
|
|
57 | #define EVENT_ATTACK 2 /* Monster attacked or Scripted Weapon used. */ |
|
|
58 | #define EVENT_DEATH 3 /* Player or monster dead. */ |
|
|
59 | #define EVENT_DROP 4 /* Object dropped on the floor. */ |
|
|
60 | #define EVENT_PICKUP 5 /* Object picked up. */ |
|
|
61 | #define EVENT_SAY 6 /* Someone speaks. */ |
|
|
62 | #define EVENT_STOP 7 /* Thrown object stopped. */ |
|
|
63 | #define EVENT_TIME 8 /* Triggered each time the object can react/move. */ |
|
|
64 | #define EVENT_THROW 9 /* Object is thrown. */ |
|
|
65 | #define EVENT_TRIGGER 10 /* Button pushed, lever pulled, etc. */ |
|
|
66 | #define EVENT_CLOSE 11 /* Container closed. */ |
|
|
67 | #define EVENT_TIMER 12 /* Timer connected triggered it. */ |
|
|
68 | /*****************************************************************************/ |
|
|
69 | /* Global events. Those are never linked to a specific object. */ |
|
|
70 | /*****************************************************************************/ |
|
|
71 | #define EVENT_BORN 13 /* A new character has been created. */ |
|
|
72 | #define EVENT_CLOCK 14 /* Global time event. */ |
|
|
73 | #define EVENT_CRASH 15 /* Triggered when the server crashes. Not recursive*/ |
|
|
74 | #define EVENT_PLAYER_DEATH 16 /* Global Death event */ |
|
|
75 | #define EVENT_GKILL 17 /* Triggered when anything got killed by anyone. */ |
|
|
76 | #define EVENT_LOGIN 18 /* Player login. */ |
|
|
77 | #define EVENT_LOGOUT 19 /* Player logout. */ |
|
|
78 | #define EVENT_MAPENTER 20 /* A player entered a map. */ |
|
|
79 | #define EVENT_MAPLEAVE 21 /* A player left a map. */ |
|
|
80 | #define EVENT_MAPRESET 22 /* A map is resetting. */ |
|
|
81 | #define EVENT_REMOVE 23 /* A Player character has been removed. */ |
|
|
82 | #define EVENT_SHOUT 24 /* A player 'shout' something. */ |
|
|
83 | #define EVENT_TELL 25 /* A player 'tell' something. */ |
|
|
84 | #define EVENT_MUZZLE 26 /* A player was Muzzled (no_shout set). */ |
|
|
85 | #define EVENT_KICK 27 /* A player was Kicked by a DM */ |
|
|
86 | |
|
|
87 | #define NR_EVENTS 28 |
53 | #define NR_EVENTS 42 |
88 | |
54 | |
89 | #include <stdarg.h> |
55 | #include <stdarg.h> |
90 | |
56 | |
91 | #define CFAPI_NONE 0 |
57 | #define CFAPI_NONE 0 |
92 | #define CFAPI_INT 1 |
58 | #define CFAPI_INT 1 |
… | |
… | |
106 | |
72 | |
107 | typedef void* (*f_plug_api) (int* type, ...); |
73 | typedef void* (*f_plug_api) (int* type, ...); |
108 | typedef int (*f_plug_postinit) (void); |
74 | typedef int (*f_plug_postinit) (void); |
109 | typedef int (*f_plug_init)(const char* iversion, f_plug_api gethooksptr); |
75 | typedef int (*f_plug_init)(const char* iversion, f_plug_api gethooksptr); |
110 | |
76 | |
111 | #ifndef WIN32 |
|
|
112 | #define LIBPTRTYPE void* |
77 | #define LIBPTRTYPE void* |
113 | #else |
|
|
114 | #define LIBPTRTYPE HMODULE |
|
|
115 | #endif |
|
|
116 | |
78 | |
117 | typedef struct _crossfire_plugin |
79 | typedef struct _crossfire_plugin |
118 | { |
80 | { |
119 | f_plug_api eventfunc; /* Event Handler function */ |
81 | f_plug_api eventfunc; /* Event Handler function */ |
120 | f_plug_api propfunc; /* Plugin getProperty function */ |
82 | f_plug_api propfunc; /* Plugin getProperty function */ |
… | |
… | |
128 | } crossfire_plugin; |
90 | } crossfire_plugin; |
129 | |
91 | |
130 | extern int plugin_number; |
92 | extern int plugin_number; |
131 | extern crossfire_plugin* plugins_list; |
93 | extern crossfire_plugin* plugins_list; |
132 | |
94 | |
133 | #ifdef WIN32 |
|
|
134 | |
|
|
135 | #define plugins_dlopen(fname) LoadLibrary(fname) |
|
|
136 | #define plugins_dlclose(lib) FreeLibrary(lib) |
|
|
137 | #define plugins_dlsym(lib,name) GetProcAddress(lib,name) |
|
|
138 | |
|
|
139 | #else /*WIN32 */ |
|
|
140 | |
|
|
141 | #define plugins_dlopen(fname) dlopen(fname,RTLD_NOW|RTLD_GLOBAL) |
95 | #define plugins_dlopen(fname) dlopen(fname,RTLD_NOW|RTLD_GLOBAL) |
142 | #define plugins_dlclose(lib) dlclose(lib) |
96 | #define plugins_dlclose(lib) dlclose(lib) |
143 | #define plugins_dlsym(lib,name) dlsym(lib,name) |
97 | #define plugins_dlsym(lib,name) dlsym(lib,name) |
144 | #define plugins_dlerror() dlerror() |
98 | #define plugins_dlerror() dlerror() |
145 | #endif /* WIN32 */ |
|
|
146 | |
99 | |
147 | |
100 | |
148 | /* OBJECT-RELATED HOOKS */ |
101 | /* OBJECT-RELATED HOOKS */ |
149 | |
102 | |
150 | #define CFAPI_OBJECT_PROP_OB_ABOVE 1 |
103 | #define CFAPI_OBJECT_PROP_OB_ABOVE 1 |