… | |
… | |
60 | #include <sys/time.h> |
60 | #include <sys/time.h> |
61 | #include <sys/socket.h> |
61 | #include <sys/socket.h> |
62 | #include <netinet/in.h> |
62 | #include <netinet/in.h> |
63 | #include <netdb.h> |
63 | #include <netdb.h> |
64 | |
64 | |
65 | #ifdef HAVE_UNISTD_H |
|
|
66 | # include <unistd.h> |
65 | #include <unistd.h> |
67 | #endif |
|
|
68 | |
|
|
69 | #ifdef HAVE_SYS_TIME_H |
|
|
70 | # include <sys/time.h> |
66 | #include <sys/time.h> |
71 | #endif |
|
|
72 | |
67 | |
73 | #include "sounds.h" |
68 | #include "sounds.h" |
74 | |
69 | |
75 | /** |
70 | /** |
76 | * This table translates the attack numbers as used within the |
71 | * This table translates the attack numbers as used within the |
… | |
… | |
153 | } |
148 | } |
154 | |
149 | |
155 | static void |
150 | static void |
156 | clear_map (player *pl) |
151 | clear_map (player *pl) |
157 | { |
152 | { |
158 | client_socket & socket = pl->socket; |
153 | client_socket &socket = *pl->socket; |
159 | |
154 | |
160 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
155 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
161 | |
156 | |
162 | if (socket.newmapcmd == 1) |
157 | if (socket.newmapcmd == 1) |
163 | socket.send_packet ("newmap"); |
158 | socket.send_packet ("newmap"); |
… | |
… | |
168 | |
163 | |
169 | /** check for map change and send new map data */ |
164 | /** check for map change and send new map data */ |
170 | static void |
165 | static void |
171 | check_map_change (player *pl) |
166 | check_map_change (player *pl) |
172 | { |
167 | { |
173 | client_socket & socket = pl->socket; |
168 | client_socket &socket = *pl->socket; |
174 | object *ob = pl->ob; |
169 | object *ob = pl->ob; |
175 | char buf[MAX_BUF]; /* eauugggh */ |
170 | char buf[MAX_BUF]; /* eauugggh */ |
176 | |
171 | |
177 | if (socket.current_map != ob->map) |
172 | if (socket.current_map != ob->map) |
178 | { |
173 | { |
… | |
… | |
249 | buf += 8; |
244 | buf += 8; |
250 | |
245 | |
251 | // initial map and its origin |
246 | // initial map and its origin |
252 | maptile *map = pl->ob->map; |
247 | maptile *map = pl->ob->map; |
253 | sint16 dx, dy; |
248 | sint16 dx, dy; |
254 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
249 | int mapx = pl->socket->mapx / 2 - pl->ob->x; |
255 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
250 | int mapy = pl->socket->mapy / 2 - pl->ob->y; |
256 | int max_distance = 8; // limit maximum path length to something generous |
251 | int max_distance = 8; // limit maximum path length to something generous |
257 | |
252 | |
258 | while (*buf && map && max_distance) |
253 | while (*buf && map && max_distance) |
259 | { |
254 | { |
260 | int dir = *buf++; |
255 | int dir = *buf++; |
… | |
… | |
311 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
306 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
312 | } |
307 | } |
313 | else |
308 | else |
314 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
309 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
315 | |
310 | |
316 | pl->socket.send_packet (bigbuf); |
311 | pl->socket->send_packet (bigbuf); |
317 | } |
312 | } |
318 | |
313 | |
319 | /** This is the Setup cmd - easy first implementation */ |
314 | /** This is the Setup cmd - easy first implementation */ |
320 | void |
315 | void |
321 | SetUp (char *buf, int len, client_socket * ns) |
316 | SetUp (char *buf, int len, client_socket * ns) |
… | |
… | |
544 | |
539 | |
545 | oldsettings = settings; |
540 | oldsettings = settings; |
546 | if (ns->status != Ns_Add || add_player (ns)) |
541 | if (ns->status != Ns_Add || add_player (ns)) |
547 | ns->send_packet ("addme_failed"); |
542 | ns->send_packet ("addme_failed"); |
548 | else |
543 | else |
549 | { |
|
|
550 | /* Basically, the add_player copies the socket structure into |
|
|
551 | * the player structure, so this one (which is from init_sockets) |
|
|
552 | * is not needed anymore. The write below should still work, as the |
|
|
553 | * stuff in ns is still relevant. |
|
|
554 | */ |
|
|
555 | ns->send_packet ("addme_success"); |
544 | ns->send_packet ("addme_success"); |
556 | socket_info.nconns--; |
|
|
557 | ns->status = Ns_Avail; |
|
|
558 | } |
|
|
559 | |
545 | |
560 | settings = oldsettings; |
546 | settings = oldsettings; |
561 | } |
547 | } |
562 | |
548 | |
563 | /** Reply to ExtendedInfos command */ |
549 | /** Reply to ExtendedInfos command */ |
… | |
… | |
708 | |
694 | |
709 | sl << "smooth " |
695 | sl << "smooth " |
710 | << uint16 (face) |
696 | << uint16 (face) |
711 | << uint16 (smoothface); |
697 | << uint16 (smoothface); |
712 | |
698 | |
713 | Send_With_Handling (ns, &sl); |
699 | ns->send_packet (sl); |
714 | } |
700 | } |
715 | |
701 | |
716 | /** |
702 | /** |
717 | * Tells client the picture it has to use |
703 | * Tells client the picture it has to use |
718 | * to smooth a picture number given as argument. |
704 | * to smooth a picture number given as argument. |
… | |
… | |
783 | * etc.). It is a lot like PlayerCmd above, but is called with the |
769 | * etc.). It is a lot like PlayerCmd above, but is called with the |
784 | * 'ncom' method which gives more information back to the client so it |
770 | * 'ncom' method which gives more information back to the client so it |
785 | * can throttle. |
771 | * can throttle. |
786 | */ |
772 | */ |
787 | void |
773 | void |
788 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
774 | NewPlayerCmd (char *buf, int len, player *pl) |
789 | { |
775 | { |
790 | int time, repeat; |
776 | int time, repeat; |
791 | char command[MAX_BUF]; |
777 | char command[MAX_BUF]; |
792 | int pktlen; |
778 | int pktlen; |
793 | |
779 | |
… | |
… | |
795 | { |
781 | { |
796 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
782 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
797 | return; |
783 | return; |
798 | } |
784 | } |
799 | |
785 | |
800 | pktlen = net_uint16 (buf); |
786 | pktlen = net_uint16 ((uint8 *)buf); |
801 | repeat = net_uint32 (buf + 2); |
787 | repeat = net_uint32 ((uint8 *)buf + 2); |
802 | |
788 | |
803 | /* -1 is special - no repeat, but don't update */ |
789 | /* -1 is special - no repeat, but don't update */ |
804 | if (repeat != -1) |
790 | if (repeat != -1) |
805 | pl->count = repeat; |
791 | pl->count = repeat; |
806 | |
792 | |
807 | if ((len - 4) >= MAX_BUF) |
793 | if ((len - 4) >= MAX_BUF) |
808 | len = MAX_BUF - 5; |
794 | len = MAX_BUF - 5; |
809 | |
795 | |
810 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
796 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
811 | command[len - 4] = '\0'; |
797 | command[len - 4] = 0; |
812 | |
|
|
813 | /* The following should never happen with a proper or honest client. |
|
|
814 | * Therefore, the error message doesn't have to be too clear - if |
|
|
815 | * someone is playing with a hacked/non working client, this gives them |
|
|
816 | * an idea of the problem, but they deserve what they get |
|
|
817 | */ |
|
|
818 | if (pl->state != ST_PLAYING) |
|
|
819 | { |
|
|
820 | new_draw_info_format (NDI_UNIQUE, 0, pl->ob, "You can not issue commands - state is not ST_PLAYING (%s)", buf); |
|
|
821 | return; |
|
|
822 | } |
|
|
823 | |
798 | |
824 | /* This should not happen anymore. */ |
799 | /* This should not happen anymore. */ |
825 | if (pl->ob->speed_left < -1.0) |
800 | if (pl->ob->speed_left < -1.0) |
826 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
801 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
827 | |
802 | |
… | |
… | |
841 | |
816 | |
842 | /* Send confirmation of command execution now */ |
817 | /* Send confirmation of command execution now */ |
843 | |
818 | |
844 | packet sl; |
819 | packet sl; |
845 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
820 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
846 | Send_With_Handling (&pl->socket, &sl); |
821 | pl->socket->send_packet (sl); |
847 | } |
822 | } |
848 | |
823 | |
849 | |
824 | |
850 | /** This is a reply to a previous query. */ |
825 | /** This is a reply to a previous query. */ |
851 | void |
826 | void |
… | |
… | |
996 | */ |
971 | */ |
997 | #if 0 |
972 | #if 0 |
998 | /* Okay, this is MAJOR UGLY. but the only way I know how to |
973 | /* Okay, this is MAJOR UGLY. but the only way I know how to |
999 | * clear the "cache" |
974 | * clear the "cache" |
1000 | */ |
975 | */ |
1001 | memset (&pl->socket.lastmap, 0, sizeof (struct Map)); |
976 | memset (&pl->socket->lastmap, 0, sizeof (struct Map)); |
1002 | draw_client_map (pl->ob); |
977 | draw_client_map (pl->ob); |
1003 | #endif |
978 | #endif |
1004 | } |
979 | } |
1005 | |
980 | |
1006 | /** |
981 | /** |
… | |
… | |
1109 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1084 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1110 | AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
1085 | AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); |
1111 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1086 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1112 | } |
1087 | } |
1113 | |
1088 | |
1114 | if (pl->socket.exp64) |
1089 | if (pl->socket->exp64) |
1115 | { |
1090 | { |
1116 | uint8 s; |
1091 | uint8 s; |
1117 | |
1092 | |
1118 | for (s = 0; s < NUM_SKILLS; s++) |
1093 | for (s = 0; s < NUM_SKILLS; s++) |
1119 | { |
1094 | { |
… | |
… | |
1129 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1104 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1130 | } |
1105 | } |
1131 | } |
1106 | } |
1132 | } |
1107 | } |
1133 | |
1108 | |
1134 | if (pl->socket.exp64) |
1109 | if (pl->socket->exp64) |
1135 | { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } |
1110 | { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } |
1136 | else |
1111 | else |
1137 | { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } |
1112 | { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } |
1138 | |
1113 | |
1139 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1114 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
… | |
… | |
1152 | if (pl->run_on) |
1127 | if (pl->run_on) |
1153 | flags |= SF_RUNON; |
1128 | flags |= SF_RUNON; |
1154 | |
1129 | |
1155 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1130 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1156 | |
1131 | |
1157 | if (pl->socket.sc_version < 1025) |
1132 | if (pl->socket->sc_version < 1025) |
1158 | { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
1133 | { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
1159 | else |
1134 | else |
1160 | { |
1135 | { |
1161 | int i; |
1136 | int i; |
1162 | |
1137 | |
… | |
… | |
1168 | |
1143 | |
1169 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1144 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1170 | } |
1145 | } |
1171 | } |
1146 | } |
1172 | |
1147 | |
1173 | if (pl->socket.monitor_spells) |
1148 | if (pl->socket->monitor_spells) |
1174 | { |
1149 | { |
1175 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1150 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1176 | AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1151 | AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); |
1177 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1152 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1178 | } |
1153 | } |
1179 | |
1154 | |
1180 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1155 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1181 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1156 | AddIfString (pl->socket->stats.range, buf, CS_STAT_RANGE); |
1182 | set_title (pl->ob, buf); |
1157 | set_title (pl->ob, buf); |
1183 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1158 | AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); |
1184 | |
1159 | |
1185 | /* Only send it away if we have some actual data */ |
1160 | /* Only send it away if we have some actual data */ |
1186 | if (sl.length () > 6) |
1161 | if (sl.length () > 6) |
1187 | Send_With_Handling (&pl->socket, &sl); |
1162 | pl->socket->send_packet (sl); |
1188 | } |
1163 | } |
1189 | |
1164 | |
1190 | /** |
1165 | /** |
1191 | * Tells the client that here is a player it should start using. |
1166 | * Tells the client that here is a player it should start using. |
1192 | */ |
1167 | */ |
… | |
… | |
1201 | sl << uint32 (pl->ob->count) |
1176 | sl << uint32 (pl->ob->count) |
1202 | << uint32 (weight) |
1177 | << uint32 (weight) |
1203 | << uint32 (pl->ob->face->number) |
1178 | << uint32 (pl->ob->face->number) |
1204 | << data8 (pl->ob->name); |
1179 | << data8 (pl->ob->name); |
1205 | |
1180 | |
1206 | Send_With_Handling (&pl->socket, &sl); |
1181 | pl->socket->send_packet (sl); |
1207 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1182 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1208 | } |
1183 | } |
1209 | |
1184 | |
1210 | /** |
1185 | /** |
1211 | * Need to send an animation sequence to the client. |
1186 | * Need to send an animation sequence to the client. |
… | |
… | |
1243 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1218 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1244 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1219 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1245 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1220 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1246 | } |
1221 | } |
1247 | |
1222 | |
1248 | Send_With_Handling (ns, &sl); |
1223 | ns->send_packet (sl); |
1249 | |
1224 | |
1250 | ns->anims_sent[anim_num] = 1; |
1225 | ns->anims_sent[anim_num] = 1; |
1251 | } |
1226 | } |
1252 | |
1227 | |
1253 | |
1228 | |
… | |
… | |
1788 | uint8 eentrysize; |
1763 | uint8 eentrysize; |
1789 | uint16 ewhatstart, ewhatflag; |
1764 | uint16 ewhatstart, ewhatflag; |
1790 | uint8 extendedinfos; |
1765 | uint8 extendedinfos; |
1791 | maptile *m; |
1766 | maptile *m; |
1792 | |
1767 | |
1793 | client_socket &socket = pl->contr->socket; |
1768 | client_socket &socket = *pl->contr->socket; |
1794 | |
1769 | |
1795 | check_map_change (pl->contr); |
1770 | check_map_change (pl->contr); |
1796 | |
1771 | |
1797 | packet sl; |
1772 | packet sl; |
1798 | packet esl; |
1773 | packet esl; |
… | |
… | |
1877 | * with no faces tells the client to blank out the |
1852 | * with no faces tells the client to blank out the |
1878 | * space. |
1853 | * space. |
1879 | */ |
1854 | */ |
1880 | got_one = 0; |
1855 | got_one = 0; |
1881 | for (i = oldlen + 2; i < sl.length (); i++) |
1856 | for (i = oldlen + 2; i < sl.length (); i++) |
1882 | if (sl.buf[i]) |
1857 | if (sl[i]) |
1883 | got_one = 1; |
1858 | got_one = 1; |
1884 | |
1859 | |
1885 | if (got_one && (mask & 0xf)) |
1860 | if (got_one && (mask & 0xf)) |
1886 | sl.buf[oldlen + 1] = mask & 0xff; |
1861 | sl[oldlen + 1] = mask & 0xff; |
1887 | else |
1862 | else |
1888 | { /*either all faces blank, either no face at all */ |
1863 | { /*either all faces blank, either no face at all */ |
1889 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1864 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1890 | sl.reset (oldlen + 2); |
1865 | sl.reset (oldlen + 2); |
1891 | else |
1866 | else |
… | |
… | |
1957 | |
1932 | |
1958 | map_clearcell (&lastcell, 0, 0, 0, count); |
1933 | map_clearcell (&lastcell, 0, 0, 0, count); |
1959 | } |
1934 | } |
1960 | |
1935 | |
1961 | if ((mask & 0xf) || need_send) |
1936 | if ((mask & 0xf) || need_send) |
1962 | sl.buf[oldlen + 1] = mask & 0xff; |
1937 | sl[oldlen + 1] = mask & 0xff; |
1963 | else |
1938 | else |
1964 | sl.reset (oldlen); |
1939 | sl.reset (oldlen); |
1965 | } |
1940 | } |
1966 | else |
1941 | else |
1967 | { |
1942 | { |
… | |
… | |
1997 | mask |= 0x8; |
1972 | mask |= 0x8; |
1998 | |
1973 | |
1999 | if (socket.extmap) |
1974 | if (socket.extmap) |
2000 | { |
1975 | { |
2001 | *last_ext |= 0x80; |
1976 | *last_ext |= 0x80; |
2002 | last_ext = sl.buf + sl.length (); |
1977 | last_ext = &sl[sl.length ()]; |
2003 | sl << uint8 (d); |
1978 | sl << uint8 (d); |
2004 | } |
1979 | } |
2005 | else |
1980 | else |
2006 | sl << uint8 (255 - 64 * d); |
1981 | sl << uint8 (255 - 64 * d); |
2007 | } |
1982 | } |
… | |
… | |
2041 | { |
2016 | { |
2042 | lastcell.stat_hp = stat_hp; |
2017 | lastcell.stat_hp = stat_hp; |
2043 | |
2018 | |
2044 | mask |= 0x8; |
2019 | mask |= 0x8; |
2045 | *last_ext |= 0x80; |
2020 | *last_ext |= 0x80; |
2046 | last_ext = sl.buf + sl.length (); |
2021 | last_ext = &sl[sl.length ()]; |
2047 | |
2022 | |
2048 | sl << uint8 (5) << uint8 (stat_hp); |
2023 | sl << uint8 (5) << uint8 (stat_hp); |
2049 | |
2024 | |
2050 | if (stat_width > 1) |
2025 | if (stat_width > 1) |
2051 | { |
2026 | { |
2052 | *last_ext |= 0x80; |
2027 | *last_ext |= 0x80; |
2053 | last_ext = sl.buf + sl.length (); |
2028 | last_ext = &sl[sl.length ()]; |
2054 | |
2029 | |
2055 | sl << uint8 (6) << uint8 (stat_width); |
2030 | sl << uint8 (6) << uint8 (stat_width); |
2056 | } |
2031 | } |
2057 | } |
2032 | } |
2058 | |
2033 | |
… | |
… | |
2060 | { |
2035 | { |
2061 | lastcell.player = player; |
2036 | lastcell.player = player; |
2062 | |
2037 | |
2063 | mask |= 0x8; |
2038 | mask |= 0x8; |
2064 | *last_ext |= 0x80; |
2039 | *last_ext |= 0x80; |
2065 | last_ext = sl.buf + sl.length (); |
2040 | last_ext = &sl[sl.length ()]; |
2066 | |
2041 | |
2067 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2042 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2068 | } |
2043 | } |
2069 | |
2044 | |
2070 | if (lastcell.flags != flags) |
2045 | if (lastcell.flags != flags) |
2071 | { |
2046 | { |
2072 | lastcell.flags = flags; |
2047 | lastcell.flags = flags; |
2073 | |
2048 | |
2074 | mask |= 0x8; |
2049 | mask |= 0x8; |
2075 | *last_ext |= 0x80; |
2050 | *last_ext |= 0x80; |
2076 | last_ext = sl.buf + sl.length (); |
2051 | last_ext = &sl[sl.length ()]; |
2077 | |
2052 | |
2078 | sl << uint8 (8) << uint8 (flags); |
2053 | sl << uint8 (8) << uint8 (flags); |
2079 | } |
2054 | } |
2080 | } |
2055 | } |
2081 | |
2056 | |
… | |
… | |
2123 | * space by checking the mask. If so, update the mask. |
2098 | * space by checking the mask. If so, update the mask. |
2124 | * if not, reset the len to that from before adding the mask |
2099 | * if not, reset the len to that from before adding the mask |
2125 | * value, so we don't send those bits. |
2100 | * value, so we don't send those bits. |
2126 | */ |
2101 | */ |
2127 | if (mask & 0xf) |
2102 | if (mask & 0xf) |
2128 | sl.buf[oldlen + 1] = mask & 0xff; |
2103 | sl[oldlen + 1] = mask & 0xff; |
2129 | else |
2104 | else |
2130 | sl.reset (oldlen); |
2105 | sl.reset (oldlen); |
2131 | |
2106 | |
2132 | if (emask & 0xf) |
2107 | if (emask & 0xf) |
2133 | esl.buf[eoldlen + 1] = emask & 0xff; |
2108 | esl[eoldlen + 1] = emask & 0xff; |
2134 | else |
2109 | else |
2135 | esl.reset (eoldlen); |
2110 | esl.reset (eoldlen); |
2136 | } /* else this is a viewable space */ |
2111 | } /* else this is a viewable space */ |
2137 | } /* for x loop */ |
2112 | } /* for x loop */ |
2138 | } /* for y loop */ |
2113 | } /* for y loop */ |
… | |
… | |
2144 | { |
2119 | { |
2145 | /* No map data will follow, so don't say the client |
2120 | /* No map data will follow, so don't say the client |
2146 | * it doesn't need draw! |
2121 | * it doesn't need draw! |
2147 | */ |
2122 | */ |
2148 | ewhatflag &= (~EMI_NOREDRAW); |
2123 | ewhatflag &= (~EMI_NOREDRAW); |
2149 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2124 | esl[ewhatstart + 1] = ewhatflag & 0xff; |
2150 | } |
2125 | } |
2151 | |
2126 | |
2152 | if (esl.length () > estartlen) |
2127 | if (esl.length () > estartlen) |
2153 | Send_With_Handling (&socket, &esl); |
2128 | socket.send_packet (esl); |
2154 | } |
2129 | } |
2155 | |
2130 | |
2156 | if (sl.length () > startlen || socket.sent_scroll) |
2131 | if (sl.length () > startlen || socket.sent_scroll) |
2157 | { |
2132 | { |
2158 | Send_With_Handling (&socket, &sl); |
2133 | socket.send_packet (sl); |
2159 | socket.sent_scroll = 0; |
2134 | socket.sent_scroll = 0; |
2160 | } |
2135 | } |
2161 | } |
2136 | } |
2162 | |
2137 | |
2163 | /** |
2138 | /** |
… | |
… | |
2189 | if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) |
2164 | if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) |
2190 | return; |
2165 | return; |
2191 | |
2166 | |
2192 | memset (&newmap, 0, sizeof (struct Map)); |
2167 | memset (&newmap, 0, sizeof (struct Map)); |
2193 | |
2168 | |
2194 | for (j = (pl->y - pl->contr->socket.mapy / 2); j < (pl->y + (pl->contr->socket.mapy + 1) / 2); j++) |
2169 | for (j = (pl->y - pl->contr->socket->mapy / 2); j < (pl->y + (pl->contr->socket->mapy + 1) / 2); j++) |
2195 | { |
2170 | { |
2196 | for (i = (pl->x - pl->contr->socket.mapx / 2); i < (pl->x + (pl->contr->socket.mapx + 1) / 2); i++) |
2171 | for (i = (pl->x - pl->contr->socket->mapx / 2); i < (pl->x + (pl->contr->socket->mapx + 1) / 2); i++) |
2197 | { |
2172 | { |
2198 | ax = i; |
2173 | ax = i; |
2199 | ay = j; |
2174 | ay = j; |
2200 | m = pm; |
2175 | m = pm; |
2201 | mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); |
2176 | mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); |
… | |
… | |
2233 | |
2208 | |
2234 | /*****************************************************************************/ |
2209 | /*****************************************************************************/ |
2235 | void |
2210 | void |
2236 | send_plugin_custom_message (object *pl, char *buf) |
2211 | send_plugin_custom_message (object *pl, char *buf) |
2237 | { |
2212 | { |
2238 | pl->contr->socket.send_packet (buf); |
2213 | pl->contr->socket->send_packet (buf); |
2239 | } |
2214 | } |
2240 | |
2215 | |
2241 | /** |
2216 | /** |
2242 | * This sends the skill number to name mapping. We ignore |
2217 | * This sends the skill number to name mapping. We ignore |
2243 | * the params - we always send the same info no matter what. |
2218 | * the params - we always send the same info no matter what. |
… | |
… | |
2255 | { |
2230 | { |
2256 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2231 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2257 | fatal (0); |
2232 | fatal (0); |
2258 | } |
2233 | } |
2259 | |
2234 | |
2260 | Send_With_Handling (ns, &sl); |
2235 | ns->send_packet (sl); |
2261 | } |
2236 | } |
2262 | |
2237 | |
2263 | /** |
2238 | /** |
2264 | * This sends the spell path to name mapping. We ignore |
2239 | * This sends the spell path to name mapping. We ignore |
2265 | * the params - we always send the same info no matter what. |
2240 | * the params - we always send the same info no matter what. |
… | |
… | |
2278 | { |
2253 | { |
2279 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2254 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2280 | fatal (0); |
2255 | fatal (0); |
2281 | } |
2256 | } |
2282 | |
2257 | |
2283 | Send_With_Handling (ns, &sl); |
2258 | ns->send_packet (sl); |
2284 | } |
2259 | } |
2285 | |
2260 | |
2286 | /** |
2261 | /** |
2287 | * This looks for any spells the player may have that have changed their stats. |
2262 | * This looks for any spells the player may have that have changed their stats. |
2288 | * it then sends an updspell packet for each spell that has changed in this way |
2263 | * it then sends an updspell packet for each spell that has changed in this way |
2289 | */ |
2264 | */ |
2290 | void |
2265 | void |
2291 | esrv_update_spells (player *pl) |
2266 | esrv_update_spells (player *pl) |
2292 | { |
2267 | { |
2293 | if (!pl->socket.monitor_spells) |
2268 | if (!pl->socket->monitor_spells) |
2294 | return; |
2269 | return; |
2295 | |
2270 | |
2296 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
2271 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
2297 | { |
2272 | { |
2298 | if (spell->type == SPELL) |
2273 | if (spell->type == SPELL) |
… | |
… | |
2328 | |
2303 | |
2329 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2304 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2330 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2305 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2331 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2306 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2332 | |
2307 | |
2333 | Send_With_Handling (&pl->socket, &sl); |
2308 | pl->socket->send_packet (sl); |
2334 | } |
2309 | } |
2335 | } |
2310 | } |
2336 | } |
2311 | } |
2337 | } |
2312 | } |
2338 | |
2313 | |
2339 | void |
2314 | void |
2340 | esrv_remove_spell (player *pl, object *spell) |
2315 | esrv_remove_spell (player *pl, object *spell) |
2341 | { |
2316 | { |
2342 | if (!pl->socket.monitor_spells) |
2317 | if (!pl->socket->monitor_spells) |
2343 | return; |
2318 | return; |
2344 | |
2319 | |
2345 | if (!pl || !spell || spell->env != pl->ob) |
2320 | if (!pl || !spell || spell->env != pl->ob) |
2346 | { |
2321 | { |
2347 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2322 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
… | |
… | |
2351 | packet sl; |
2326 | packet sl; |
2352 | |
2327 | |
2353 | sl << "delspell " |
2328 | sl << "delspell " |
2354 | << uint32 (spell->count); |
2329 | << uint32 (spell->count); |
2355 | |
2330 | |
2356 | Send_With_Handling (&pl->socket, &sl); |
2331 | pl->socket->send_packet (sl); |
2357 | } |
2332 | } |
2358 | |
2333 | |
2359 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2334 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2360 | static void |
2335 | static void |
2361 | append_spell (player *pl, packet &sl, object *spell) |
2336 | append_spell (player *pl, packet &sl, object *spell) |
… | |
… | |
2409 | { |
2384 | { |
2410 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2385 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2411 | return; |
2386 | return; |
2412 | } |
2387 | } |
2413 | |
2388 | |
2414 | if (!pl->socket.monitor_spells) |
2389 | if (!pl->socket->monitor_spells) |
2415 | return; |
2390 | return; |
2416 | |
2391 | |
2417 | packet sl; |
2392 | packet sl; |
2418 | |
2393 | |
2419 | sl << "addspell "; |
2394 | sl << "addspell "; |
… | |
… | |
2438 | if (spell->type != SPELL) |
2413 | if (spell->type != SPELL) |
2439 | continue; |
2414 | continue; |
2440 | |
2415 | |
2441 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2416 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2442 | { |
2417 | { |
2443 | Send_With_Handling (&pl->socket, &sl); |
2418 | pl->socket->send_packet (sl); |
2444 | |
2419 | |
2445 | sl.reset (); |
2420 | sl.reset (); |
2446 | sl << "addspell "; |
2421 | sl << "addspell "; |
2447 | } |
2422 | } |
2448 | |
2423 | |
… | |
… | |
2462 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2437 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2463 | fatal (0); |
2438 | fatal (0); |
2464 | } |
2439 | } |
2465 | |
2440 | |
2466 | /* finally, we can send the packet */ |
2441 | /* finally, we can send the packet */ |
2467 | Send_With_Handling (&pl->socket, &sl); |
2442 | pl->socket->send_packet (sl); |
2468 | |
|
|
2469 | } |
2443 | } |
2470 | |
2444 | |