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

Comparing deliantra/server/plugins/cfperl/cfperl.xs (file contents):
Revision 1.3 by root, Fri Feb 3 16:26:15 2006 UTC vs.
Revision 1.8 by root, Sat Feb 4 00:33:07 2006 UTC

1/*****************************************************************************/ 1/*****************************************************************************/
2/* That code is placed under the GNU General Public Licence (GPL) */
3/* (C)2001-2005 by Chachkoff Yann (Feel free to deliver your complaints) */
4/*****************************************************************************/
5/* CrossFire, A Multiplayer game for X-windows */ 2/* CrossFire, A Multiplayer game for the X Window System */
6/* */
7/* Copyright (C) 2000 Mark Wedel */
8/* Copyright (C) 1992 Frank Tore Johansen */
9/* Copyright (C) 2006 perl plugin by Marc Lehmann <cf@schmorpd.e> */
10/* */
11/* This program is free software; you can redistribute it and/or modify */
12/* it under the terms of the GNU General Public License as published by */
13/* the Free Software Foundation; either version 2 of the License, or */
14/* (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19/* GNU General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU General Public License */
22/* along with this program; if not, write to the Free Software */
23/* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24/* */ 3/* */
25/*****************************************************************************/ 4/*****************************************************************************/
5
6/*
7 * This code is placed under the GNU General Public Licence (GPL)
8 *
9 * Copyright (C) 2001-2005 by Chachkoff Yann
10 * Copyright (C) 2006 by Marc Lehmann <cf@schmorpd.e>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25*/
26 26
27#include <EXTERN.h> 27#include <EXTERN.h>
28#include <perl.h> 28#include <perl.h>
29#include <XSUB.h> 29#include <XSUB.h>
30 30
51 51
52static f_plug_api gethook; 52static f_plug_api gethook;
53static f_plug_api registerGlobalEvent; 53static f_plug_api registerGlobalEvent;
54static f_plug_api unregisterGlobalEvent; 54static f_plug_api unregisterGlobalEvent;
55static f_plug_api systemDirectory; 55static f_plug_api systemDirectory;
56static f_plug_api reCmp;
57 56
58typedef struct 57typedef struct
59{ 58{
60 object* who; 59 object* who;
61 object* activator; 60 object* activator;
129 case CFAPI_DOUBLE: 128 case CFAPI_DOUBLE:
130 sv = newSViv (*va_arg (args, double *)); 129 sv = newSViv (*va_arg (args, double *));
131 break; 130 break;
132 131
133 case CFAPI_STRING: 132 case CFAPI_STRING:
134 sv = newSVpv (va_arg (args, char *), 0); 133 {
134 char *str = va_arg (args, char *);
135 sv = str ? newSVpv (str, 0) : &PL_sv_undef;
136 }
135 break; 137 break;
136 138
137 case CFAPI_POBJECT: 139 case CFAPI_POBJECT:
138 { 140 {
139 object *obj = va_arg (args, object *); 141 object *obj = va_arg (args, object *);
157 } 159 }
158 } 160 }
159 break; 161 break;
160 162
161 case CFAPI_PMAP: 163 case CFAPI_PMAP:
162 sv = newSVptr (va_arg (args, object *), "cf::map"); 164 sv = newSVptr (va_arg (args, mapstruct *), "cf::map");
163 break; 165 break;
164 166
165 case CFAPI_PPLAYER: 167 case CFAPI_PPLAYER:
166 sv = newSVptr (va_arg (args, object *), "cf::player"); 168 sv = newSVptr (va_arg (args, player *), "cf::player");
167 break; 169 break;
168 170
169 case CFAPI_PARCH: 171 case CFAPI_PARCH:
170 sv = newSVptr (va_arg (args, object *), "cf::arch"); 172 sv = newSVptr (va_arg (args, archetype *), "cf::arch");
171 break; 173 break;
172 174
173 case CFAPI_PPARTY: 175 case CFAPI_PPARTY:
174 sv = newSVptr (va_arg (args, object *), "cf::party"); 176 sv = newSVptr (va_arg (args, partylist *), "cf::party");
175 break; 177 break;
176 178
177 case CFAPI_PREGION: 179 case CFAPI_PREGION:
178 sv = newSVptr (va_arg (args, object *), "cf::region"); 180 sv = newSVptr (va_arg (args, region *), "cf::region");
179 break; 181 break;
180 182
181 default: 183 default:
182 assert (("unhandled type in newSVcfapi", 0)); 184 assert (("unhandled type in newSVcfapi", 0));
183 } 185 }
216 218
217 PUTBACK; 219 PUTBACK;
218 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL); 220 int count = call_pv ("cf::inject_event", G_SCALAR | G_EVAL);
219 SPAGAIN; 221 SPAGAIN;
220 222
223 if (SvTRUE (ERRSV))
224 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
225
221 context->returnvalue = count > 0 ? POPi : 0; 226 context->returnvalue = count > 0 ? POPi : 0;
222 227
223 PUTBACK; 228 PUTBACK;
224 FREETMPS; 229 FREETMPS;
225 LEAVE; 230 LEAVE;
226
227 if (SvTRUE (ERRSV))
228 LOG (llevError, "event '%d' callback evaluation error: %s", context->event_code, SvPV_nolen (ERRSV));
229} 231}
230 232
231///////////////////////////////////////////////////////////////////////////// 233/////////////////////////////////////////////////////////////////////////////
232 234
233int 235int
260 262
261 PUTBACK; 263 PUTBACK;
262 int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL); 264 int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL);
263 SPAGAIN; 265 SPAGAIN;
264 266
267 if (SvTRUE (ERRSV))
268 LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV));
269
265 int returnvalue = count > 0 ? POPi : -1; 270 int returnvalue = count > 0 ? POPi : -1;
266 271
267 PUTBACK; 272 PUTBACK;
268 FREETMPS; 273 FREETMPS;
269 LEAVE; 274 LEAVE;
270
271 if (SvTRUE (ERRSV))
272 LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV));
273 275
274 return returnvalue; 276 return returnvalue;
275} 277}
276 278
277void * 279void *
332 printf (PLUGIN_VERSION " post init\n"); 334 printf (PLUGIN_VERSION " post init\n");
333 335
334 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event"); 336 registerGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_register_global_event");
335 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event"); 337 unregisterGlobalEvent = gethook (&rtype, hooktype, "cfapi_system_unregister_global_event");
336 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory"); 338 systemDirectory = gethook (&rtype, hooktype, "cfapi_system_directory");
337 reCmp = gethook (&rtype, hooktype, "cfapi_system_re_cmp");
338 cf_init_plugin (gethook); 339 cf_init_plugin (gethook);
339 340
340 /* Pick the global events you want to monitor from this plugin */ 341 /* Pick the global events you want to monitor from this plugin */
341 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener); 342 registerGlobalEvent (NULL, EVENT_BORN, PLUGIN_NAME, globalEventListener);
342 registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener); 343 registerGlobalEvent (NULL, EVENT_CLOCK, PLUGIN_NAME, globalEventListener);
357 char *argv[] = { 358 char *argv[] = {
358 "", 359 "",
359 "-e" 360 "-e"
360 "BEGIN {" 361 "BEGIN {"
361 " cf->bootstrap;" 362 " cf->bootstrap;"
362 " unshift @INC, cf::maps_directory ('perl');" 363 " unshift @INC, cf::datadir ();"
363 "}" 364 "}"
364 "" 365 ""
365 "use cf;" 366 "use cf;"
366 }; 367 };
367 368
368 perl = perl_alloc (); 369 perl = perl_alloc ();
369 perl_construct (perl); 370 perl_construct (perl);
370 371
371 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) 372 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
372 || perl_run (perl))
373 { 373 {
374 printf ("unable to initialize perl-interpreter, continuing without.\n"); 374 printf ("unable to initialize perl-interpreter, continuing without.\n");
375 375
376 perl_destruct (perl); 376 perl_destruct (perl);
377 perl_free (perl); 377 perl_free (perl);
804 const_iv (FLAG_IS_WATER) 804 const_iv (FLAG_IS_WATER)
805 const_iv (FLAG_CONTENT_ON_GEN) 805 const_iv (FLAG_CONTENT_ON_GEN)
806 const_iv (FLAG_IS_A_TEMPLATE) 806 const_iv (FLAG_IS_A_TEMPLATE)
807 const_iv (FLAG_IS_BUILDABLE) 807 const_iv (FLAG_IS_BUILDABLE)
808 const_iv (FLAG_AFK) 808 const_iv (FLAG_AFK)
809
810 const_iv (NDI_BLACK)
811 const_iv (NDI_WHITE)
812 const_iv (NDI_NAVY)
813 const_iv (NDI_RED)
814 const_iv (NDI_ORANGE)
815 const_iv (NDI_BLUE)
816 const_iv (NDI_DK_ORANGE)
817 const_iv (NDI_GREEN)
818 const_iv (NDI_LT_GREEN)
819 const_iv (NDI_GREY)
820 const_iv (NDI_BROWN)
821 const_iv (NDI_GOLD)
822 const_iv (NDI_TAN)
823 const_iv (NDI_MAX_COLOR)
824 const_iv (NDI_COLOR_MASK)
825 const_iv (NDI_UNIQUE)
826 const_iv (NDI_ALL)
827
828 const_iv (F_APPLIED)
829 const_iv (F_LOCATION)
830 const_iv (F_UNPAID)
831 const_iv (F_MAGIC)
832 const_iv (F_CURSED)
833 const_iv (F_DAMNED)
834 const_iv (F_OPEN)
835 const_iv (F_NOPICK)
836 const_iv (F_LOCKED)
809 }; 837 };
810 838
811 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 839 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
812 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 840 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
813 841
976 prop (CFAPI_INT, OBJECT_PROP_DAM) 1004 prop (CFAPI_INT, OBJECT_PROP_DAM)
977 prop (CFAPI_STRING, OBJECT_PROP_GOD) 1005 prop (CFAPI_STRING, OBJECT_PROP_GOD)
978 prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME) 1006 prop (CFAPI_STRING, OBJECT_PROP_ARCH_NAME)
979 prop (CFAPI_INT, OBJECT_PROP_INVISIBLE) 1007 prop (CFAPI_INT, OBJECT_PROP_INVISIBLE)
980 prop (CFAPI_INT, OBJECT_PROP_FACE) 1008 prop (CFAPI_INT, OBJECT_PROP_FACE)
981 prop (CFAPI_STRING, PLAYER_PROP_IP)
982 prop (CFAPI_POBJECT, PLAYER_PROP_MARKED_ITEM)
983 prop (CFAPI_PPARTY, PLAYER_PROP_PARTY)
984 }; 1009 };
985 1010
986 HV *prop_type = get_hv ("cf::PROP_TYPE", 1); 1011 HV *prop_type = get_hv ("cf::PROP_TYPE", 1);
987 HV *prop_idx = get_hv ("cf::PROP_IDX", 1); 1012 HV *prop_idx = get_hv ("cf::PROP_IDX", 1);
988 1013
993 } 1018 }
994} 1019}
995 1020
996void 1021void
997LOG (int level, char *msg) 1022LOG (int level, char *msg)
1023 PROTOTYPE: $$
998 C_ARGS: level, "%s", msg 1024 C_ARGS: level, "%s", msg
999 1025
1000char * 1026char *
1001cf_get_maps_directory (char *path) 1027cf_get_maps_directory (char *path)
1028 PROTOTYPE: $
1002 ALIAS: maps_directory = 0 1029 ALIAS: maps_directory = 0
1003 1030
1031char *
1032mapdir ()
1033 PROTOTYPE:
1034 ALIAS:
1035 mapdir = 0
1036 uniquedir = 1
1037 tmpdir = 2
1038 confdir = 3
1039 localdir = 4
1040 playerdir = 5
1041 datadir = 6
1042 CODE:
1043{
1044 int unused_type;
1045 RETVAL = (char *)systemDirectory (&unused_type, ix);
1046}
1047 OUTPUT: RETVAL
1048
1049int
1050cf_find_animation (char *text)
1051 PROTOTYPE: $
1052
1004MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1053MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1005 1054
1006PROTOTYPES: DISABLE
1007
1008SV * 1055SV *
1009cf_object_get_property (object *obj, int type, int idx) 1056get_property (object *obj, int type, int idx)
1010 CODE: 1057 CODE:
1011 RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx)); 1058 RETVAL = newSVcfapi (type, cf_object_get_property (obj, idx));
1012 OUTPUT: 1059 OUTPUT: RETVAL
1013 RETVAL 1060
1061SV *
1062set_property (object *obj, int type, int idx, SV *newval)
1063 CODE:
1064 switch (type)
1065 {
1066 case CFAPI_INT:
1067 cf_object_set_int_property (obj, idx, SvIV (newval));
1068 break;
1069 case CFAPI_LONG:
1070 cf_object_set_long_property (obj, idx, SvNV (newval));
1071 break;
1072 case CFAPI_STRING:
1073 cf_object_set_string_property (obj, idx, SvPV_nolen (newval));
1074 break;
1075 default:
1076 croak ("unhandled type '%d' in set_property '%d'", type, idx);
1077 }
1014 1078
1015int cf_object_get_resistance (object *op, int rtype) 1079int cf_object_get_resistance (object *op, int rtype)
1016 ALIAS: resistance = 0 1080 ALIAS: resistance = 0
1017 1081
1018int cf_object_get_flag (object *op, int flag) 1082int cf_object_get_flag (object *op, int flag)
1092 1156
1093char * 1157char *
1094base_name (object *ob, int plural) 1158base_name (object *ob, int plural)
1095 CODE: 1159 CODE:
1096 RETVAL = cf_query_base_name (ob, plural); 1160 RETVAL = cf_query_base_name (ob, plural);
1161 OUTPUT: RETVAL
1162
1163MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1164
1165object *cf_create_object_by_name (const char *name = 0)
1166 PROTOTYPE: ;$
1167 ALIAS:
1168 create_object = 0
1169 new = 0
1170 CODE:
1171 RETVAL = name ? cf_create_object_by_name (name) : cf_create_object ();
1097 OUTPUT: 1172 OUTPUT:
1098 RETVAL 1173 RETVAL
1099
1100MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1101
1102object *cf_create_object ()
1103 ALIAS: new = 0
1104
1105object *cf_create_object_by_name (const char *name)
1106 ALIAS: new_from_name = 0
1107
1108void cf_free_object (object *ob)
1109 1174
1110void cf_fix_object (object *pl) 1175void cf_fix_object (object *pl)
1176 ALIAS: fix = 0
1111 1177
1112object *cf_insert_ob_in_ob (object *ob, object *where) 1178object *cf_insert_ob_in_ob (object *ob, object *where)
1113 1179
1114 1180
1115MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 1181MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1116 1182
1117player *player (object *op) 1183player *player (object *op)
1118 CODE: 1184 CODE:
1119 RETVAL = cf_player_find (cf_query_name (op)); 1185 RETVAL = cf_player_find (cf_query_name (op));
1120 OUTPUT: 1186 OUTPUT: RETVAL
1121 RETVAL
1122 1187
1123void cf_player_message (object *obj, char *txt, int flags = 0) 1188void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
1124 1189
1125object *cf_player_send_inventory (object *op) 1190object *cf_player_send_inventory (object *op)
1126 1191
1192char *cf_player_get_ip (object *op)
1193 ALIAS: ip = 0
1194
1195object *cf_player_get_marked_item (object *op)
1196 ALIAS: marked_item = 0
1197
1198void cf_player_set_marked_item (object *op, object *ob)
1199
1200partylist *cf_player_get_party (object *op)
1201 ALIAS: party = 0
1202
1203void cf_player_set_party (object *op, partylist *party)
1204
1127 1205
1128MODULE = cf PACKAGE = cf::object::map PREFIX = cf_ 1206MODULE = cf PACKAGE = cf::object::map PREFIX = cf_
1129 1207
1130mapstruct *cf_map_get_map (char *name)
1131 ALIAS: map = 0
1132
1133mapstruct *cf_map_get_first ()
1134 ALIAS: first = 0
1135
1136object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags)
1137
1138object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1139
1140object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1141 C_ARGS: str, map, nx, ny
1142
1143#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1144
1145
1146MODULE = cf PACKAGE = cf::player PREFIX = cf_ 1208MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
1147 1209
1148player *cf_player_find (char *name) 1210player *cf_player_find (char *name)
1211 PROTOTYPE: $
1149 1212
1150void cf_player_move (player *pl, int dir) 1213void cf_player_move (player *pl, int dir)
1151 1214
1215# nonstandard
1216object *ob (player *pl)
1217 CODE:
1218 RETVAL = pl->ob;
1219 OUTPUT: RETVAL
1152 1220
1221
1153MODULE = cf PACKAGE = cf::map PREFIX = cf_ 1222MODULE = cf PACKAGE = cf::map PREFIX = cf_map_
1154 1223
1155SV * 1224SV *
1156get_property (mapstruct *obj, int type, int idx) 1225get_property (mapstruct *obj, int type, int idx)
1157 CODE: 1226 CODE:
1158 RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx)); 1227 RETVAL = newSVcfapi (type, cf_map_get_property (obj, idx));
1159 OUTPUT: 1228 OUTPUT: RETVAL
1160 RETVAL 1229
1230SV *
1231set_property (mapstruct *obj, int type, int idx, SV *newval)
1232 CODE:
1233 switch (type)
1234 {
1235 case CFAPI_INT:
1236 cf_map_set_int_property (obj, idx, SvIV (newval));
1237 break;
1238 default:
1239 croak ("unhandled type '%d' in set_property '%d'", type, idx);
1240 }
1241
1242mapstruct *cf_map_get_map (char *name)
1243 PROTOTYPE: $
1244 ALIAS: map = 0
1245
1246mapstruct *cf_map_get_first ()
1247 PROTOTYPE:
1248 ALIAS: first = 0
1249
1250object *cf_map_insert_object_there (mapstruct *where, object *op, object *originator, int flags)
1251
1252object *cf_map_insert_object (mapstruct *where, object* op, int x, int y)
1253
1254object* cf_map_present_arch_by_name (mapstruct *map, const char* str, int nx, int ny)
1255 C_ARGS: str, map, nx, ny
1256
1257#int cf_map_get_flags (mapstruct* map, mapstruct** nmap, I16 x, I16 y, I16 *nx, I16 *ny)
1258
1161 1259
1162 1260
1163MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_ 1261MODULE = cf PACKAGE = cf::arch PREFIX = cf_archetype_
1164 1262
1165archetype*cf_archetype_get_first() 1263archetype*cf_archetype_get_first()
1264 PROTOTYPE:
1166 ALIAS: first = 0 1265 ALIAS: first = 0
1167 1266
1168archetype *cf_archetype_get_next (archetype *arch) 1267archetype *cf_archetype_get_next (archetype *arch)
1169 ALIAS: next = 0 1268 ALIAS: next = 0
1170 1269
1177const char *cf_archetype_get_name (archetype *arch) 1276const char *cf_archetype_get_name (archetype *arch)
1178 ALIAS: name = 0 1277 ALIAS: name = 0
1179 1278
1180MODULE = cf PACKAGE = cf::party PREFIX = cf_party_ 1279MODULE = cf PACKAGE = cf::party PREFIX = cf_party_
1181 1280
1182const char *cf_party_get_name (partylist *party)
1183
1184partylist *cf_party_get_first () 1281partylist *cf_party_get_first ()
1282 PROTOTYPE:
1185 ALIAS: first = 0 1283 ALIAS: first = 0
1186 1284
1187partylist *cf_party_get_next (partylist *party) 1285partylist *cf_party_get_next (partylist *party)
1188 ALIAS: next = 0 1286 ALIAS: next = 0
1189 1287
1288const char *cf_party_get_name (partylist *party)
1289
1190const char *cf_party_get_password (partylist *party) 1290const char *cf_party_get_password (partylist *party)
1191 ALIAS: password = 0 1291 ALIAS: password = 0
1192 1292
1193player *cf_party_get_first_player (partylist *party) 1293player *cf_party_get_first_player (partylist *party)
1194 ALIAS: first_player = 0 1294 ALIAS: first_player = 0
1198 1298
1199 1299
1200MODULE = cf PACKAGE = cf::region PREFIX = cf_region_ 1300MODULE = cf PACKAGE = cf::region PREFIX = cf_region_
1201 1301
1202region *cf_region_get_first () 1302region *cf_region_get_first ()
1303 PROTOTYPE:
1203 ALIAS: first = 0 1304 ALIAS: first = 0
1204 1305
1205const char *cf_region_get_name (region *reg) 1306const char *cf_region_get_name (region *reg)
1206 ALIAS: name = 0 1307 ALIAS: name = 0
1207 1308

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines