--- deliantra/server/plugins/cfperl/cfperl.xs 2006/02/03 16:26:15 1.3 +++ deliantra/server/plugins/cfperl/cfperl.xs 2006/02/04 00:33:07 1.8 @@ -1,29 +1,29 @@ /*****************************************************************************/ -/* That code is placed under the GNU General Public Licence (GPL) */ -/* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */ -/*****************************************************************************/ -/* CrossFire, A Multiplayer game for X-windows */ -/* */ -/* Copyright (C) 2000 Mark Wedel */ -/* Copyright (C) 1992 Frank Tore Johansen */ -/* Copyright (C) 2006 perl plugin by Marc Lehmann */ -/* */ -/* This program is free software; you can redistribute it and/or modify */ -/* it under the terms of the GNU General Public License as published by */ -/* the Free Software Foundation; either version 2 of the License, or */ -/* (at your option) any later version. */ -/* */ -/* This program is distributed in the hope that it will be useful, */ -/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ -/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ -/* GNU General Public License for more details. */ -/* */ -/* You should have received a copy of the GNU General Public License */ -/* along with this program; if not, write to the Free Software */ -/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* CrossFire, A Multiplayer game for the X Window System */ /* */ /*****************************************************************************/ +/* + * This code is placed under the GNU General Public Licence (GPL) + * + * Copyright (C) 2001-2005 by Chachkoff Yann + * Copyright (C) 2006 by Marc Lehmann + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #include #include #include @@ -53,7 +53,6 @@ static f_plug_api registerGlobalEvent; static f_plug_api unregisterGlobalEvent; static f_plug_api systemDirectory; -static f_plug_api reCmp; typedef struct { @@ -131,7 +130,10 @@ break; case CFAPI_STRING: - sv = newSVpv (va_arg (args, char *), 0); + { + char *str = va_arg (args, char *); + sv = str ? newSVpv (str, 0) : &PL_sv_undef; + } break; case CFAPI_POBJECT: @@ -159,23 +161,23 @@ break; case CFAPI_PMAP: - sv = newSVptr (va_arg (args, object *), "cf::map"); + sv = newSVptr (va_arg (args, mapstruct *), "cf::map"); break; case CFAPI_PPLAYER: - sv = newSVptr (va_arg (args, object *), "cf::player"); + sv = newSVptr (va_arg (args, player *), "cf::player"); break; case CFAPI_PARCH: - sv = newSVptr (va_arg (args, object *), "cf::arch"); + sv = newSVptr (va_arg (args, archetype *), "cf::arch"); break; case CFAPI_PPARTY: - sv = newSVptr (va_arg (args, object *), "cf::party"); + sv = newSVptr (va_arg (args, partylist *), "cf::party"); break; case CFAPI_PREGION: - sv = newSVptr (va_arg (args, object *), "cf::region"); + sv = newSVptr (va_arg (args, region *), "cf::region"); break; default: @@ -218,14 +220,14 @@ int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); SPAGAIN; + if (SvTRUE (ERRSV)) + LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); + context->returnvalue = count > 0 ? POPi : 0; PUTBACK; FREETMPS; LEAVE; - - if (SvTRUE (ERRSV)) - LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV)); } ///////////////////////////////////////////////////////////////////////////// @@ -262,15 +264,15 @@ int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL); SPAGAIN; + if (SvTRUE (ERRSV)) + LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV)); + int returnvalue = count > 0 ? POPi : -1; PUTBACK; FREETMPS; LEAVE; - if (SvTRUE (ERRSV)) - LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV)); - return returnvalue; } @@ -334,7 +336,6 @@ registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); - reCmp = gethook (&rtype, hooktype, "cfapi_system_re_cmp"); cf_init_plugin (gethook); /* Pick the global events you want to monitor from this plugin */ @@ -359,7 +360,7 @@ "-e" "BEGIN {" " cf->bootstrap;" - " unshift @INC, cf::maps_directory ('perl');" + " unshift @INC, cf::datadir ();" "}" "" "use cf;" @@ -368,8 +369,7 @@ perl = perl_alloc (); perl_construct (perl); - if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) - || perl_run (perl)) + if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) { printf ("unable to initialize perl-interpreter, continuing without.\n"); @@ -806,6 +806,34 @@ const_iv (FLAG_IS_A_TEMPLATE) const_iv (FLAG_IS_BUILDABLE) const_iv (FLAG_AFK) + + const_iv (NDI_BLACK) + const_iv (NDI_WHITE) + const_iv (NDI_NAVY) + const_iv (NDI_RED) + const_iv (NDI_ORANGE) + const_iv (NDI_BLUE) + const_iv (NDI_DK_ORANGE) + const_iv (NDI_GREEN) + const_iv (NDI_LT_GREEN) + const_iv (NDI_GREY) + const_iv (NDI_BROWN) + const_iv (NDI_GOLD) + const_iv (NDI_TAN) + const_iv (NDI_MAX_COLOR) + const_iv (NDI_COLOR_MASK) + const_iv (NDI_UNIQUE) + const_iv (NDI_ALL) + + const_iv (F_APPLIED) + const_iv (F_LOCATION) + const_iv (F_UNPAID) + const_iv (F_MAGIC) + const_iv (F_CURSED) + const_iv (F_DAMNED) + const_iv (F_OPEN) + const_iv (F_NOPICK) + const_iv (F_LOCKED) }; for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) @@ -978,9 +1006,6 @@ prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME) prop (CFAPI_INT, OBJECT_PROP_INVISIBLE) prop (CFAPI_INT, OBJECT_PROP_FACE) - prop (CFAPI_STRING, PLAYER_PROP_IP) - prop (CFAPI_POBJECT, PLAYER_PROP_MARKED_ITEM) - prop (CFAPI_PPARTY, PLAYER_PROP_PARTY) }; HV *prop_type = get_hv ("cf::PROP_TYPE", 1); @@ -995,22 +1020,61 @@ void LOG (int level, char *msg) + PROTOTYPE: $$ C_ARGS: level, "%s", msg char * cf_get_maps_directory (char *path) + PROTOTYPE: $ ALIAS: maps_directory = 0 -MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ +char * +mapdir () + PROTOTYPE: + ALIAS: + mapdir = 0 + uniquedir = 1 + tmpdir = 2 + confdir = 3 + localdir = 4 + playerdir = 5 + datadir = 6 + CODE: +{ + int unused_type; + RETVAL = (char *)systemDirectory (&unused_type, ix); +} + OUTPUT: RETVAL -PROTOTYPES: DISABLE +int +cf_find_animation (char *text) + PROTOTYPE: $ + +MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ SV * -cf_object_get_property (object *obj, int type, int idx) +get_property (object *obj, int type, int idx) CODE: RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); - OUTPUT: - RETVAL + OUTPUT: RETVAL + +SV * +set_property (object *obj, int type, int idx, SV *newval) + CODE: + switch (type) + { + case CFAPI_INT: + cf_object_set_int_property (obj, idx, SvIV (newval)); + break; + case CFAPI_LONG: + cf_object_set_long_property (obj, idx, SvNV (newval)); + break; + case CFAPI_STRING: + cf_object_set_string_property (obj, idx, SvPV_nolen (newval)); + break; + default: + croak ("unhandled type '%d' in set_property '%d'", type, idx); + } int cf_object_get_resistance (object *op, int rtype) ALIAS: resistance = 0 @@ -1094,20 +1158,22 @@ base_name (object *ob, int plural) CODE: RETVAL = cf_query_base_name (ob, plural); - OUTPUT: - RETVAL + OUTPUT: RETVAL MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ -object *cf_create_object () - ALIAS: new = 0 - -object *cf_create_object_by_name (const char *name) - ALIAS: new_from_name = 0 - -void cf_free_object (object *ob) +object *cf_create_object_by_name (const char *name = 0) + PROTOTYPE: ;$ + ALIAS: + create_object = 0 + new = 0 + CODE: + RETVAL = name ? cf_create_object_by_name (name) : cf_create_object (); + OUTPUT: + RETVAL void cf_fix_object (object *pl) + ALIAS: fix = 0 object *cf_insert_ob_in_ob (object *ob, object *where) @@ -1117,52 +1183,85 @@ player *player (object *op) CODE: RETVAL = cf_player_find (cf_query_name (op)); - OUTPUT: - RETVAL + OUTPUT: RETVAL -void cf_player_message (object *obj, char *txt, int flags = 0) +void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) object *cf_player_send_inventory (object *op) +char *cf_player_get_ip (object *op) + ALIAS: ip = 0 -MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ - -mapstruct *cf_map_get_map (char *name) - ALIAS: map = 0 - -mapstruct *cf_map_get_first () - ALIAS: first = 0 +object *cf_player_get_marked_item (object *op) + ALIAS: marked_item = 0 -object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) +void cf_player_set_marked_item (object *op, object *ob) -object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) +partylist *cf_player_get_party (object *op) + ALIAS: party = 0 -object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) - C_ARGS: str, map, nx, ny +void cf_player_set_party (object *op, partylist *party) -#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) +MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ -MODULE = cf PACKAGE = cf::player PREFIX = cf_ +MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ player *cf_player_find (char *name) + PROTOTYPE: $ void cf_player_move (player *pl, int dir) +# nonstandard +object *ob (player *pl) + CODE: + RETVAL = pl->ob; + OUTPUT: RETVAL + -MODULE = cf PACKAGE = cf::map PREFIX = cf_ +MODULE = cf PACKAGE = cf::map PREFIX = cf_map_ SV * get_property (mapstruct *obj, int type, int idx) CODE: RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx)); - OUTPUT: - RETVAL + OUTPUT: RETVAL + +SV * +set_property (mapstruct *obj, int type, int idx, SV *newval) + CODE: + switch (type) + { + case CFAPI_INT: + cf_map_set_int_property (obj, idx, SvIV (newval)); + break; + default: + croak ("unhandled type '%d' in set_property '%d'", type, idx); + } + +mapstruct *cf_map_get_map (char *name) + PROTOTYPE: $ + ALIAS: map = 0 + +mapstruct *cf_map_get_first () + PROTOTYPE: + ALIAS: first = 0 + +object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags) + +object *cf_map_insert_object (mapstruct *where, object* op, int x, int y) + +object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny) + C_ARGS: str, map, nx, ny + +#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny) + MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ archetype*cf_archetype_get_first() + PROTOTYPE: ALIAS: first = 0 archetype *cf_archetype_get_next (archetype *arch) @@ -1179,14 +1278,15 @@ MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ -const char *cf_party_get_name (partylist *party) - partylist *cf_party_get_first () + PROTOTYPE: ALIAS: first = 0 partylist *cf_party_get_next (partylist *party) ALIAS: next = 0 +const char *cf_party_get_name (partylist *party) + const char *cf_party_get_password (partylist *party) ALIAS: password = 0 @@ -1200,6 +1300,7 @@ MODULE = cf PACKAGE = cf::region PREFIX = cf_region_ region *cf_region_get_first () + PROTOTYPE: ALIAS: first = 0 const char *cf_region_get_name (region *reg)