ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/plugins.C
(Generate patch)

Comparing deliantra/server/server/plugins.C (file contents):
Revision 1.7 by root, Mon Aug 28 16:52:51 2006 UTC vs.
Revision 1.8 by root, Tue Aug 29 05:03:55 2006 UTC

1/* 1/*
2 * static char *rcsid_plugins_c = 2 * static char *rcsid_plugins_c =
3 * "$Id: plugins.C,v 1.7 2006/08/28 16:52:51 root Exp $"; 3 * "$Id: plugins.C,v 1.8 2006/08/29 05:03:55 root Exp $";
4 */ 4 */
5 5
6/*****************************************************************************/ 6/*****************************************************************************/
7/* CrossFire, A Multiplayer game for X-windows */ 7/* CrossFire, A Multiplayer game for X-windows */
8/* */ 8/* */
204 } 204 }
205 if (tmp) 205 if (tmp)
206 esrv_del_item(tmp->contr, op->count); 206 esrv_del_item(tmp->contr, op->count);
207} 207}
208 208
209int execute_event(object* op, int eventcode, object* activator, object* third, const char* message, int fix)
210{
211 object *tmp, *next;
212 crossfire_plugin* plugin;
213 int rv = 0;
214 for (tmp = op->inv; tmp != NULL; tmp = next) {
215 next = tmp->below;
216 if (tmp->type == EVENT_CONNECTOR && tmp->subtype == eventcode) {
217#if 0
218 LOG(llevDebug, "********** EVENT HANDLER **********\n");
219 LOG(llevDebug, " - Who am I :%s\n", op->name);
220 if (activator != NULL)
221 LOG(llevDebug, " - Activator :%s\n", activator->name);
222 if (third != NULL)
223 LOG(llevDebug, " - Other object :%s\n", third->name);
224 LOG(llevDebug, " - Event code :%d\n", tmp->subtype);
225 if (tmp->title != NULL)
226 LOG(llevDebug, " - Event plugin :%s\n", tmp->title);
227 if (tmp->slaying != NULL)
228 LOG(llevDebug, " - Event hook :%s\n", tmp->slaying);
229 if (tmp->name != NULL)
230 LOG(llevDebug, " - Event options :%s\n", tmp->name);
231#endif
232
233 if (tmp->title == NULL) {
234 object *env = object_get_env_recursive(tmp);
235 LOG(llevError, "Event object without title at %d/%d in map %s\n", env->x, env->y, env->map->name);
236 send_removed_object(tmp);
237 remove_ob(tmp);
238 free_object(tmp);
239 } else if (tmp->slaying == NULL) {
240 object *env = object_get_env_recursive(tmp);
241 LOG(llevError, "Event object without slaying at %d/%d in map %s\n", env->x, env->y, env->map->name);
242 send_removed_object(tmp);
243 remove_ob(tmp);
244 free_object(tmp);
245 } else {
246 plugin = plugins_find_plugin(tmp->title);
247 if (plugin == NULL) {
248 object *env = object_get_env_recursive(tmp);
249 LOG(llevError, "The requested plugin doesn't exist: %s at %d/%d in map %s\n", tmp->title, env->x, env->y, env->map->name);
250 send_removed_object(tmp);
251 remove_ob(tmp);
252 free_object(tmp);
253 } else if (plugin->eventfunc) {
254 int rvt = 0;
255 int *rv;
256
257 rv = (int*) plugin->eventfunc(&rvt, op, eventcode, activator, third, message, fix, tmp->slaying, tmp->name, tmp);
258 return *rv;
259 }
260 }
261 }
262 }
263 return rv;
264}
265
266int execute_global_event(int eventcode, ...)
267{
268 va_list args;
269 object* op;
270 object* op2;
271 object* op3;
272 mapstruct *map;
273 player* pl;
274 char* buf;
275 int i, rt, retval = 0, *tmpretval = NULL, fix;
276 crossfire_plugin* cp;
277 if (plugins_list == NULL)
278 return -1;
279
280 va_start(args, eventcode);
281
282 switch (eventcode) {
283
284 case EVENT_CLOCK:
285 case EVENT_CRASH:
286 case EVENT_TELL:
287 /* no additional arguments */
288 for (cp = plugins_list; cp != NULL; cp = cp->next) {
289 if (cp->gevent[eventcode] != NULL)
290 cp->gevent[eventcode](&rt, eventcode);
291 }
292 break;
293
294 case EVENT_SHOUT:
295 /*SHOUT: op, parms, priority*/
296 op = va_arg(args, object*);
297 buf = va_arg(args, char*);
298 i = va_arg(args, int);
299 for (cp = plugins_list; cp != NULL; cp = cp->next) {
300 if (cp->gevent[eventcode] != NULL)
301 cp->gevent[eventcode](&rt, eventcode, op, buf, i);
302 }
303 break;
304
305 case EVENT_MUZZLE:
306 /*MUZZLE: op, parms*/
307 op = va_arg(args, object*);
308 buf = va_arg(args, char*);
309 for (cp = plugins_list; cp != NULL; cp = cp->next) {
310 if (cp->gevent[eventcode] != NULL)
311 cp->gevent[eventcode](&rt, eventcode, op, buf);
312 }
313 break;
314
315 case EVENT_KICK:
316 /*KICK: op, parms*/
317 op = va_arg(args, object*);
318 buf = va_arg(args, char*);
319 for (cp = plugins_list; cp != NULL; cp = cp->next) {
320 if (cp->gevent[eventcode] != NULL)
321 cp->gevent[eventcode](&rt, eventcode, op, buf);
322 }
323 break;
324 }
325 va_end(args);
326
327 return retval;
328}
329
330extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr); 209extern "C" int cfperl_initPlugin (const char *iversion, f_plug_api gethooksptr);
331extern "C" void *cfperl_getPluginProperty (int *type, ...); 210extern "C" void *cfperl_getPluginProperty (int *type, ...);
332extern "C" int cfperl_postInitPlugin (); 211extern "C" int cfperl_postInitPlugin ();
333extern "C" int cfperl_closePlugin (); 212extern "C" int cfperl_closePlugin ();
334 213
3178 *type = CFAPI_NONE; 3057 *type = CFAPI_NONE;
3179 return NULL; 3058 return NULL;
3180} 3059}
3181 3060
3182void* cfapi_object_say(int* type, ...) 3061void* cfapi_object_say(int* type, ...)
3183{ 3062{ abort(); }
3184 static int rv;
3185 object* op;
3186 char* msg;
3187 va_list args;
3188
3189 va_start(args, type);
3190 op = va_arg(args, object*);
3191 msg = va_arg(args, char*);
3192 va_end(args);
3193
3194 rv = command_say(op, msg);
3195 *type = CFAPI_INT;
3196 return &rv;
3197}
3198void* cfapi_object_speak(int* type, ...) 3063void* cfapi_object_speak(int* type, ...)
3199{ 3064{ abort(); }
3200 object* op;
3201 char* msg;
3202 va_list args;
3203 static char buf[MAX_BUF];
3204
3205 va_start(args, type);
3206 op = va_arg(args, object*);
3207 msg = va_arg(args, char*);
3208 va_end(args);
3209
3210 if (!op || !msg)
3211 return NULL;
3212 sprintf(buf, "%s says: ", op->name);
3213 strncat(buf, msg, MAX_BUF-strlen(buf)-1);
3214 buf[MAX_BUF-1]=0;
3215 new_info_map(NDI_WHITE, op->map, buf);
3216 communicate(op, msg);
3217 *type = CFAPI_NONE;
3218 return NULL;
3219}
3220/* PLAYER SUBCLASS */ 3065/* PLAYER SUBCLASS */
3221void* cfapi_player_find(int* type, ...) 3066void* cfapi_player_find(int* type, ...)
3222{ 3067{
3223 va_list args; 3068 va_list args;
3224 void* rv; 3069 void* rv;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines