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.79 by root, Thu Dec 14 05:09:32 2006 UTC vs.
Revision 1.108 by elmex, Mon Dec 25 11:16:48 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>
36 36
37#include <EXTERN.h> 37#include <EXTERN.h>
38#include <perl.h> 38#include <perl.h>
39#include <XSUB.h> 39#include <XSUB.h>
40 40
41#include "CoroAPI.h"
41#include "perlxsi.c" 42#include "perlxsi.c"
42 43
43extern sint64 *levels; // the experience table 44extern sint64 *levels; // the experience table
44 45
45typedef object object_ornull; 46typedef object object_ornull;
59static f_plug_api object_set_property = cfapi_object_set_property; 60static f_plug_api object_set_property = cfapi_object_set_property;
60static f_plug_api object_insert = cfapi_object_insert; 61static f_plug_api object_insert = cfapi_object_insert;
61 62
62static PerlInterpreter *perl; 63static PerlInterpreter *perl;
63 64
64static AV *cb_global, *cb_object, *cb_player, *cb_type, *cb_map; 65static AV *cb_global, *cb_object, *cb_player, *cb_client, *cb_type, *cb_map;
65 66
66////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 67//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
67 68
68static SV * 69static SV *
69newSVptr (void *ptr, const char *klass, HV *hv = newHV ()) 70newSVptr (void *ptr, const char *klass, HV *hv = newHV ())
136inline SV *to_sv (unsigned long v) { return newSVuv (v); } 137inline SV *to_sv (unsigned long v) { return newSVuv (v); }
137inline SV *to_sv ( signed long long v) { return newSVval64 (v); } 138inline SV *to_sv ( signed long long v) { return newSVval64 (v); }
138inline SV *to_sv (unsigned long long v) { return newSVval64 (v); } 139inline SV *to_sv (unsigned long long v) { return newSVval64 (v); }
139inline SV *to_sv (float v) { return newSVnv (v); } 140inline SV *to_sv (float v) { return newSVnv (v); }
140inline SV *to_sv (double v) { return newSVnv (v); } 141inline SV *to_sv (double v) { return newSVnv (v); }
141inline SV *to_sv (client_socket *v) { return newSVattachable (v, "cf::client_socket::wrap"); } 142inline SV *to_sv (client * v) { return newSVattachable (v, "cf::client::wrap"); }
142inline SV *to_sv (player * v) { return newSVattachable (v, "cf::player::wrap"); } 143inline 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"); } 144inline 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"); } 145inline SV *to_sv (maptile * v) { return newSVattachable (v, "cf::map::wrap"); }
145inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); } 146inline SV *to_sv (archetype * v) { return newSVptr (v, "cf::arch::wrap"); }
146inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); } 147inline SV *to_sv (partylist * v) { return newSVptr (v, "cf::party::wrap"); }
174inline void sv_to (SV *sv, unsigned long &v) { v = SvUV (sv); } 175inline 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); } 176inline 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); } 177inline 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); } 178inline void sv_to (SV *sv, float &v) { v = SvNV (sv); }
178inline void sv_to (SV *sv, double &v) { v = SvNV (sv); } 179inline 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"); } 180inline 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"); } 181inline 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"); } 182inline 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"); } 183inline 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"); } 184inline 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"); } 185inline 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; } 193inline void sv_to (SV *sv, refptr<T> &v) { T *tmp; sv_to (sv, tmp); v = tmp; }
193 194
194template<int N> 195template<int N>
195inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 196inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
196 197
198inline void sv_to (SV *sv, rangetype &v) { v = (rangetype) SvIV (sv); }
199inline void sv_to (SV *sv, bowtype_t &v) { v = (bowtype_t) SvIV (sv); }
200inline void sv_to (SV *sv, petmode_t &v) { v = (petmode_t) SvIV (sv); }
201inline void sv_to (SV *sv, usekeytype &v) { v = (usekeytype) SvIV (sv); }
202inline void sv_to (SV *sv, unapplymode &v) { v = (unapplymode) SvIV (sv); }
203
197inline void sv_to (SV *sv, UUID &v) 204inline void sv_to (SV *sv, UUID &v)
198{ 205{
199 unsigned int version; 206 unsigned int version;
200 207
201 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version) 208 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version)
202 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 209 croak ("unparsable uuid: %s", SvPV_nolen (sv));
203} 210}
211
212inline void sv_to (SV *sv, object::flags_t::reference v) { v = boolSV (sv); }
204 213
205static SV * 214static SV *
206newSVdt_va (va_list &ap, data_type type) 215newSVdt_va (va_list &ap, data_type type)
207{ 216{
208 SV *sv; 217 SV *sv;
243 case DT_MAP: 252 case DT_MAP:
244 // va_arg (object *) when void * is passed is an XSI extension 253 // va_arg (object *) when void * is passed is an XSI extension
245 sv = to_sv (va_arg (ap, maptile *)); 254 sv = to_sv (va_arg (ap, maptile *));
246 break; 255 break;
247 256
248 case DT_SOCKET: 257 case DT_CLIENT:
249 sv = to_sv (va_arg (ap, client_socket *)); 258 sv = to_sv (va_arg (ap, client *));
250 break; 259 break;
251 260
252 case DT_PLAYER: 261 case DT_PLAYER:
253 sv = to_sv (va_arg (ap, player *)); 262 sv = to_sv (va_arg (ap, player *));
254 break; 263 break;
361 370
362 HV *hv = (HV *)SvRV ((SV *)self); 371 HV *hv = (HV *)SvRV ((SV *)self);
363 372
364 if (SvREFCNT ((SV *)self) == 1 373 if (SvREFCNT ((SV *)self) == 1
365 && SvREFCNT ((SV *)hv) == 1 374 && SvREFCNT ((SV *)hv) == 1
366 && !HvKEYS (hv)) 375 && !HvTOTALKEYS (hv))
367 { 376 {
368 SvREFCNT_dec ((SV *)self); 377 SvREFCNT_dec ((SV *)self);
369 self = 0; 378 self = 0;
370 } 379 }
371} 380}
412 421
413 switch (type) 422 switch (type)
414 { 423 {
415 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; 424 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break;
416 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; 425 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break;
426 case DT_CLIENT: INVOKE_CLIENT (REATTACH, obj); break;
417 case DT_MAP: INVOKE_MAP (REATTACH, obj); break; 427 case DT_MAP: INVOKE_MAP (REATTACH, obj); break;
418 } 428 }
419} 429}
420 430
421template<class subclass> 431template<class subclass>
834 PL_exit_flags |= PERL_EXIT_DESTRUCT_END; 844 PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
835 845
836 char *argv[] = { 846 char *argv[] = {
837 "", 847 "",
838 "-e" 848 "-e"
839 "cf->bootstrap;" 849 "use Event; use Coro;" // required for bootstrap
850 "cf->bootstrap;" // required for datadir :*>
840 "unshift @INC, cf::datadir ();" 851 "unshift @INC, cf::datadir ();"
841 "require cf;" 852 "require cf;"
842 }; 853 };
843 854
844 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl)) 855 if (perl_parse (perl, xs_init, 2, argv, (char **)NULL) || perl_run (perl))
905 AV *callbacks = 0; 916 AV *callbacks = 0;
906 917
907 object *op; 918 object *op;
908 player *pl; 919 player *pl;
909 maptile *map; 920 maptile *map;
921 client *ns;
910 922
911 // callback call ordering is: 923 // callback call ordering is:
912 // 1. per-object callback 924 // 1. per-object callback
913 // 2. per-class object 925 // 2. per-class object
914 // 3. per-type callback 926 // 3. per-type callback
972 gather_callbacks (callbacks, map->cb, event); 984 gather_callbacks (callbacks, map->cb, event);
973 985
974 gather_callbacks (callbacks, cb_map, event); 986 gather_callbacks (callbacks, cb_map, event);
975 break; 987 break;
976 988
989 case KLASS_CLIENT:
990 dt = (data_type) va_arg (ap, int);
991 assert (("first argument must be of type client", dt == DT_CLIENT));
992 ns = va_arg (ap, client *);
993
994 if (ns->cb)
995 gather_callbacks (callbacks, ns->cb, event);
996
997 gather_callbacks (callbacks, cb_client, event);
998 break;
999
977 default: 1000 default:
978 assert (("unsupported event klass in cfperl_invoke", 0)); 1001 assert (("unsupported event klass in cfperl_invoke", 0));
979 } 1002 }
980 1003
981 // short-circuit processing if no callbacks found/defined 1004 // short-circuit processing if no callbacks found/defined
994 1017
995 switch (KLASS_OF (event)) 1018 switch (KLASS_OF (event))
996 { 1019 {
997 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; 1020 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break;
998 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; 1021 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break;
1022 case KLASS_CLIENT: PUSHs (sv_2mortal (newSVdt (DT_CLIENT, ns))); break;
999 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; 1023 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break;
1000 } 1024 }
1001 1025
1002 for (;;) 1026 for (;;)
1003 { 1027 {
1055cfperl_result_DOUBLE (int idx) 1079cfperl_result_DOUBLE (int idx)
1056{ 1080{
1057 return SvNV (cfperl_result (idx)); 1081 return SvNV (cfperl_result (idx));
1058} 1082}
1059 1083
1084/////////////////////////////////////////////////////////////////////////////
1085
1086struct EventAPI *watcher_base::GEventAPI;
1087
1088static void iw_dispatch (pe_event *ev)
1089{
1090 iw *w = (iw *)ev->ext_data;
1091 w->call (*w);
1092}
1093
1094void
1095iw::alloc ()
1096{
1097 pe = GEventAPI->new_idle (0, 0);
1098
1099 pe->base.callback = (void *)iw_dispatch;
1100 pe->base.ext_data = (void *)this;
1101}
1102
1103static void iow_dispatch (pe_event *ev)
1104{
1105 iow *w = (iow *)ev->ext_data;
1106 w->call (*w, ((pe_ioevent *)ev)->got);
1107}
1108
1109void
1110iow::alloc ()
1111{
1112 pe = GEventAPI->new_io (0, 0);
1113
1114 pe->base.callback = (void *)iow_dispatch;
1115 pe->base.ext_data = (void *)this;
1116
1117 pe->fd = -1;
1118 pe->poll = 0;
1119}
1120
1121void
1122iow::fd (int fd)
1123{
1124 pe->fd = fd;
1125}
1126
1127int
1128iow::poll ()
1129{
1130 return pe->poll;
1131}
1132
1133void
1134iow::poll (int events)
1135{
1136 if (pe->poll != events)
1137 {
1138 if (pe->poll) stop ();
1139 pe->poll = events;
1140 if (pe->poll) start ();
1141 }
1142}
1143
1060MODULE = cf PACKAGE = cf PREFIX = cf_ 1144MODULE = cf PACKAGE = cf PREFIX = cf_
1061 1145
1062BOOT: 1146BOOT:
1063{ 1147{
1064 HV *stash = gv_stashpv ("cf", 1); 1148 HV *stash = gv_stashpv ("cf", 1);
1149
1150 I_EVENT_API (PACKAGE);
1151 watcher_base::GEventAPI = GEventAPI;
1152 I_CORO_API (PACKAGE);
1065 1153
1066 newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1)); 1154 newCONSTSUB (stash, "VERSION", newSVpv (VERSION, sizeof (VERSION) - 1));
1067 1155
1068 static const struct { 1156 static const struct {
1069 const char *name; 1157 const char *name;
1083 const_iv (POTION) 1171 const_iv (POTION)
1084 const_iv (FOOD) 1172 const_iv (FOOD)
1085 const_iv (POISON) 1173 const_iv (POISON)
1086 const_iv (BOOK) 1174 const_iv (BOOK)
1087 const_iv (CLOCK) 1175 const_iv (CLOCK)
1088 const_iv (LIGHTNING)
1089 const_iv (ARROW) 1176 const_iv (ARROW)
1090 const_iv (BOW) 1177 const_iv (BOW)
1091 const_iv (WEAPON) 1178 const_iv (WEAPON)
1092 const_iv (ARMOUR) 1179 const_iv (ARMOUR)
1093 const_iv (PEDESTAL) 1180 const_iv (PEDESTAL)
1113 const_iv (AMULET) 1200 const_iv (AMULET)
1114 const_iv (PLAYERMOVER) 1201 const_iv (PLAYERMOVER)
1115 const_iv (TELEPORTER) 1202 const_iv (TELEPORTER)
1116 const_iv (CREATOR) 1203 const_iv (CREATOR)
1117 const_iv (SKILL) 1204 const_iv (SKILL)
1118 const_iv (EXPERIENCE)
1119 const_iv (EARTHWALL) 1205 const_iv (EARTHWALL)
1120 const_iv (GOLEM) 1206 const_iv (GOLEM)
1121 const_iv (THROWN_OBJ) 1207 const_iv (THROWN_OBJ)
1122 const_iv (BLINDNESS) 1208 const_iv (BLINDNESS)
1123 const_iv (GOD) 1209 const_iv (GOD)
1143 const_iv (FLOOR) 1229 const_iv (FLOOR)
1144 const_iv (FLESH) 1230 const_iv (FLESH)
1145 const_iv (INORGANIC) 1231 const_iv (INORGANIC)
1146 const_iv (SKILL_TOOL) 1232 const_iv (SKILL_TOOL)
1147 const_iv (LIGHTER) 1233 const_iv (LIGHTER)
1148 const_iv (TRAP_PART)
1149 const_iv (WALL) 1234 const_iv (BUILDABLE_WALL)
1150 const_iv (LIGHT_SOURCE)
1151 const_iv (MISC_OBJECT) 1235 const_iv (MISC_OBJECT)
1152 const_iv (MONSTER)
1153 const_iv (SPAWN_GENERATOR)
1154 const_iv (LAMP) 1236 const_iv (LAMP)
1155 const_iv (DUPLICATOR) 1237 const_iv (DUPLICATOR)
1156 const_iv (TOOL)
1157 const_iv (SPELLBOOK) 1238 const_iv (SPELLBOOK)
1158 const_iv (BUILDFAC)
1159 const_iv (CLOAK) 1239 const_iv (CLOAK)
1160 const_iv (SPINNER) 1240 const_iv (SPINNER)
1161 const_iv (GATE) 1241 const_iv (GATE)
1162 const_iv (BUTTON) 1242 const_iv (BUTTON)
1163 const_iv (CF_HANDLE) 1243 const_iv (CF_HANDLE)
1170 const_iv (SPELL_EFFECT) 1250 const_iv (SPELL_EFFECT)
1171 const_iv (CONVERTER) 1251 const_iv (CONVERTER)
1172 const_iv (BRACERS) 1252 const_iv (BRACERS)
1173 const_iv (POISONING) 1253 const_iv (POISONING)
1174 const_iv (SAVEBED) 1254 const_iv (SAVEBED)
1175 const_iv (POISONCLOUD)
1176 const_iv (FIREHOLES)
1177 const_iv (WAND) 1255 const_iv (WAND)
1178 const_iv (SCROLL) 1256 const_iv (SCROLL)
1179 const_iv (DIRECTOR) 1257 const_iv (DIRECTOR)
1180 const_iv (GIRDLE) 1258 const_iv (GIRDLE)
1181 const_iv (FORCE) 1259 const_iv (FORCE)
1196 const_iv (DISEASE) 1274 const_iv (DISEASE)
1197 const_iv (SYMPTOM) 1275 const_iv (SYMPTOM)
1198 const_iv (BUILDER) 1276 const_iv (BUILDER)
1199 const_iv (MATERIAL) 1277 const_iv (MATERIAL)
1200 const_iv (ITEM_TRANSFORMER) 1278 const_iv (ITEM_TRANSFORMER)
1201 const_iv (QUEST)
1202 1279
1203 const_iv (NUM_SUBTYPES) 1280 const_iv (NUM_SUBTYPES)
1204 1281
1205 const_iv (ST_BD_BUILD) 1282 const_iv (ST_BD_BUILD)
1206 const_iv (ST_BD_REMOVE) 1283 const_iv (ST_BD_REMOVE)
1259 const_iv (FLAG_MONSTER) 1336 const_iv (FLAG_MONSTER)
1260 const_iv (FLAG_FRIENDLY) 1337 const_iv (FLAG_FRIENDLY)
1261 const_iv (FLAG_GENERATOR) 1338 const_iv (FLAG_GENERATOR)
1262 const_iv (FLAG_IS_THROWN) 1339 const_iv (FLAG_IS_THROWN)
1263 const_iv (FLAG_AUTO_APPLY) 1340 const_iv (FLAG_AUTO_APPLY)
1264 const_iv (FLAG_TREASURE)
1265 const_iv (FLAG_PLAYER_SOLD) 1341 const_iv (FLAG_PLAYER_SOLD)
1266 const_iv (FLAG_SEE_INVISIBLE) 1342 const_iv (FLAG_SEE_INVISIBLE)
1267 const_iv (FLAG_CAN_ROLL) 1343 const_iv (FLAG_CAN_ROLL)
1268 const_iv (FLAG_OVERLAY_FLOOR) 1344 const_iv (FLAG_OVERLAY_FLOOR)
1269 const_iv (FLAG_IS_TURNABLE) 1345 const_iv (FLAG_IS_TURNABLE)
1344 const_iv (FLAG_ACTIVATE_ON_RELEASE) 1420 const_iv (FLAG_ACTIVATE_ON_RELEASE)
1345 const_iv (FLAG_IS_WATER) 1421 const_iv (FLAG_IS_WATER)
1346 const_iv (FLAG_CONTENT_ON_GEN) 1422 const_iv (FLAG_CONTENT_ON_GEN)
1347 const_iv (FLAG_IS_A_TEMPLATE) 1423 const_iv (FLAG_IS_A_TEMPLATE)
1348 const_iv (FLAG_IS_BUILDABLE) 1424 const_iv (FLAG_IS_BUILDABLE)
1349 const_iv (FLAG_AFK)
1350 1425
1351 const_iv (NDI_BLACK) 1426 const_iv (NDI_BLACK)
1352 const_iv (NDI_WHITE) 1427 const_iv (NDI_WHITE)
1353 const_iv (NDI_NAVY) 1428 const_iv (NDI_NAVY)
1354 const_iv (NDI_RED) 1429 const_iv (NDI_RED)
1392 const_iv (F_BUY) 1467 const_iv (F_BUY)
1393 const_iv (F_SHOP) 1468 const_iv (F_SHOP)
1394 const_iv (F_SELL) 1469 const_iv (F_SELL)
1395 1470
1396 const_iv (P_BLOCKSVIEW) 1471 const_iv (P_BLOCKSVIEW)
1472 const_iv (P_PLAYER)
1397 const_iv (P_NO_MAGIC) 1473 const_iv (P_NO_MAGIC)
1398 const_iv (P_IS_ALIVE) 1474 const_iv (P_IS_ALIVE)
1399 const_iv (P_NO_CLERIC) 1475 const_iv (P_NO_CLERIC)
1400 const_iv (P_NEED_UPDATE) 1476 const_iv (P_NEED_UPDATE)
1401 const_iv (P_NO_ERROR)
1402 const_iv (P_OUT_OF_MAP) 1477 const_iv (P_OUT_OF_MAP)
1403 const_iv (P_NEW_MAP) 1478 const_iv (P_NEW_MAP)
1404 1479
1405 const_iv (UP_OBJ_INSERT) 1480 const_iv (UP_OBJ_INSERT)
1406 const_iv (UP_OBJ_REMOVE) 1481 const_iv (UP_OBJ_REMOVE)
1552 const_iv (MAP_LOADING) 1627 const_iv (MAP_LOADING)
1553 const_iv (MAP_SAVING) 1628 const_iv (MAP_SAVING)
1554 1629
1555 const_iv (KLASS_GLOBAL) 1630 const_iv (KLASS_GLOBAL)
1556 const_iv (KLASS_OBJECT) 1631 const_iv (KLASS_OBJECT)
1632 const_iv (KLASS_CLIENT)
1557 const_iv (KLASS_PLAYER) 1633 const_iv (KLASS_PLAYER)
1558 const_iv (KLASS_MAP) 1634 const_iv (KLASS_MAP)
1635
1636 const_iv (CS_QUERY_YESNO)
1637 const_iv (CS_QUERY_SINGLECHAR)
1638 const_iv (CS_QUERY_HIDEINPUT)
1639
1640 const_iv (ST_DEAD)
1641 const_iv (ST_SETUP)
1642 const_iv (ST_PLAYING)
1643 const_iv (ST_CUSTOM)
1644
1645 const_iv (ST_CHANGE_CLASS)
1646 const_iv (ST_CONFIRM_QUIT)
1647 const_iv (ST_GET_PARTY_PASSWORD)
1559 }; 1648 };
1560 1649
1561 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1650 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1562 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1651 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1563 1652
1580 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0)); 1669 av_push (event, newSVpv ((char *)eiv->name + eiv->skip, 0));
1581 av_push (event, newSViv (eiv->klass)); 1670 av_push (event, newSViv (eiv->klass));
1582 av_store (av, eiv->iv, newRV_noinc ((SV *)event)); 1671 av_store (av, eiv->iv, newRV_noinc ((SV *)event));
1583 newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv)); 1672 newCONSTSUB (stash, (char *)eiv->name, newSViv (eiv->iv));
1584 } 1673 }
1585
1586 //I_EVENT_API (PACKAGE);
1587} 1674}
1588 1675
1589void _init_vars () 1676void _init_vars ()
1590 CODE: 1677 CODE:
1591 cb_global = get_av ("cf::CB_GLOBAL", 1); 1678 cb_global = get_av ("cf::CB_GLOBAL", 1);
1592 cb_object = get_av ("cf::CB_OBJECT", 1); 1679 cb_object = get_av ("cf::CB_OBJECT", 1);
1593 cb_player = get_av ("cf::CB_PLAYER", 1); 1680 cb_player = get_av ("cf::CB_PLAYER", 1);
1681 cb_client = get_av ("cf::CB_CLIENT", 1);
1594 cb_type = get_av ("cf::CB_TYPE" , 1); 1682 cb_type = get_av ("cf::CB_TYPE" , 1);
1595 cb_map = get_av ("cf::CB_MAP" , 1); 1683 cb_map = get_av ("cf::CB_MAP" , 1);
1596 1684
1597void _global_reattach () 1685void _global_reattach ()
1598 CODE: 1686 CODE:
1599{ 1687{
1600 // reattach to all attachable objects in the game. 1688 // reattach to all attachable objects in the game.
1689 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
1690 reattach (*i);
1691
1601 for (player *pl = first_player; pl; pl = pl->next) 1692 for (player *pl = first_player; pl; pl = pl->next)
1602 reattach (pl); 1693 reattach (pl);
1603 1694
1604 for (maptile *map = first_map; map; map = map->next) 1695 for (maptile *map = first_map; map; map = map->next)
1605 reattach (map); 1696 reattach (map);
1606 1697
1607 for (object *op = object::first; op; op = op->next) 1698 for (object *op = object::first; op; op = op->next)
1608 reattach (op); 1699 reattach (op);
1609} 1700}
1610
1611bool
1612add_client_socket (int fd, const char *peername)
1613 1701
1614NV floor (NV x) 1702NV floor (NV x)
1615 1703
1616NV ceil (NV x) 1704NV ceil (NV x)
1617 1705
1672 1760
1673int random_roll (int min, int max, object *op, int goodbad); 1761int random_roll (int min, int max, object *op, int goodbad);
1674 1762
1675const char *cost_string_from_value(uint64 cost, int approx = 0) 1763const char *cost_string_from_value(uint64 cost, int approx = 0)
1676 1764
1677int invoke (int event, ...)
1678 CODE:
1679 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1680 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1681 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1682 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1683 OUTPUT: RETVAL
1684
1685int 1765int
1686exp_to_level (val64 exp) 1766exp_to_level (val64 exp)
1687 CODE: 1767 CODE:
1688{ 1768{
1689 int i = 0; 1769 int i = 0;
1719 RETVAL = newSVpv (resist_plus[atnr], 0); 1799 RETVAL = newSVpv (resist_plus[atnr], 0);
1720 else 1800 else
1721 XSRETURN_UNDEF; 1801 XSRETURN_UNDEF;
1722 OUTPUT: RETVAL 1802 OUTPUT: RETVAL
1723 1803
1804MODULE = cf PACKAGE = cf::attachable
1805
1724int 1806int
1725_valid (SV *obj) 1807valid (SV *obj)
1726 CODE: 1808 CODE:
1727 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1809 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1728 OUTPUT: 1810 OUTPUT:
1729 RETVAL 1811 RETVAL
1812
1813MODULE = cf PACKAGE = cf::global
1814
1815int invoke (SV *klass, int event, ...)
1816 CODE:
1817 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1818 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1819 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1820 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1821 OUTPUT: RETVAL
1730 1822
1731MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1823MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1732 1824
1733INCLUDE: $PERL genacc object ../include/object.h | 1825INCLUDE: $PERL genacc object ../include/object.h |
1734 1826
1753 RETVAL = object::first; 1845 RETVAL = object::first;
1754 OUTPUT: RETVAL 1846 OUTPUT: RETVAL
1755 1847
1756# missing properties 1848# missing properties
1757 1849
1758int flag (object *op, int flag, int value = 1)
1759 PROTOTYPE: $$;$
1760 CODE:
1761 RETVAL = QUERY_FLAG (op, flag);
1762 if (items >= 3)
1763 if (value)
1764 SET_FLAG (op, flag);
1765 else
1766 CLEAR_FLAG (op, flag);
1767 OUTPUT: RETVAL
1768
1769object *head (object *op) 1850object *head (object *op)
1770 PROTOTYPE: $ 1851 PROTOTYPE: $
1771 CODE: 1852 CODE:
1772 RETVAL = op->head ? op->head : op; 1853 RETVAL = op->head ? op->head : op;
1773 OUTPUT: RETVAL 1854 OUTPUT: RETVAL
1783 PROTOTYPE: $ 1864 PROTOTYPE: $
1784 PPCODE: 1865 PPCODE:
1785{ 1866{
1786 object *o; 1867 object *o;
1787 for (o = obj->inv; o; o = o->below) 1868 for (o = obj->inv; o; o = o->below)
1788 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1869 XPUSHs (sv_2mortal (to_sv (o)));
1789} 1870}
1871
1872void
1873set_animation (object *op, int idx)
1874 CODE:
1875 SET_ANIMATION (op, idx);
1876
1877void
1878object::drain_stat ()
1879
1880void
1881object::drain_specific_stat (int stat)
1882
1883void
1884object::change_luck (int change)
1885
1886void
1887object::add_statbonus ()
1888
1889void
1890object::remove_statbonus ()
1790 1891
1791object *find_best_object_match (object *op, const char *match) 1892object *find_best_object_match (object *op, const char *match)
1792 1893
1793object *find_marked_object (object *op) 1894object *find_marked_object (object *op)
1794
1795int resistance (object *op, int rtype, int newval = 0)
1796 CODE:
1797 if (rtype < 0 || rtype >= NROFATTACKS)
1798 croak ("resistance out of bounds");
1799 RETVAL = op->resist [rtype];
1800 if (items >= 3)
1801 op->resist [rtype] = newval;
1802 OUTPUT: RETVAL
1803
1804void set_resistance (object *op, int rtype, int val)
1805 CODE:
1806 if (rtype < 0 || rtype >= NROFATTACKS)
1807 op->resist[rtype] = val;
1808 1895
1809int need_identify (const object *obj); 1896int need_identify (const object *obj);
1810 1897
1811int apply_shop_mat (object *shop_mat, object *op); 1898int apply_shop_mat (object *shop_mat, object *op);
1812 1899
1826 1913
1827void remove (object *op) 1914void remove (object *op)
1828 CODE: 1915 CODE:
1829 op->remove (); 1916 op->remove ();
1830 1917
1831void destroy (object *op, int recursive = 0) 1918void
1832 CODE: 1919object::destroy (int recursive = 0)
1833 op->destroy (recursive);
1834 1920
1835object *cf_object_present_archname_inside (object *op, char *whatstr) 1921object *cf_object_present_archname_inside (object *op, char *whatstr)
1836 1922
1837int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1923int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1838 1924
1879 OUTPUT: RETVAL 1965 OUTPUT: RETVAL
1880 1966
1881int query_money (object *op) 1967int query_money (object *op)
1882 ALIAS: money = 0 1968 ALIAS: money = 0
1883 1969
1884int query_cost (object *op, object *who, int flags) 1970val64 query_cost (object *op, object *who, int flags)
1885 ALIAS: cost = 0 1971 ALIAS: cost = 0
1886 1972
1887void spring_trap (object *op, object *victim) 1973void spring_trap (object *op, object *victim)
1888 1974
1889int check_trigger (object *op, object *cause) 1975int check_trigger (object *op, object *cause)
1896 1982
1897object *cf_object_insert_in_ob (object *ob, object *where) 1983object *cf_object_insert_in_ob (object *ob, object *where)
1898 1984
1899int cf_object_teleport (object *op, maptile *map, int x, int y) 1985int cf_object_teleport (object *op, maptile *map, int x, int y)
1900 1986
1901void update (object *op, int action) 1987void update_object (object *op, int action)
1902 CODE:
1903 update_object (op, action);
1904 1988
1905object *cf_create_object_by_name (const char *name) 1989object *cf_create_object_by_name (const char *name)
1906 1990
1907void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1991void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1908 1992
1920 2004
1921void remove_button_link (object *op); 2005void remove_button_link (object *op);
1922 2006
1923 2007
1924MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2008MODULE = cf PACKAGE = cf::object PREFIX = cf_
1925
1926void cf_fix_object (object *pl)
1927 ALIAS: fix = 0
1928 2009
1929object *cf_insert_ob_in_ob (object *ob, object *where) 2010object *cf_insert_ob_in_ob (object *ob, object *where)
1930 2011
1931# no clean way to get an object from an archetype - stupid idiotic 2012# no clean way to get an object from an archetype - stupid idiotic
1932# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2013# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
1955 2036
1956player *contr (object *op) 2037player *contr (object *op)
1957 CODE: 2038 CODE:
1958 RETVAL = op->contr; 2039 RETVAL = op->contr;
1959 OUTPUT: RETVAL 2040 OUTPUT: RETVAL
2041
2042void
2043object::roll_stats ()
2044
2045void
2046object::update_stats ()
2047
2048void
2049object::swap_stats (int a, int b)
1960 2050
1961const char *get_ob_key_value (object *op, const char *key) 2051const char *get_ob_key_value (object *op, const char *key)
1962 2052
1963bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 2053bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
1964 2054
1990base_name (object *op, int plural = op->nrof > 1) 2080base_name (object *op, int plural = op->nrof > 1)
1991 CODE: 2081 CODE:
1992 RETVAL = query_base_name (op, plural); 2082 RETVAL = query_base_name (op, plural);
1993 OUTPUT: RETVAL 2083 OUTPUT: RETVAL
1994 2084
2085object *decrease_ob_nr (object *op, unsigned long i)
2086
1995MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_ 2087MODULE = cf PACKAGE = cf::object::player PREFIX = cf_player_
1996 2088
1997player *player (object *op) 2089player *player (object *op)
1998 CODE: 2090 CODE:
1999 RETVAL = op->contr; 2091 RETVAL = op->contr;
2000 OUTPUT: RETVAL 2092 OUTPUT: RETVAL
2001 2093
2094void check_score (object *op)
2095
2002void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE) 2096void cf_player_message (object *obj, char *txt, int flags = NDI_ORANGE | NDI_UNIQUE)
2003 2097
2004object *cf_player_send_inventory (object *op) 2098object *cf_player_send_inventory (object *op)
2005 2099
2006char *cf_player_get_ip (object *op) 2100char *cf_player_get_ip (object *op)
2037 2131
2038 2132
2039MODULE = cf PACKAGE = cf::player PREFIX = cf_player_ 2133MODULE = cf PACKAGE = cf::player PREFIX = cf_player_
2040 2134
2041INCLUDE: $PERL genacc player ../include/player.h | 2135INCLUDE: $PERL genacc player ../include/player.h |
2042
2043char *
2044client (player *pl)
2045 CODE:
2046 RETVAL = pl->socket->client;
2047 OUTPUT:
2048 RETVAL
2049
2050char *
2051host (player *pl)
2052 CODE:
2053 RETVAL = pl->socket->host;
2054 OUTPUT:
2055 RETVAL
2056 2136
2057int invoke (player *pl, int event, ...) 2137int invoke (player *pl, int event, ...)
2058 CODE: 2138 CODE:
2059 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER"); 2139 if (KLASS_OF (event) != KLASS_PLAYER) croak ("event class must be PLAYER");
2060 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2140 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2062 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); 2142 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av));
2063 OUTPUT: RETVAL 2143 OUTPUT: RETVAL
2064 2144
2065SV *registry (player *pl) 2145SV *registry (player *pl)
2066 2146
2147player *
2148create ()
2149 CODE:
2150 RETVAL = player::create ();
2151 OUTPUT:
2152 RETVAL
2153
2154player *
2155load (const char *path)
2156 CODE:
2157 RETVAL = player::load (path);
2158 OUTPUT:
2159 RETVAL
2160
2161void
2162player::save (bool final = false)
2163
2164void
2165player::connect (client *ns)
2166
2167void
2168save_stats (player *pl)
2169 CODE:
2170 pl->ob->stats.hp = pl->ob->stats.maxhp;
2171 pl->ob->stats.sp = pl->ob->stats.maxsp;
2172 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2173 pl->orig_stats = pl->ob->stats;
2174
2067player *cf_player_find (char *name) 2175player *cf_player_find (char *name)
2068 PROTOTYPE: $ 2176 PROTOTYPE: $
2069 2177
2070void cf_player_move (player *pl, int dir) 2178void cf_player_move (player *pl, int dir)
2071 2179
2074player *first () 2182player *first ()
2075 CODE: 2183 CODE:
2076 RETVAL = first_player; 2184 RETVAL = first_player;
2077 OUTPUT: RETVAL 2185 OUTPUT: RETVAL
2078 2186
2079player *next (player *pl)
2080 CODE:
2081 RETVAL = pl->next;
2082 OUTPUT: RETVAL
2083
2084bool 2187bool
2085cell_visible (player *pl, int dx, int dy) 2188cell_visible (player *pl, int dx, int dy)
2086 CODE: 2189 CODE:
2087 RETVAL = FABS (dx) <= pl->socket->mapx / 2 && FABS (dy) <= pl->socket->mapy / 2 2190 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2088 && !pl->blocked_los [dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]; 2191 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2089 OUTPUT: 2192 OUTPUT:
2090 RETVAL 2193 RETVAL
2091 2194
2092void 2195void
2093buggy_mapscroll (player *pl, int value = 1)
2094 CODE:
2095 pl->socket->buggy_mapscroll = value;
2096
2097void
2098send (player *pl, SV *packet) 2196send (player *pl, SV *packet)
2099 CODE: 2197 CODE:
2100{ 2198{
2101 STRLEN len; 2199 STRLEN len;
2102 char *buf = SvPVbyte (packet, len); 2200 char *buf = SvPVbyte (packet, len);
2103 2201
2202 if (pl->ns)
2104 pl->socket->send_packet (buf, len); 2203 pl->ns->send_packet (buf, len);
2105} 2204}
2106 2205
2107int 2206int
2108listening (player *pl, int new_value = -1) 2207listening (player *pl, int new_value = -1)
2109 CODE: 2208 CODE:
2128 if (y) sv_to (y, pl->bed_y); 2227 if (y) sv_to (y, pl->bed_y);
2129 2228
2130void 2229void
2131list () 2230list ()
2132 PPCODE: 2231 PPCODE:
2133{
2134 player *pl;
2135 for (pl = first_player; pl; pl = pl->next) 2232 for (player *pl = first_player; pl; pl = pl->next)
2136 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 2233 XPUSHs (sv_2mortal (to_sv (pl)));
2137}
2138 2234
2139bool 2235bool
2140peaceful (player *pl, bool new_setting = 0) 2236peaceful (player *pl, bool new_setting = 0)
2141 PROTOTYPE: $;$ 2237 PROTOTYPE: $;$
2142 CODE: 2238 CODE:
2390 2486
2391MODULE = cf PACKAGE = cf::settings 2487MODULE = cf PACKAGE = cf::settings
2392 2488
2393INCLUDE: $PERL genacc Settings ../include/global.h | 2489INCLUDE: $PERL genacc Settings ../include/global.h |
2394 2490
2395MODULE = cf PACKAGE = cf::client_socket 2491MODULE = cf PACKAGE = cf::client
2396 2492
2397INCLUDE: $PERL genacc client_socket ../include/newserver.h | 2493INCLUDE: $PERL genacc client ../include/client.h |
2398 2494
2399int invoke (client_socket *ns, int event, ...) 2495int invoke (client *ns, int event, ...)
2400 CODE: 2496 CODE:
2401 if (KLASS_OF (event) != KLASS_SOCKET) croak ("event class must be SOCKET"); 2497 if (KLASS_OF (event) != KLASS_CLIENT) croak ("event class must be CLIENT");
2402 AV *av = (AV *)sv_2mortal ((SV *)newAV ()); 2498 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
2403 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i))); 2499 for (int i = 2; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
2404 RETVAL = INVOKE_((event_type)event, ARG_SOCKET (ns), ARG_AV (av)); 2500 RETVAL = INVOKE_((event_type)event, ARG_CLIENT (ns), ARG_AV (av));
2405 OUTPUT: RETVAL 2501 OUTPUT: RETVAL
2406 2502
2407SV *registry (client_socket *ns) 2503SV *registry (client *ns)
2408 2504
2505void
2506list ()
2507 PPCODE:
2508 EXTEND (SP, clients.size ());
2509 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2510 PUSHs (sv_2mortal (to_sv (*i)));
2511
2512client *
2513create (int fd, const char *peername)
2514 CODE:
2515 RETVAL = client::create (fd, peername);
2516 OUTPUT:
2517 RETVAL
2518
2519void
2520client::send_packet (SV *packet)
2521 CODE:
2522{
2523 STRLEN len;
2524 char *buf = SvPVbyte (packet, len);
2525
2526 THIS->send_packet (buf, len);
2527}
2528
2529void
2530client::destroy ()
2531

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines