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

Comparing deliantra/server/server/cfperl.xs (file contents):
Revision 1.81 by root, Thu Dec 14 21:46:34 2006 UTC vs.
Revision 1.106 by root, Sat Dec 23 15:49:40 2006 UTC

19 * GNU General Public License for more details. 19 * GNU General Public License for more details.
20 * 20 *
21 * You should have received a copy of the GNU General Public License 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 22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24*/ 24 */
25 25
26#define PLUGIN_NAME "perl" 26#define PLUGIN_NAME "perl"
27#define PLUGIN_VERSION "cfperl 0.5" 27#define PLUGIN_VERSION "cfperl 0.5"
28 28
29#include <plugin_common.h> 29#include <plugin_common.h>
59static f_plug_api object_set_property = cfapi_object_set_property; 59static f_plug_api object_set_property = cfapi_object_set_property;
60static f_plug_api object_insert = cfapi_object_insert; 60static f_plug_api object_insert = cfapi_object_insert;
61 61
62static PerlInterpreter *perl; 62static PerlInterpreter *perl;
63 63
64static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 64static AV *cb_global, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
65 65
66////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 66//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 67
68static SV * 68static SV *
69newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) 69newSVptr (void *ptr, const char *klass, HV *hv = newHV ())
136inline SV *to_sv (unsigned long v) { return newSVuv (v); } 136inline SV *to_sv (unsigned long v) { return newSVuv (v); }
137inline SV *to_sv ( signed long long v) { return newSVval64 (v); } 137inline SV *to_sv ( signed long long v) { return newSVval64 (v); }
138inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 138inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
139inline SV *to_sv (float v) { return newSVnv (v); } 139inline SV *to_sv (float v) { return newSVnv (v); }
140inline SV *to_sv (double v) { return newSVnv (v); } 140inline SV *to_sv (double v) { return newSVnv (v); }
141inline SV *to_sv (client_socket *v) { return newSVattachable (v, "cf::client_socket::wrap"); } 141inline SV *to_sv (client * v) { return newSVattachable (v, "cf::client::wrap"); }
142inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } 142inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); }
143inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); } 143inline SV *to_sv (object * v) { return newSVattachable (v, v && v->type == PLAYER ? "cf::object::player::wrap" : "cf::object::wrap"); }
144inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); } 144inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); }
145inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } 145inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); }
146inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } 146inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); }
174inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 174inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); }
175inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); } 175inline void sv_to (SV *sv, signed long long &v) { v = ( signed long long)SvVAL64 (sv); }
176inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); } 176inline void sv_to (SV *sv, unsigned long long &v) { v = (unsigned long long)SvVAL64 (sv); }
177inline void sv_to (SV *sv, float &v) { v = SvNV (sv); } 177inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
178inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 178inline void sv_to (SV *sv, double &v) { v = SvNV (sv); }
179inline void sv_to (SV *sv, client_socket *&v) { v = (client_socket *)SvPTR_ornull (sv, "cf::client_socket"); } 179inline void sv_to (SV *sv, client * &v) { v = (client *)SvPTR_ornull (sv, "cf::client"); }
180inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); } 180inline void sv_to (SV *sv, player * &v) { v = (player *)SvPTR_ornull (sv, "cf::player"); }
181inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); } 181inline void sv_to (SV *sv, object * &v) { v = (object *)SvPTR_ornull (sv, "cf::object"); }
182inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); } 182inline void sv_to (SV *sv, archetype * &v) { v = (archetype *)SvPTR_ornull (sv, "cf::arch"); }
183inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)SvPTR_ornull (sv, "cf::map"); } 183inline void sv_to (SV *sv, maptile * &v) { v = (maptile *)SvPTR_ornull (sv, "cf::map"); }
184inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); } 184inline void sv_to (SV *sv, partylist * &v) { v = (partylist *)SvPTR_ornull (sv, "cf::party"); }
192inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; } 192inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
193 193
194template<int N> 194template<int N>
195inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 195inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
196 196
197inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
198inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
199inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
200inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
201inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
202
197inline void sv_to (SV *sv, UUID &v) 203inline void sv_to (SV *sv, UUID &v)
198{ 204{
199 unsigned int version; 205 unsigned int version;
200 206
201 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) 207 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version)
202 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 208 croak ("unparsable uuid: %s", SvPV_nolen (sv));
203} 209}
210
211inline void sv_to (SV *sv, object::flags_t::reference v) { v = boolSV (sv); }
204 212
205static SV * 213static SV *
206newSVdt_va (va_list &ap, data_type type) 214newSVdt_va (va_list &ap, data_type type)
207{ 215{
208 SV *sv; 216 SV *sv;
243 case DT_MAP: 251 case DT_MAP:
244 // va_arg (object *) when void * is passed is an XSI extension 252 // va_arg (object *) when void * is passed is an XSI extension
245 sv = to_sv (va_arg (ap, maptile *)); 253 sv = to_sv (va_arg (ap, maptile *));
246 break; 254 break;
247 255
248 case DT_SOCKET: 256 case DT_CLIENT:
249 sv = to_sv (va_arg (ap, client_socket *)); 257 sv = to_sv (va_arg (ap, client *));
250 break; 258 break;
251 259
252 case DT_PLAYER: 260 case DT_PLAYER:
253 sv = to_sv (va_arg (ap, player *)); 261 sv = to_sv (va_arg (ap, player *));
254 break; 262 break;
361 369
362 HV *hv = (HV *)SvRV ((SV *)self); 370 HV *hv = (HV *)SvRV ((SV *)self);
363 371
364 if (SvREFCNT ((SV *)self) == 1 372 if (SvREFCNT ((SV *)self) == 1
365 && SvREFCNT ((SV *)hv) == 1 373 && SvREFCNT ((SV *)hv) == 1
366 && !HvKEYS (hv)) 374 && !HvTOTALKEYS (hv))
367 { 375 {
368 SvREFCNT_dec ((SV *)self); 376 SvREFCNT_dec ((SV *)self);
369 self = 0; 377 self = 0;
370 } 378 }
371} 379}
412 420
413 switch (type) 421 switch (type)
414 { 422 {
415 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; 423 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break;
416 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; 424 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break;
425 case DT_CLIENT: INVOKE_CLIENT (REATTACH, obj); break;
417 case DT_MAP: INVOKE_MAP (REATTACH, obj); break; 426 case DT_MAP: INVOKE_MAP (REATTACH, obj); break;
418 } 427 }
419} 428}
420 429
421template<class subclass> 430template<class subclass>
835 844
836 char *argv[] = { 845 char *argv[] = {
837 "", 846 "",
838 "-e" 847 "-e"
839 "use Event;" // required for bootstrap 848 "use Event;" // required for bootstrap
840 "cf->bootstrap;" // requiored for datadir :*> 849 "cf->bootstrap;" // required for datadir :*>
841 "unshift @INC, cf::datadir ();" 850 "unshift @INC, cf::datadir ();"
842 "require cf;" 851 "require cf;"
843 }; 852 };
844 853
845 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 854 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
906 AV *callbacks = 0; 915 AV *callbacks = 0;
907 916
908 object *op; 917 object *op;
909 player *pl; 918 player *pl;
910 maptile *map; 919 maptile *map;
920 client *ns;
911 921
912 // callback call ordering is: 922 // callback call ordering is:
913 // 1. per-object callback 923 // 1. per-object callback
914 // 2. per-class object 924 // 2. per-class object
915 // 3. per-type callback 925 // 3. per-type callback
973 gather_callbacks (callbacks, map->cb, event); 983 gather_callbacks (callbacks, map->cb, event);
974 984
975 gather_callbacks (callbacks, cb_map, event); 985 gather_callbacks (callbacks, cb_map, event);
976 break; 986 break;
977 987
988 case KLASS_CLIENT:
989 dt = (data_type) va_arg (ap, int);
990 assert (("first argument must be of type client", dt == DT_CLIENT));
991 ns = va_arg (ap, client *);
992
993 if (ns->cb)
994 gather_callbacks (callbacks, ns->cb, event);
995
996 gather_callbacks (callbacks, cb_client, event);
997 break;
998
978 default: 999 default:
979 assert (("unsupported event klass in cfperl_invoke", 0)); 1000 assert (("unsupported event klass in cfperl_invoke", 0));
980 } 1001 }
981 1002
982 // short-circuit processing if no callbacks found/defined 1003 // short-circuit processing if no callbacks found/defined
995 1016
996 switch (KLASS_OF (event)) 1017 switch (KLASS_OF (event))
997 { 1018 {
998 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; 1019 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break;
999 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; 1020 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break;
1021 case KLASS_CLIENT: PUSHs (sv_2mortal (newSVdt (DT_CLIENT, ns))); break;
1000 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; 1022 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break;
1001 } 1023 }
1002 1024
1003 for (;;) 1025 for (;;)
1004 { 1026 {
1060 1082
1061///////////////////////////////////////////////////////////////////////////// 1083/////////////////////////////////////////////////////////////////////////////
1062 1084
1063struct EventAPI *watcher_base::GEventAPI; 1085struct EventAPI *watcher_base::GEventAPI;
1064 1086
1087static void iw_dispatch (pe_event *ev)
1088{
1089 iw *w = (iw *)ev->ext_data;
1090 w->call (*w);
1091}
1092
1093void
1094iw::alloc ()
1095{
1096 pe = GEventAPI->new_idle (0, 0);
1097
1098 pe->base.callback = (void *)iw_dispatch;
1099 pe->base.ext_data = (void *)this;
1100}
1101
1065static void iow_dispatch (pe_event *ev) 1102static void iow_dispatch (pe_event *ev)
1066{ 1103{
1067 iow *w = (iow *)ev->ext_data; 1104 iow *w = (iow *)ev->ext_data;
1068 w->call (*w, ((pe_ioevent *)ev)->got); 1105 w->call (*w, ((pe_ioevent *)ev)->got);
1069} 1106}
1078 1115
1079 pe->fd = -1; 1116 pe->fd = -1;
1080 pe->poll = 0; 1117 pe->poll = 0;
1081} 1118}
1082 1119
1083iow & 1120void
1084iow::fd (int fd) 1121iow::fd (int fd)
1085{ 1122{
1086 pe->fd = fd; 1123 pe->fd = fd;
1087
1088 return *this;
1089} 1124}
1090 1125
1091int 1126int
1092iow::poll () 1127iow::poll ()
1093{ 1128{
1094 return pe->poll; 1129 return pe->poll;
1095} 1130}
1096 1131
1097iow & 1132void
1098iow::poll (int events) 1133iow::poll (int events)
1099{ 1134{
1100 if (pe->poll != events) 1135 if (pe->poll != events)
1101 { 1136 {
1102 if (pe->poll) stop (); 1137 if (pe->poll) stop ();
1103 pe->poll = events; 1138 pe->poll = events;
1104 if (pe->poll) start (); 1139 if (pe->poll) start ();
1105 } 1140 }
1106
1107 return *this;
1108} 1141}
1109 1142
1110MODULE = cf PACKAGE = cf PREFIX = cf_ 1143MODULE = cf PACKAGE = cf PREFIX = cf_
1111 1144
1112BOOT: 1145BOOT:
1136 const_iv (POTION) 1169 const_iv (POTION)
1137 const_iv (FOOD) 1170 const_iv (FOOD)
1138 const_iv (POISON) 1171 const_iv (POISON)
1139 const_iv (BOOK) 1172 const_iv (BOOK)
1140 const_iv (CLOCK) 1173 const_iv (CLOCK)
1141 const_iv (LIGHTNING)
1142 const_iv (ARROW) 1174 const_iv (ARROW)
1143 const_iv (BOW) 1175 const_iv (BOW)
1144 const_iv (WEAPON) 1176 const_iv (WEAPON)
1145 const_iv (ARMOUR) 1177 const_iv (ARMOUR)
1146 const_iv (PEDESTAL) 1178 const_iv (PEDESTAL)
1166 const_iv (AMULET) 1198 const_iv (AMULET)
1167 const_iv (PLAYERMOVER) 1199 const_iv (PLAYERMOVER)
1168 const_iv (TELEPORTER) 1200 const_iv (TELEPORTER)
1169 const_iv (CREATOR) 1201 const_iv (CREATOR)
1170 const_iv (SKILL) 1202 const_iv (SKILL)
1171 const_iv (EXPERIENCE)
1172 const_iv (EARTHWALL) 1203 const_iv (EARTHWALL)
1173 const_iv (GOLEM) 1204 const_iv (GOLEM)
1174 const_iv (THROWN_OBJ) 1205 const_iv (THROWN_OBJ)
1175 const_iv (BLINDNESS) 1206 const_iv (BLINDNESS)
1176 const_iv (GOD) 1207 const_iv (GOD)
1196 const_iv (FLOOR) 1227 const_iv (FLOOR)
1197 const_iv (FLESH) 1228 const_iv (FLESH)
1198 const_iv (INORGANIC) 1229 const_iv (INORGANIC)
1199 const_iv (SKILL_TOOL) 1230 const_iv (SKILL_TOOL)
1200 const_iv (LIGHTER) 1231 const_iv (LIGHTER)
1201 const_iv (TRAP_PART)
1202 const_iv (WALL) 1232 const_iv (BUILDABLE_WALL)
1203 const_iv (LIGHT_SOURCE)
1204 const_iv (MISC_OBJECT) 1233 const_iv (MISC_OBJECT)
1205 const_iv (MONSTER)
1206 const_iv (SPAWN_GENERATOR)
1207 const_iv (LAMP) 1234 const_iv (LAMP)
1208 const_iv (DUPLICATOR) 1235 const_iv (DUPLICATOR)
1209 const_iv (TOOL)
1210 const_iv (SPELLBOOK) 1236 const_iv (SPELLBOOK)
1211 const_iv (BUILDFAC)
1212 const_iv (CLOAK) 1237 const_iv (CLOAK)
1213 const_iv (SPINNER) 1238 const_iv (SPINNER)
1214 const_iv (GATE) 1239 const_iv (GATE)
1215 const_iv (BUTTON) 1240 const_iv (BUTTON)
1216 const_iv (CF_HANDLE) 1241 const_iv (CF_HANDLE)
1223 const_iv (SPELL_EFFECT) 1248 const_iv (SPELL_EFFECT)
1224 const_iv (CONVERTER) 1249 const_iv (CONVERTER)
1225 const_iv (BRACERS) 1250 const_iv (BRACERS)
1226 const_iv (POISONING) 1251 const_iv (POISONING)
1227 const_iv (SAVEBED) 1252 const_iv (SAVEBED)
1228 const_iv (POISONCLOUD)
1229 const_iv (FIREHOLES)
1230 const_iv (WAND) 1253 const_iv (WAND)
1231 const_iv (SCROLL) 1254 const_iv (SCROLL)
1232 const_iv (DIRECTOR) 1255 const_iv (DIRECTOR)
1233 const_iv (GIRDLE) 1256 const_iv (GIRDLE)
1234 const_iv (FORCE) 1257 const_iv (FORCE)
1249 const_iv (DISEASE) 1272 const_iv (DISEASE)
1250 const_iv (SYMPTOM) 1273 const_iv (SYMPTOM)
1251 const_iv (BUILDER) 1274 const_iv (BUILDER)
1252 const_iv (MATERIAL) 1275 const_iv (MATERIAL)
1253 const_iv (ITEM_TRANSFORMER) 1276 const_iv (ITEM_TRANSFORMER)
1254 const_iv (QUEST)
1255 1277
1256 const_iv (NUM_SUBTYPES) 1278 const_iv (NUM_SUBTYPES)
1257 1279
1258 const_iv (ST_BD_BUILD) 1280 const_iv (ST_BD_BUILD)
1259 const_iv (ST_BD_REMOVE) 1281 const_iv (ST_BD_REMOVE)
1312 const_iv (FLAG_MONSTER) 1334 const_iv (FLAG_MONSTER)
1313 const_iv (FLAG_FRIENDLY) 1335 const_iv (FLAG_FRIENDLY)
1314 const_iv (FLAG_GENERATOR) 1336 const_iv (FLAG_GENERATOR)
1315 const_iv (FLAG_IS_THROWN) 1337 const_iv (FLAG_IS_THROWN)
1316 const_iv (FLAG_AUTO_APPLY) 1338 const_iv (FLAG_AUTO_APPLY)
1317 const_iv (FLAG_TREASURE)
1318 const_iv (FLAG_PLAYER_SOLD) 1339 const_iv (FLAG_PLAYER_SOLD)
1319 const_iv (FLAG_SEE_INVISIBLE) 1340 const_iv (FLAG_SEE_INVISIBLE)
1320 const_iv (FLAG_CAN_ROLL) 1341 const_iv (FLAG_CAN_ROLL)
1321 const_iv (FLAG_OVERLAY_FLOOR) 1342 const_iv (FLAG_OVERLAY_FLOOR)
1322 const_iv (FLAG_IS_TURNABLE) 1343 const_iv (FLAG_IS_TURNABLE)
1397 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1418 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1398 const_iv (FLAG_IS_WATER) 1419 const_iv (FLAG_IS_WATER)
1399 const_iv (FLAG_CONTENT_ON_GEN) 1420 const_iv (FLAG_CONTENT_ON_GEN)
1400 const_iv (FLAG_IS_A_TEMPLATE) 1421 const_iv (FLAG_IS_A_TEMPLATE)
1401 const_iv (FLAG_IS_BUILDABLE) 1422 const_iv (FLAG_IS_BUILDABLE)
1402 const_iv (FLAG_AFK)
1403 1423
1404 const_iv (NDI_BLACK) 1424 const_iv (NDI_BLACK)
1405 const_iv (NDI_WHITE) 1425 const_iv (NDI_WHITE)
1406 const_iv (NDI_NAVY) 1426 const_iv (NDI_NAVY)
1407 const_iv (NDI_RED) 1427 const_iv (NDI_RED)
1445 const_iv (F_BUY) 1465 const_iv (F_BUY)
1446 const_iv (F_SHOP) 1466 const_iv (F_SHOP)
1447 const_iv (F_SELL) 1467 const_iv (F_SELL)
1448 1468
1449 const_iv (P_BLOCKSVIEW) 1469 const_iv (P_BLOCKSVIEW)
1470 const_iv (P_PLAYER)
1450 const_iv (P_NO_MAGIC) 1471 const_iv (P_NO_MAGIC)
1451 const_iv (P_IS_ALIVE) 1472 const_iv (P_IS_ALIVE)
1452 const_iv (P_NO_CLERIC) 1473 const_iv (P_NO_CLERIC)
1453 const_iv (P_NEED_UPDATE) 1474 const_iv (P_NEED_UPDATE)
1454 const_iv (P_NO_ERROR)
1455 const_iv (P_OUT_OF_MAP) 1475 const_iv (P_OUT_OF_MAP)
1456 const_iv (P_NEW_MAP) 1476 const_iv (P_NEW_MAP)
1457 1477
1458 const_iv (UP_OBJ_INSERT) 1478 const_iv (UP_OBJ_INSERT)
1459 const_iv (UP_OBJ_REMOVE) 1479 const_iv (UP_OBJ_REMOVE)
1605 const_iv (MAP_LOADING) 1625 const_iv (MAP_LOADING)
1606 const_iv (MAP_SAVING) 1626 const_iv (MAP_SAVING)
1607 1627
1608 const_iv (KLASS_GLOBAL) 1628 const_iv (KLASS_GLOBAL)
1609 const_iv (KLASS_OBJECT) 1629 const_iv (KLASS_OBJECT)
1630 const_iv (KLASS_CLIENT)
1610 const_iv (KLASS_PLAYER) 1631 const_iv (KLASS_PLAYER)
1611 const_iv (KLASS_MAP) 1632 const_iv (KLASS_MAP)
1633
1634 const_iv (CS_QUERY_YESNO)
1635 const_iv (CS_QUERY_SINGLECHAR)
1636 const_iv (CS_QUERY_HIDEINPUT)
1637
1638 const_iv (ST_DEAD)
1639 const_iv (ST_SETUP)
1640 const_iv (ST_PLAYING)
1641 const_iv (ST_CUSTOM)
1642
1643 const_iv (ST_CHANGE_CLASS)
1644 const_iv (ST_CONFIRM_QUIT)
1645 const_iv (ST_GET_PARTY_PASSWORD)
1612 }; 1646 };
1613 1647
1614 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1648 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1615 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1649 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1616 1650
1640void _init_vars () 1674void _init_vars ()
1641 CODE: 1675 CODE:
1642 cb_global = get_av ("cf::CB_GLOBAL", 1); 1676 cb_global = get_av ("cf::CB_GLOBAL", 1);
1643 cb_object = get_av ("cf::CB_OBJECT", 1); 1677 cb_object = get_av ("cf::CB_OBJECT", 1);
1644 cb_player = get_av ("cf::CB_PLAYER", 1); 1678 cb_player = get_av ("cf::CB_PLAYER", 1);
1679 cb_client = get_av ("cf::CB_CLIENT", 1);
1645 cb_type = get_av ("cf::CB_TYPE" , 1); 1680 cb_type = get_av ("cf::CB_TYPE" , 1);
1646 cb_map = get_av ("cf::CB_MAP" , 1); 1681 cb_map = get_av ("cf::CB_MAP" , 1);
1647 1682
1648void _global_reattach () 1683void _global_reattach ()
1649 CODE: 1684 CODE:
1650{ 1685{
1651 // reattach to all attachable objects in the game. 1686 // reattach to all attachable objects in the game.
1687 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
1688 reattach (*i);
1689
1652 for (player *pl = first_player; pl; pl = pl->next) 1690 for (player *pl = first_player; pl; pl = pl->next)
1653 reattach (pl); 1691 reattach (pl);
1654 1692
1655 for (maptile *map = first_map; map; map = map->next) 1693 for (maptile *map = first_map; map; map = map->next)
1656 reattach (map); 1694 reattach (map);
1657 1695
1658 for (object *op = object::first; op; op = op->next) 1696 for (object *op = object::first; op; op = op->next)
1659 reattach (op); 1697 reattach (op);
1660} 1698}
1661
1662bool
1663add_client_socket (int fd, const char *peername)
1664 1699
1665NV floor (NV x) 1700NV floor (NV x)
1666 1701
1667NV ceil (NV x) 1702NV ceil (NV x)
1668 1703
1723 1758
1724int random_roll (int min, int max, object *op, int goodbad); 1759int random_roll (int min, int max, object *op, int goodbad);
1725 1760
1726const char *cost_string_from_value(uint64 cost, int approx = 0) 1761const char *cost_string_from_value(uint64 cost, int approx = 0)
1727 1762
1728int invoke (int event, ...)
1729 CODE:
1730 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1731 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1732 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1733 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1734 OUTPUT: RETVAL
1735
1736int 1763int
1737exp_to_level (val64 exp) 1764exp_to_level (val64 exp)
1738 CODE: 1765 CODE:
1739{ 1766{
1740 int i = 0; 1767 int i = 0;
1770 RETVAL = newSVpv (resist_plus[atnr], 0); 1797 RETVAL = newSVpv (resist_plus[atnr], 0);
1771 else 1798 else
1772 XSRETURN_UNDEF; 1799 XSRETURN_UNDEF;
1773 OUTPUT: RETVAL 1800 OUTPUT: RETVAL
1774 1801
1802MODULE = cf PACKAGE = cf::attachable
1803
1775int 1804int
1776_valid (SV *obj) 1805valid (SV *obj)
1777 CODE: 1806 CODE:
1778 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1807 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1779 OUTPUT: 1808 OUTPUT:
1780 RETVAL 1809 RETVAL
1810
1811MODULE = cf PACKAGE = cf::global
1812
1813int invoke (SV *klass, int event, ...)
1814 CODE:
1815 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1816 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1817 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1818 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1819 OUTPUT: RETVAL
1781 1820
1782MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1821MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1783 1822
1784INCLUDE: $PERL genacc object ../include/object.h | 1823INCLUDE: $PERL genacc object ../include/object.h |
1785 1824
1804 RETVAL = object::first; 1843 RETVAL = object::first;
1805 OUTPUT: RETVAL 1844 OUTPUT: RETVAL
1806 1845
1807# missing properties 1846# missing properties
1808 1847
1809int flag (object *op, int flag, int value = 1)
1810 PROTOTYPE: $$;$
1811 CODE:
1812 RETVAL = QUERY_FLAG (op, flag);
1813 if (items >= 3)
1814 if (value)
1815 SET_FLAG (op, flag);
1816 else
1817 CLEAR_FLAG (op, flag);
1818 OUTPUT: RETVAL
1819
1820object *head (object *op) 1848object *head (object *op)
1821 PROTOTYPE: $ 1849 PROTOTYPE: $
1822 CODE: 1850 CODE:
1823 RETVAL = op->head ? op->head : op; 1851 RETVAL = op->head ? op->head : op;
1824 OUTPUT: RETVAL 1852 OUTPUT: RETVAL
1834 PROTOTYPE: $ 1862 PROTOTYPE: $
1835 PPCODE: 1863 PPCODE:
1836{ 1864{
1837 object *o; 1865 object *o;
1838 for (o = obj->inv; o; o = o->below) 1866 for (o = obj->inv; o; o = o->below)
1839 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1867 XPUSHs (sv_2mortal (to_sv (o)));
1840} 1868}
1869
1870void
1871set_animation (object *op, int idx)
1872 CODE:
1873 SET_ANIMATION (op, idx);
1874
1875void
1876object::drain_stat ()
1877
1878void
1879object::drain_specific_stat (int stat)
1880
1881void
1882object::change_luck (int change)
1883
1884void
1885object::add_statbonus ()
1886
1887void
1888object::remove_statbonus ()
1841 1889
1842object *find_best_object_match (object *op, const char *match) 1890object *find_best_object_match (object *op, const char *match)
1843 1891
1844object *find_marked_object (object *op) 1892object *find_marked_object (object *op)
1845
1846int resistance (object *op, int rtype, int newval = 0)
1847 CODE:
1848 if (rtype < 0 || rtype >= NROFATTACKS)
1849 croak ("resistance out of bounds");
1850 RETVAL = op->resist [rtype];
1851 if (items >= 3)
1852 op->resist [rtype] = newval;
1853 OUTPUT: RETVAL
1854
1855void set_resistance (object *op, int rtype, int val)
1856 CODE:
1857 if (rtype < 0 || rtype >= NROFATTACKS)
1858 op->resist[rtype] = val;
1859 1893
1860int need_identify (const object *obj); 1894int need_identify (const object *obj);
1861 1895
1862int apply_shop_mat (object *shop_mat, object *op); 1896int apply_shop_mat (object *shop_mat, object *op);
1863 1897
1877 1911
1878void remove (object *op) 1912void remove (object *op)
1879 CODE: 1913 CODE:
1880 op->remove (); 1914 op->remove ();
1881 1915
1882void destroy (object *op, int recursive = 0) 1916void
1883 CODE: 1917object::destroy (int recursive = 0)
1884 op->destroy (recursive);
1885 1918
1886object *cf_object_present_archname_inside (object *op, char *whatstr) 1919object *cf_object_present_archname_inside (object *op, char *whatstr)
1887 1920
1888int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1921int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1889 1922
1947 1980
1948object *cf_object_insert_in_ob (object *ob, object *where) 1981object *cf_object_insert_in_ob (object *ob, object *where)
1949 1982
1950int cf_object_teleport (object *op, maptile *map, int x, int y) 1983int cf_object_teleport (object *op, maptile *map, int x, int y)
1951 1984
1952void update (object *op, int action) 1985void update_object (object *op, int action)
1953 CODE:
1954 update_object (op, action);
1955 1986
1956object *cf_create_object_by_name (const char *name) 1987object *cf_create_object_by_name (const char *name)
1957 1988
1958void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1989void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1959 1990
1971 2002
1972void remove_button_link (object *op); 2003void remove_button_link (object *op);
1973 2004
1974 2005
1975MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2006MODULE = cf PACKAGE = cf::object PREFIX = cf_
1976
1977void cf_fix_object (object *pl)
1978 ALIAS: fix = 0
1979 2007
1980object *cf_insert_ob_in_ob (object *ob, object *where) 2008object *cf_insert_ob_in_ob (object *ob, object *where)
1981 2009
1982# no clean way to get an object from an archetype - stupid idiotic 2010# no clean way to get an object from an archetype - stupid idiotic
1983# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2011# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2006 2034
2007player *contr (object *op) 2035player *contr (object *op)
2008 CODE: 2036 CODE:
2009 RETVAL = op->contr; 2037 RETVAL = op->contr;
2010 OUTPUT: RETVAL 2038 OUTPUT: RETVAL
2039
2040void
2041object::roll_stats ()
2042
2043void
2044object::update_stats ()
2045
2046void
2047object::swap_stats (int a, int b)
2011 2048
2012const char *get_ob_key_value (object *op, const char *key) 2049const char *get_ob_key_value (object *op, const char *key)
2013 2050
2014bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 2051bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
2015 2052
2041base_name (object *op, int plural = op->nrof > 1) 2078base_name (object *op, int plural = op->nrof > 1)
2042 CODE: 2079 CODE:
2043 RETVAL = query_base_name (op, plural); 2080 RETVAL = query_base_name (op, plural);
2044 OUTPUT: RETVAL 2081 OUTPUT: RETVAL
2045 2082
2083object *decrease_ob_nr (object *op, unsigned long i)
2084
2046MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 2085MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
2047 2086
2048player *player (object *op) 2087player *player (object *op)
2049 CODE: 2088 CODE:
2050 RETVAL = op->contr; 2089 RETVAL = op->contr;
2051 OUTPUT: RETVAL 2090 OUTPUT: RETVAL
2052 2091
2092void check_score (object *op)
2093
2053void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2094void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2054 2095
2055object *cf_player_send_inventory (object *op) 2096object *cf_player_send_inventory (object *op)
2056 2097
2057char *cf_player_get_ip (object *op) 2098char *cf_player_get_ip (object *op)
2088 2129
2089 2130
2090MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2131MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2091 2132
2092INCLUDE: $PERL genacc player ../include/player.h | 2133INCLUDE: $PERL genacc player ../include/player.h |
2093
2094char *
2095client (player *pl)
2096 CODE:
2097 RETVAL = pl->socket->client;
2098 OUTPUT:
2099 RETVAL
2100
2101char *
2102host (player *pl)
2103 CODE:
2104 RETVAL = pl->socket->host;
2105 OUTPUT:
2106 RETVAL
2107 2134
2108int invoke (player *pl, int event, ...) 2135int invoke (player *pl, int event, ...)
2109 CODE: 2136 CODE:
2110 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2137 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
2111 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2138 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2113 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); 2140 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av));
2114 OUTPUT: RETVAL 2141 OUTPUT: RETVAL
2115 2142
2116SV *registry (player *pl) 2143SV *registry (player *pl)
2117 2144
2145player *
2146create ()
2147 CODE:
2148 RETVAL = player::create ();
2149 OUTPUT:
2150 RETVAL
2151
2152player *
2153load (const char *path)
2154 CODE:
2155 RETVAL = player::load (path);
2156 OUTPUT:
2157 RETVAL
2158
2159void
2160player::save (bool final = false)
2161
2162void
2163player::connect (client *ns)
2164
2165void
2166save_stats (player *pl)
2167 CODE:
2168 pl->ob->stats.hp = pl->ob->stats.maxhp;
2169 pl->ob->stats.sp = pl->ob->stats.maxsp;
2170 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2171 pl->orig_stats = pl->ob->stats;
2172
2118player *cf_player_find (char *name) 2173player *cf_player_find (char *name)
2119 PROTOTYPE: $ 2174 PROTOTYPE: $
2120 2175
2121void cf_player_move (player *pl, int dir) 2176void cf_player_move (player *pl, int dir)
2122 2177
2125player *first () 2180player *first ()
2126 CODE: 2181 CODE:
2127 RETVAL = first_player; 2182 RETVAL = first_player;
2128 OUTPUT: RETVAL 2183 OUTPUT: RETVAL
2129 2184
2130player *next (player *pl)
2131 CODE:
2132 RETVAL = pl->next;
2133 OUTPUT: RETVAL
2134
2135bool 2185bool
2136cell_visible (player *pl, int dx, int dy) 2186cell_visible (player *pl, int dx, int dy)
2137 CODE: 2187 CODE:
2138 RETVAL = FABS (dx) <= pl->socket->mapx / 2 && FABS (dy) <= pl->socket->mapy / 2 2188 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2139 && !pl->blocked_los [dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]; 2189 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2140 OUTPUT: 2190 OUTPUT:
2141 RETVAL 2191 RETVAL
2142 2192
2143void 2193void
2144buggy_mapscroll (player *pl, int value = 1)
2145 CODE:
2146 pl->socket->buggy_mapscroll = value;
2147
2148void
2149send (player *pl, SV *packet) 2194send (player *pl, SV *packet)
2150 CODE: 2195 CODE:
2151{ 2196{
2152 STRLEN len; 2197 STRLEN len;
2153 char *buf = SvPVbyte (packet, len); 2198 char *buf = SvPVbyte (packet, len);
2154 2199
2200 if (pl->ns)
2155 pl->socket->send_packet (buf, len); 2201 pl->ns->send_packet (buf, len);
2156} 2202}
2157 2203
2158int 2204int
2159listening (player *pl, int new_value = -1) 2205listening (player *pl, int new_value = -1)
2160 CODE: 2206 CODE:
2179 if (y) sv_to (y, pl->bed_y); 2225 if (y) sv_to (y, pl->bed_y);
2180 2226
2181void 2227void
2182list () 2228list ()
2183 PPCODE: 2229 PPCODE:
2184{
2185 player *pl;
2186 for (pl = first_player; pl; pl = pl->next) 2230 for (player *pl = first_player; pl; pl = pl->next)
2187 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 2231 XPUSHs (sv_2mortal (to_sv (pl)));
2188}
2189 2232
2190bool 2233bool
2191peaceful (player *pl, bool new_setting = 0) 2234peaceful (player *pl, bool new_setting = 0)
2192 PROTOTYPE: $;$ 2235 PROTOTYPE: $;$
2193 CODE: 2236 CODE:
2441 2484
2442MODULE = cf PACKAGE = cf::settings 2485MODULE = cf PACKAGE = cf::settings
2443 2486
2444INCLUDE: $PERL genacc Settings ../include/global.h | 2487INCLUDE: $PERL genacc Settings ../include/global.h |
2445 2488
2446MODULE = cf PACKAGE = cf::client_socket 2489MODULE = cf PACKAGE = cf::client
2447 2490
2448INCLUDE: $PERL genacc client_socket ../include/newserver.h | 2491INCLUDE: $PERL genacc client ../include/client.h |
2449 2492
2450int invoke (client_socket *ns, int event, ...) 2493int invoke (client *ns, int event, ...)
2451 CODE: 2494 CODE:
2452 if (KLASS_OF (event) != KLASS_SOCKET) croak ("event class must be SOCKET"); 2495 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2453 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2496 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2454 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 2497 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2455 RETVAL = INVOKE_((event_type)event, ARG_SOCKET (ns), ARG_AV (av)); 2498 RETVAL = INVOKE_((event_type)event, ARG_CLIENT (ns), ARG_AV (av));
2456 OUTPUT: RETVAL 2499 OUTPUT: RETVAL
2457 2500
2458SV *registry (client_socket *ns) 2501SV *registry (client *ns)
2459 2502
2503void
2504list ()
2505 PPCODE:
2506 EXTEND (SP, clients.size ());
2507 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2508 PUSHs (sv_2mortal (to_sv (*i)));
2509
2510client *
2511create (int fd, const char *peername)
2512 CODE:
2513 RETVAL = client::create (fd, peername);
2514 OUTPUT:
2515 RETVAL
2516
2517void
2518client::send_packet (SV *packet)
2519 CODE:
2520{
2521 STRLEN len;
2522 char *buf = SvPVbyte (packet, len);
2523
2524 THIS->send_packet (buf, len);
2525}
2526
2527void
2528client::destroy ()
2529

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines