… | |
… | |
46 | */ |
46 | */ |
47 | |
47 | |
48 | #include <global.h> |
48 | #include <global.h> |
49 | #include <sproto.h> |
49 | #include <sproto.h> |
50 | |
50 | |
51 | #include <newclient.h> |
|
|
52 | #include <newserver.h> |
|
|
53 | #include <living.h> |
51 | #include <living.h> |
54 | #include <commands.h> |
52 | #include <commands.h> |
55 | |
53 | |
56 | /* This block is basically taken from socket.c - I assume if it works there, |
54 | /* This block is basically taken from socket.c - I assume if it works there, |
57 | * it should work here. |
55 | * it should work here. |
… | |
… | |
60 | #include <sys/time.h> |
58 | #include <sys/time.h> |
61 | #include <sys/socket.h> |
59 | #include <sys/socket.h> |
62 | #include <netinet/in.h> |
60 | #include <netinet/in.h> |
63 | #include <netdb.h> |
61 | #include <netdb.h> |
64 | |
62 | |
65 | #ifdef HAVE_UNISTD_H |
|
|
66 | # include <unistd.h> |
63 | #include <unistd.h> |
67 | #endif |
|
|
68 | |
|
|
69 | #ifdef HAVE_SYS_TIME_H |
|
|
70 | # include <sys/time.h> |
64 | #include <sys/time.h> |
71 | #endif |
|
|
72 | |
65 | |
73 | #include "sounds.h" |
66 | #include "sounds.h" |
74 | |
67 | |
75 | /** |
68 | /** |
76 | * This table translates the attack numbers as used within the |
69 | * This table translates the attack numbers as used within the |
… | |
… | |
93 | -1, /* life stealing */ |
86 | -1, /* life stealing */ |
94 | -1 /* Disease - not fully done yet */ |
87 | -1 /* Disease - not fully done yet */ |
95 | }; |
88 | }; |
96 | |
89 | |
97 | static void |
90 | static void |
98 | socket_map_scroll (NewSocket * ns, int dx, int dy) |
91 | socket_map_scroll (client * ns, int dx, int dy) |
99 | { |
92 | { |
100 | struct Map newmap; |
93 | struct Map newmap; |
101 | int x, y, mx, my; |
94 | int x, y, mx, my; |
102 | |
95 | |
103 | { |
96 | { |
… | |
… | |
153 | } |
146 | } |
154 | |
147 | |
155 | static void |
148 | static void |
156 | clear_map (player *pl) |
149 | clear_map (player *pl) |
157 | { |
150 | { |
158 | NewSocket & socket = pl->socket; |
151 | client &socket = *pl->socket; |
159 | |
152 | |
160 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
153 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
161 | |
154 | |
162 | if (socket.newmapcmd == 1) |
155 | if (socket.newmapcmd == 1) |
163 | socket.send_packet ("newmap"); |
156 | socket.send_packet ("newmap"); |
… | |
… | |
168 | |
161 | |
169 | /** check for map change and send new map data */ |
162 | /** check for map change and send new map data */ |
170 | static void |
163 | static void |
171 | check_map_change (player *pl) |
164 | check_map_change (player *pl) |
172 | { |
165 | { |
173 | NewSocket & socket = pl->socket; |
166 | client &socket = *pl->socket; |
174 | object *ob = pl->ob; |
167 | object *ob = pl->ob; |
175 | char buf[MAX_BUF]; /* eauugggh */ |
168 | char buf[MAX_BUF]; /* eauugggh */ |
176 | |
169 | |
177 | if (socket.current_map != ob->map) |
170 | if (socket.current_map != ob->map) |
178 | { |
171 | { |
… | |
… | |
221 | |
214 | |
222 | socket.current_x = ob->x; |
215 | socket.current_x = ob->x; |
223 | socket.current_y = ob->y; |
216 | socket.current_y = ob->y; |
224 | } |
217 | } |
225 | |
218 | |
|
|
219 | /** |
|
|
220 | * RequestInfo is sort of a meta command. There is some specific |
|
|
221 | * request of information, but we call other functions to provide |
|
|
222 | * that information. |
|
|
223 | */ |
|
|
224 | void |
|
|
225 | RequestInfo (char *buf, int len, client * ns) |
|
|
226 | { |
|
|
227 | char *params = NULL, *cp; |
|
|
228 | |
|
|
229 | /* No match */ |
|
|
230 | char bigbuf[MAX_BUF]; |
|
|
231 | int slen; |
|
|
232 | |
|
|
233 | /* Set up replyinfo before we modify any of the buffers - this is used |
|
|
234 | * if we don't find a match. |
|
|
235 | */ |
|
|
236 | strcpy (bigbuf, "replyinfo "); |
|
|
237 | slen = strlen (bigbuf); |
|
|
238 | safe_strcat (bigbuf, buf, &slen, MAX_BUF); |
|
|
239 | |
|
|
240 | /* find the first space, make it null, and update the |
|
|
241 | * params pointer. |
|
|
242 | */ |
|
|
243 | for (cp = buf; *cp != '\0'; cp++) |
|
|
244 | if (*cp == ' ') |
|
|
245 | { |
|
|
246 | *cp = '\0'; |
|
|
247 | params = cp + 1; |
|
|
248 | break; |
|
|
249 | } |
|
|
250 | |
|
|
251 | if (!strcmp (buf, "image_info")) |
|
|
252 | send_image_info (ns, params); |
|
|
253 | else if (!strcmp (buf, "image_sums")) |
|
|
254 | send_image_sums (ns, params); |
|
|
255 | else if (!strcmp (buf, "skill_info")) |
|
|
256 | send_skill_info (ns, params); |
|
|
257 | else if (!strcmp (buf, "spell_paths")) |
|
|
258 | send_spell_paths (ns, params); |
|
|
259 | else |
|
|
260 | ns->send_packet (bigbuf, len); |
|
|
261 | } |
|
|
262 | |
226 | void |
263 | void |
227 | ExtCmd (char *buf, int len, player *pl) |
264 | ExtCmd (char *buf, int len, player *pl) |
228 | { |
265 | { |
229 | INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len)); |
266 | INVOKE_PLAYER (EXTCMD, pl, ARG_DATA (buf, len)); |
230 | } |
267 | } |
… | |
… | |
249 | buf += 8; |
286 | buf += 8; |
250 | |
287 | |
251 | // initial map and its origin |
288 | // initial map and its origin |
252 | maptile *map = pl->ob->map; |
289 | maptile *map = pl->ob->map; |
253 | sint16 dx, dy; |
290 | sint16 dx, dy; |
254 | int mapx = pl->socket.mapx / 2 - pl->ob->x; |
291 | int mapx = pl->socket->mapx / 2 - pl->ob->x; |
255 | int mapy = pl->socket.mapy / 2 - pl->ob->y; |
292 | int mapy = pl->socket->mapy / 2 - pl->ob->y; |
256 | int max_distance = 8; // limit maximum path length to something generous |
293 | int max_distance = 8; // limit maximum path length to something generous |
257 | |
294 | |
258 | while (*buf && map && max_distance) |
295 | while (*buf && map && max_distance) |
259 | { |
296 | { |
260 | int dir = *buf++; |
297 | int dir = *buf++; |
… | |
… | |
311 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
348 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
312 | } |
349 | } |
313 | else |
350 | else |
314 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
351 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
315 | |
352 | |
316 | pl->socket.send_packet (bigbuf); |
353 | pl->socket->send_packet (bigbuf); |
317 | } |
354 | } |
318 | |
355 | |
319 | /** This is the Setup cmd - easy first implementation */ |
356 | /** This is the Setup cmd - easy first implementation */ |
320 | void |
357 | void |
321 | SetUp (char *buf, int len, NewSocket * ns) |
358 | SetUp (char *buf, int len, client * ns) |
322 | { |
359 | { |
323 | int s, slen; |
360 | int s, slen; |
324 | char *cmd, *param, cmdback[HUGE_BUF]; |
361 | char *cmd, *param, cmdback[HUGE_BUF]; |
325 | |
362 | |
326 | /* run through the cmds of setup |
363 | /* run through the cmds of setup |
… | |
… | |
536 | * This is what takes care of it. We tell the client how things worked out. |
573 | * This is what takes care of it. We tell the client how things worked out. |
537 | * I am not sure if this file is the best place for this function. however, |
574 | * I am not sure if this file is the best place for this function. however, |
538 | * it either has to be here or init_sockets needs to be exported. |
575 | * it either has to be here or init_sockets needs to be exported. |
539 | */ |
576 | */ |
540 | void |
577 | void |
541 | AddMeCmd (char *buf, int len, NewSocket * ns) |
578 | AddMeCmd (char *buf, int len, client * ns) |
542 | { |
579 | { |
543 | Settings oldsettings; |
580 | Settings oldsettings; |
544 | |
581 | |
545 | oldsettings = settings; |
582 | oldsettings = settings; |
546 | if (ns->status != Ns_Add || add_player (ns)) |
583 | if (ns->status != Ns_Add || add_player (ns)) |
547 | ns->send_packet ("addme_failed"); |
584 | ns->send_packet ("addme_failed"); |
548 | else |
585 | 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"); |
586 | ns->send_packet ("addme_success"); |
556 | socket_info.nconns--; |
|
|
557 | ns->status = Ns_Avail; |
|
|
558 | } |
|
|
559 | |
587 | |
560 | settings = oldsettings; |
588 | settings = oldsettings; |
561 | } |
589 | } |
562 | |
590 | |
563 | /** Reply to ExtendedInfos command */ |
591 | /** Reply to ExtendedInfos command */ |
564 | void |
592 | void |
565 | ToggleExtendedInfos (char *buf, int len, NewSocket * ns) |
593 | ToggleExtendedInfos (char *buf, int len, client * ns) |
566 | { |
594 | { |
567 | char cmdback[MAX_BUF]; |
595 | char cmdback[MAX_BUF]; |
568 | char command[50]; |
596 | char command[50]; |
569 | int info, nextinfo; |
597 | int info, nextinfo; |
570 | |
598 | |
… | |
… | |
621 | #define MSG_TYPE_MONUMENT 5 |
649 | #define MSG_TYPE_MONUMENT 5 |
622 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
650 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
623 | |
651 | |
624 | /** Reply to ExtendedInfos command */ |
652 | /** Reply to ExtendedInfos command */ |
625 | void |
653 | void |
626 | ToggleExtendedText (char *buf, int len, NewSocket * ns) |
654 | ToggleExtendedText (char *buf, int len, client * ns) |
627 | { |
655 | { |
628 | char cmdback[MAX_BUF]; |
656 | char cmdback[MAX_BUF]; |
629 | char temp[10]; |
657 | char temp[10]; |
630 | char command[50]; |
658 | char command[50]; |
631 | int info, nextinfo, i, flag; |
659 | int info, nextinfo, i, flag; |
… | |
… | |
682 | * a piece of data from us that we know the client wants. So |
710 | * a piece of data from us that we know the client wants. So |
683 | * if we know the client wants it, might as well push it to the |
711 | * if we know the client wants it, might as well push it to the |
684 | * client. |
712 | * client. |
685 | */ |
713 | */ |
686 | static void |
714 | static void |
687 | SendSmooth (NewSocket * ns, uint16 face) |
715 | SendSmooth (client * ns, uint16 face) |
688 | { |
716 | { |
689 | uint16 smoothface; |
717 | uint16 smoothface; |
690 | |
718 | |
691 | /* If we can't find a face, return and set it so we won't try to send this |
719 | /* If we can't find a face, return and set it so we won't try to send this |
692 | * again. |
720 | * again. |
… | |
… | |
708 | |
736 | |
709 | sl << "smooth " |
737 | sl << "smooth " |
710 | << uint16 (face) |
738 | << uint16 (face) |
711 | << uint16 (smoothface); |
739 | << uint16 (smoothface); |
712 | |
740 | |
713 | Send_With_Handling (ns, &sl); |
741 | ns->send_packet (sl); |
714 | } |
742 | } |
715 | |
743 | |
716 | /** |
744 | /** |
717 | * Tells client the picture it has to use |
745 | * Tells client the picture it has to use |
718 | * to smooth a picture number given as argument. |
746 | * to smooth a picture number given as argument. |
719 | */ |
747 | */ |
720 | void |
748 | void |
721 | AskSmooth (char *buf, int len, NewSocket * ns) |
749 | AskSmooth (char *buf, int len, client * ns) |
722 | { |
750 | { |
723 | uint16 facenbr; |
751 | uint16 facenbr; |
724 | |
752 | |
725 | facenbr = atoi (buf); |
753 | facenbr = atoi (buf); |
726 | SendSmooth (ns, facenbr); |
754 | SendSmooth (ns, facenbr); |
… | |
… | |
783 | * etc.). It is a lot like PlayerCmd above, but is called with the |
811 | * 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 |
812 | * 'ncom' method which gives more information back to the client so it |
785 | * can throttle. |
813 | * can throttle. |
786 | */ |
814 | */ |
787 | void |
815 | void |
788 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
816 | NewPlayerCmd (char *buf, int len, player *pl) |
789 | { |
817 | { |
790 | int time, repeat; |
818 | int time, repeat; |
791 | char command[MAX_BUF]; |
819 | char command[MAX_BUF]; |
792 | int pktlen; |
820 | int pktlen; |
793 | |
821 | |
… | |
… | |
795 | { |
823 | { |
796 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
824 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
797 | return; |
825 | return; |
798 | } |
826 | } |
799 | |
827 | |
800 | pktlen = net_uint16 (buf); |
828 | pktlen = net_uint16 ((uint8 *)buf); |
801 | repeat = net_uint32 (buf + 2); |
829 | repeat = net_uint32 ((uint8 *)buf + 2); |
802 | |
830 | |
803 | /* -1 is special - no repeat, but don't update */ |
831 | /* -1 is special - no repeat, but don't update */ |
804 | if (repeat != -1) |
832 | if (repeat != -1) |
805 | pl->count = repeat; |
833 | pl->count = repeat; |
806 | |
834 | |
807 | if ((len - 4) >= MAX_BUF) |
835 | if ((len - 4) >= MAX_BUF) |
808 | len = MAX_BUF - 5; |
836 | len = MAX_BUF - 5; |
809 | |
837 | |
810 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
838 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
811 | command[len - 4] = '\0'; |
839 | 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 | |
840 | |
824 | /* This should not happen anymore. */ |
841 | /* This should not happen anymore. */ |
825 | if (pl->ob->speed_left < -1.0) |
842 | if (pl->ob->speed_left < -1.0) |
826 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
843 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
827 | |
844 | |
… | |
… | |
841 | |
858 | |
842 | /* Send confirmation of command execution now */ |
859 | /* Send confirmation of command execution now */ |
843 | |
860 | |
844 | packet sl; |
861 | packet sl; |
845 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
862 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
846 | Send_With_Handling (&pl->socket, &sl); |
863 | pl->socket->send_packet (sl); |
847 | } |
864 | } |
848 | |
865 | |
849 | |
866 | |
850 | /** This is a reply to a previous query. */ |
867 | /** This is a reply to a previous query. */ |
851 | void |
868 | void |
… | |
… | |
918 | * something older than the server. If we assume the client will be |
935 | * something older than the server. If we assume the client will be |
919 | * backwards compatible, having it be a later version should not be a |
936 | * backwards compatible, having it be a later version should not be a |
920 | * problem. |
937 | * problem. |
921 | */ |
938 | */ |
922 | void |
939 | void |
923 | VersionCmd (char *buf, int len, NewSocket * ns) |
940 | VersionCmd (char *buf, int len, client * ns) |
924 | { |
941 | { |
925 | char *cp; |
942 | char *cp; |
926 | char version_warning[256]; |
943 | char version_warning[256]; |
927 | |
944 | |
928 | if (!buf) |
945 | if (!buf) |
… | |
… | |
952 | cp = strchr (cp + 1, ' '); |
969 | cp = strchr (cp + 1, ' '); |
953 | if (cp) |
970 | if (cp) |
954 | { |
971 | { |
955 | LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
972 | LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
956 | |
973 | |
957 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
974 | assign (ns->version, cp + 1); |
958 | |
975 | |
959 | /* This is first implementation - i skip all beta DX clients with it |
|
|
960 | * Add later stuff here for other clients |
|
|
961 | */ |
|
|
962 | |
|
|
963 | /* these are old dxclients */ |
|
|
964 | /* Version 1024 added support for singular + plural name values - |
|
|
965 | * requiing this minimal value reduces complexity of that code, and it |
|
|
966 | * has been around for a long time. |
|
|
967 | */ |
|
|
968 | if (ns->sc_version < 1026) |
976 | if (ns->sc_version < 1026) |
969 | { |
977 | { |
970 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
978 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
971 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
979 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
972 | ns->send_packet (version_warning); |
980 | ns->send_packet (version_warning); |
… | |
… | |
974 | |
982 | |
975 | } |
983 | } |
976 | } |
984 | } |
977 | |
985 | |
978 | /** sound related functions. */ |
986 | /** sound related functions. */ |
979 | |
|
|
980 | void |
987 | void |
981 | SetSound (char *buf, int len, NewSocket * ns) |
988 | SetSound (char *buf, int len, client * ns) |
982 | { |
989 | { |
983 | ns->sound = atoi (buf); |
990 | ns->sound = atoi (buf); |
984 | } |
991 | } |
985 | |
992 | |
986 | /** client wants the map resent */ |
993 | /** client wants the map resent */ |
… | |
… | |
996 | */ |
1003 | */ |
997 | #if 0 |
1004 | #if 0 |
998 | /* Okay, this is MAJOR UGLY. but the only way I know how to |
1005 | /* Okay, this is MAJOR UGLY. but the only way I know how to |
999 | * clear the "cache" |
1006 | * clear the "cache" |
1000 | */ |
1007 | */ |
1001 | memset (&pl->socket.lastmap, 0, sizeof (struct Map)); |
1008 | memset (&pl->socket->lastmap, 0, sizeof (struct Map)); |
1002 | draw_client_map (pl->ob); |
1009 | draw_client_map (pl->ob); |
1003 | #endif |
1010 | #endif |
1004 | } |
1011 | } |
1005 | |
1012 | |
1006 | /** |
1013 | /** |
… | |
… | |
1044 | /** |
1051 | /** |
1045 | * Asks the client to query the user. This way, the client knows |
1052 | * Asks the client to query the user. This way, the client knows |
1046 | * it needs to send something back (vs just printing out a message) |
1053 | * it needs to send something back (vs just printing out a message) |
1047 | */ |
1054 | */ |
1048 | void |
1055 | void |
1049 | send_query (NewSocket * ns, uint8 flags, char *text) |
1056 | send_query (client * ns, uint8 flags, char *text) |
1050 | { |
1057 | { |
1051 | char buf[MAX_BUF]; |
1058 | char buf[MAX_BUF]; |
1052 | |
1059 | |
1053 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1060 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1054 | ns->send_packet (buf); |
1061 | ns->send_packet (buf); |
… | |
… | |
1109 | AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); |
1116 | 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); |
1117 | 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); |
1118 | AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); |
1112 | } |
1119 | } |
1113 | |
1120 | |
1114 | if (pl->socket.exp64) |
1121 | if (pl->socket->exp64) |
1115 | { |
1122 | { |
1116 | uint8 s; |
1123 | uint8 s; |
1117 | |
1124 | |
1118 | for (s = 0; s < NUM_SKILLS; s++) |
1125 | for (s = 0; s < NUM_SKILLS; s++) |
1119 | { |
1126 | { |
… | |
… | |
1129 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1136 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1130 | } |
1137 | } |
1131 | } |
1138 | } |
1132 | } |
1139 | } |
1133 | |
1140 | |
1134 | if (pl->socket.exp64) |
1141 | if (pl->socket->exp64) |
1135 | { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } |
1142 | { AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64) } |
1136 | else |
1143 | else |
1137 | { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } |
1144 | { AddIfInt (pl->last_stats.exp, (int) pl->ob->stats.exp, CS_STAT_EXP) } |
1138 | |
1145 | |
1139 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
1146 | AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); |
… | |
… | |
1152 | if (pl->run_on) |
1159 | if (pl->run_on) |
1153 | flags |= SF_RUNON; |
1160 | flags |= SF_RUNON; |
1154 | |
1161 | |
1155 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1162 | AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); |
1156 | |
1163 | |
1157 | if (pl->socket.sc_version < 1025) |
1164 | if (pl->socket->sc_version < 1025) |
1158 | { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
1165 | { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } |
1159 | else |
1166 | else |
1160 | { |
1167 | { |
1161 | int i; |
1168 | int i; |
1162 | |
1169 | |
… | |
… | |
1168 | |
1175 | |
1169 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1176 | AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); |
1170 | } |
1177 | } |
1171 | } |
1178 | } |
1172 | |
1179 | |
1173 | if (pl->socket.monitor_spells) |
1180 | if (pl->socket->monitor_spells) |
1174 | { |
1181 | { |
1175 | AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
1182 | 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); |
1183 | 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); |
1184 | AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); |
1178 | } |
1185 | } |
1179 | |
1186 | |
1180 | rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ |
1187 | 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); |
1188 | AddIfString (pl->socket->stats.range, buf, CS_STAT_RANGE); |
1182 | set_title (pl->ob, buf); |
1189 | set_title (pl->ob, buf); |
1183 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1190 | AddIfString (pl->socket->stats.title, buf, CS_STAT_TITLE); |
1184 | |
1191 | |
1185 | /* Only send it away if we have some actual data */ |
1192 | /* Only send it away if we have some actual data */ |
1186 | if (sl.length () > 6) |
1193 | if (sl.length () > 6) |
1187 | Send_With_Handling (&pl->socket, &sl); |
1194 | pl->socket->send_packet (sl); |
1188 | } |
1195 | } |
1189 | |
1196 | |
1190 | /** |
1197 | /** |
1191 | * Tells the client that here is a player it should start using. |
1198 | * Tells the client that here is a player it should start using. |
1192 | */ |
1199 | */ |
… | |
… | |
1201 | sl << uint32 (pl->ob->count) |
1208 | sl << uint32 (pl->ob->count) |
1202 | << uint32 (weight) |
1209 | << uint32 (weight) |
1203 | << uint32 (pl->ob->face->number) |
1210 | << uint32 (pl->ob->face->number) |
1204 | << data8 (pl->ob->name); |
1211 | << data8 (pl->ob->name); |
1205 | |
1212 | |
1206 | Send_With_Handling (&pl->socket, &sl); |
1213 | pl->socket->send_packet (sl); |
1207 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1214 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1208 | } |
1215 | } |
1209 | |
1216 | |
1210 | /** |
1217 | /** |
1211 | * Need to send an animation sequence to the client. |
1218 | * Need to send an animation sequence to the client. |
… | |
… | |
1213 | * sent them the face yet (this can become quite costly in terms of |
1220 | * sent them the face yet (this can become quite costly in terms of |
1214 | * how much we are sending - on the other hand, this should only happen |
1221 | * how much we are sending - on the other hand, this should only happen |
1215 | * when the player logs in and picks stuff up. |
1222 | * when the player logs in and picks stuff up. |
1216 | */ |
1223 | */ |
1217 | void |
1224 | void |
1218 | esrv_send_animation (NewSocket * ns, short anim_num) |
1225 | esrv_send_animation (client * ns, short anim_num) |
1219 | { |
1226 | { |
1220 | int i; |
1227 | int i; |
1221 | |
1228 | |
1222 | /* Do some checking on the anim_num we got. Note that the animations |
1229 | /* Do some checking on the anim_num we got. Note that the animations |
1223 | * are added in contigous order, so if the number is in the valid |
1230 | * are added in contigous order, so if the number is in the valid |
… | |
… | |
1243 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1250 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1244 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1251 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1245 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1252 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1246 | } |
1253 | } |
1247 | |
1254 | |
1248 | Send_With_Handling (ns, &sl); |
1255 | ns->send_packet (sl); |
1249 | |
1256 | |
1250 | ns->anims_sent[anim_num] = 1; |
1257 | ns->anims_sent[anim_num] = 1; |
1251 | } |
1258 | } |
1252 | |
1259 | |
1253 | |
1260 | |
… | |
… | |
1260 | /** |
1267 | /** |
1261 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1268 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1262 | * the face yet, we will also send it. |
1269 | * the face yet, we will also send it. |
1263 | */ |
1270 | */ |
1264 | static void |
1271 | static void |
1265 | esrv_map_setbelow (NewSocket * ns, int x, int y, short face_num, struct Map *newmap) |
1272 | esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap) |
1266 | { |
1273 | { |
1267 | if (newmap->cells[x][y].count >= MAP_LAYERS) |
1274 | if (newmap->cells[x][y].count >= MAP_LAYERS) |
1268 | { |
1275 | { |
1269 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1276 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1270 | return; |
1277 | return; |
… | |
… | |
1290 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1297 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1291 | }; |
1298 | }; |
1292 | |
1299 | |
1293 | /** Checkes if map cells have changed */ |
1300 | /** Checkes if map cells have changed */ |
1294 | static int |
1301 | static int |
1295 | mapcellchanged (NewSocket * ns, int i, int j, struct Map *newmap) |
1302 | mapcellchanged (client * ns, int i, int j, struct Map *newmap) |
1296 | { |
1303 | { |
1297 | int k; |
1304 | int k; |
1298 | |
1305 | |
1299 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1306 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1300 | return 1; |
1307 | return 1; |
… | |
… | |
1313 | * cnum is the client number, cur is the the buffer we put all of |
1320 | * cnum is the client number, cur is the the buffer we put all of |
1314 | * this data into. we return the end of the data. layers is |
1321 | * this data into. we return the end of the data. layers is |
1315 | * how many layers of data we should back. |
1322 | * how many layers of data we should back. |
1316 | */ |
1323 | */ |
1317 | static uint8 * |
1324 | static uint8 * |
1318 | compactlayer (NewSocket * ns, unsigned char *cur, int numlayers, struct Map *newmap) |
1325 | compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap) |
1319 | { |
1326 | { |
1320 | int x, y, k; |
1327 | int x, y, k; |
1321 | int face; |
1328 | int face; |
1322 | unsigned char *fcur; |
1329 | unsigned char *fcur; |
1323 | struct MapLayer layers[MAP_LAYERS]; |
1330 | struct MapLayer layers[MAP_LAYERS]; |
… | |
… | |
1431 | * needs to get sent - if so, it adds the data, sending the head |
1438 | * needs to get sent - if so, it adds the data, sending the head |
1432 | * if needed, and returning 1. If this no data needs to get |
1439 | * if needed, and returning 1. If this no data needs to get |
1433 | * sent, it returns zero. |
1440 | * sent, it returns zero. |
1434 | */ |
1441 | */ |
1435 | static int |
1442 | static int |
1436 | check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer) |
1443 | check_head (packet &sl, client &ns, int ax, int ay, int layer) |
1437 | { |
1444 | { |
1438 | short face_num; |
1445 | short face_num; |
1439 | |
1446 | |
1440 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1447 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1441 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1448 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
… | |
… | |
1475 | * the case, it seems to make more sense to have these layer values |
1482 | * the case, it seems to make more sense to have these layer values |
1476 | * actually match. |
1483 | * actually match. |
1477 | */ |
1484 | */ |
1478 | |
1485 | |
1479 | static int |
1486 | static int |
1480 | update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1487 | update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1481 | { |
1488 | { |
1482 | object *ob, *head; |
1489 | object *ob, *head; |
1483 | uint16 face_num; |
1490 | uint16 face_num; |
1484 | int bx, by, i; |
1491 | int bx, by, i; |
1485 | |
1492 | |
… | |
… | |
1698 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1705 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1699 | * take. |
1706 | * take. |
1700 | */ |
1707 | */ |
1701 | |
1708 | |
1702 | static inline int |
1709 | static inline int |
1703 | update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1710 | update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1704 | { |
1711 | { |
1705 | object *ob; |
1712 | object *ob; |
1706 | int smoothlevel; /* old face_num; */ |
1713 | int smoothlevel; /* old face_num; */ |
1707 | |
1714 | |
1708 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1715 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1742 | * Returns the size of a data for a map square as returned by |
1749 | * Returns the size of a data for a map square as returned by |
1743 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1750 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1744 | * available. |
1751 | * available. |
1745 | */ |
1752 | */ |
1746 | int |
1753 | int |
1747 | getExtendedMapInfoSize (NewSocket * ns) |
1754 | getExtendedMapInfoSize (client * ns) |
1748 | { |
1755 | { |
1749 | int result = 0; |
1756 | int result = 0; |
1750 | |
1757 | |
1751 | if (ns->ext_mapinfos) |
1758 | if (ns->ext_mapinfos) |
1752 | { |
1759 | { |
… | |
… | |
1788 | uint8 eentrysize; |
1795 | uint8 eentrysize; |
1789 | uint16 ewhatstart, ewhatflag; |
1796 | uint16 ewhatstart, ewhatflag; |
1790 | uint8 extendedinfos; |
1797 | uint8 extendedinfos; |
1791 | maptile *m; |
1798 | maptile *m; |
1792 | |
1799 | |
1793 | NewSocket &socket = pl->contr->socket; |
1800 | client &socket = *pl->contr->socket; |
1794 | |
1801 | |
1795 | check_map_change (pl->contr); |
1802 | check_map_change (pl->contr); |
1796 | |
1803 | |
1797 | packet sl; |
1804 | packet sl; |
1798 | packet esl; |
1805 | packet esl; |
… | |
… | |
1877 | * with no faces tells the client to blank out the |
1884 | * with no faces tells the client to blank out the |
1878 | * space. |
1885 | * space. |
1879 | */ |
1886 | */ |
1880 | got_one = 0; |
1887 | got_one = 0; |
1881 | for (i = oldlen + 2; i < sl.length (); i++) |
1888 | for (i = oldlen + 2; i < sl.length (); i++) |
1882 | if (sl.buf[i]) |
1889 | if (sl[i]) |
1883 | got_one = 1; |
1890 | got_one = 1; |
1884 | |
1891 | |
1885 | if (got_one && (mask & 0xf)) |
1892 | if (got_one && (mask & 0xf)) |
1886 | sl.buf[oldlen + 1] = mask & 0xff; |
1893 | sl[oldlen + 1] = mask & 0xff; |
1887 | else |
1894 | else |
1888 | { /*either all faces blank, either no face at all */ |
1895 | { /*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 */ |
1896 | if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ |
1890 | sl.reset (oldlen + 2); |
1897 | sl.reset (oldlen + 2); |
1891 | else |
1898 | else |
… | |
… | |
1957 | |
1964 | |
1958 | map_clearcell (&lastcell, 0, 0, 0, count); |
1965 | map_clearcell (&lastcell, 0, 0, 0, count); |
1959 | } |
1966 | } |
1960 | |
1967 | |
1961 | if ((mask & 0xf) || need_send) |
1968 | if ((mask & 0xf) || need_send) |
1962 | sl.buf[oldlen + 1] = mask & 0xff; |
1969 | sl[oldlen + 1] = mask & 0xff; |
1963 | else |
1970 | else |
1964 | sl.reset (oldlen); |
1971 | sl.reset (oldlen); |
1965 | } |
1972 | } |
1966 | else |
1973 | else |
1967 | { |
1974 | { |
… | |
… | |
1997 | mask |= 0x8; |
2004 | mask |= 0x8; |
1998 | |
2005 | |
1999 | if (socket.extmap) |
2006 | if (socket.extmap) |
2000 | { |
2007 | { |
2001 | *last_ext |= 0x80; |
2008 | *last_ext |= 0x80; |
2002 | last_ext = sl.buf + sl.length (); |
2009 | last_ext = &sl[sl.length ()]; |
2003 | sl << uint8 (d); |
2010 | sl << uint8 (d); |
2004 | } |
2011 | } |
2005 | else |
2012 | else |
2006 | sl << uint8 (255 - 64 * d); |
2013 | sl << uint8 (255 - 64 * d); |
2007 | } |
2014 | } |
… | |
… | |
2041 | { |
2048 | { |
2042 | lastcell.stat_hp = stat_hp; |
2049 | lastcell.stat_hp = stat_hp; |
2043 | |
2050 | |
2044 | mask |= 0x8; |
2051 | mask |= 0x8; |
2045 | *last_ext |= 0x80; |
2052 | *last_ext |= 0x80; |
2046 | last_ext = sl.buf + sl.length (); |
2053 | last_ext = &sl[sl.length ()]; |
2047 | |
2054 | |
2048 | sl << uint8 (5) << uint8 (stat_hp); |
2055 | sl << uint8 (5) << uint8 (stat_hp); |
2049 | |
2056 | |
2050 | if (stat_width > 1) |
2057 | if (stat_width > 1) |
2051 | { |
2058 | { |
2052 | *last_ext |= 0x80; |
2059 | *last_ext |= 0x80; |
2053 | last_ext = sl.buf + sl.length (); |
2060 | last_ext = &sl[sl.length ()]; |
2054 | |
2061 | |
2055 | sl << uint8 (6) << uint8 (stat_width); |
2062 | sl << uint8 (6) << uint8 (stat_width); |
2056 | } |
2063 | } |
2057 | } |
2064 | } |
2058 | |
2065 | |
… | |
… | |
2060 | { |
2067 | { |
2061 | lastcell.player = player; |
2068 | lastcell.player = player; |
2062 | |
2069 | |
2063 | mask |= 0x8; |
2070 | mask |= 0x8; |
2064 | *last_ext |= 0x80; |
2071 | *last_ext |= 0x80; |
2065 | last_ext = sl.buf + sl.length (); |
2072 | last_ext = &sl[sl.length ()]; |
2066 | |
2073 | |
2067 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2074 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2068 | } |
2075 | } |
2069 | |
2076 | |
2070 | if (lastcell.flags != flags) |
2077 | if (lastcell.flags != flags) |
2071 | { |
2078 | { |
2072 | lastcell.flags = flags; |
2079 | lastcell.flags = flags; |
2073 | |
2080 | |
2074 | mask |= 0x8; |
2081 | mask |= 0x8; |
2075 | *last_ext |= 0x80; |
2082 | *last_ext |= 0x80; |
2076 | last_ext = sl.buf + sl.length (); |
2083 | last_ext = &sl[sl.length ()]; |
2077 | |
2084 | |
2078 | sl << uint8 (8) << uint8 (flags); |
2085 | sl << uint8 (8) << uint8 (flags); |
2079 | } |
2086 | } |
2080 | } |
2087 | } |
2081 | |
2088 | |
… | |
… | |
2123 | * space by checking the mask. If so, update the mask. |
2130 | * space by checking the mask. If so, update the mask. |
2124 | * if not, reset the len to that from before adding the mask |
2131 | * if not, reset the len to that from before adding the mask |
2125 | * value, so we don't send those bits. |
2132 | * value, so we don't send those bits. |
2126 | */ |
2133 | */ |
2127 | if (mask & 0xf) |
2134 | if (mask & 0xf) |
2128 | sl.buf[oldlen + 1] = mask & 0xff; |
2135 | sl[oldlen + 1] = mask & 0xff; |
2129 | else |
2136 | else |
2130 | sl.reset (oldlen); |
2137 | sl.reset (oldlen); |
2131 | |
2138 | |
2132 | if (emask & 0xf) |
2139 | if (emask & 0xf) |
2133 | esl.buf[eoldlen + 1] = emask & 0xff; |
2140 | esl[eoldlen + 1] = emask & 0xff; |
2134 | else |
2141 | else |
2135 | esl.reset (eoldlen); |
2142 | esl.reset (eoldlen); |
2136 | } /* else this is a viewable space */ |
2143 | } /* else this is a viewable space */ |
2137 | } /* for x loop */ |
2144 | } /* for x loop */ |
2138 | } /* for y loop */ |
2145 | } /* for y loop */ |
… | |
… | |
2144 | { |
2151 | { |
2145 | /* No map data will follow, so don't say the client |
2152 | /* No map data will follow, so don't say the client |
2146 | * it doesn't need draw! |
2153 | * it doesn't need draw! |
2147 | */ |
2154 | */ |
2148 | ewhatflag &= (~EMI_NOREDRAW); |
2155 | ewhatflag &= (~EMI_NOREDRAW); |
2149 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2156 | esl[ewhatstart + 1] = ewhatflag & 0xff; |
2150 | } |
2157 | } |
2151 | |
2158 | |
2152 | if (esl.length () > estartlen) |
2159 | if (esl.length () > estartlen) |
2153 | Send_With_Handling (&socket, &esl); |
2160 | socket.send_packet (esl); |
2154 | } |
2161 | } |
2155 | |
2162 | |
2156 | if (sl.length () > startlen || socket.sent_scroll) |
2163 | if (sl.length () > startlen || socket.sent_scroll) |
2157 | { |
2164 | { |
2158 | Send_With_Handling (&socket, &sl); |
2165 | socket.send_packet (sl); |
2159 | socket.sent_scroll = 0; |
2166 | socket.sent_scroll = 0; |
2160 | } |
2167 | } |
2161 | } |
2168 | } |
2162 | |
2169 | |
2163 | /** |
2170 | /** |
… | |
… | |
2189 | if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) |
2196 | if (pm == NULL || pm->in_memory != MAP_IN_MEMORY) |
2190 | return; |
2197 | return; |
2191 | |
2198 | |
2192 | memset (&newmap, 0, sizeof (struct Map)); |
2199 | memset (&newmap, 0, sizeof (struct Map)); |
2193 | |
2200 | |
2194 | for (j = (pl->y - pl->contr->socket.mapy / 2); j < (pl->y + (pl->contr->socket.mapy + 1) / 2); j++) |
2201 | for (j = (pl->y - pl->contr->socket->mapy / 2); j < (pl->y + (pl->contr->socket->mapy + 1) / 2); j++) |
2195 | { |
2202 | { |
2196 | for (i = (pl->x - pl->contr->socket.mapx / 2); i < (pl->x + (pl->contr->socket.mapx + 1) / 2); i++) |
2203 | for (i = (pl->x - pl->contr->socket->mapx / 2); i < (pl->x + (pl->contr->socket->mapx + 1) / 2); i++) |
2197 | { |
2204 | { |
2198 | ax = i; |
2205 | ax = i; |
2199 | ay = j; |
2206 | ay = j; |
2200 | m = pm; |
2207 | m = pm; |
2201 | mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); |
2208 | mflags = get_map_flags (m, &m, ax, ay, &ax, &ay); |
… | |
… | |
2233 | |
2240 | |
2234 | /*****************************************************************************/ |
2241 | /*****************************************************************************/ |
2235 | void |
2242 | void |
2236 | send_plugin_custom_message (object *pl, char *buf) |
2243 | send_plugin_custom_message (object *pl, char *buf) |
2237 | { |
2244 | { |
2238 | pl->contr->socket.send_packet (buf); |
2245 | pl->contr->socket->send_packet (buf); |
2239 | } |
2246 | } |
2240 | |
2247 | |
2241 | /** |
2248 | /** |
2242 | * This sends the skill number to name mapping. We ignore |
2249 | * This sends the skill number to name mapping. We ignore |
2243 | * the params - we always send the same info no matter what. |
2250 | * the params - we always send the same info no matter what. |
2244 | */ |
2251 | */ |
2245 | void |
2252 | void |
2246 | send_skill_info (NewSocket *ns, char *params) |
2253 | send_skill_info (client *ns, char *params) |
2247 | { |
2254 | { |
2248 | packet sl; |
2255 | packet sl; |
2249 | sl << "replyinfo skill_info\n"; |
2256 | sl << "replyinfo skill_info\n"; |
2250 | |
2257 | |
2251 | for (int i = 1; i < NUM_SKILLS; i++) |
2258 | for (int i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2255 | { |
2262 | { |
2256 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2263 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2257 | fatal (0); |
2264 | fatal (0); |
2258 | } |
2265 | } |
2259 | |
2266 | |
2260 | Send_With_Handling (ns, &sl); |
2267 | ns->send_packet (sl); |
2261 | } |
2268 | } |
2262 | |
2269 | |
2263 | /** |
2270 | /** |
2264 | * This sends the spell path to name mapping. We ignore |
2271 | * This sends the spell path to name mapping. We ignore |
2265 | * the params - we always send the same info no matter what. |
2272 | * the params - we always send the same info no matter what. |
2266 | */ |
2273 | */ |
2267 | void |
2274 | void |
2268 | send_spell_paths (NewSocket * ns, char *params) |
2275 | send_spell_paths (client * ns, char *params) |
2269 | { |
2276 | { |
2270 | packet sl; |
2277 | packet sl; |
2271 | |
2278 | |
2272 | sl << "replyinfo spell_paths\n"; |
2279 | sl << "replyinfo spell_paths\n"; |
2273 | |
2280 | |
… | |
… | |
2278 | { |
2285 | { |
2279 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2286 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2280 | fatal (0); |
2287 | fatal (0); |
2281 | } |
2288 | } |
2282 | |
2289 | |
2283 | Send_With_Handling (ns, &sl); |
2290 | ns->send_packet (sl); |
2284 | } |
2291 | } |
2285 | |
2292 | |
2286 | /** |
2293 | /** |
2287 | * This looks for any spells the player may have that have changed their stats. |
2294 | * 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 |
2295 | * it then sends an updspell packet for each spell that has changed in this way |
2289 | */ |
2296 | */ |
2290 | void |
2297 | void |
2291 | esrv_update_spells (player *pl) |
2298 | esrv_update_spells (player *pl) |
2292 | { |
2299 | { |
2293 | if (!pl->socket.monitor_spells) |
2300 | if (!pl->socket->monitor_spells) |
2294 | return; |
2301 | return; |
2295 | |
2302 | |
2296 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
2303 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
2297 | { |
2304 | { |
2298 | if (spell->type == SPELL) |
2305 | if (spell->type == SPELL) |
… | |
… | |
2328 | |
2335 | |
2329 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2336 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2330 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2337 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2331 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2338 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2332 | |
2339 | |
2333 | Send_With_Handling (&pl->socket, &sl); |
2340 | pl->socket->send_packet (sl); |
2334 | } |
2341 | } |
2335 | } |
2342 | } |
2336 | } |
2343 | } |
2337 | } |
2344 | } |
2338 | |
2345 | |
2339 | void |
2346 | void |
2340 | esrv_remove_spell (player *pl, object *spell) |
2347 | esrv_remove_spell (player *pl, object *spell) |
2341 | { |
2348 | { |
2342 | if (!pl->socket.monitor_spells) |
2349 | if (!pl->socket->monitor_spells) |
2343 | return; |
2350 | return; |
2344 | |
2351 | |
2345 | if (!pl || !spell || spell->env != pl->ob) |
2352 | if (!pl || !spell || spell->env != pl->ob) |
2346 | { |
2353 | { |
2347 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2354 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
… | |
… | |
2351 | packet sl; |
2358 | packet sl; |
2352 | |
2359 | |
2353 | sl << "delspell " |
2360 | sl << "delspell " |
2354 | << uint32 (spell->count); |
2361 | << uint32 (spell->count); |
2355 | |
2362 | |
2356 | Send_With_Handling (&pl->socket, &sl); |
2363 | pl->socket->send_packet (sl); |
2357 | } |
2364 | } |
2358 | |
2365 | |
2359 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2366 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2360 | static void |
2367 | static void |
2361 | append_spell (player *pl, packet &sl, object *spell) |
2368 | append_spell (player *pl, packet &sl, object *spell) |
… | |
… | |
2409 | { |
2416 | { |
2410 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2417 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2411 | return; |
2418 | return; |
2412 | } |
2419 | } |
2413 | |
2420 | |
2414 | if (!pl->socket.monitor_spells) |
2421 | if (!pl->socket->monitor_spells) |
2415 | return; |
2422 | return; |
2416 | |
2423 | |
2417 | packet sl; |
2424 | packet sl; |
2418 | |
2425 | |
2419 | sl << "addspell "; |
2426 | sl << "addspell "; |
… | |
… | |
2438 | if (spell->type != SPELL) |
2445 | if (spell->type != SPELL) |
2439 | continue; |
2446 | continue; |
2440 | |
2447 | |
2441 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2448 | if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2442 | { |
2449 | { |
2443 | Send_With_Handling (&pl->socket, &sl); |
2450 | pl->socket->send_packet (sl); |
2444 | |
2451 | |
2445 | sl.reset (); |
2452 | sl.reset (); |
2446 | sl << "addspell "; |
2453 | sl << "addspell "; |
2447 | } |
2454 | } |
2448 | |
2455 | |
… | |
… | |
2462 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2469 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2463 | fatal (0); |
2470 | fatal (0); |
2464 | } |
2471 | } |
2465 | |
2472 | |
2466 | /* finally, we can send the packet */ |
2473 | /* finally, we can send the packet */ |
2467 | Send_With_Handling (&pl->socket, &sl); |
2474 | pl->socket->send_packet (sl); |
2468 | |
|
|
2469 | } |
2475 | } |
2470 | |
2476 | |