--- deliantra/server/plugins/cfperl/cfperl.xs 2006/02/03 07:51:14 1.2 +++ deliantra/server/plugins/cfperl/cfperl.xs 2006/02/03 21:22:53 1.6 @@ -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 { @@ -159,23 +158,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 +217,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 +261,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; } @@ -283,9 +282,12 @@ va_start (args, type); propname = va_arg (args, char *); //printf ("Property name: %s\n", propname); - + if (!strcmp (propname, "command?")) { + if (!perl) + return NULL; + const char *cmdname = va_arg (args, const char *); HV *hv = get_hv ("cf::COMMAND", 1); SV **svp = hv_fetch (hv, cmdname, strlen (cmdname) + 1, 0); @@ -331,7 +333,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 */ @@ -356,7 +357,7 @@ "-e" "BEGIN {" " cf->bootstrap;" - " unshift @INC, cf::maps_directory ('perl');" + " unshift @INC, cf::datadir ();" "}" "" "use cf;" @@ -365,8 +366,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"); @@ -803,6 +803,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; ) @@ -975,9 +1003,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); @@ -992,22 +1017,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 @@ -1091,15 +1155,16 @@ 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 () + PROTOTYPE: ALIAS: new = 0 object *cf_create_object_by_name (const char *name) + PROTOTYPE: $ ALIAS: new_from_name = 0 void cf_free_object (object *ob) @@ -1114,52 +1179,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) @@ -1176,14 +1274,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 @@ -1197,6 +1296,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)