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.94 by elmex, Wed Dec 20 14:11:42 2006 UTC vs.
Revision 1.101 by root, Fri Dec 22 06:02:29 2006 UTC

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 ())
361 361
362 HV *hv = (HV *)SvRV ((SV *)self); 362 HV *hv = (HV *)SvRV ((SV *)self);
363 363
364 if (SvREFCNT ((SV *)self) == 1 364 if (SvREFCNT ((SV *)self) == 1
365 && SvREFCNT ((SV *)hv) == 1 365 && SvREFCNT ((SV *)hv) == 1
366 && !HvKEYS (hv)) 366 && !HvTOTALKEYS (hv))
367 { 367 {
368 SvREFCNT_dec ((SV *)self); 368 SvREFCNT_dec ((SV *)self);
369 self = 0; 369 self = 0;
370 } 370 }
371} 371}
412 412
413 switch (type) 413 switch (type)
414 { 414 {
415 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break; 415 case DT_OBJECT: INVOKE_OBJECT (REATTACH, obj); break;
416 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break; 416 case DT_PLAYER: INVOKE_PLAYER (REATTACH, obj); break;
417 case DT_CLIENT: INVOKE_CLIENT (REATTACH, obj); break;
417 case DT_MAP: INVOKE_MAP (REATTACH, obj); break; 418 case DT_MAP: INVOKE_MAP (REATTACH, obj); break;
418 } 419 }
419} 420}
420 421
421template<class subclass> 422template<class subclass>
906 AV *callbacks = 0; 907 AV *callbacks = 0;
907 908
908 object *op; 909 object *op;
909 player *pl; 910 player *pl;
910 maptile *map; 911 maptile *map;
912 client *ns;
911 913
912 // callback call ordering is: 914 // callback call ordering is:
913 // 1. per-object callback 915 // 1. per-object callback
914 // 2. per-class object 916 // 2. per-class object
915 // 3. per-type callback 917 // 3. per-type callback
973 gather_callbacks (callbacks, map->cb, event); 975 gather_callbacks (callbacks, map->cb, event);
974 976
975 gather_callbacks (callbacks, cb_map, event); 977 gather_callbacks (callbacks, cb_map, event);
976 break; 978 break;
977 979
980 case KLASS_CLIENT:
981 dt = (data_type) va_arg (ap, int);
982 assert (("first argument must be of type client", dt == DT_CLIENT));
983 ns = va_arg (ap, client *);
984
985 if (ns->cb)
986 gather_callbacks (callbacks, ns->cb, event);
987
988 gather_callbacks (callbacks, cb_client, event);
989 break;
990
978 default: 991 default:
979 assert (("unsupported event klass in cfperl_invoke", 0)); 992 assert (("unsupported event klass in cfperl_invoke", 0));
980 } 993 }
981 994
982 // short-circuit processing if no callbacks found/defined 995 // short-circuit processing if no callbacks found/defined
995 1008
996 switch (KLASS_OF (event)) 1009 switch (KLASS_OF (event))
997 { 1010 {
998 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break; 1011 case KLASS_OBJECT: PUSHs (sv_2mortal (newSVdt (DT_OBJECT, op))); break;
999 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break; 1012 case KLASS_PLAYER: PUSHs (sv_2mortal (newSVdt (DT_PLAYER, pl))); break;
1013 case KLASS_CLIENT: PUSHs (sv_2mortal (newSVdt (DT_CLIENT, ns))); break;
1000 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break; 1014 case KLASS_MAP: PUSHs (sv_2mortal (newSVdt (DT_MAP, map))); break;
1001 } 1015 }
1002 1016
1003 for (;;) 1017 for (;;)
1004 { 1018 {
1209 const_iv (LIGHTER) 1223 const_iv (LIGHTER)
1210 const_iv (BUILDABLE_WALL) 1224 const_iv (BUILDABLE_WALL)
1211 const_iv (MISC_OBJECT) 1225 const_iv (MISC_OBJECT)
1212 const_iv (LAMP) 1226 const_iv (LAMP)
1213 const_iv (DUPLICATOR) 1227 const_iv (DUPLICATOR)
1214 const_iv (TOOL)
1215 const_iv (SPELLBOOK) 1228 const_iv (SPELLBOOK)
1216 const_iv (BUILDFAC)
1217 const_iv (CLOAK) 1229 const_iv (CLOAK)
1218 const_iv (SPINNER) 1230 const_iv (SPINNER)
1219 const_iv (GATE) 1231 const_iv (GATE)
1220 const_iv (BUTTON) 1232 const_iv (BUTTON)
1221 const_iv (CF_HANDLE) 1233 const_iv (CF_HANDLE)
1606 const_iv (MAP_LOADING) 1618 const_iv (MAP_LOADING)
1607 const_iv (MAP_SAVING) 1619 const_iv (MAP_SAVING)
1608 1620
1609 const_iv (KLASS_GLOBAL) 1621 const_iv (KLASS_GLOBAL)
1610 const_iv (KLASS_OBJECT) 1622 const_iv (KLASS_OBJECT)
1623 const_iv (KLASS_CLIENT)
1611 const_iv (KLASS_PLAYER) 1624 const_iv (KLASS_PLAYER)
1612 const_iv (KLASS_MAP) 1625 const_iv (KLASS_MAP)
1626
1627 const_iv (CS_QUERY_YESNO)
1628 const_iv (CS_QUERY_SINGLECHAR)
1629 const_iv (CS_QUERY_HIDEINPUT)
1630
1631 const_iv (ST_DEAD)
1632 const_iv (ST_SETUP)
1633 const_iv (ST_PLAYING)
1634 const_iv (ST_CUSTOM)
1635
1636 const_iv (ST_PLAY_AGAIN)
1637 const_iv (ST_ROLL_STAT)
1638 const_iv (ST_CHANGE_CLASS)
1639 const_iv (ST_CONFIRM_QUIT)
1640 const_iv (ST_CONFIGURE)
1641 const_iv (ST_GET_NAME)
1642 const_iv (ST_GET_PASSWORD)
1643 const_iv (ST_CONFIRM_PASSWORD)
1644 const_iv (ST_GET_PARTY_PASSWORD)
1613 }; 1645 };
1614 1646
1615 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1647 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1616 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1648 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1617 1649
1641void _init_vars () 1673void _init_vars ()
1642 CODE: 1674 CODE:
1643 cb_global = get_av ("cf::CB_GLOBAL", 1); 1675 cb_global = get_av ("cf::CB_GLOBAL", 1);
1644 cb_object = get_av ("cf::CB_OBJECT", 1); 1676 cb_object = get_av ("cf::CB_OBJECT", 1);
1645 cb_player = get_av ("cf::CB_PLAYER", 1); 1677 cb_player = get_av ("cf::CB_PLAYER", 1);
1678 cb_client = get_av ("cf::CB_CLIENT", 1);
1646 cb_type = get_av ("cf::CB_TYPE" , 1); 1679 cb_type = get_av ("cf::CB_TYPE" , 1);
1647 cb_map = get_av ("cf::CB_MAP" , 1); 1680 cb_map = get_av ("cf::CB_MAP" , 1);
1648 1681
1649void _global_reattach () 1682void _global_reattach ()
1650 CODE: 1683 CODE:
1651{ 1684{
1652 // reattach to all attachable objects in the game. 1685 // reattach to all attachable objects in the game.
1686 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
1687 reattach (*i);
1688
1653 for (player *pl = first_player; pl; pl = pl->next) 1689 for (player *pl = first_player; pl; pl = pl->next)
1654 reattach (pl); 1690 reattach (pl);
1655 1691
1656 for (maptile *map = first_map; map; map = map->next) 1692 for (maptile *map = first_map; map; map = map->next)
1657 reattach (map); 1693 reattach (map);
1658 1694
1659 for (object *op = object::first; op; op = op->next) 1695 for (object *op = object::first; op; op = op->next)
1660 reattach (op); 1696 reattach (op);
1661} 1697}
1662
1663bool
1664add_client (int fd, const char *peername)
1665 1698
1666NV floor (NV x) 1699NV floor (NV x)
1667 1700
1668NV ceil (NV x) 1701NV ceil (NV x)
1669 1702
1724 1757
1725int random_roll (int min, int max, object *op, int goodbad); 1758int random_roll (int min, int max, object *op, int goodbad);
1726 1759
1727const char *cost_string_from_value(uint64 cost, int approx = 0) 1760const char *cost_string_from_value(uint64 cost, int approx = 0)
1728 1761
1729int invoke (int event, ...)
1730 CODE:
1731 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1732 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1733 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1734 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1735 OUTPUT: RETVAL
1736
1737int 1762int
1738exp_to_level (val64 exp) 1763exp_to_level (val64 exp)
1739 CODE: 1764 CODE:
1740{ 1765{
1741 int i = 0; 1766 int i = 0;
1771 RETVAL = newSVpv (resist_plus[atnr], 0); 1796 RETVAL = newSVpv (resist_plus[atnr], 0);
1772 else 1797 else
1773 XSRETURN_UNDEF; 1798 XSRETURN_UNDEF;
1774 OUTPUT: RETVAL 1799 OUTPUT: RETVAL
1775 1800
1801MODULE = cf PACKAGE = cf::attachable
1802
1776int 1803int
1777_valid (SV *obj) 1804valid (SV *obj)
1778 CODE: 1805 CODE:
1779 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1806 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1780 OUTPUT: 1807 OUTPUT:
1781 RETVAL 1808 RETVAL
1809
1810MODULE = cf PACKAGE = cf::global
1811
1812int invoke (SV *klass, int event, ...)
1813 CODE:
1814 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1815 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1816 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1817 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1818 OUTPUT: RETVAL
1782 1819
1783MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1820MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1784 1821
1785INCLUDE: $PERL genacc object ../include/object.h | 1822INCLUDE: $PERL genacc object ../include/object.h |
1786 1823
1835 PROTOTYPE: $ 1872 PROTOTYPE: $
1836 PPCODE: 1873 PPCODE:
1837{ 1874{
1838 object *o; 1875 object *o;
1839 for (o = obj->inv; o; o = o->below) 1876 for (o = obj->inv; o; o = o->below)
1840 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1877 XPUSHs (sv_2mortal (to_sv (o)));
1841} 1878}
1842 1879
1843object *find_best_object_match (object *op, const char *match) 1880object *find_best_object_match (object *op, const char *match)
1844 1881
1845object *find_marked_object (object *op) 1882object *find_marked_object (object *op)
2121 OUTPUT: RETVAL 2158 OUTPUT: RETVAL
2122 2159
2123bool 2160bool
2124cell_visible (player *pl, int dx, int dy) 2161cell_visible (player *pl, int dx, int dy)
2125 CODE: 2162 CODE:
2126 RETVAL = FABS (dx) <= pl->socket->mapx / 2 && FABS (dy) <= pl->socket->mapy / 2 2163 RETVAL = FABS (dx) <= pl->ns->mapx / 2 && FABS (dy) <= pl->ns->mapy / 2
2127 && !pl->blocked_los [dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2]; 2164 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2128 OUTPUT: 2165 OUTPUT:
2129 RETVAL 2166 RETVAL
2130 2167
2131void 2168void
2132send (player *pl, SV *packet) 2169send (player *pl, SV *packet)
2133 CODE: 2170 CODE:
2134{ 2171{
2135 STRLEN len; 2172 STRLEN len;
2136 char *buf = SvPVbyte (packet, len); 2173 char *buf = SvPVbyte (packet, len);
2137 2174
2175 if (pl->ns)
2138 pl->socket->send_packet (buf, len); 2176 pl->ns->send_packet (buf, len);
2139} 2177}
2140 2178
2141int 2179int
2142listening (player *pl, int new_value = -1) 2180listening (player *pl, int new_value = -1)
2143 CODE: 2181 CODE:
2162 if (y) sv_to (y, pl->bed_y); 2200 if (y) sv_to (y, pl->bed_y);
2163 2201
2164void 2202void
2165list () 2203list ()
2166 PPCODE: 2204 PPCODE:
2167{
2168 player *pl;
2169 for (pl = first_player; pl; pl = pl->next) 2205 for (player *pl = first_player; pl; pl = pl->next)
2170 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 2206 XPUSHs (sv_2mortal (to_sv (pl)));
2171}
2172 2207
2173bool 2208bool
2174peaceful (player *pl, bool new_setting = 0) 2209peaceful (player *pl, bool new_setting = 0)
2175 PROTOTYPE: $;$ 2210 PROTOTYPE: $;$
2176 CODE: 2211 CODE:
2439 OUTPUT: RETVAL 2474 OUTPUT: RETVAL
2440 2475
2441SV *registry (client *ns) 2476SV *registry (client *ns)
2442 2477
2443void 2478void
2479list ()
2480 PPCODE:
2481 EXTEND (SP, clients.size ());
2482 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2483 PUSHs (sv_2mortal (to_sv (*i)));
2484
2485client *
2486create (int fd, const char *peername)
2487 CODE:
2488 RETVAL = client::create (fd, peername);
2489 OUTPUT:
2490 RETVAL
2491
2492void
2493client::send_packet (SV *packet)
2494 CODE:
2495{
2496 STRLEN len;
2497 char *buf = SvPVbyte (packet, len);
2498
2499 THIS->send_packet (buf, len);
2500}
2501
2502void
2444client::destroy () 2503client::destroy ()
2445 2504

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines