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.70 by elmex, Mon Dec 4 15:15:34 2006 UTC vs.
Revision 1.78 by root, Thu Dec 14 04:30:32 2006 UTC

43extern sint64 *levels; // the experience table 43extern sint64 *levels; // the experience table
44 44
45typedef object object_ornull; 45typedef object object_ornull;
46typedef maptile maptile_ornull; 46typedef maptile maptile_ornull;
47 47
48#if IVSIZE >= 8
49 typedef IV val64;
50# define newSVval64 newSViv
51# define SvVAL64 SvIV
52#else
48typedef double val64; 53 typedef double val64;
49#define newSVval64 newSVnv 54# define newSVval64 newSVnv
50#define SvVAL64 SvNV 55# define SvVAL64 SvNV
56#endif
51 57
52static f_plug_api gethook = cfapi_get_hooks; 58static f_plug_api gethook = cfapi_get_hooks;
53static f_plug_api object_set_property = cfapi_object_set_property; 59static f_plug_api object_set_property = cfapi_object_set_property;
54static f_plug_api object_insert = cfapi_object_insert; 60static f_plug_api object_insert = cfapi_object_insert;
55 61
148inline SV *to_sv (treasurelist * v) { return to_sv (v->name); } 154inline SV *to_sv (treasurelist * v) { return to_sv (v->name); }
149 155
150inline SV *to_sv (UUID v) 156inline SV *to_sv (UUID v)
151{ 157{
152 char buf[128]; 158 char buf[128];
153 snprintf (buf, 128, "<1,%llx>", (unsigned long long)v.seq); 159 snprintf (buf, 128, "<1,%" PRIx64 ">", v.seq);
154 return newSVpv (buf, 0); 160 return newSVpv (buf, 0);
155} 161}
156 162
157inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; } 163inline void sv_to (SV *sv, shstr &v) { v = SvOK (sv) ? SvPV_nolen (sv) : 0; }
158inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; } //TODO: verify that all simple pointers are strdup-managed 164inline void sv_to (SV *sv, char * &v) { free (v); v = SvOK (sv) ? strdup (SvPV_nolen (sv)) : 0; }
159inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); } 165inline void sv_to (SV *sv, bool &v) { v = SvIV (sv); }
160inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); } 166inline void sv_to (SV *sv, signed char &v) { v = SvIV (sv); }
161inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); } 167inline void sv_to (SV *sv, unsigned char &v) { v = SvIV (sv); }
162inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); } 168inline void sv_to (SV *sv, signed short &v) { v = SvIV (sv); }
163inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); } 169inline void sv_to (SV *sv, unsigned short &v) { v = SvIV (sv); }
187inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); } 193inline void sv_to (SV *sv, char (&v)[N]) { assign (v, SvPV_nolen (sv)); }
188 194
189inline void sv_to (SV *sv, UUID &v) 195inline void sv_to (SV *sv, UUID &v)
190{ 196{
191 unsigned int version; 197 unsigned int version;
192 unsigned long long seq;
193 198
194 if (2 != sscanf (SvPV_nolen (sv), "<%d.%llx>", &version, &seq) || 1 != version) 199 if (2 != sscanf (SvPV_nolen (sv), "<%d.%" SCNx64 ">", &version, &v.seq) || 1 != version)
195 croak ("unparsable uuid: %s", SvPV_nolen (sv)); 200 croak ("unparsable uuid: %s", SvPV_nolen (sv));
196
197 v.seq = seq;
198} 201}
199 202
200static SV * 203static SV *
201newSVdt_va (va_list &ap, data_type type) 204newSVdt_va (va_list &ap, data_type type)
202{ 205{
768static CommArray_s rtn_cmd; 771static CommArray_s rtn_cmd;
769 772
770static int 773static int
771runPluginCommand (object *obj, char *params) 774runPluginCommand (object *obj, char *params)
772{ 775{
773 dSP; 776 return -1;
774
775 ENTER;
776 SAVETMPS;
777
778 PUSHMARK (SP);
779
780 EXTEND (SP, 3);
781 PUSHs (sv_2mortal (newSVpv (rtn_cmd.name, 0)));
782 PUSHs (sv_2mortal (newSVcfapi (CFAPI_POBJECT, obj)));
783
784 if (params)
785 PUSHs (sv_2mortal (newSVpv (params, 0)));
786
787 PUTBACK;
788 int count = call_pv ("cf::inject_command", G_SCALAR | G_EVAL);
789 SPAGAIN;
790
791 if (SvTRUE (ERRSV))
792 LOG (llevError, "command '%s' callback evaluation error: %s", rtn_cmd.name, SvPV_nolen (ERRSV));
793
794 int returnvalue = count > 0 ? POPi : -1;
795
796 PUTBACK;
797 FREETMPS;
798 LEAVE;
799
800 return returnvalue;
801} 777}
802 778
803extern "C" void *cfperl_getPluginProperty (int *type, ...) 779extern "C" void *cfperl_getPluginProperty (int *type, ...)
804{ 780{
805 va_list args; 781 va_list args;
808 va_start (args, type); 784 va_start (args, type);
809 propname = va_arg (args, char *); 785 propname = va_arg (args, char *);
810 //printf ("Property name: %s\n", propname); 786 //printf ("Property name: %s\n", propname);
811 787
812 if (!strcmp (propname, "command?")) 788 if (!strcmp (propname, "command?"))
813 {
814 if (!perl)
815 return NULL; 789 return NULL;
816
817 const char *cmdname = va_arg (args, const char *);
818 HV *hv = get_hv ("cf::COMMAND", 1);
819 SV **svp = hv_fetch (hv, cmdname, strlen (cmdname) + 1, 0);
820
821 va_end (args);
822
823 if (svp)
824 {
825 // this is totaly broken, should stash it into %COMMAND
826 rtn_cmd.name = cmdname;
827 rtn_cmd.time = SvNV (*svp);
828 rtn_cmd.func = runPluginCommand;
829
830 return &rtn_cmd;
831 }
832 }
833 else if (!strcmp (propname, "Identification")) 790 else if (!strcmp (propname, "Identification"))
834 { 791 {
835 va_end (args); 792 va_end (args);
836 return (void*) PLUGIN_NAME; 793 return (void *)PLUGIN_NAME;
837 } 794 }
838 else if (!strcmp (propname, "FullName")) 795 else if (!strcmp (propname, "FullName"))
839 { 796 {
840 va_end (args); 797 va_end (args);
841 return (void*) PLUGIN_VERSION; 798 return (void *)PLUGIN_VERSION;
842 } 799 }
843 else 800 else
844 va_end (args); 801 va_end (args);
845 802
846 return NULL; 803 return NULL;
944 object *op; 901 object *op;
945 player *pl; 902 player *pl;
946 maptile *map; 903 maptile *map;
947 904
948 // callback call ordering is: 905 // callback call ordering is:
949 // 1. per-object callback (NYI) 906 // 1. per-object callback
950 // 2. per-class object 907 // 2. per-class object
951 // 2a. per-type callback 908 // 3. per-type callback
952 // 4. global callbacks 909 // 4. global callbacks
953 910
954 gather_callbacks (callbacks, cb_global, event); 911 gather_callbacks (callbacks, cb_global, event);
955 912
956 switch (KLASS_OF (event)) 913 switch (KLASS_OF (event))
1084 1041
1085int 1042int
1086cfperl_result_INT (int idx) 1043cfperl_result_INT (int idx)
1087{ 1044{
1088 return SvIV (cfperl_result (idx)); 1045 return SvIV (cfperl_result (idx));
1046}
1047
1048double
1049cfperl_result_DOUBLE (int idx)
1050{
1051 return SvNV (cfperl_result (idx));
1089} 1052}
1090 1053
1091MODULE = cf PACKAGE = cf PREFIX = cf_ 1054MODULE = cf PACKAGE = cf PREFIX = cf_
1092 1055
1093BOOT: 1056BOOT:
1617 //I_EVENT_API (PACKAGE); 1580 //I_EVENT_API (PACKAGE);
1618} 1581}
1619 1582
1620void _init_vars () 1583void _init_vars ()
1621 CODE: 1584 CODE:
1622 cb_global = get_av ("cf::CB_GLOBAL", 1); 1585 cb_global = get_av ("cf::CB_GLOBAL", 1);
1623 cb_object = get_av ("cf::CB_OBJECT", 1); 1586 cb_object = get_av ("cf::CB_OBJECT", 1);
1624 cb_player = get_av ("cf::CB_PLAYER", 1); 1587 cb_player = get_av ("cf::CB_PLAYER", 1);
1625 cb_type = get_av ("cf::CB_TYPE" , 1); 1588 cb_type = get_av ("cf::CB_TYPE" , 1);
1626 cb_map = get_av ("cf::CB_MAP" , 1); 1589 cb_map = get_av ("cf::CB_MAP" , 1);
1627 1590
1628void _global_reattach () 1591void _global_reattach ()
1629 CODE: 1592 CODE:
1630{ 1593{
1631 // reattach to all attachable objects in the game. 1594 // reattach to all attachable objects in the game.
1636 reattach (map); 1599 reattach (map);
1637 1600
1638 for (object *op = object::first; op; op = op->next) 1601 for (object *op = object::first; op; op = op->next)
1639 reattach (op); 1602 reattach (op);
1640} 1603}
1604
1605bool
1606add_client_socket (int fd, const char *peername)
1641 1607
1642NV floor (NV x) 1608NV floor (NV x)
1643 1609
1644NV ceil (NV x) 1610NV ceil (NV x)
1645 1611
1693 } 1659 }
1694 OUTPUT: RETVAL 1660 OUTPUT: RETVAL
1695 1661
1696void _exit (int status = 0) 1662void _exit (int status = 0)
1697 1663
1698int cf_find_animation (char *text) 1664int find_animation (char *text)
1699 PROTOTYPE: $ 1665 PROTOTYPE: $
1700 1666
1701int random_roll(int min, int max, object *op, int goodbad); 1667int random_roll (int min, int max, object *op, int goodbad);
1702 1668
1703const char *cost_string_from_value(uint64 cost, int approx = 0) 1669const char *cost_string_from_value(uint64 cost, int approx = 0)
1704 1670
1705int invoke (int event, ...) 1671int invoke (int event, ...)
1706 CODE: 1672 CODE:
1822 1788
1823object *find_best_object_match (object *op, const char *match) 1789object *find_best_object_match (object *op, const char *match)
1824 1790
1825object *find_marked_object (object *op) 1791object *find_marked_object (object *op)
1826 1792
1827int cf_object_get_resistance (object *op, int rtype) 1793int resistance (object *op, int rtype, int newval = 0)
1828 ALIAS: resistance = 0 1794 CODE:
1795 if (rtype < 0 || rtype >= NROFATTACKS)
1796 croak ("resistance out of bounds");
1797 RETVAL = op->resist [rtype];
1798 if (items >= 3)
1799 op->resist [rtype] = newval;
1800 OUTPUT: RETVAL
1801
1802void set_resistance (object *op, int rtype, int val)
1803 CODE:
1804 if (rtype < 0 || rtype >= NROFATTACKS)
1805 op->resist[rtype] = val;
1829 1806
1830int need_identify (const object *obj); 1807int need_identify (const object *obj);
1831 1808
1832int apply_shop_mat (object *shop_mat, object *op); 1809int apply_shop_mat (object *shop_mat, object *op);
1833 1810
1835 CODE: 1812 CODE:
1836 RETVAL = move_ob (op, dir, originator); 1813 RETVAL = move_ob (op, dir, originator);
1837 OUTPUT: 1814 OUTPUT:
1838 RETVAL 1815 RETVAL
1839 1816
1840void cf_object_apply (object *op, object *author, int flags = 0) 1817void apply (object *applier, object *applied, int flags = 0)
1818 CODE:
1819 manual_apply (applied, applier, flags);
1841 1820
1842void cf_object_apply_below (object *op) 1821void apply_below (object *op)
1822 CODE:
1823 player_apply_below (op);
1843 1824
1844void cf_object_remove (object *op) 1825void remove (object *op)
1826 CODE:
1827 op->remove ();
1845 1828
1846void cf_object_free (object *op) 1829void destroy (object *op, int recursive = 0)
1830 CODE:
1831 op->destroy (recursive);
1847 1832
1848object *cf_object_present_archname_inside (object *op, char *whatstr) 1833object *cf_object_present_archname_inside (object *op, char *whatstr)
1849 1834
1850int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0) 1835int cf_object_transfer (object *op, int x, int y, int r = 0, object_ornull *orig = 0)
1851 1836
1852int cf_object_change_map (object *op, int x, int y, maptile *map) 1837int cf_object_change_map (object *op, int x, int y, maptile *map)
1853 1838
1854object *cf_object_clone (object *op, int clonetype = 0) 1839object *clone (object *op, int recursive = 0)
1840 CODE:
1841 if (recursive)
1842 RETVAL = object_create_clone (op);
1843 else
1844 {
1845 RETVAL = object::create ();
1846 op->copy_to (RETVAL);
1847 }
1848 OUTPUT: RETVAL
1855 1849
1856int cf_object_pay_item (object *op, object *buyer) 1850int pay_item (object *op, object *buyer)
1851 CODE:
1852 RETVAL = pay_for_item (op, buyer);
1853 OUTPUT: RETVAL
1857 1854
1858int cf_object_pay_amount (object *op, uint64 amount) 1855int pay_amount (object *op, uint64 amount)
1856 CODE:
1857 RETVAL = pay_for_amount (amount, op);
1858 OUTPUT: RETVAL
1859 1859
1860void pay_player (object *op, uint64 amount) 1860void pay_player (object *op, uint64 amount)
1861 1861
1862val64 pay_player_arch (object *op, const char *arch, uint64 amount) 1862val64 pay_player_arch (object *op, const char *arch, uint64 amount)
1863 1863
1864int cf_object_cast_spell (object *caster, object *ctoo, int dir, object *spell_ob, char *stringarg = 0) 1864int cast_spell (object *op, object *caster, int dir, object *spell_ob, char *stringarg = 0)
1865 1865
1866int cf_object_cast_ability (object *caster, object *ctoo, int dir, object *sp_, char *stringarg = 0) 1866void learn_spell (object *op, object *sp, int special_prayer = 0)
1867 CODE:
1868 do_learn_spell (op, sp, special_prayer);
1867 1869
1868void cf_object_learn_spell (object *op, object *sp)
1869
1870void cf_object_forget_spell (object *op, object *sp) 1870void forget_spell (object *op, object *sp)
1871 CODE:
1872 do_forget_spell (op, query_name (sp));
1871 1873
1872object *cf_object_check_for_spell (object *op, char *spellname) 1874object *check_for_spell (object *op, char *spellname)
1875 CODE:
1876 RETVAL = check_spell_known (op, spellname);
1877 OUTPUT: RETVAL
1873 1878
1874int cf_object_query_money (object *op) 1879int query_money (object *op)
1875 ALIAS: money = 0 1880 ALIAS: money = 0
1876 1881
1877int cf_object_query_cost (object *op, object *who, int flags) 1882int query_cost (object *op, object *who, int flags)
1878 ALIAS: cost = 0 1883 ALIAS: cost = 0
1879 1884
1880void cf_object_activate_rune (object *op , object *victim) 1885void spring_trap (object *op, object *victim)
1881 1886
1882int cf_object_check_trigger (object *op, object *cause) 1887int check_trigger (object *op, object *cause)
1883 1888
1884int cf_object_out_of_map (object *op, int x, int y)
1885
1886void cf_object_drop (object *op, object *author) 1889void drop (object *who, object *op)
1887 1890
1888void cf_object_take (object *op, object *author) 1891void pick_up (object *who, object *op)
1889 1892
1890object *cf_object_insert_object (object *op, object *container) 1893object *cf_object_insert_object (object *op, object *container)
1891 1894
1892object *cf_object_insert_in_ob (object *ob, object *where) 1895object *cf_object_insert_in_ob (object *ob, object *where)
1893 1896
1894int cf_object_teleport (object *op, maptile *map, int x, int y) 1897int cf_object_teleport (object *op, maptile *map, int x, int y)
1895 1898
1896void cf_object_update (object *op, int flags) 1899void update (object *op, int action)
1897 1900 CODE:
1898void cf_object_pickup (object *op, object *what) 1901 update_object (op, action);
1899 1902
1900object *cf_create_object_by_name (const char *name) 1903object *cf_create_object_by_name (const char *name)
1901 1904
1902void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0) 1905void change_exp (object *op, uint64 exp, const char *skill_name = 0, int flag = 0)
1903 1906
1912void use_trigger (object *op); 1915void use_trigger (object *op);
1913 1916
1914void add_button_link (object *button, maptile *map, int connected); 1917void add_button_link (object *button, maptile *map, int connected);
1915 1918
1916void remove_button_link (object *op); 1919void remove_button_link (object *op);
1917
1918void
1919cf_object_set_resistance (object *op, int rtype, int val)
1920 CODE:
1921 if (rtype >= 0 && rtype < NROFATTACKS)
1922 op->resist[rtype] = val;
1923 1920
1924 1921
1925MODULE = cf PACKAGE = cf::object PREFIX = cf_ 1922MODULE = cf PACKAGE = cf::object PREFIX = cf_
1926 1923
1927void cf_fix_object (object *pl) 1924void cf_fix_object (object *pl)
2042INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h | 2039INCLUDE: $PERL genacc player ../include/newserver.h ../include/player.h |
2043 2040
2044char * 2041char *
2045client (player *pl) 2042client (player *pl)
2046 CODE: 2043 CODE:
2047 RETVAL = pl->socket.client; 2044 RETVAL = pl->socket->client;
2048 OUTPUT: 2045 OUTPUT:
2049 RETVAL 2046 RETVAL
2050 2047
2051char * 2048char *
2052host (player *pl) 2049host (player *pl)
2053 CODE: 2050 CODE:
2054 RETVAL = pl->socket.host; 2051 RETVAL = pl->socket->host;
2055 OUTPUT: 2052 OUTPUT:
2056 RETVAL 2053 RETVAL
2057 2054
2058int invoke (player *pl, int event, ...) 2055int invoke (player *pl, int event, ...)
2059 CODE: 2056 CODE:
2087 OUTPUT: RETVAL 2084 OUTPUT: RETVAL
2088 2085
2089bool 2086bool
2090cell_visible (player *pl, int dx, int dy) 2087cell_visible (player *pl, int dx, int dy)
2091 CODE: 2088 CODE:
2092 RETVAL = FABS (dx) <= pl->socket.mapx / 2 && FABS (dy) <= pl->socket.mapy / 2 2089 RETVAL = FABS (dx) <= pl->socket->mapx / 2 && FABS (dy) <= pl->socket->mapy / 2
2093 && !pl->blocked_los [dx + pl->socket.mapx / 2][dy + pl->socket.mapy / 2]; 2090 && !pl->blocked_los [dx + pl->socket->mapx / 2][dy + pl->socket->mapy / 2];
2094 OUTPUT: 2091 OUTPUT:
2095 RETVAL 2092 RETVAL
2096 2093
2097void 2094void
2098buggy_mapscroll (player *pl, int value = 1) 2095buggy_mapscroll (player *pl, int value = 1)
2099 CODE: 2096 CODE:
2100 pl->socket.buggy_mapscroll = value; 2097 pl->socket->buggy_mapscroll = value;
2101 2098
2102void 2099void
2103send (player *pl, SV *packet) 2100send (player *pl, SV *packet)
2104 CODE: 2101 CODE:
2105{ 2102{
2106 STRLEN len; 2103 STRLEN len;
2107 char *buf = SvPVbyte (packet, len); 2104 char *buf = SvPVbyte (packet, len);
2108 2105
2109 Write_String_To_Socket (&pl->socket, buf, len); 2106 pl->socket->send_packet (buf, len);
2110} 2107}
2111 2108
2112int 2109int
2113listening (player *pl, int new_value = -1) 2110listening (player *pl, int new_value = -1)
2114 CODE: 2111 CODE:
2201 2198
2202void clean_tmp_map (maptile *map) 2199void clean_tmp_map (maptile *map)
2203 2200
2204void play_sound_map (maptile *map, int x, int y, int sound_num) 2201void play_sound_map (maptile *map, int x, int y, int sound_num)
2205 2202
2203int out_of_map (maptile *map, int x, int y)
2204
2206maptile *tile_map (maptile *map, unsigned int dir) 2205maptile *tile_map (maptile *map, unsigned int dir)
2207 CODE: 2206 CODE:
2208 RETVAL = dir < 4 ? map->tile_map [dir] : 0; 2207 RETVAL = dir < 4 ? map->tile_map [dir] : 0;
2209 OUTPUT: 2208 OUTPUT:
2210 RETVAL 2209 RETVAL
2393 2392
2394MODULE = cf PACKAGE = cf::living 2393MODULE = cf PACKAGE = cf::living
2395 2394
2396INCLUDE: $PERL genacc living ../include/living.h | 2395INCLUDE: $PERL genacc living ../include/living.h |
2397 2396
2397MODULE = cf PACKAGE = cf::settings
2398
2399INCLUDE: $PERL genacc Settings ../include/global.h |
2400

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines