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.104 by root, Sat Dec 23 06:41:39 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_CHANGE_CLASS)
1637 const_iv (ST_CONFIRM_QUIT)
1638 const_iv (ST_GET_PARTY_PASSWORD)
1613 }; 1639 };
1614 1640
1615 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; ) 1641 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ-- > const_iv; )
1616 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv)); 1642 newCONSTSUB (stash, (char *)civ->name, newSViv (civ->iv));
1617 1643
1641void _init_vars () 1667void _init_vars ()
1642 CODE: 1668 CODE:
1643 cb_global = get_av ("cf::CB_GLOBAL", 1); 1669 cb_global = get_av ("cf::CB_GLOBAL", 1);
1644 cb_object = get_av ("cf::CB_OBJECT", 1); 1670 cb_object = get_av ("cf::CB_OBJECT", 1);
1645 cb_player = get_av ("cf::CB_PLAYER", 1); 1671 cb_player = get_av ("cf::CB_PLAYER", 1);
1672 cb_client = get_av ("cf::CB_CLIENT", 1);
1646 cb_type = get_av ("cf::CB_TYPE" , 1); 1673 cb_type = get_av ("cf::CB_TYPE" , 1);
1647 cb_map = get_av ("cf::CB_MAP" , 1); 1674 cb_map = get_av ("cf::CB_MAP" , 1);
1648 1675
1649void _global_reattach () 1676void _global_reattach ()
1650 CODE: 1677 CODE:
1651{ 1678{
1652 // reattach to all attachable objects in the game. 1679 // reattach to all attachable objects in the game.
1680 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
1681 reattach (*i);
1682
1653 for (player *pl = first_player; pl; pl = pl->next) 1683 for (player *pl = first_player; pl; pl = pl->next)
1654 reattach (pl); 1684 reattach (pl);
1655 1685
1656 for (maptile *map = first_map; map; map = map->next) 1686 for (maptile *map = first_map; map; map = map->next)
1657 reattach (map); 1687 reattach (map);
1658 1688
1659 for (object *op = object::first; op; op = op->next) 1689 for (object *op = object::first; op; op = op->next)
1660 reattach (op); 1690 reattach (op);
1661} 1691}
1662
1663bool
1664add_client (int fd, const char *peername)
1665 1692
1666NV floor (NV x) 1693NV floor (NV x)
1667 1694
1668NV ceil (NV x) 1695NV ceil (NV x)
1669 1696
1724 1751
1725int random_roll (int min, int max, object *op, int goodbad); 1752int random_roll (int min, int max, object *op, int goodbad);
1726 1753
1727const char *cost_string_from_value(uint64 cost, int approx = 0) 1754const char *cost_string_from_value(uint64 cost, int approx = 0)
1728 1755
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 1756int
1738exp_to_level (val64 exp) 1757exp_to_level (val64 exp)
1739 CODE: 1758 CODE:
1740{ 1759{
1741 int i = 0; 1760 int i = 0;
1771 RETVAL = newSVpv (resist_plus[atnr], 0); 1790 RETVAL = newSVpv (resist_plus[atnr], 0);
1772 else 1791 else
1773 XSRETURN_UNDEF; 1792 XSRETURN_UNDEF;
1774 OUTPUT: RETVAL 1793 OUTPUT: RETVAL
1775 1794
1795MODULE = cf PACKAGE = cf::attachable
1796
1776int 1797int
1777_valid (SV *obj) 1798valid (SV *obj)
1778 CODE: 1799 CODE:
1779 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext); 1800 RETVAL = SvROK (obj) && mg_find (SvRV (obj), PERL_MAGIC_ext);
1780 OUTPUT: 1801 OUTPUT:
1781 RETVAL 1802 RETVAL
1803
1804MODULE = cf PACKAGE = cf::global
1805
1806int invoke (SV *klass, int event, ...)
1807 CODE:
1808 if (KLASS_OF (event) != KLASS_GLOBAL) croak ("event class must be GLOBAL");
1809 AV *av = (AV *)sv_2mortal ((SV *)newAV ());
1810 for (int i = 1; i < items; i++) av_push (av, SvREFCNT_inc (ST (i)));
1811 RETVAL = INVOKE_((event_type)event, ARG_AV (av));
1812 OUTPUT: RETVAL
1782 1813
1783MODULE = cf PACKAGE = cf::object PREFIX = cf_object_ 1814MODULE = cf PACKAGE = cf::object PREFIX = cf_object_
1784 1815
1785INCLUDE: $PERL genacc object ../include/object.h | 1816INCLUDE: $PERL genacc object ../include/object.h |
1786 1817
1808# missing properties 1839# missing properties
1809 1840
1810int flag (object *op, int flag, int value = 1) 1841int flag (object *op, int flag, int value = 1)
1811 PROTOTYPE: $$;$ 1842 PROTOTYPE: $$;$
1812 CODE: 1843 CODE:
1813 RETVAL = QUERY_FLAG (op, flag); 1844 RETVAL = op->flag [flag];
1814 if (items >= 3) 1845 if (items >= 3)
1815 if (value) 1846 op->flag [flag] = value;
1816 SET_FLAG (op, flag);
1817 else
1818 CLEAR_FLAG (op, flag);
1819 OUTPUT: RETVAL 1847 OUTPUT: RETVAL
1820 1848
1821object *head (object *op) 1849object *head (object *op)
1822 PROTOTYPE: $ 1850 PROTOTYPE: $
1823 CODE: 1851 CODE:
1835 PROTOTYPE: $ 1863 PROTOTYPE: $
1836 PPCODE: 1864 PPCODE:
1837{ 1865{
1838 object *o; 1866 object *o;
1839 for (o = obj->inv; o; o = o->below) 1867 for (o = obj->inv; o; o = o->below)
1840 XPUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, o))); 1868 XPUSHs (sv_2mortal (to_sv (o)));
1841} 1869}
1870
1871void
1872set_animation (object *op, int idx)
1873 CODE:
1874 SET_ANIMATION (op, idx);
1875
1876void
1877object::drain_stat ()
1878
1879void
1880object::drain_specific_stat (int stat)
1881
1882void
1883object::change_luck (int change)
1884
1885void
1886object::add_statbonus ()
1887
1888void
1889object::remove_statbonus ()
1842 1890
1843object *find_best_object_match (object *op, const char *match) 1891object *find_best_object_match (object *op, const char *match)
1844 1892
1845object *find_marked_object (object *op) 1893object *find_marked_object (object *op)
1846 1894
1947 1995
1948object *cf_object_insert_in_ob (object *ob, object *where) 1996object *cf_object_insert_in_ob (object *ob, object *where)
1949 1997
1950int cf_object_teleport (object *op, maptile *map, int x, int y) 1998int cf_object_teleport (object *op, maptile *map, int x, int y)
1951 1999
1952void update (object *op, int action) 2000void update_object (object *op, int action)
1953 CODE:
1954 update_object (op, action);
1955 2001
1956object *cf_create_object_by_name (const char *name) 2002object *cf_create_object_by_name (const char *name)
1957 2003
1958void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 2004void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1959 2005
1971 2017
1972void remove_button_link (object *op); 2018void remove_button_link (object *op);
1973 2019
1974 2020
1975MODULE = cf PACKAGE = cf::object PREFIX = cf_ 2021MODULE = cf PACKAGE = cf::object PREFIX = cf_
1976
1977void cf_fix_object (object *pl)
1978 ALIAS: fix = 0
1979 2022
1980object *cf_insert_ob_in_ob (object *ob, object *where) 2023object *cf_insert_ob_in_ob (object *ob, object *where)
1981 2024
1982# no clean way to get an object from an archetype - stupid idiotic 2025# no clean way to get an object from an archetype - stupid idiotic
1983# dumb kludgy misdesigned plug-in api slowly gets on my nerves. 2026# dumb kludgy misdesigned plug-in api slowly gets on my nerves.
2006 2049
2007player *contr (object *op) 2050player *contr (object *op)
2008 CODE: 2051 CODE:
2009 RETVAL = op->contr; 2052 RETVAL = op->contr;
2010 OUTPUT: RETVAL 2053 OUTPUT: RETVAL
2054
2055void
2056object::roll_stats ()
2057
2058void
2059object::update_stats ()
2060
2061void
2062object::swap_stats (int a, int b)
2011 2063
2012const char *get_ob_key_value (object *op, const char *key) 2064const char *get_ob_key_value (object *op, const char *key)
2013 2065
2014bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1) 2066bool set_ob_key_value (object *op, const char *key, const char *value = 0, int add_key = 1)
2015 2067
2101 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av)); 2153 RETVAL = INVOKE_((event_type)event, ARG_PLAYER (pl), ARG_AV (av));
2102 OUTPUT: RETVAL 2154 OUTPUT: RETVAL
2103 2155
2104SV *registry (player *pl) 2156SV *registry (player *pl)
2105 2157
2158player *
2159create ()
2160 CODE:
2161 RETVAL = player::create ();
2162 OUTPUT:
2163 RETVAL
2164
2165player *
2166load (const char *path)
2167 CODE:
2168 RETVAL = player::load (path);
2169 OUTPUT:
2170 RETVAL
2171
2172void
2173player::save (bool final = false)
2174
2175void
2176player::connect (client *ns)
2177
2178void
2179save_stats (player *pl)
2180 CODE:
2181 pl->ob->stats.hp = pl->ob->stats.maxhp;
2182 pl->ob->stats.sp = pl->ob->stats.maxsp;
2183 pl->ob->stats.grace = pl->ob->stats.maxgrace;
2184 pl->orig_stats = pl->ob->stats;
2185
2106player *cf_player_find (char *name) 2186player *cf_player_find (char *name)
2107 PROTOTYPE: $ 2187 PROTOTYPE: $
2108 2188
2109void cf_player_move (player *pl, int dir) 2189void cf_player_move (player *pl, int dir)
2110 2190
2113player *first () 2193player *first ()
2114 CODE: 2194 CODE:
2115 RETVAL = first_player; 2195 RETVAL = first_player;
2116 OUTPUT: RETVAL 2196 OUTPUT: RETVAL
2117 2197
2118player *next (player *pl)
2119 CODE:
2120 RETVAL = pl->next;
2121 OUTPUT: RETVAL
2122
2123bool 2198bool
2124cell_visible (player *pl, int dx, int dy) 2199cell_visible (player *pl, int dx, int dy)
2125 CODE: 2200 CODE:
2126 RETVAL = FABS (dx) <= pl->socket->mapx / 2 && FABS (dy) <= pl->socket->mapy / 2 2201 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]; 2202 && !pl->blocked_los [dx + pl->ns->mapx / 2][dy + pl->ns->mapy / 2];
2128 OUTPUT: 2203 OUTPUT:
2129 RETVAL 2204 RETVAL
2130 2205
2131void 2206void
2132send (player *pl, SV *packet) 2207send (player *pl, SV *packet)
2133 CODE: 2208 CODE:
2134{ 2209{
2135 STRLEN len; 2210 STRLEN len;
2136 char *buf = SvPVbyte (packet, len); 2211 char *buf = SvPVbyte (packet, len);
2137 2212
2213 if (pl->ns)
2138 pl->socket->send_packet (buf, len); 2214 pl->ns->send_packet (buf, len);
2139} 2215}
2140 2216
2141int 2217int
2142listening (player *pl, int new_value = -1) 2218listening (player *pl, int new_value = -1)
2143 CODE: 2219 CODE:
2162 if (y) sv_to (y, pl->bed_y); 2238 if (y) sv_to (y, pl->bed_y);
2163 2239
2164void 2240void
2165list () 2241list ()
2166 PPCODE: 2242 PPCODE:
2167{
2168 player *pl;
2169 for (pl = first_player; pl; pl = pl->next) 2243 for (player *pl = first_player; pl; pl = pl->next)
2170 XPUSHs (newSVcfapi (CFAPI_PPLAYER, pl)); 2244 XPUSHs (sv_2mortal (to_sv (pl)));
2171}
2172 2245
2173bool 2246bool
2174peaceful (player *pl, bool new_setting = 0) 2247peaceful (player *pl, bool new_setting = 0)
2175 PROTOTYPE: $;$ 2248 PROTOTYPE: $;$
2176 CODE: 2249 CODE:
2439 OUTPUT: RETVAL 2512 OUTPUT: RETVAL
2440 2513
2441SV *registry (client *ns) 2514SV *registry (client *ns)
2442 2515
2443void 2516void
2517list ()
2518 PPCODE:
2519 EXTEND (SP, clients.size ());
2520 for (sockvec::iterator i = clients.begin (); i != clients.end (); ++i)
2521 PUSHs (sv_2mortal (to_sv (*i)));
2522
2523client *
2524create (int fd, const char *peername)
2525 CODE:
2526 RETVAL = client::create (fd, peername);
2527 OUTPUT:
2528 RETVAL
2529
2530void
2531client::send_packet (SV *packet)
2532 CODE:
2533{
2534 STRLEN len;
2535 char *buf = SvPVbyte (packet, len);
2536
2537 THIS->send_packet (buf, len);
2538}
2539
2540void
2444client::destroy () 2541client::destroy ()
2445 2542

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines