… | |
… | |
57 | #include <commands.h> |
57 | #include <commands.h> |
58 | |
58 | |
59 | /* This block is basically taken from socket.c - I assume if it works there, |
59 | /* This block is basically taken from socket.c - I assume if it works there, |
60 | * it should work here. |
60 | * it should work here. |
61 | */ |
61 | */ |
62 | #ifndef WIN32 /* ---win32 exclude unix headers */ |
|
|
63 | # include <sys/types.h> |
62 | #include <sys/types.h> |
64 | # include <sys/time.h> |
63 | #include <sys/time.h> |
65 | # include <sys/socket.h> |
64 | #include <sys/socket.h> |
66 | # include <netinet/in.h> |
65 | #include <netinet/in.h> |
67 | # include <netdb.h> |
66 | #include <netdb.h> |
68 | #endif /* win32 */ |
|
|
69 | |
67 | |
70 | #ifdef HAVE_UNISTD_H |
68 | #ifdef HAVE_UNISTD_H |
71 | # include <unistd.h> |
69 | # include <unistd.h> |
72 | #endif |
70 | #endif |
73 | |
71 | |
… | |
… | |
104 | { |
102 | { |
105 | struct Map newmap; |
103 | struct Map newmap; |
106 | int x, y, mx, my; |
104 | int x, y, mx, my; |
107 | |
105 | |
108 | { |
106 | { |
109 | char buf[MAXSOCKBUF]; |
107 | packet sl; |
110 | |
108 | |
111 | sprintf (buf, "map_scroll %d %d", dx, dy); |
109 | sl.printf ("map_scroll %d %d", dx, dy); |
112 | Write_String_To_Socket (ns, buf, strlen (buf)); |
110 | ns->send_packet (sl); |
113 | } |
111 | } |
114 | |
112 | |
115 | /* If we are using the Map1aCmd, we may in fact send |
113 | /* If we are using the Map1aCmd, we may in fact send |
116 | * head information that is outside the viewable map. |
114 | * head information that is outside the viewable map. |
117 | * So set the mx,my to the max value we want to |
115 | * So set the mx,my to the max value we want to |
… | |
… | |
163 | NewSocket & socket = pl->socket; |
161 | NewSocket & socket = pl->socket; |
164 | |
162 | |
165 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
163 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
166 | |
164 | |
167 | if (socket.newmapcmd == 1) |
165 | if (socket.newmapcmd == 1) |
168 | Write_String_To_Socket (&socket, "newmap", 6); |
166 | socket.send_packet ("newmap"); |
169 | |
167 | |
170 | socket.update_look = 1; |
168 | socket.update_look = 1; |
171 | socket.look_position = 0; |
169 | socket.look_position = 0; |
172 | } |
170 | } |
173 | |
171 | |
… | |
… | |
204 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, ob->map->width, ob->map->height, ob->map->path); |
202 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, ob->map->width, ob->map->height, ob->map->path); |
205 | } |
203 | } |
206 | else |
204 | else |
207 | snprintf (buf, MAX_BUF, "mapinfo current"); |
205 | snprintf (buf, MAX_BUF, "mapinfo current"); |
208 | |
206 | |
209 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
207 | socket.send_packet (buf); |
210 | } |
208 | } |
211 | } |
209 | } |
212 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
210 | else if (socket.current_x != ob->x || socket.current_y != ob->y) |
213 | { |
211 | { |
214 | int dx = ob->x - socket.current_x; |
212 | int dx = ob->x - socket.current_x; |
… | |
… | |
316 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
314 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
317 | } |
315 | } |
318 | else |
316 | else |
319 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
317 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
320 | |
318 | |
321 | Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); |
319 | pl->socket.send_packet (bigbuf); |
322 | } |
320 | } |
323 | |
321 | |
324 | /** This is the Setup cmd - easy first implementation */ |
322 | /** This is the Setup cmd - easy first implementation */ |
325 | void |
323 | void |
326 | SetUp (char *buf, int len, NewSocket * ns) |
324 | SetUp (char *buf, int len, NewSocket * ns) |
… | |
… | |
333 | * |
331 | * |
334 | * we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
332 | * we send the status of the cmd back, or a FALSE is the cmd is the server unknown |
335 | * The client then must sort this out |
333 | * The client then must sort this out |
336 | */ |
334 | */ |
337 | |
335 | |
338 | LOG (llevInfo, "Get SetupCmd:: %s\n", buf); |
336 | //LOG (llevInfo, "Get SetupCmd:: %s\n", buf); |
|
|
337 | |
339 | strcpy (cmdback, "setup"); |
338 | strcpy (cmdback, "setup"); |
340 | for (s = 0; s < len;) |
339 | for (s = 0; s < len; ) |
341 | { |
340 | { |
342 | |
|
|
343 | cmd = &buf[s]; |
341 | cmd = &buf[s]; |
344 | |
342 | |
345 | /* find the next space, and put a null there */ |
343 | /* find the next space, and put a null there */ |
346 | for (; buf[s] && buf[s] != ' '; s++); |
344 | for (; buf[s] && buf[s] != ' '; s++) |
|
|
345 | ; |
|
|
346 | |
347 | buf[s++] = 0; |
347 | buf[s++] = 0; |
|
|
348 | |
348 | while (buf[s] == ' ') |
349 | while (buf[s] == ' ') |
349 | s++; |
350 | s++; |
350 | |
351 | |
351 | if (s >= len) |
352 | if (s >= len) |
352 | break; |
353 | break; |
353 | |
354 | |
354 | param = &buf[s]; |
355 | param = &buf[s]; |
355 | |
356 | |
356 | for (; buf[s] && buf[s] != ' '; s++); |
357 | for (; buf[s] && buf[s] != ' '; s++) |
|
|
358 | ; |
|
|
359 | |
357 | buf[s++] = 0; |
360 | buf[s++] = 0; |
|
|
361 | |
358 | while (buf[s] == ' ') |
362 | while (buf[s] == ' ') |
359 | s++; |
363 | s++; |
360 | |
364 | |
361 | slen = strlen (cmdback); |
365 | slen = strlen (cmdback); |
362 | safe_strcat (cmdback, " ", &slen, HUGE_BUF); |
366 | safe_strcat (cmdback, " ", &slen, HUGE_BUF); |
… | |
… | |
523 | * report a failure to the client. |
527 | * report a failure to the client. |
524 | */ |
528 | */ |
525 | safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF); |
529 | safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF); |
526 | } |
530 | } |
527 | } /* for processing all the setup commands */ |
531 | } /* for processing all the setup commands */ |
|
|
532 | |
528 | LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback); |
533 | LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback); |
529 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
534 | ns->send_packet (cmdback); |
530 | } |
535 | } |
531 | |
536 | |
532 | /** |
537 | /** |
533 | * The client has requested to be added to the game. |
538 | * The client has requested to be added to the game. |
534 | * This is what takes care of it. We tell the client how things worked out. |
539 | * This is what takes care of it. We tell the client how things worked out. |
… | |
… | |
540 | { |
545 | { |
541 | Settings oldsettings; |
546 | Settings oldsettings; |
542 | |
547 | |
543 | oldsettings = settings; |
548 | oldsettings = settings; |
544 | if (ns->status != Ns_Add || add_player (ns)) |
549 | if (ns->status != Ns_Add || add_player (ns)) |
545 | { |
550 | ns->send_packet ("addme_failed"); |
546 | Write_String_To_Socket (ns, "addme_failed", 12); |
|
|
547 | } |
|
|
548 | else |
551 | else |
549 | { |
552 | { |
550 | /* Basically, the add_player copies the socket structure into |
553 | /* Basically, the add_player copies the socket structure into |
551 | * the player structure, so this one (which is from init_sockets) |
554 | * the player structure, so this one (which is from init_sockets) |
552 | * is not needed anymore. The write below should still work, as the |
555 | * is not needed anymore. The write below should still work, as the |
553 | * stuff in ns is still relevant. |
556 | * stuff in ns is still relevant. |
554 | */ |
557 | */ |
555 | Write_String_To_Socket (ns, "addme_success", 13); |
558 | ns->send_packet ("addme_success"); |
556 | socket_info.nconns--; |
559 | socket_info.nconns--; |
557 | ns->status = Ns_Avail; |
560 | ns->status = Ns_Avail; |
558 | } |
561 | } |
|
|
562 | |
559 | settings = oldsettings; |
563 | settings = oldsettings; |
560 | } |
564 | } |
561 | |
565 | |
562 | /** Reply to ExtendedInfos command */ |
566 | /** Reply to ExtendedInfos command */ |
563 | void |
567 | void |
… | |
… | |
607 | { |
611 | { |
608 | strcat (cmdback, " "); |
612 | strcat (cmdback, " "); |
609 | strcat (cmdback, "smoothing"); |
613 | strcat (cmdback, "smoothing"); |
610 | } |
614 | } |
611 | |
615 | |
612 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
616 | ns->send_packet (cmdback); |
613 | } |
617 | } |
614 | |
618 | |
615 | /* |
619 | /* |
616 | #define MSG_TYPE_BOOK 1 |
620 | #define MSG_TYPE_BOOK 1 |
617 | #define MSG_TYPE_CARD 2 |
621 | #define MSG_TYPE_CARD 2 |
… | |
… | |
670 | strcat (cmdback, " "); |
674 | strcat (cmdback, " "); |
671 | snprintf (temp, sizeof (temp), "%d", i); |
675 | snprintf (temp, sizeof (temp), "%d", i); |
672 | strcat (cmdback, temp); |
676 | strcat (cmdback, temp); |
673 | } |
677 | } |
674 | |
678 | |
675 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
679 | ns->send_packet (cmdback); |
676 | } |
680 | } |
677 | |
681 | |
678 | /** |
682 | /** |
679 | * A lot like the old AskSmooth (in fact, now called by AskSmooth). |
683 | * A lot like the old AskSmooth (in fact, now called by AskSmooth). |
680 | * Basically, it makes no sense to wait for the client to request a |
684 | * Basically, it makes no sense to wait for the client to request a |
… | |
… | |
684 | */ |
688 | */ |
685 | static void |
689 | static void |
686 | SendSmooth (NewSocket * ns, uint16 face) |
690 | SendSmooth (NewSocket * ns, uint16 face) |
687 | { |
691 | { |
688 | uint16 smoothface; |
692 | uint16 smoothface; |
689 | unsigned char reply[MAX_BUF]; |
|
|
690 | SockList sl; |
|
|
691 | |
693 | |
692 | /* If we can't find a face, return and set it so we won't try to send this |
694 | /* If we can't find a face, return and set it so we won't try to send this |
693 | * again. |
695 | * again. |
694 | */ |
696 | */ |
695 | if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) |
697 | if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) |
… | |
… | |
703 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
705 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
704 | esrv_send_face (ns, smoothface, 0); |
706 | esrv_send_face (ns, smoothface, 0); |
705 | |
707 | |
706 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
708 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
707 | |
709 | |
708 | sl.buf = reply; |
710 | packet sl; |
709 | strcpy ((char *) sl.buf, "smooth "); |
711 | |
710 | sl.len = strlen ((char *) sl.buf); |
712 | sl << "smooth " |
711 | SockList_AddShort (&sl, face); |
713 | << uint16 (face) |
712 | SockList_AddShort (&sl, smoothface); |
714 | << uint16 (smoothface); |
|
|
715 | |
713 | Send_With_Handling (ns, &sl); |
716 | Send_With_Handling (ns, &sl); |
714 | } |
717 | } |
715 | |
718 | |
716 | /** |
719 | /** |
717 | * Tells client the picture it has to use |
720 | * Tells client the picture it has to use |
… | |
… | |
724 | |
727 | |
725 | facenbr = atoi (buf); |
728 | facenbr = atoi (buf); |
726 | SendSmooth (ns, facenbr); |
729 | SendSmooth (ns, facenbr); |
727 | } |
730 | } |
728 | |
731 | |
729 | |
|
|
730 | |
|
|
731 | |
|
|
732 | |
|
|
733 | /** |
732 | /** |
734 | * This handles the general commands from the client (ie, north, fire, cast, |
733 | * This handles the general commands from the client (ie, north, fire, cast, |
735 | * etc.) |
734 | * etc.) |
736 | */ |
735 | */ |
737 | void |
736 | void |
… | |
… | |
790 | */ |
789 | */ |
791 | void |
790 | void |
792 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
791 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
793 | { |
792 | { |
794 | int time, repeat; |
793 | int time, repeat; |
795 | short packet; |
|
|
796 | unsigned char command[MAX_BUF]; |
794 | char command[MAX_BUF]; |
797 | SockList sl; |
795 | int pktlen; |
798 | |
796 | |
799 | if (len < 7) |
797 | if (len < 7) |
800 | { |
798 | { |
801 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
799 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
802 | return; |
800 | return; |
803 | } |
801 | } |
804 | |
802 | |
805 | packet = GetShort_String (buf); |
803 | pktlen = net_uint16 (buf); |
806 | repeat = GetInt_String (buf + 2); |
804 | repeat = net_uint32 (buf + 2); |
|
|
805 | |
807 | /* -1 is special - no repeat, but don't update */ |
806 | /* -1 is special - no repeat, but don't update */ |
808 | if (repeat != -1) |
807 | if (repeat != -1) |
809 | { |
|
|
810 | pl->count = repeat; |
808 | pl->count = repeat; |
811 | } |
809 | |
812 | if ((len - 4) >= MAX_BUF) |
810 | if ((len - 4) >= MAX_BUF) |
813 | len = MAX_BUF - 5; |
811 | len = MAX_BUF - 5; |
814 | |
812 | |
815 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
813 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
816 | command[len - 4] = '\0'; |
814 | command[len - 4] = '\0'; |
… | |
… | |
826 | return; |
824 | return; |
827 | } |
825 | } |
828 | |
826 | |
829 | /* This should not happen anymore. */ |
827 | /* This should not happen anymore. */ |
830 | if (pl->ob->speed_left < -1.0) |
828 | if (pl->ob->speed_left < -1.0) |
831 | { |
|
|
832 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
829 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
833 | } |
830 | |
834 | /* In c_new.c */ |
831 | /* In c_new.c */ |
835 | execute_newserver_command (pl->ob, (char *) command); |
832 | execute_newserver_command (pl->ob, (char *) command); |
836 | /* Perhaps something better should be done with a left over count. |
833 | /* Perhaps something better should be done with a left over count. |
837 | * Cleaning up the input should probably be done first - all actions |
834 | * Cleaning up the input should probably be done first - all actions |
838 | * for the command that issued the count should be done before any other |
835 | * for the command that issued the count should be done before any other |
839 | * commands. |
836 | * commands. |
840 | */ |
837 | */ |
841 | pl->count = 0; |
838 | pl->count = 0; |
842 | |
839 | |
843 | /* Send confirmation of command execution now */ |
|
|
844 | sl.buf = command; |
|
|
845 | strcpy ((char *) sl.buf, "comc "); |
|
|
846 | sl.len = 5; |
|
|
847 | SockList_AddShort (&sl, packet); |
|
|
848 | if (FABS (pl->ob->speed) < 0.001) |
840 | if (FABS (pl->ob->speed) < 0.001) |
849 | time = MAX_TIME * 100; |
841 | time = MAX_TIME * 100; |
850 | else |
842 | else |
851 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
843 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
852 | SockList_AddInt (&sl, time); |
844 | |
|
|
845 | /* Send confirmation of command execution now */ |
|
|
846 | |
|
|
847 | packet sl; |
|
|
848 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
853 | Send_With_Handling (&pl->socket, &sl); |
849 | Send_With_Handling (&pl->socket, &sl); |
854 | } |
850 | } |
855 | |
851 | |
856 | |
852 | |
857 | /** This is a reply to a previous query. */ |
853 | /** This is a reply to a previous query. */ |
… | |
… | |
970 | /* these are old dxclients */ |
966 | /* these are old dxclients */ |
971 | /* Version 1024 added support for singular + plural name values - |
967 | /* Version 1024 added support for singular + plural name values - |
972 | * requiing this minimal value reduces complexity of that code, and it |
968 | * requiing this minimal value reduces complexity of that code, and it |
973 | * has been around for a long time. |
969 | * has been around for a long time. |
974 | */ |
970 | */ |
975 | if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) |
971 | if (ns->sc_version < 1026) |
976 | { |
972 | { |
977 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
973 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
978 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
974 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
979 | Write_String_To_Socket (ns, version_warning, strlen (version_warning)); |
975 | ns->send_packet (version_warning); |
980 | } |
976 | } |
981 | |
977 | |
982 | } |
978 | } |
983 | } |
979 | } |
984 | |
980 | |
… | |
… | |
1056 | send_query (NewSocket * ns, uint8 flags, char *text) |
1052 | send_query (NewSocket * ns, uint8 flags, char *text) |
1057 | { |
1053 | { |
1058 | char buf[MAX_BUF]; |
1054 | char buf[MAX_BUF]; |
1059 | |
1055 | |
1060 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1056 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1061 | Write_String_To_Socket (ns, buf, strlen (buf)); |
1057 | ns->send_packet (buf); |
1062 | } |
1058 | } |
1063 | |
1059 | |
1064 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1060 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1065 | Old = New; \ |
1061 | Old = New; \ |
1066 | SockList_AddChar(&sl, Type); \ |
1062 | sl << uint8 (Type) << uint64 (New); \ |
1067 | SockList_AddInt64(&sl, New); \ |
|
|
1068 | } |
1063 | } |
1069 | |
1064 | |
1070 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
1065 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
1071 | Old = New; \ |
1066 | Old = New; \ |
1072 | SockList_AddChar(&sl, Type); \ |
1067 | sl << uint8 (Type) << uint32 (New); \ |
1073 | SockList_AddInt(&sl, New); \ |
|
|
1074 | } |
1068 | } |
1075 | |
1069 | |
1076 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
1070 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
1077 | Old = New; \ |
1071 | Old = New; \ |
1078 | SockList_AddChar(&sl, Type); \ |
1072 | sl << uint8 (Type) << uint16 (New); \ |
1079 | SockList_AddShort(&sl, New); \ |
|
|
1080 | } |
1073 | } |
1081 | |
1074 | |
1082 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
1075 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
1083 | Old = New; \ |
1076 | Old = New; \ |
1084 | SockList_AddChar(&sl, Type); \ |
1077 | sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \ |
1085 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
|
|
1086 | } |
1078 | } |
1087 | |
1079 | |
1088 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
1080 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
1089 | if (Old) free(Old);\ |
|
|
1090 | Old = strdup_local(New);\ |
1081 | free(Old); Old = strdup (New);\ |
1091 | SockList_AddChar(&sl, Type); \ |
1082 | sl << uint8 (Type) << data8 (New); \ |
1092 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
|
|
1093 | strcpy((char*)sl.buf + sl.len, New); \ |
|
|
1094 | sl.len += strlen(New); \ |
|
|
1095 | } |
1083 | } |
1096 | |
1084 | |
1097 | /** |
1085 | /** |
1098 | * Sends a statistics update. We look at the old values, |
1086 | * Sends a statistics update. We look at the old values, |
1099 | * and only send what has changed. Stat mapping values are in newclient.h |
1087 | * and only send what has changed. Stat mapping values are in newclient.h |
… | |
… | |
1101 | * commands for now. |
1089 | * commands for now. |
1102 | */ |
1090 | */ |
1103 | void |
1091 | void |
1104 | esrv_update_stats (player *pl) |
1092 | esrv_update_stats (player *pl) |
1105 | { |
1093 | { |
1106 | SockList sl; |
|
|
1107 | char buf[MAX_BUF]; |
1094 | char buf[MAX_BUF]; |
1108 | uint16 flags; |
1095 | uint16 flags; |
1109 | |
1096 | |
1110 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1097 | packet sl; |
1111 | strcpy ((char *) sl.buf, "stats "); |
1098 | sl << "stats "; |
1112 | sl.len = strlen ((char *) sl.buf); |
|
|
1113 | |
1099 | |
1114 | if (pl->ob != NULL) |
1100 | if (pl->ob != NULL) |
1115 | { |
1101 | { |
1116 | AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
1102 | AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
1117 | AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); |
1103 | AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); |
… | |
… | |
1134 | |
1120 | |
1135 | for (s = 0; s < NUM_SKILLS; s++) |
1121 | for (s = 0; s < NUM_SKILLS; s++) |
1136 | { |
1122 | { |
1137 | if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) |
1123 | if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) |
1138 | { |
1124 | { |
1139 | |
|
|
1140 | /* Always send along the level if exp changes. This is only |
1125 | /* Always send along the level if exp changes. This is only |
1141 | * 1 extra byte, but keeps processing simpler. |
1126 | * 1 extra byte, but keeps processing simpler. |
1142 | */ |
1127 | */ |
1143 | SockList_AddChar (&sl, (char) (s + CS_STAT_SKILLINFO)); |
1128 | sl << uint8 (s + CS_STAT_SKILLINFO) |
1144 | SockList_AddChar (&sl, (char) pl->last_skill_ob[s]->level); |
1129 | << uint8 (pl->last_skill_ob[s]->level) |
1145 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1130 | << uint64 (pl->last_skill_ob[s]->stats.exp); |
|
|
1131 | |
1146 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1132 | pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; |
1147 | } |
1133 | } |
1148 | } |
1134 | } |
1149 | } |
1135 | } |
1150 | |
1136 | |
… | |
… | |
1206 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1192 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1207 | #endif |
1193 | #endif |
1208 | Send_With_Handling (&pl->socket, &sl); |
1194 | Send_With_Handling (&pl->socket, &sl); |
1209 | } |
1195 | } |
1210 | |
1196 | |
1211 | free (sl.buf); |
|
|
1212 | } |
1197 | } |
1213 | |
1198 | |
1214 | /** |
1199 | /** |
1215 | * Tells the client that here is a player it should start using. |
1200 | * Tells the client that here is a player it should start using. |
1216 | */ |
1201 | */ |
1217 | void |
1202 | void |
1218 | esrv_new_player (player *pl, uint32 weight) |
1203 | esrv_new_player (player *pl, uint32 weight) |
1219 | { |
1204 | { |
1220 | SockList sl; |
|
|
1221 | |
|
|
1222 | pl->last_weight = weight; |
1205 | pl->last_weight = weight; |
1223 | |
1206 | |
1224 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1207 | packet sl; |
|
|
1208 | sl << "player "; |
1225 | |
1209 | |
1226 | strcpy ((char *) sl.buf, "player "); |
1210 | sl << uint32 (pl->ob->count) |
1227 | sl.len = strlen ((char *) sl.buf); |
1211 | << uint32 (weight) |
1228 | SockList_AddInt (&sl, pl->ob->count); |
1212 | << uint32 (pl->ob->face->number) |
1229 | SockList_AddInt (&sl, weight); |
1213 | << data8 (pl->ob->name); |
1230 | SockList_AddInt (&sl, pl->ob->face->number); |
|
|
1231 | |
|
|
1232 | SockList_AddChar (&sl, (char) strlen (pl->ob->name)); |
|
|
1233 | strcpy ((char *) sl.buf + sl.len, pl->ob->name); |
|
|
1234 | sl.len += strlen (pl->ob->name); |
|
|
1235 | |
1214 | |
1236 | Send_With_Handling (&pl->socket, &sl); |
1215 | Send_With_Handling (&pl->socket, &sl); |
1237 | free (sl.buf); |
|
|
1238 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1216 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1239 | } |
1217 | } |
1240 | |
1218 | |
1241 | /** |
1219 | /** |
1242 | * Need to send an animation sequence to the client. |
1220 | * Need to send an animation sequence to the client. |
… | |
… | |
1246 | * when the player logs in and picks stuff up. |
1224 | * when the player logs in and picks stuff up. |
1247 | */ |
1225 | */ |
1248 | void |
1226 | void |
1249 | esrv_send_animation (NewSocket * ns, short anim_num) |
1227 | esrv_send_animation (NewSocket * ns, short anim_num) |
1250 | { |
1228 | { |
1251 | SockList sl; |
|
|
1252 | int i; |
1229 | int i; |
1253 | |
1230 | |
1254 | /* Do some checking on the anim_num we got. Note that the animations |
1231 | /* Do some checking on the anim_num we got. Note that the animations |
1255 | * are added in contigous order, so if the number is in the valid |
1232 | * are added in contigous order, so if the number is in the valid |
1256 | * range, it must be a valid animation. |
1233 | * range, it must be a valid animation. |
… | |
… | |
1259 | { |
1236 | { |
1260 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
1237 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
1261 | return; |
1238 | return; |
1262 | } |
1239 | } |
1263 | |
1240 | |
1264 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1241 | packet sl; |
1265 | strcpy ((char *) sl.buf, "anim "); |
1242 | |
1266 | sl.len = 5; |
1243 | sl << "anim " |
1267 | SockList_AddShort (&sl, anim_num); |
1244 | << uint16 (anim_num) |
1268 | SockList_AddShort (&sl, 0); /* flags - not used right now */ |
1245 | << uint16 (0); /* flags - not used right now */ |
|
|
1246 | |
1269 | /* Build up the list of faces. Also, send any information (ie, the |
1247 | /* Build up the list of faces. Also, send any information (ie, the |
1270 | * the face itself) down to the client. |
1248 | * the face itself) down to the client. |
1271 | */ |
1249 | */ |
1272 | for (i = 0; i < animations[anim_num].num_animations; i++) |
1250 | for (i = 0; i < animations[anim_num].num_animations; i++) |
1273 | { |
1251 | { |
1274 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1252 | if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) |
1275 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1253 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1276 | SockList_AddShort (&sl, animations[anim_num].faces[i]); /* flags - not used right now */ |
1254 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1277 | } |
1255 | } |
|
|
1256 | |
1278 | Send_With_Handling (ns, &sl); |
1257 | Send_With_Handling (ns, &sl); |
1279 | free (sl.buf); |
1258 | |
1280 | ns->anims_sent[anim_num] = 1; |
1259 | ns->anims_sent[anim_num] = 1; |
1281 | } |
1260 | } |
1282 | |
1261 | |
1283 | |
1262 | |
1284 | /****************************************************************************** |
1263 | /****************************************************************************** |
… | |
… | |
1298 | { |
1277 | { |
1299 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1278 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1300 | return; |
1279 | return; |
1301 | abort (); |
1280 | abort (); |
1302 | } |
1281 | } |
|
|
1282 | |
1303 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1283 | newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; |
1304 | newmap->cells[x][y].count++; |
1284 | newmap->cells[x][y].count++; |
|
|
1285 | |
1305 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1286 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1306 | esrv_send_face (ns, face_num, 0); |
1287 | esrv_send_face (ns, face_num, 0); |
1307 | } |
1288 | } |
1308 | |
1289 | |
1309 | struct LayerCell |
1290 | struct LayerCell |
… | |
… | |
1416 | static void |
1397 | static void |
1417 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1398 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1418 | { |
1399 | { |
1419 | static long frames, bytes, tbytes, tframes; |
1400 | static long frames, bytes, tbytes, tframes; |
1420 | char *cur; |
1401 | char *cur; |
1421 | SockList sl; |
|
|
1422 | |
1402 | |
1423 | |
1403 | packet sl; |
1424 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1404 | sl << "map "; |
1425 | strcpy ((char *) sl.buf, "map "); |
|
|
1426 | sl.len = strlen ((char *) sl.buf); |
|
|
1427 | |
1405 | |
1428 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
1406 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
1429 | sl.len = cur - (char *) sl.buf; |
1407 | sl.len = cur - (char *) sl.buf; |
1430 | |
1408 | |
1431 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1409 | /* LOG(llevDebug, "Sending map command.\n");*/ |
… | |
… | |
1443 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1421 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1444 | Send_With_Handling (ns, &sl); |
1422 | Send_With_Handling (ns, &sl); |
1445 | ns->sent_scroll = 0; |
1423 | ns->sent_scroll = 0; |
1446 | } |
1424 | } |
1447 | |
1425 | |
1448 | free (sl.buf); |
|
|
1449 | } |
1426 | } |
1450 | |
1427 | |
1451 | |
1428 | |
1452 | /** Clears a map cell */ |
1429 | /** Clears a map cell */ |
1453 | static void |
1430 | static void |
… | |
… | |
1495 | * needs to get sent - if so, it adds the data, sending the head |
1472 | * needs to get sent - if so, it adds the data, sending the head |
1496 | * if needed, and returning 1. If this no data needs to get |
1473 | * if needed, and returning 1. If this no data needs to get |
1497 | * sent, it returns zero. |
1474 | * sent, it returns zero. |
1498 | */ |
1475 | */ |
1499 | static int |
1476 | static int |
1500 | check_head (SockList & sl, NewSocket & ns, int ax, int ay, int layer) |
1477 | check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer) |
1501 | { |
1478 | { |
1502 | short face_num; |
1479 | short face_num; |
1503 | |
1480 | |
1504 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1481 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1505 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1482 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1506 | else |
1483 | else |
1507 | face_num = 0; |
1484 | face_num = 0; |
1508 | |
1485 | |
1509 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1486 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1510 | { |
1487 | { |
1511 | SockList_AddShort (&sl, face_num); |
1488 | sl << uint16 (face_num); |
1512 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1489 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1513 | esrv_send_face (&ns, face_num, 0); |
1490 | esrv_send_face (&ns, face_num, 0); |
|
|
1491 | |
1514 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1492 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1515 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1493 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1516 | return 1; |
1494 | return 1; |
1517 | } |
1495 | } |
1518 | |
1496 | |
… | |
… | |
1538 | * the case, it seems to make more sense to have these layer values |
1516 | * the case, it seems to make more sense to have these layer values |
1539 | * actually match. |
1517 | * actually match. |
1540 | */ |
1518 | */ |
1541 | |
1519 | |
1542 | static int |
1520 | static int |
1543 | update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1521 | update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1544 | { |
1522 | { |
1545 | object *ob, *head; |
1523 | object *ob, *head; |
1546 | uint16 face_num; |
1524 | uint16 face_num; |
1547 | int bx, by, i; |
1525 | int bx, by, i; |
1548 | |
1526 | |
1549 | /* If there is a multipart object stored away, treat that as more important. |
1527 | /* If there is a multipart object stored away, treat that as more important. |
1550 | * If not, then do the normal processing. |
1528 | * If not, then do the normal processing. |
1551 | */ |
1529 | */ |
1552 | |
|
|
1553 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1530 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1554 | |
1531 | |
1555 | /* Check to see if this head is part of the set of objects |
1532 | /* Check to see if this head is part of the set of objects |
1556 | * we would normally send for this space. If so, then |
1533 | * we would normally send for this space. If so, then |
1557 | * don't use the head value. We need to do the check |
1534 | * don't use the head value. We need to do the check |
… | |
… | |
1722 | |
1699 | |
1723 | /* Another hack - because of heads and whatnot, this face may match one |
1700 | /* Another hack - because of heads and whatnot, this face may match one |
1724 | * we already sent for a lower layer. In that case, don't send |
1701 | * we already sent for a lower layer. In that case, don't send |
1725 | * this one. |
1702 | * this one. |
1726 | */ |
1703 | */ |
1727 | if (face_num && layer + 1 < MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer + 1] == face_num) |
1704 | if (face_num && layer + 1 < MAP_LAYERS && ns.lastmap.cells[sx][sy].faces[layer + 1] == face_num) |
1728 | { |
|
|
1729 | face_num = 0; |
1705 | face_num = 0; |
1730 | } |
|
|
1731 | |
1706 | |
1732 | /* We've gotten what face we want to use for the object. Now see if |
1707 | /* We've gotten what face we want to use for the object. Now see if |
1733 | * if it has changed since we last sent it to the client. |
1708 | * if it has changed since we last sent it to the client. |
1734 | */ |
1709 | */ |
1735 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) |
1710 | if (ns.lastmap.cells[sx][sy].faces[layer] != face_num) |
1736 | { |
1711 | { |
1737 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1712 | ns.lastmap.cells[sx][sy].faces[layer] = face_num; |
1738 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1713 | if (!(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1739 | esrv_send_face (ns, face_num, 0); |
1714 | esrv_send_face (&ns, face_num, 0); |
1740 | SockList_AddShort (sl, face_num); |
1715 | |
|
|
1716 | sl << uint16 (face_num); |
1741 | return 1; |
1717 | return 1; |
1742 | } |
1718 | } |
|
|
1719 | |
1743 | /* Nothing changed */ |
1720 | /* Nothing changed */ |
1744 | return 0; |
1721 | return 0; |
1745 | } |
1722 | } |
1746 | |
1723 | |
1747 | /** |
1724 | /** |
… | |
… | |
1762 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1739 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1763 | * take. |
1740 | * take. |
1764 | */ |
1741 | */ |
1765 | |
1742 | |
1766 | static inline int |
1743 | static inline int |
1767 | update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1744 | update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1768 | { |
1745 | { |
1769 | object *ob; |
1746 | object *ob; |
1770 | int smoothlevel; /* old face_num; */ |
1747 | int smoothlevel; /* old face_num; */ |
1771 | |
1748 | |
1772 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1749 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1777 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) |
1754 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) |
1778 | smoothlevel = 0; |
1755 | smoothlevel = 0; |
1779 | else |
1756 | else |
1780 | { |
1757 | { |
1781 | smoothlevel = ob->smoothlevel; |
1758 | smoothlevel = ob->smoothlevel; |
1782 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1759 | if (smoothlevel && !(ns.faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1783 | SendSmooth (ns, ob->face->number); |
1760 | SendSmooth (&ns, ob->face->number); |
1784 | } /* else not already head object or blank face */ |
1761 | } /* else not already head object or blank face */ |
1785 | |
1762 | |
1786 | /* We've gotten what face we want to use for the object. Now see if |
1763 | /* We've gotten what face we want to use for the object. Now see if |
1787 | * if it has changed since we last sent it to the client. |
1764 | * if it has changed since we last sent it to the client. |
1788 | */ |
1765 | */ |
1789 | if (smoothlevel > 255) |
1766 | if (smoothlevel > 255) |
1790 | smoothlevel = 255; |
1767 | smoothlevel = 255; |
1791 | else if (smoothlevel < 0) |
1768 | else if (smoothlevel < 0) |
1792 | smoothlevel = 0; |
1769 | smoothlevel = 0; |
|
|
1770 | |
1793 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) |
1771 | if (ns.lastmap.cells[sx][sy].smooth[layer] != smoothlevel) |
1794 | { |
1772 | { |
1795 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1773 | ns.lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1796 | SockList_AddChar (sl, (uint8) (smoothlevel & 0xFF)); |
1774 | sl << uint8 (smoothlevel); |
1797 | return 1; |
1775 | return 1; |
1798 | } |
1776 | } |
|
|
1777 | |
1799 | /* Nothing changed */ |
1778 | /* Nothing changed */ |
1800 | return 0; |
1779 | return 0; |
1801 | } |
1780 | } |
1802 | |
1781 | |
1803 | /** |
1782 | /** |
… | |
… | |
1844 | draw_client_map1 (object *pl) |
1823 | draw_client_map1 (object *pl) |
1845 | { |
1824 | { |
1846 | int x, y, ax, ay, d, startlen, max_x, max_y, oldlen; |
1825 | int x, y, ax, ay, d, startlen, max_x, max_y, oldlen; |
1847 | sint16 nx, ny; |
1826 | sint16 nx, ny; |
1848 | int estartlen, eoldlen; |
1827 | int estartlen, eoldlen; |
1849 | SockList sl; |
|
|
1850 | SockList esl; /*For extended Map info */ |
|
|
1851 | uint16 mask, emask; |
1828 | uint16 mask, emask; |
1852 | uint8 eentrysize; |
1829 | uint8 eentrysize; |
1853 | uint16 ewhatstart, ewhatflag; |
1830 | uint16 ewhatstart, ewhatflag; |
1854 | uint8 extendedinfos; |
1831 | uint8 extendedinfos; |
1855 | maptile *m; |
1832 | maptile *m; |
1856 | |
1833 | |
1857 | NewSocket & socket = pl->contr->socket; |
1834 | NewSocket &socket = pl->contr->socket; |
1858 | |
1835 | |
1859 | check_map_change (pl->contr); |
1836 | check_map_change (pl->contr); |
1860 | |
1837 | |
1861 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1838 | packet sl; |
1862 | if (socket.mapmode == Map1Cmd) |
1839 | packet esl; |
1863 | strcpy ((char *) sl.buf, "map1 "); |
1840 | |
1864 | else |
1841 | sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); |
1865 | strcpy ((char *) sl.buf, "map1a "); |
|
|
1866 | sl.len = strlen ((char *) sl.buf); |
|
|
1867 | startlen = sl.len; |
1842 | startlen = sl.len; |
1868 | |
1843 | |
1869 | /*Extendedmapinfo structure initialisation */ |
1844 | /*Extendedmapinfo structure initialisation */ |
1870 | if (socket.ext_mapinfos) |
1845 | if (socket.ext_mapinfos) |
1871 | { |
1846 | { |
1872 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
1873 | strcpy ((char *) esl.buf, "mapextended "); |
|
|
1874 | esl.len = strlen ((char *) esl.buf); |
|
|
1875 | extendedinfos = EMI_NOREDRAW; |
1847 | extendedinfos = EMI_NOREDRAW; |
1876 | |
1848 | |
1877 | if (socket.EMI_smooth) |
1849 | if (socket.EMI_smooth) |
1878 | extendedinfos |= EMI_SMOOTH; |
1850 | extendedinfos |= EMI_SMOOTH; |
1879 | |
1851 | |
1880 | ewhatstart = esl.len; |
1852 | ewhatstart = esl.len; |
1881 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1853 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1882 | could need to be taken away */ |
1854 | could need to be taken away */ |
1883 | SockList_AddChar (&esl, extendedinfos); |
|
|
1884 | eentrysize = getExtendedMapInfoSize (&socket); |
1855 | eentrysize = getExtendedMapInfoSize (&socket); |
1885 | SockList_AddChar (&esl, eentrysize); |
1856 | esl << "mapextended " |
|
|
1857 | << uint8 (extendedinfos) |
|
|
1858 | << uint8 (eentrysize); |
1886 | estartlen = esl.len; |
1859 | estartlen = esl.len; |
1887 | } |
1860 | } |
1888 | else |
1861 | else |
1889 | { |
1862 | { |
1890 | /* suppress compiler warnings */ |
1863 | /* suppress compiler warnings */ |
… | |
… | |
1931 | { |
1904 | { |
1932 | int i, got_one; |
1905 | int i, got_one; |
1933 | |
1906 | |
1934 | oldlen = sl.len; |
1907 | oldlen = sl.len; |
1935 | |
1908 | |
1936 | SockList_AddShort (&sl, mask); |
1909 | sl << uint16 (mask); |
1937 | |
1910 | |
1938 | if (check_head (sl, socket, ax, ay, 2)) |
1911 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
1939 | mask |= 0x4; |
|
|
1940 | if (check_head (sl, socket, ax, ay, 1)) |
1912 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
1941 | mask |= 0x2; |
|
|
1942 | if (check_head (sl, socket, ax, ay, 0)) |
1913 | if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; |
1943 | mask |= 0x1; |
|
|
1944 | |
1914 | |
1945 | /* If all we are doing is sending 0 (blank) faces, we don't |
1915 | /* If all we are doing is sending 0 (blank) faces, we don't |
1946 | * actually need to send that - just the coordinates |
1916 | * actually need to send that - just the coordinates |
1947 | * with no faces tells the client to blank out the |
1917 | * with no faces tells the client to blank out the |
1948 | * space. |
1918 | * space. |
… | |
… | |
1985 | * if this hasn't already been done. If the space is out |
1955 | * if this hasn't already been done. If the space is out |
1986 | * of the map, it shouldn't have a head |
1956 | * of the map, it shouldn't have a head |
1987 | */ |
1957 | */ |
1988 | if (lastcell.count != -1) |
1958 | if (lastcell.count != -1) |
1989 | { |
1959 | { |
1990 | SockList_AddShort (&sl, mask); |
1960 | sl << uint16 (mask); |
1991 | map_clearcell (&lastcell, 0, 0, 0, -1); |
1961 | map_clearcell (&lastcell, 0, 0, 0, -1); |
1992 | } |
1962 | } |
1993 | } |
1963 | } |
1994 | else if (d > 3) |
1964 | else if (d > 3) |
1995 | { |
1965 | { |
… | |
… | |
1999 | * reason. Still may need to send the head for this space. |
1969 | * reason. Still may need to send the head for this space. |
2000 | */ |
1970 | */ |
2001 | |
1971 | |
2002 | oldlen = sl.len; |
1972 | oldlen = sl.len; |
2003 | |
1973 | |
2004 | SockList_AddShort (&sl, mask); |
1974 | sl << uint16 (mask); |
2005 | |
1975 | |
2006 | if (lastcell.count != -1) |
1976 | if (lastcell.count != -1) |
2007 | need_send = 1; |
1977 | need_send = 1; |
2008 | |
1978 | |
2009 | count = -1; |
1979 | count = -1; |
2010 | |
1980 | |
2011 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
1981 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2012 | { |
1982 | { |
2013 | /* Now check to see if any heads need to be sent */ |
1983 | /* Now check to see if any heads need to be sent */ |
2014 | |
1984 | |
2015 | if (check_head (sl, socket, ax, ay, 2)) |
1985 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
2016 | mask |= 0x4; |
|
|
2017 | if (check_head (sl, socket, ax, ay, 1)) |
1986 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
2018 | mask |= 0x2; |
|
|
2019 | if (check_head (sl, socket, ax, ay, 0)) |
1987 | if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; |
2020 | mask |= 0x1; |
|
|
2021 | |
1988 | |
2022 | lastcell.count = count; |
1989 | lastcell.count = count; |
2023 | } |
1990 | } |
2024 | else |
1991 | else |
2025 | { |
1992 | { |
… | |
… | |
2054 | */ |
2021 | */ |
2055 | oldlen = sl.len; |
2022 | oldlen = sl.len; |
2056 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2023 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2057 | eoldlen = esl.len; |
2024 | eoldlen = esl.len; |
2058 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2025 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2059 | SockList_AddShort (&sl, mask); |
2026 | sl << uint16 (mask); |
2060 | |
2027 | |
2061 | if (socket.ext_mapinfos) |
2028 | if (socket.ext_mapinfos) |
2062 | SockList_AddShort (&esl, emask); |
2029 | esl << uint16 (emask); |
2063 | |
2030 | |
2064 | unsigned char dummy; |
2031 | unsigned char dummy; |
2065 | unsigned char *last_ext = &dummy; |
2032 | unsigned char *last_ext = &dummy; |
2066 | |
2033 | |
2067 | /* Darkness changed */ |
2034 | /* Darkness changed */ |
… | |
… | |
2071 | |
2038 | |
2072 | if (socket.extmap) |
2039 | if (socket.extmap) |
2073 | { |
2040 | { |
2074 | *last_ext |= 0x80; |
2041 | *last_ext |= 0x80; |
2075 | last_ext = sl.buf + sl.len; |
2042 | last_ext = sl.buf + sl.len; |
2076 | SockList_AddChar (&sl, d); |
2043 | sl << uint8 (d); |
2077 | } |
2044 | } |
2078 | else |
2045 | else |
2079 | SockList_AddChar (&sl, 255 - 64 * d); |
2046 | sl << uint8 (255 - 64 * d); |
2080 | } |
2047 | } |
2081 | |
2048 | |
2082 | lastcell.count = d; |
2049 | lastcell.count = d; |
2083 | |
2050 | |
2084 | if (socket.extmap) |
2051 | if (socket.extmap) |
2085 | { |
2052 | { |
2086 | uint8 stat_hp = 0; |
2053 | uint8 stat_hp = 0; |
2087 | uint8 stat_width = 0; |
2054 | uint8 stat_width = 0; |
2088 | uint8 flags = 0; |
2055 | uint8 flags = 0; |
2089 | tag_t player = 0; |
2056 | UUID player = 0; |
2090 | |
2057 | |
2091 | // send hp information, if applicable |
2058 | // send hp information, if applicable |
2092 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2059 | if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) |
2093 | { |
2060 | { |
2094 | if (op->head || op->invisible) |
2061 | if (op->head || op->invisible) |
… | |
… | |
2115 | lastcell.stat_hp = stat_hp; |
2082 | lastcell.stat_hp = stat_hp; |
2116 | |
2083 | |
2117 | mask |= 0x8; |
2084 | mask |= 0x8; |
2118 | *last_ext |= 0x80; |
2085 | *last_ext |= 0x80; |
2119 | last_ext = sl.buf + sl.len; |
2086 | last_ext = sl.buf + sl.len; |
2120 | SockList_AddChar (&sl, 5); |
2087 | |
2121 | SockList_AddChar (&sl, stat_hp); |
2088 | sl << uint8 (5) << uint8 (stat_hp); |
2122 | |
2089 | |
2123 | if (stat_width > 1) |
2090 | if (stat_width > 1) |
2124 | { |
2091 | { |
2125 | *last_ext |= 0x80; |
2092 | *last_ext |= 0x80; |
2126 | last_ext = sl.buf + sl.len; |
2093 | last_ext = sl.buf + sl.len; |
2127 | SockList_AddChar (&sl, 6); |
2094 | |
2128 | SockList_AddChar (&sl, stat_width); |
2095 | sl << uint8 (6) << uint8 (stat_width); |
2129 | } |
2096 | } |
2130 | } |
2097 | } |
2131 | |
2098 | |
2132 | if (lastcell.player != player) |
2099 | if (lastcell.player != player) |
2133 | { |
2100 | { |
2134 | lastcell.player = player; |
2101 | lastcell.player = player; |
2135 | |
2102 | |
2136 | mask |= 0x8; |
2103 | mask |= 0x8; |
2137 | *last_ext |= 0x80; |
2104 | *last_ext |= 0x80; |
2138 | last_ext = sl.buf + sl.len; |
2105 | last_ext = sl.buf + sl.len; |
2139 | SockList_AddChar (&sl, 0x47); |
2106 | |
2140 | SockList_AddChar (&sl, 4); |
2107 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2141 | SockList_AddInt (&sl, player); |
|
|
2142 | } |
2108 | } |
2143 | |
2109 | |
2144 | if (lastcell.flags != flags) |
2110 | if (lastcell.flags != flags) |
2145 | { |
2111 | { |
2146 | lastcell.flags = flags; |
2112 | lastcell.flags = flags; |
2147 | |
2113 | |
2148 | mask |= 0x8; |
2114 | mask |= 0x8; |
2149 | *last_ext |= 0x80; |
2115 | *last_ext |= 0x80; |
2150 | last_ext = sl.buf + sl.len; |
2116 | last_ext = sl.buf + sl.len; |
2151 | SockList_AddChar (&sl, 8); |
2117 | |
2152 | SockList_AddChar (&sl, flags); |
2118 | sl << uint8 (8) << uint8 (flags); |
2153 | } |
2119 | } |
2154 | } |
2120 | } |
2155 | |
2121 | |
2156 | /* Floor face */ |
2122 | /* Floor face */ |
2157 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) |
2123 | if (update_space (sl, socket, m, nx, ny, ax, ay, 2)) |
2158 | mask |= 0x4; |
2124 | mask |= 0x4; |
2159 | |
2125 | |
2160 | if (socket.EMI_smooth) |
2126 | if (socket.EMI_smooth) |
2161 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 2)) |
2127 | if (update_smooth (esl, socket, m, nx, ny, ax, ay, 2)) |
2162 | emask |= 0x4; |
2128 | emask |= 0x4; |
2163 | |
2129 | |
2164 | /* Middle face */ |
2130 | /* Middle face */ |
2165 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 1)) |
2131 | if (update_space (sl, socket, m, nx, ny, ax, ay, 1)) |
2166 | mask |= 0x2; |
2132 | mask |= 0x2; |
2167 | |
2133 | |
2168 | if (socket.EMI_smooth) |
2134 | if (socket.EMI_smooth) |
2169 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 1)) |
2135 | if (update_smooth (esl, socket, m, nx, ny, ax, ay, 1)) |
2170 | emask |= 0x2; |
2136 | emask |= 0x2; |
2171 | |
2137 | |
2172 | if (nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) |
2138 | if (nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) |
2173 | { |
2139 | { |
2174 | if (lastcell.faces[0] != pl->face->number) |
2140 | if (lastcell.faces[0] != pl->face->number) |
… | |
… | |
2177 | mask |= 0x1; |
2143 | mask |= 0x1; |
2178 | |
2144 | |
2179 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2145 | if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) |
2180 | esrv_send_face (&socket, pl->face->number, 0); |
2146 | esrv_send_face (&socket, pl->face->number, 0); |
2181 | |
2147 | |
2182 | SockList_AddShort (&sl, pl->face->number); |
2148 | sl << uint16 (pl->face->number); |
2183 | } |
2149 | } |
2184 | } |
2150 | } |
2185 | else |
2151 | else |
2186 | { |
2152 | { |
2187 | /* Top face */ |
2153 | /* Top face */ |
2188 | if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) |
2154 | if (update_space (sl, socket, m, nx, ny, ax, ay, 0)) |
2189 | mask |= 0x1; |
2155 | mask |= 0x1; |
2190 | |
2156 | |
2191 | if (socket.EMI_smooth) |
2157 | if (socket.EMI_smooth) |
2192 | if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) |
2158 | if (update_smooth (esl, socket, m, nx, ny, ax, ay, 0)) |
2193 | emask |= 0x1; |
2159 | emask |= 0x1; |
2194 | } |
2160 | } |
2195 | |
2161 | |
2196 | /* Check to see if we are in fact sending anything for this |
2162 | /* Check to see if we are in fact sending anything for this |
2197 | * space by checking the mask. If so, update the mask. |
2163 | * space by checking the mask. If so, update the mask. |
… | |
… | |
2223 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2189 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2224 | } |
2190 | } |
2225 | |
2191 | |
2226 | if (esl.len > estartlen) |
2192 | if (esl.len > estartlen) |
2227 | Send_With_Handling (&socket, &esl); |
2193 | Send_With_Handling (&socket, &esl); |
2228 | |
|
|
2229 | free (esl.buf); |
|
|
2230 | } |
2194 | } |
2231 | |
2195 | |
2232 | if (sl.len > startlen || socket.sent_scroll) |
2196 | if (sl.len > startlen || socket.sent_scroll) |
2233 | { |
2197 | { |
2234 | Send_With_Handling (&socket, &sl); |
2198 | Send_With_Handling (&socket, &sl); |
2235 | socket.sent_scroll = 0; |
2199 | socket.sent_scroll = 0; |
2236 | } |
2200 | } |
2237 | |
|
|
2238 | free (sl.buf); |
|
|
2239 | } |
2201 | } |
2240 | |
2202 | |
2241 | /** |
2203 | /** |
2242 | * Draws client map. |
2204 | * Draws client map. |
2243 | */ |
2205 | */ |
… | |
… | |
2357 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap); |
2319 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap); |
2358 | } |
2320 | } |
2359 | } /* Is a valid space */ |
2321 | } /* Is a valid space */ |
2360 | } |
2322 | } |
2361 | } |
2323 | } |
|
|
2324 | |
2362 | esrv_map_doneredraw (&pl->contr->socket, &newmap); |
2325 | esrv_map_doneredraw (&pl->contr->socket, &newmap); |
2363 | |
2326 | |
2364 | check_map_change (pl->contr); |
2327 | check_map_change (pl->contr); |
2365 | } |
2328 | } |
2366 | |
2329 | |
… | |
… | |
2375 | |
2338 | |
2376 | /*****************************************************************************/ |
2339 | /*****************************************************************************/ |
2377 | void |
2340 | void |
2378 | send_plugin_custom_message (object *pl, char *buf) |
2341 | send_plugin_custom_message (object *pl, char *buf) |
2379 | { |
2342 | { |
2380 | cs_write_string (&pl->contr->socket, buf, strlen (buf)); |
2343 | pl->contr->socket.send_packet (buf); |
2381 | } |
2344 | } |
2382 | |
2345 | |
2383 | /** |
2346 | /** |
2384 | * This sends the skill number to name mapping. We ignore |
2347 | * This sends the skill number to name mapping. We ignore |
2385 | * the params - we always send the same info no matter what. |
2348 | * the params - we always send the same info no matter what. |
2386 | */ |
2349 | */ |
2387 | void |
2350 | void |
2388 | send_skill_info (NewSocket * ns, char *params) |
2351 | send_skill_info (NewSocket *ns, char *params) |
2389 | { |
2352 | { |
2390 | SockList sl; |
2353 | packet sl; |
2391 | int i; |
2354 | sl << "replyinfo skill_info\n"; |
2392 | |
2355 | |
2393 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
2394 | strcpy ((char *) sl.buf, "replyinfo skill_info\n"); |
|
|
2395 | for (i = 1; i < NUM_SKILLS; i++) |
2356 | for (int i = 1; i < NUM_SKILLS; i++) |
2396 | { |
2357 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2397 | sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2358 | |
2398 | } |
|
|
2399 | sl.len = strlen ((char *) sl.buf); |
|
|
2400 | if (sl.len >= MAXSOCKBUF) |
2359 | if (sl.len >= MAXSOCKBUF) |
2401 | { |
2360 | { |
2402 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2361 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2403 | fatal (0); |
2362 | fatal (0); |
2404 | } |
2363 | } |
|
|
2364 | |
2405 | Send_With_Handling (ns, &sl); |
2365 | Send_With_Handling (ns, &sl); |
2406 | free (sl.buf); |
|
|
2407 | } |
2366 | } |
2408 | |
2367 | |
2409 | /** |
2368 | /** |
2410 | * This sends the spell path to name mapping. We ignore |
2369 | * This sends the spell path to name mapping. We ignore |
2411 | * the params - we always send the same info no matter what. |
2370 | * the params - we always send the same info no matter what. |
2412 | */ |
2371 | */ |
2413 | void |
2372 | void |
2414 | send_spell_paths (NewSocket * ns, char *params) |
2373 | send_spell_paths (NewSocket * ns, char *params) |
2415 | { |
2374 | { |
2416 | SockList sl; |
2375 | packet sl; |
2417 | int i; |
|
|
2418 | |
2376 | |
2419 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2377 | sl << "replyinfo spell_paths\n"; |
2420 | strcpy ((char *) sl.buf, "replyinfo spell_paths\n"); |
2378 | |
2421 | for (i = 0; i < NRSPELLPATHS; i++) |
2379 | for (int i = 0; i < NRSPELLPATHS; i++) |
2422 | sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", 1 << i, spellpathnames[i]); |
2380 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
2423 | sl.len = strlen ((char *) sl.buf); |
2381 | |
2424 | if (sl.len >= MAXSOCKBUF) |
2382 | if (sl.len >= MAXSOCKBUF) |
2425 | { |
2383 | { |
2426 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2384 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2427 | fatal (0); |
2385 | fatal (0); |
2428 | } |
2386 | } |
|
|
2387 | |
2429 | Send_With_Handling (ns, &sl); |
2388 | Send_With_Handling (ns, &sl); |
2430 | free (sl.buf); |
|
|
2431 | } |
2389 | } |
2432 | |
2390 | |
2433 | /** |
2391 | /** |
2434 | * This looks for any spells the player may have that have changed their stats. |
2392 | * This looks for any spells the player may have that have changed their stats. |
2435 | * it then sends an updspell packet for each spell that has changed in this way |
2393 | * it then sends an updspell packet for each spell that has changed in this way |
2436 | */ |
2394 | */ |
2437 | void |
2395 | void |
2438 | esrv_update_spells (player *pl) |
2396 | esrv_update_spells (player *pl) |
2439 | { |
2397 | { |
2440 | SockList sl; |
|
|
2441 | int flags = 0; |
|
|
2442 | object *spell; |
|
|
2443 | |
|
|
2444 | if (!pl->socket.monitor_spells) |
2398 | if (!pl->socket.monitor_spells) |
2445 | return; |
2399 | return; |
|
|
2400 | |
2446 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2401 | for (object *spell = pl->ob->inv; spell; spell = spell->below) |
2447 | { |
2402 | { |
2448 | if (spell->type == SPELL) |
2403 | if (spell->type == SPELL) |
2449 | { |
2404 | { |
|
|
2405 | int flags = 0; |
|
|
2406 | |
2450 | /* check if we need to update it */ |
2407 | /* check if we need to update it */ |
2451 | if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) |
2408 | if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) |
2452 | { |
2409 | { |
2453 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2410 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2454 | flags |= UPD_SP_MANA; |
2411 | flags |= UPD_SP_MANA; |
2455 | } |
2412 | } |
|
|
2413 | |
2456 | if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) |
2414 | if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) |
2457 | { |
2415 | { |
2458 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2416 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2459 | flags |= UPD_SP_GRACE; |
2417 | flags |= UPD_SP_GRACE; |
2460 | } |
2418 | } |
|
|
2419 | |
2461 | if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) |
2420 | if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) |
2462 | { |
2421 | { |
2463 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2422 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2464 | flags |= UPD_SP_DAMAGE; |
2423 | flags |= UPD_SP_DAMAGE; |
2465 | } |
2424 | } |
|
|
2425 | |
2466 | if (flags != 0) |
2426 | if (flags) |
2467 | { |
2427 | { |
2468 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2428 | packet sl; |
2469 | strcpy ((char *) sl.buf, "updspell "); |
2429 | |
2470 | sl.len = strlen ((char *) sl.buf); |
2430 | sl << "updspell " |
2471 | SockList_AddChar (&sl, flags); |
2431 | << uint8 (flags) |
2472 | SockList_AddInt (&sl, spell->count); |
2432 | << uint32 (spell->count); |
2473 | if (flags & UPD_SP_MANA) |
2433 | |
2474 | SockList_AddShort (&sl, spell->last_sp); |
2434 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2475 | if (flags & UPD_SP_GRACE) |
2435 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2476 | SockList_AddShort (&sl, spell->last_grace); |
2436 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2477 | if (flags & UPD_SP_DAMAGE) |
2437 | |
2478 | SockList_AddShort (&sl, spell->last_eat); |
|
|
2479 | flags = 0; |
|
|
2480 | Send_With_Handling (&pl->socket, &sl); |
2438 | Send_With_Handling (&pl->socket, &sl); |
2481 | free (sl.buf); |
|
|
2482 | } |
2439 | } |
2483 | } |
2440 | } |
2484 | } |
2441 | } |
2485 | } |
2442 | } |
2486 | |
2443 | |
2487 | void |
2444 | void |
2488 | esrv_remove_spell (player *pl, object *spell) |
2445 | esrv_remove_spell (player *pl, object *spell) |
2489 | { |
2446 | { |
2490 | SockList sl; |
|
|
2491 | |
|
|
2492 | if (!pl->socket.monitor_spells) |
2447 | if (!pl->socket.monitor_spells) |
2493 | return; |
2448 | return; |
|
|
2449 | |
2494 | if (!pl || !spell || spell->env != pl->ob) |
2450 | if (!pl || !spell || spell->env != pl->ob) |
2495 | { |
2451 | { |
2496 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2452 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2497 | return; |
2453 | return; |
2498 | } |
2454 | } |
2499 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2455 | |
2500 | strcpy ((char *) sl.buf, "delspell "); |
2456 | packet sl; |
2501 | sl.len = strlen ((char *) sl.buf); |
2457 | |
2502 | SockList_AddInt (&sl, spell->count); |
2458 | sl << "delspell " |
|
|
2459 | << uint32 (spell->count); |
|
|
2460 | |
2503 | Send_With_Handling (&pl->socket, &sl); |
2461 | Send_With_Handling (&pl->socket, &sl); |
2504 | free (sl.buf); |
|
|
2505 | } |
2462 | } |
2506 | |
2463 | |
2507 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2464 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2508 | static void |
2465 | static void |
2509 | append_spell (player *pl, SockList * sl, object *spell) |
2466 | append_spell (player *pl, packet &sl, object *spell) |
2510 | { |
2467 | { |
2511 | int len, i, skill = 0; |
2468 | int len, i, skill = 0; |
2512 | |
2469 | |
2513 | if (!(spell->name)) |
2470 | if (!(spell->name)) |
2514 | { |
2471 | { |
2515 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
2472 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
2516 | return; |
2473 | return; |
2517 | } |
2474 | } |
2518 | SockList_AddInt (sl, spell->count); |
2475 | |
2519 | SockList_AddShort (sl, spell->level); |
|
|
2520 | SockList_AddShort (sl, spell->casting_time); |
|
|
2521 | /* store costs and damage in the object struct, to compare to later */ |
2476 | /* store costs and damage in the object struct, to compare to later */ |
2522 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2477 | spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); |
2523 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2478 | spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); |
2524 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2479 | spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); |
2525 | /* send the current values */ |
|
|
2526 | SockList_AddShort (sl, spell->last_sp); |
|
|
2527 | SockList_AddShort (sl, spell->last_grace); |
|
|
2528 | SockList_AddShort (sl, spell->last_eat); |
|
|
2529 | |
2480 | |
2530 | /* figure out which skill it uses, if it uses one */ |
2481 | /* figure out which skill it uses, if it uses one */ |
2531 | if (spell->skill) |
2482 | if (spell->skill) |
2532 | { |
2483 | { |
2533 | for (i = 1; i < NUM_SKILLS; i++) |
2484 | for (i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2535 | { |
2486 | { |
2536 | skill = i + CS_STAT_SKILLINFO; |
2487 | skill = i + CS_STAT_SKILLINFO; |
2537 | break; |
2488 | break; |
2538 | } |
2489 | } |
2539 | } |
2490 | } |
2540 | SockList_AddChar (sl, skill); |
|
|
2541 | |
2491 | |
2542 | SockList_AddInt (sl, spell->path_attuned); |
2492 | /* send the current values */ |
|
|
2493 | sl << uint32 (spell->count) |
|
|
2494 | << uint16 (spell->level) |
|
|
2495 | << uint16 (spell->casting_time) |
|
|
2496 | << uint16 (spell->last_sp) |
|
|
2497 | << uint16 (spell->last_grace) |
|
|
2498 | << uint16 (spell->last_eat) |
|
|
2499 | << uint8 (skill) |
|
|
2500 | << uint32 (spell->path_attuned) |
2543 | SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); |
2501 | << uint32 (spell->face ? spell->face->number : 0) |
2544 | |
2502 | << data8 (spell->name) |
2545 | len = strlen (spell->name); |
2503 | << data16 (spell->msg); |
2546 | SockList_AddChar (sl, (char) len); |
|
|
2547 | memcpy (sl->buf + sl->len, spell->name, len); |
|
|
2548 | sl->len += len; |
|
|
2549 | |
|
|
2550 | if (!spell->msg) |
|
|
2551 | { |
|
|
2552 | SockList_AddShort (sl, 0); |
|
|
2553 | } |
|
|
2554 | else |
|
|
2555 | { |
|
|
2556 | len = strlen (spell->msg); |
|
|
2557 | SockList_AddShort (sl, len); |
|
|
2558 | memcpy (sl->buf + sl->len, spell->msg, len); |
|
|
2559 | sl->len += len; |
|
|
2560 | } |
|
|
2561 | } |
2504 | } |
2562 | |
2505 | |
2563 | /** |
2506 | /** |
2564 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2507 | * This tells the client to add the spell *ob, if *ob is NULL, then add |
2565 | * all spells in the player's inventory. |
2508 | * all spells in the player's inventory. |
2566 | */ |
2509 | */ |
2567 | void |
2510 | void |
2568 | esrv_add_spells (player *pl, object *spell) |
2511 | esrv_add_spells (player *pl, object *spell) |
2569 | { |
2512 | { |
2570 | SockList sl; |
|
|
2571 | |
|
|
2572 | if (!pl) |
2513 | if (!pl) |
2573 | { |
2514 | { |
2574 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2515 | LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); |
2575 | return; |
2516 | return; |
2576 | } |
2517 | } |
|
|
2518 | |
2577 | if (!pl->socket.monitor_spells) |
2519 | if (!pl->socket.monitor_spells) |
2578 | return; |
2520 | return; |
2579 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2521 | |
2580 | strcpy ((char *) sl.buf, "addspell "); |
2522 | packet sl; |
2581 | sl.len = strlen ((char *) sl.buf); |
2523 | |
|
|
2524 | sl << "addspell "; |
|
|
2525 | |
2582 | if (!spell) |
2526 | if (!spell) |
2583 | { |
2527 | { |
2584 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2528 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2585 | { |
2529 | { |
2586 | /* were we to simply keep appending data here, we could exceed |
2530 | /* were we to simply keep appending data here, we could exceed |
… | |
… | |
2596 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2540 | * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem |
2597 | * like it will fix this |
2541 | * like it will fix this |
2598 | */ |
2542 | */ |
2599 | if (spell->type != SPELL) |
2543 | if (spell->type != SPELL) |
2600 | continue; |
2544 | continue; |
|
|
2545 | |
2601 | if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2546 | if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) |
2602 | { |
2547 | { |
2603 | Send_With_Handling (&pl->socket, &sl); |
2548 | Send_With_Handling (&pl->socket, &sl); |
2604 | strcpy ((char *) sl.buf, "addspell "); |
2549 | strcpy ((char *) sl.buf, "addspell "); |
2605 | sl.len = strlen ((char *) sl.buf); |
2550 | sl.len = strlen ((char *) sl.buf); |
2606 | } |
2551 | } |
|
|
2552 | |
2607 | append_spell (pl, &sl, spell); |
2553 | append_spell (pl, sl, spell); |
2608 | } |
2554 | } |
2609 | } |
2555 | } |
2610 | else if (spell->type != SPELL) |
2556 | else if (spell->type != SPELL) |
2611 | { |
2557 | { |
2612 | LOG (llevError, "Asked to send a non-spell object as a spell"); |
2558 | LOG (llevError, "Asked to send a non-spell object as a spell"); |
2613 | return; |
2559 | return; |
2614 | } |
2560 | } |
2615 | else |
2561 | else |
2616 | append_spell (pl, &sl, spell); |
2562 | append_spell (pl, sl, spell); |
|
|
2563 | |
2617 | if (sl.len >= MAXSOCKBUF) |
2564 | if (sl.length () >= MAXSOCKBUF) |
2618 | { |
2565 | { |
2619 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2566 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2620 | fatal (0); |
2567 | fatal (0); |
2621 | } |
2568 | } |
|
|
2569 | |
2622 | /* finally, we can send the packet */ |
2570 | /* finally, we can send the packet */ |
2623 | Send_With_Handling (&pl->socket, &sl); |
2571 | Send_With_Handling (&pl->socket, &sl); |
2624 | free (sl.buf); |
2572 | |
2625 | } |
2573 | } |
|
|
2574 | |