1 |
/*****************************************************************************/ |
2 |
/* Template for version 2.0 plugins. */ |
3 |
/* Contact: yann.chachkoff@myrealbox.com */ |
4 |
/*****************************************************************************/ |
5 |
/* That code is placed under the GNU General Public Licence (GPL) */ |
6 |
/* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */ |
7 |
/*****************************************************************************/ |
8 |
/* CrossFire, A Multiplayer game for X-windows */ |
9 |
/* */ |
10 |
/* Copyright (C) 2000 Mark Wedel */ |
11 |
/* Copyright (C) 1992 Frank Tore Johansen */ |
12 |
/* */ |
13 |
/* This program is free software; you can redistribute it and/or modify */ |
14 |
/* it under the terms of the GNU General Public License as published by */ |
15 |
/* the Free Software Foundation; either version 2 of the License, or */ |
16 |
/* (at your option) any later version. */ |
17 |
/* */ |
18 |
/* This program is distributed in the hope that it will be useful, */ |
19 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
20 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ |
21 |
/* GNU General Public License for more details. */ |
22 |
/* */ |
23 |
/* You should have received a copy of the GNU General Public License */ |
24 |
/* along with this program; if not, write to the Free Software */ |
25 |
/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
26 |
/* */ /*****************************************************************************/ |
27 |
|
28 |
/* First let's include the header file needed */ |
29 |
|
30 |
#include <plugin_template.h> |
31 |
#include <stdarg.h> |
32 |
|
33 |
f_plug_api gethook; |
34 |
f_plug_api registerGlobalEvent; |
35 |
f_plug_api unregisterGlobalEvent; |
36 |
f_plug_api systemDirectory; |
37 |
f_plug_api reCmp; |
38 |
|
39 |
CFPContext* context_stack; |
40 |
CFPContext* current_context; |
41 |
static int current_command = -999; |
42 |
|
43 |
void initContextStack() |
44 |
{ |
45 |
current_context = NULL; |
46 |
context_stack = NULL; |
47 |
} |
48 |
|
49 |
void pushContext(CFPContext* context) |
50 |
{ |
51 |
CFPContext* stack_context; |
52 |
if (current_context == NULL) |
53 |
{ |
54 |
context_stack = context; |
55 |
context->down = NULL; |
56 |
} |
57 |
else |
58 |
{ |
59 |
context->down = current_context; |
60 |
} |
61 |
current_context = context; |
62 |
} |
63 |
|
64 |
CFPContext* popContext() |
65 |
{ |
66 |
CFPContext* oldcontext; |
67 |
if (current_context != NULL) |
68 |
{ |
69 |
oldcontext = current_context; |
70 |
current_context = current_context->down; |
71 |
return oldcontext; |
72 |
} |
73 |
else |
74 |
return NULL; |
75 |
} |
76 |
|
77 |
int initPlugin(const char* iversion, f_plug_api gethooksptr) |
78 |
{ |
79 |
gethook = gethooksptr; |
80 |
int i; |
81 |
printf("Template 2.0a init\n"); |
82 |
|
83 |
/* Place your initialization code here */ |
84 |
return 0; |
85 |
} |
86 |
|
87 |
void* getPluginProperty(int* type, ...) |
88 |
{ |
89 |
va_list args; |
90 |
char* propname; |
91 |
int i; |
92 |
va_start(args, type); |
93 |
propname = va_arg(args, char *); |
94 |
printf("Property name: %s\n", propname); |
95 |
|
96 |
if (!strcmp(propname, "Identification")) |
97 |
{ |
98 |
va_end(args); |
99 |
return PLUGIN_NAME; |
100 |
} |
101 |
else if (!strcmp(propname, "FullName")) |
102 |
{ |
103 |
va_end(args); |
104 |
return PLUGIN_VERSION; |
105 |
} |
106 |
return NULL; |
107 |
} |
108 |
|
109 |
int runPluginCommand(object* op, char* params) |
110 |
{ |
111 |
return -1; |
112 |
} |
113 |
|
114 |
int postInitPlugin() |
115 |
{ |
116 |
int hooktype = 1; |
117 |
int rtype = 0; |
118 |
|
119 |
printf("Template 2.0a post init\n"); |
120 |
registerGlobalEvent = gethook(&rtype,hooktype,"cfapi_system_register_global_event"); |
121 |
unregisterGlobalEvent = gethook(&rtype,hooktype,"cfapi_system_unregister_global_event"); |
122 |
systemDirectory = gethook(&rtype,hooktype,"cfapi_system_directory"); |
123 |
reCmp = gethook(&rtype,hooktype,"cfapi_system_re_cmp"); |
124 |
cf_init_plugin( gethook ); |
125 |
initContextStack(); |
126 |
/* Pick the global events you want to monitor from this plugin */ |
127 |
/*registerGlobalEvent(NULL,EVENT_BORN,PLUGIN_NAME,globalEventListener); |
128 |
registerGlobalEvent(NULL,EVENT_CLOCK,PLUGIN_NAME,globalEventListener); |
129 |
registerGlobalEvent(NULL,EVENT_CRASH,PLUGIN_NAME,globalEventListener); |
130 |
registerGlobalEvent(NULL,EVENT_PLAYER_DEATH,PLUGIN_NAME,globalEventListener); |
131 |
registerGlobalEvent(NULL,EVENT_GKILL,PLUGIN_NAME,globalEventListener); |
132 |
registerGlobalEvent(NULL,EVENT_LOGIN,PLUGIN_NAME,globalEventListener); |
133 |
registerGlobalEvent(NULL,EVENT_LOGOUT,PLUGIN_NAME,globalEventListener); |
134 |
registerGlobalEvent(NULL,EVENT_MAPENTER,PLUGIN_NAME,globalEventListener); |
135 |
registerGlobalEvent(NULL,EVENT_MAPLEAVE,PLUGIN_NAME,globalEventListener); |
136 |
registerGlobalEvent(NULL,EVENT_MAPRESET,PLUGIN_NAME,globalEventListener); |
137 |
registerGlobalEvent(NULL,EVENT_REMOVE,PLUGIN_NAME,globalEventListener); |
138 |
registerGlobalEvent(NULL,EVENT_SHOUT,PLUGIN_NAME,globalEventListener); |
139 |
registerGlobalEvent(NULL,EVENT_TELL,PLUGIN_NAME,globalEventListener); |
140 |
registerGlobalEvent(NULL,EVENT_MUZZLE,PLUGIN_NAME,globalEventListener); |
141 |
registerGlobalEvent(NULL,EVENT_KICK,PLUGIN_NAME,globalEventListener);*/ |
142 |
return 0; |
143 |
} |
144 |
|
145 |
void* globalEventListener(int* type, ...) |
146 |
{ |
147 |
va_list args; |
148 |
static int rv=0; |
149 |
CFPContext* context; |
150 |
context = malloc(sizeof(CFPContext)); |
151 |
char* buf; |
152 |
player* pl; |
153 |
object* op; |
154 |
|
155 |
va_start(args, type); |
156 |
context->event_code = va_arg(args, int); |
157 |
printf("****** Global event listener called ***********\n"); |
158 |
printf("- Event code: %d\n", context->event_code); |
159 |
|
160 |
context->message[0]=0; |
161 |
|
162 |
context->who = NULL; |
163 |
context->activator = NULL; |
164 |
context->third = NULL; |
165 |
rv = context->returnvalue = 0; |
166 |
switch(context->event_code) |
167 |
{ |
168 |
case EVENT_CRASH: |
169 |
printf( "Unimplemented for now\n"); |
170 |
break; |
171 |
case EVENT_BORN: |
172 |
context->activator = va_arg(args, object*); |
173 |
break; |
174 |
case EVENT_PLAYER_DEATH: |
175 |
context->who = va_arg(args, object*); |
176 |
break; |
177 |
case EVENT_GKILL: |
178 |
context->who = va_arg(args, object*); |
179 |
context->activator = va_arg(args, object*); |
180 |
break; |
181 |
case EVENT_LOGIN: |
182 |
pl = va_arg(args, player*); |
183 |
context->activator = pl->ob; |
184 |
buf = va_arg(args, char*); |
185 |
if (buf !=0) |
186 |
strcpy(context->message,buf); |
187 |
break; |
188 |
case EVENT_LOGOUT: |
189 |
pl = va_arg(args, player*); |
190 |
context->activator = pl->ob; |
191 |
buf = va_arg(args, char*); |
192 |
if (buf !=0) |
193 |
strcpy(context->message,buf); |
194 |
break; |
195 |
case EVENT_REMOVE: |
196 |
context->activator = va_arg(args, object*); |
197 |
break; |
198 |
case EVENT_SHOUT: |
199 |
context->activator = va_arg(args, object*); |
200 |
buf = va_arg(args, char*); |
201 |
if (buf !=0) |
202 |
strcpy(context->message,buf); |
203 |
break; |
204 |
case EVENT_MUZZLE: |
205 |
context->activator = va_arg(args, object*); |
206 |
buf = va_arg(args, char*); |
207 |
if (buf !=0) |
208 |
strcpy(context->message,buf); |
209 |
break; |
210 |
case EVENT_KICK: |
211 |
context->activator = va_arg(args, object*); |
212 |
buf = va_arg(args, char*); |
213 |
if (buf !=0) |
214 |
strcpy(context->message,buf); |
215 |
break; |
216 |
case EVENT_MAPENTER: |
217 |
context->activator = va_arg(args, object*); |
218 |
break; |
219 |
case EVENT_MAPLEAVE: |
220 |
context->activator = va_arg(args, object*); |
221 |
break; |
222 |
case EVENT_CLOCK: |
223 |
break; |
224 |
case EVENT_MAPRESET: |
225 |
buf = va_arg(args, char*); |
226 |
if (buf !=0) |
227 |
strcpy(context->message,buf); |
228 |
break; |
229 |
case EVENT_TELL: |
230 |
break; |
231 |
} |
232 |
va_end(args); |
233 |
context->returnvalue = 0; |
234 |
|
235 |
pushContext(context); |
236 |
/* Put your plugin action(s) here */ |
237 |
context = popContext(); |
238 |
rv = context->returnvalue; |
239 |
free(context); |
240 |
printf("*********** Execution complete ****************\n"); |
241 |
|
242 |
return &rv; |
243 |
} |
244 |
|
245 |
void* eventListener(int* type, ...) |
246 |
{ |
247 |
static int rv=0; |
248 |
va_list args; |
249 |
char* buf; |
250 |
CFPContext* context; |
251 |
|
252 |
context = malloc(sizeof(CFPContext)); |
253 |
|
254 |
context->message[0]=0; |
255 |
|
256 |
va_start(args,type); |
257 |
|
258 |
context->who = va_arg(args, object*); |
259 |
context->event_code = va_arg(args,int); |
260 |
context->activator = va_arg(args, object*); |
261 |
context->third = va_arg(args, object*); |
262 |
buf = va_arg(args, char*); |
263 |
if (buf !=0) |
264 |
strcpy(context->message,buf); |
265 |
context->fix = va_arg(args, int); |
266 |
strcpy(context->options,va_arg(args, char*)); |
267 |
context->returnvalue = 0; |
268 |
va_end(args); |
269 |
|
270 |
pushContext(context); |
271 |
/* Put your plugin action(s) here */ |
272 |
context = popContext(); |
273 |
rv = context->returnvalue; |
274 |
free(context); |
275 |
printf("Execution complete"); |
276 |
return &rv; |
277 |
} |
278 |
|
279 |
int closePlugin() |
280 |
{ |
281 |
printf("Template 2.0a closing\n"); |
282 |
return 0; |
283 |
} |
284 |
|