… | |
… | |
102 | { |
102 | { |
103 | struct Map newmap; |
103 | struct Map newmap; |
104 | int x, y, mx, my; |
104 | int x, y, mx, my; |
105 | |
105 | |
106 | { |
106 | { |
107 | char buf[MAXSOCKBUF]; |
107 | packet sl; |
108 | |
108 | |
109 | sprintf (buf, "map_scroll %d %d", dx, dy); |
109 | sl.printf ("map_scroll %d %d", dx, dy); |
110 | Write_String_To_Socket (ns, buf, strlen (buf)); |
110 | ns->send_packet (sl); |
111 | } |
111 | } |
112 | |
112 | |
113 | /* If we are using the Map1aCmd, we may in fact send |
113 | /* If we are using the Map1aCmd, we may in fact send |
114 | * head information that is outside the viewable map. |
114 | * head information that is outside the viewable map. |
115 | * 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 |
… | |
… | |
161 | NewSocket & socket = pl->socket; |
161 | NewSocket & socket = pl->socket; |
162 | |
162 | |
163 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
163 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
164 | |
164 | |
165 | if (socket.newmapcmd == 1) |
165 | if (socket.newmapcmd == 1) |
166 | Write_String_To_Socket (&socket, "newmap", 6); |
166 | socket.send_packet ("newmap"); |
167 | |
167 | |
168 | socket.update_look = 1; |
168 | socket.update_look = 1; |
169 | socket.look_position = 0; |
169 | socket.look_position = 0; |
170 | } |
170 | } |
171 | |
171 | |
… | |
… | |
202 | 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); |
203 | } |
203 | } |
204 | else |
204 | else |
205 | snprintf (buf, MAX_BUF, "mapinfo current"); |
205 | snprintf (buf, MAX_BUF, "mapinfo current"); |
206 | |
206 | |
207 | Write_String_To_Socket (&socket, buf, strlen (buf)); |
207 | socket.send_packet (buf); |
208 | } |
208 | } |
209 | } |
209 | } |
210 | 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) |
211 | { |
211 | { |
212 | int dx = ob->x - socket.current_x; |
212 | int dx = ob->x - socket.current_x; |
… | |
… | |
314 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
314 | snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); |
315 | } |
315 | } |
316 | else |
316 | else |
317 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
317 | snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); |
318 | |
318 | |
319 | Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); |
319 | pl->socket.send_packet (bigbuf); |
320 | } |
320 | } |
321 | |
321 | |
322 | /** This is the Setup cmd - easy first implementation */ |
322 | /** This is the Setup cmd - easy first implementation */ |
323 | void |
323 | void |
324 | SetUp (char *buf, int len, NewSocket * ns) |
324 | SetUp (char *buf, int len, NewSocket * ns) |
… | |
… | |
331 | * |
331 | * |
332 | * 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 |
333 | * The client then must sort this out |
333 | * The client then must sort this out |
334 | */ |
334 | */ |
335 | |
335 | |
336 | LOG (llevInfo, "Get SetupCmd:: %s\n", buf); |
336 | //LOG (llevInfo, "Get SetupCmd:: %s\n", buf); |
|
|
337 | |
337 | strcpy (cmdback, "setup"); |
338 | strcpy (cmdback, "setup"); |
338 | for (s = 0; s < len;) |
339 | for (s = 0; s < len; ) |
339 | { |
340 | { |
340 | |
|
|
341 | cmd = &buf[s]; |
341 | cmd = &buf[s]; |
342 | |
342 | |
343 | /* find the next space, and put a null there */ |
343 | /* find the next space, and put a null there */ |
344 | for (; buf[s] && buf[s] != ' '; s++); |
344 | for (; buf[s] && buf[s] != ' '; s++) |
|
|
345 | ; |
|
|
346 | |
345 | buf[s++] = 0; |
347 | buf[s++] = 0; |
|
|
348 | |
346 | while (buf[s] == ' ') |
349 | while (buf[s] == ' ') |
347 | s++; |
350 | s++; |
348 | |
351 | |
349 | if (s >= len) |
352 | if (s >= len) |
350 | break; |
353 | break; |
351 | |
354 | |
352 | param = &buf[s]; |
355 | param = &buf[s]; |
353 | |
356 | |
354 | for (; buf[s] && buf[s] != ' '; s++); |
357 | for (; buf[s] && buf[s] != ' '; s++) |
|
|
358 | ; |
|
|
359 | |
355 | buf[s++] = 0; |
360 | buf[s++] = 0; |
|
|
361 | |
356 | while (buf[s] == ' ') |
362 | while (buf[s] == ' ') |
357 | s++; |
363 | s++; |
358 | |
364 | |
359 | slen = strlen (cmdback); |
365 | slen = strlen (cmdback); |
360 | safe_strcat (cmdback, " ", &slen, HUGE_BUF); |
366 | safe_strcat (cmdback, " ", &slen, HUGE_BUF); |
… | |
… | |
521 | * report a failure to the client. |
527 | * report a failure to the client. |
522 | */ |
528 | */ |
523 | safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF); |
529 | safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF); |
524 | } |
530 | } |
525 | } /* for processing all the setup commands */ |
531 | } /* for processing all the setup commands */ |
|
|
532 | |
526 | LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback); |
533 | LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback); |
527 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
534 | ns->send_packet (cmdback); |
528 | } |
535 | } |
529 | |
536 | |
530 | /** |
537 | /** |
531 | * The client has requested to be added to the game. |
538 | * The client has requested to be added to the game. |
532 | * 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. |
… | |
… | |
538 | { |
545 | { |
539 | Settings oldsettings; |
546 | Settings oldsettings; |
540 | |
547 | |
541 | oldsettings = settings; |
548 | oldsettings = settings; |
542 | if (ns->status != Ns_Add || add_player (ns)) |
549 | if (ns->status != Ns_Add || add_player (ns)) |
543 | { |
550 | ns->send_packet ("addme_failed"); |
544 | Write_String_To_Socket (ns, "addme_failed", 12); |
|
|
545 | } |
|
|
546 | else |
551 | else |
547 | { |
552 | { |
548 | /* Basically, the add_player copies the socket structure into |
553 | /* Basically, the add_player copies the socket structure into |
549 | * the player structure, so this one (which is from init_sockets) |
554 | * the player structure, so this one (which is from init_sockets) |
550 | * 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 |
551 | * stuff in ns is still relevant. |
556 | * stuff in ns is still relevant. |
552 | */ |
557 | */ |
553 | Write_String_To_Socket (ns, "addme_success", 13); |
558 | ns->send_packet ("addme_success"); |
554 | socket_info.nconns--; |
559 | socket_info.nconns--; |
555 | ns->status = Ns_Avail; |
560 | ns->status = Ns_Avail; |
556 | } |
561 | } |
|
|
562 | |
557 | settings = oldsettings; |
563 | settings = oldsettings; |
558 | } |
564 | } |
559 | |
565 | |
560 | /** Reply to ExtendedInfos command */ |
566 | /** Reply to ExtendedInfos command */ |
561 | void |
567 | void |
… | |
… | |
605 | { |
611 | { |
606 | strcat (cmdback, " "); |
612 | strcat (cmdback, " "); |
607 | strcat (cmdback, "smoothing"); |
613 | strcat (cmdback, "smoothing"); |
608 | } |
614 | } |
609 | |
615 | |
610 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
616 | ns->send_packet (cmdback); |
611 | } |
617 | } |
612 | |
618 | |
613 | /* |
619 | /* |
614 | #define MSG_TYPE_BOOK 1 |
620 | #define MSG_TYPE_BOOK 1 |
615 | #define MSG_TYPE_CARD 2 |
621 | #define MSG_TYPE_CARD 2 |
… | |
… | |
668 | strcat (cmdback, " "); |
674 | strcat (cmdback, " "); |
669 | snprintf (temp, sizeof (temp), "%d", i); |
675 | snprintf (temp, sizeof (temp), "%d", i); |
670 | strcat (cmdback, temp); |
676 | strcat (cmdback, temp); |
671 | } |
677 | } |
672 | |
678 | |
673 | Write_String_To_Socket (ns, cmdback, strlen (cmdback)); |
679 | ns->send_packet (cmdback); |
674 | } |
680 | } |
675 | |
681 | |
676 | /** |
682 | /** |
677 | * 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). |
678 | * 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 |
… | |
… | |
682 | */ |
688 | */ |
683 | static void |
689 | static void |
684 | SendSmooth (NewSocket * ns, uint16 face) |
690 | SendSmooth (NewSocket * ns, uint16 face) |
685 | { |
691 | { |
686 | uint16 smoothface; |
692 | uint16 smoothface; |
687 | unsigned char reply[MAX_BUF]; |
|
|
688 | SockList sl; |
|
|
689 | |
693 | |
690 | /* 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 |
691 | * again. |
695 | * again. |
692 | */ |
696 | */ |
693 | if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) |
697 | if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) |
… | |
… | |
701 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
705 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
702 | esrv_send_face (ns, smoothface, 0); |
706 | esrv_send_face (ns, smoothface, 0); |
703 | |
707 | |
704 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
708 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
705 | |
709 | |
706 | sl.buf = reply; |
710 | packet sl; |
707 | strcpy ((char *) sl.buf, "smooth "); |
|
|
708 | sl.len = strlen ((char *) sl.buf); |
|
|
709 | |
711 | |
710 | sl << uint16 (face) << uint16 (smoothface); |
712 | sl << "smooth " |
|
|
713 | << uint16 (face) |
|
|
714 | << uint16 (smoothface); |
711 | |
715 | |
712 | Send_With_Handling (ns, &sl); |
716 | Send_With_Handling (ns, &sl); |
713 | } |
717 | } |
714 | |
718 | |
715 | /** |
719 | /** |
… | |
… | |
723 | |
727 | |
724 | facenbr = atoi (buf); |
728 | facenbr = atoi (buf); |
725 | SendSmooth (ns, facenbr); |
729 | SendSmooth (ns, facenbr); |
726 | } |
730 | } |
727 | |
731 | |
728 | |
|
|
729 | |
|
|
730 | |
|
|
731 | |
|
|
732 | /** |
732 | /** |
733 | * 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, |
734 | * etc.) |
734 | * etc.) |
735 | */ |
735 | */ |
736 | void |
736 | void |
… | |
… | |
789 | */ |
789 | */ |
790 | void |
790 | void |
791 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
791 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
792 | { |
792 | { |
793 | int time, repeat; |
793 | int time, repeat; |
794 | short packet; |
|
|
795 | unsigned char command[MAX_BUF]; |
794 | char command[MAX_BUF]; |
796 | SockList sl; |
795 | int pktlen; |
797 | |
796 | |
798 | if (len < 7) |
797 | if (len < 7) |
799 | { |
798 | { |
800 | 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); |
801 | return; |
800 | return; |
802 | } |
801 | } |
803 | |
802 | |
804 | packet = GetShort_String (buf); |
803 | pktlen = net_uint16 (buf); |
805 | repeat = GetInt_String (buf + 2); |
804 | repeat = net_uint32 (buf + 2); |
|
|
805 | |
806 | /* -1 is special - no repeat, but don't update */ |
806 | /* -1 is special - no repeat, but don't update */ |
807 | if (repeat != -1) |
807 | if (repeat != -1) |
808 | { |
|
|
809 | pl->count = repeat; |
808 | pl->count = repeat; |
810 | } |
809 | |
811 | if ((len - 4) >= MAX_BUF) |
810 | if ((len - 4) >= MAX_BUF) |
812 | len = MAX_BUF - 5; |
811 | len = MAX_BUF - 5; |
813 | |
812 | |
814 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
813 | strncpy ((char *) command, (char *) buf + 6, len - 4); |
815 | command[len - 4] = '\0'; |
814 | command[len - 4] = '\0'; |
… | |
… | |
825 | return; |
824 | return; |
826 | } |
825 | } |
827 | |
826 | |
828 | /* This should not happen anymore. */ |
827 | /* This should not happen anymore. */ |
829 | if (pl->ob->speed_left < -1.0) |
828 | if (pl->ob->speed_left < -1.0) |
830 | { |
|
|
831 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
829 | LOG (llevError, "Player has negative time - shouldn't do command.\n"); |
832 | } |
830 | |
833 | /* In c_new.c */ |
831 | /* In c_new.c */ |
834 | execute_newserver_command (pl->ob, (char *) command); |
832 | execute_newserver_command (pl->ob, (char *) command); |
835 | /* Perhaps something better should be done with a left over count. |
833 | /* Perhaps something better should be done with a left over count. |
836 | * Cleaning up the input should probably be done first - all actions |
834 | * Cleaning up the input should probably be done first - all actions |
837 | * 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 |
838 | * commands. |
836 | * commands. |
839 | */ |
837 | */ |
840 | pl->count = 0; |
838 | pl->count = 0; |
841 | |
839 | |
842 | /* Send confirmation of command execution now */ |
|
|
843 | sl.buf = command; |
|
|
844 | strcpy ((char *) sl.buf, "comc "); |
|
|
845 | sl.len = 5; |
|
|
846 | |
|
|
847 | if (FABS (pl->ob->speed) < 0.001) |
840 | if (FABS (pl->ob->speed) < 0.001) |
848 | time = MAX_TIME * 100; |
841 | time = MAX_TIME * 100; |
849 | else |
842 | else |
850 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
843 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
851 | |
844 | |
|
|
845 | /* Send confirmation of command execution now */ |
|
|
846 | |
|
|
847 | packet sl; |
852 | sl << uint16 (packet) << uint32 (time); |
848 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
853 | |
|
|
854 | Send_With_Handling (&pl->socket, &sl); |
849 | Send_With_Handling (&pl->socket, &sl); |
855 | } |
850 | } |
856 | |
851 | |
857 | |
852 | |
858 | /** This is a reply to a previous query. */ |
853 | /** This is a reply to a previous query. */ |
… | |
… | |
971 | /* these are old dxclients */ |
966 | /* these are old dxclients */ |
972 | /* Version 1024 added support for singular + plural name values - |
967 | /* Version 1024 added support for singular + plural name values - |
973 | * requiing this minimal value reduces complexity of that code, and it |
968 | * requiing this minimal value reduces complexity of that code, and it |
974 | * has been around for a long time. |
969 | * has been around for a long time. |
975 | */ |
970 | */ |
976 | if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) |
971 | if (ns->sc_version < 1026) |
977 | { |
972 | { |
978 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
973 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
979 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
974 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
980 | Write_String_To_Socket (ns, version_warning, strlen (version_warning)); |
975 | ns->send_packet (version_warning); |
981 | } |
976 | } |
982 | |
977 | |
983 | } |
978 | } |
984 | } |
979 | } |
985 | |
980 | |
… | |
… | |
1057 | send_query (NewSocket * ns, uint8 flags, char *text) |
1052 | send_query (NewSocket * ns, uint8 flags, char *text) |
1058 | { |
1053 | { |
1059 | char buf[MAX_BUF]; |
1054 | char buf[MAX_BUF]; |
1060 | |
1055 | |
1061 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1056 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1062 | Write_String_To_Socket (ns, buf, strlen (buf)); |
1057 | ns->send_packet (buf); |
1063 | } |
1058 | } |
1064 | |
1059 | |
1065 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1060 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1066 | Old = New; \ |
1061 | Old = New; \ |
1067 | SockList_AddChar(&sl, Type); \ |
1062 | sl << uint8 (Type) << uint64 (New); \ |
1068 | SockList_AddInt64(&sl, New); \ |
|
|
1069 | } |
1063 | } |
1070 | |
1064 | |
1071 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
1065 | #define AddIfInt(Old,New,Type) if (Old != New) {\ |
1072 | Old = New; \ |
1066 | Old = New; \ |
1073 | SockList_AddChar(&sl, Type); \ |
1067 | sl << uint8 (Type) << uint32 (New); \ |
1074 | SockList_AddInt(&sl, New); \ |
|
|
1075 | } |
1068 | } |
1076 | |
1069 | |
1077 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
1070 | #define AddIfShort(Old,New,Type) if (Old != New) {\ |
1078 | Old = New; \ |
1071 | Old = New; \ |
1079 | SockList_AddChar(&sl, Type); \ |
1072 | sl << uint8 (Type) << uint16 (New); \ |
1080 | SockList_AddShort(&sl, New); \ |
|
|
1081 | } |
1073 | } |
1082 | |
1074 | |
1083 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
1075 | #define AddIfFloat(Old,New,Type) if (Old != New) {\ |
1084 | Old = New; \ |
1076 | Old = New; \ |
1085 | SockList_AddChar(&sl, Type); \ |
1077 | sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \ |
1086 | SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\ |
|
|
1087 | } |
1078 | } |
1088 | |
1079 | |
1089 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
1080 | #define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ |
1090 | if (Old) free(Old);\ |
|
|
1091 | Old = strdup_local(New);\ |
1081 | free(Old); Old = strdup (New);\ |
1092 | SockList_AddChar(&sl, Type); \ |
1082 | sl << uint8 (Type) << data8 (New); \ |
1093 | SockList_AddChar(&sl, ( char )strlen(New)); \ |
|
|
1094 | strcpy((char*)sl.buf + sl.len, New); \ |
|
|
1095 | sl.len += strlen(New); \ |
|
|
1096 | } |
1083 | } |
1097 | |
1084 | |
1098 | /** |
1085 | /** |
1099 | * Sends a statistics update. We look at the old values, |
1086 | * Sends a statistics update. We look at the old values, |
1100 | * 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 |
… | |
… | |
1102 | * commands for now. |
1089 | * commands for now. |
1103 | */ |
1090 | */ |
1104 | void |
1091 | void |
1105 | esrv_update_stats (player *pl) |
1092 | esrv_update_stats (player *pl) |
1106 | { |
1093 | { |
1107 | SockList sl; |
|
|
1108 | char buf[MAX_BUF]; |
1094 | char buf[MAX_BUF]; |
1109 | uint16 flags; |
1095 | uint16 flags; |
1110 | |
1096 | |
1111 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1097 | packet sl; |
1112 | strcpy ((char *) sl.buf, "stats "); |
1098 | sl << "stats "; |
1113 | sl.len = strlen ((char *) sl.buf); |
|
|
1114 | |
1099 | |
1115 | if (pl->ob != NULL) |
1100 | if (pl->ob != NULL) |
1116 | { |
1101 | { |
1117 | 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); |
1118 | 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); |
… | |
… | |
1135 | |
1120 | |
1136 | for (s = 0; s < NUM_SKILLS; s++) |
1121 | for (s = 0; s < NUM_SKILLS; s++) |
1137 | { |
1122 | { |
1138 | 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) |
1139 | { |
1124 | { |
1140 | |
|
|
1141 | /* Always send along the level if exp changes. This is only |
1125 | /* Always send along the level if exp changes. This is only |
1142 | * 1 extra byte, but keeps processing simpler. |
1126 | * 1 extra byte, but keeps processing simpler. |
1143 | */ |
1127 | */ |
1144 | SockList_AddChar (&sl, (char) (s + CS_STAT_SKILLINFO)); |
1128 | sl << uint8 (s + CS_STAT_SKILLINFO) |
1145 | SockList_AddChar (&sl, (char) pl->last_skill_ob[s]->level); |
1129 | << uint8 (pl->last_skill_ob[s]->level) |
1146 | SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); |
1130 | << uint64 (pl->last_skill_ob[s]->stats.exp); |
|
|
1131 | |
1147 | 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; |
1148 | } |
1133 | } |
1149 | } |
1134 | } |
1150 | } |
1135 | } |
1151 | |
1136 | |
… | |
… | |
1207 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1192 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1208 | #endif |
1193 | #endif |
1209 | Send_With_Handling (&pl->socket, &sl); |
1194 | Send_With_Handling (&pl->socket, &sl); |
1210 | } |
1195 | } |
1211 | |
1196 | |
1212 | free (sl.buf); |
|
|
1213 | } |
1197 | } |
1214 | |
1198 | |
1215 | /** |
1199 | /** |
1216 | * 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. |
1217 | */ |
1201 | */ |
1218 | void |
1202 | void |
1219 | esrv_new_player (player *pl, uint32 weight) |
1203 | esrv_new_player (player *pl, uint32 weight) |
1220 | { |
1204 | { |
1221 | SockList sl; |
|
|
1222 | |
|
|
1223 | pl->last_weight = weight; |
1205 | pl->last_weight = weight; |
1224 | |
1206 | |
1225 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1207 | packet sl; |
|
|
1208 | sl << "player "; |
1226 | |
1209 | |
1227 | strcpy ((char *) sl.buf, "player "); |
1210 | sl << uint32 (pl->ob->count) |
1228 | sl.len = strlen ((char *) sl.buf); |
1211 | << uint32 (weight) |
1229 | SockList_AddInt (&sl, pl->ob->count); |
1212 | << uint32 (pl->ob->face->number) |
1230 | SockList_AddInt (&sl, weight); |
1213 | << data8 (pl->ob->name); |
1231 | SockList_AddInt (&sl, pl->ob->face->number); |
|
|
1232 | |
|
|
1233 | SockList_AddChar (&sl, (char) strlen (pl->ob->name)); |
|
|
1234 | strcpy ((char *) sl.buf + sl.len, pl->ob->name); |
|
|
1235 | sl.len += strlen (pl->ob->name); |
|
|
1236 | |
1214 | |
1237 | Send_With_Handling (&pl->socket, &sl); |
1215 | Send_With_Handling (&pl->socket, &sl); |
1238 | free (sl.buf); |
|
|
1239 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1216 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1240 | } |
1217 | } |
1241 | |
1218 | |
1242 | /** |
1219 | /** |
1243 | * Need to send an animation sequence to the client. |
1220 | * Need to send an animation sequence to the client. |
… | |
… | |
1247 | * when the player logs in and picks stuff up. |
1224 | * when the player logs in and picks stuff up. |
1248 | */ |
1225 | */ |
1249 | void |
1226 | void |
1250 | esrv_send_animation (NewSocket * ns, short anim_num) |
1227 | esrv_send_animation (NewSocket * ns, short anim_num) |
1251 | { |
1228 | { |
1252 | SockList sl; |
|
|
1253 | int i; |
1229 | int i; |
1254 | |
1230 | |
1255 | /* 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 |
1256 | * 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 |
1257 | * range, it must be a valid animation. |
1233 | * range, it must be a valid animation. |
… | |
… | |
1260 | { |
1236 | { |
1261 | 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); |
1262 | return; |
1238 | return; |
1263 | } |
1239 | } |
1264 | |
1240 | |
1265 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1241 | packet sl; |
1266 | strcpy ((char *) sl.buf, "anim "); |
1242 | |
1267 | sl.len = 5; |
1243 | sl << "anim " |
1268 | SockList_AddShort (&sl, anim_num); |
1244 | << uint16 (anim_num) |
1269 | SockList_AddShort (&sl, 0); /* flags - not used right now */ |
1245 | << uint16 (0); /* flags - not used right now */ |
|
|
1246 | |
1270 | /* 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 |
1271 | * the face itself) down to the client. |
1248 | * the face itself) down to the client. |
1272 | */ |
1249 | */ |
1273 | for (i = 0; i < animations[anim_num].num_animations; i++) |
1250 | for (i = 0; i < animations[anim_num].num_animations; i++) |
1274 | { |
1251 | { |
1275 | 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)) |
1276 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1253 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1277 | 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 */ |
1278 | } |
1255 | } |
|
|
1256 | |
1279 | Send_With_Handling (ns, &sl); |
1257 | Send_With_Handling (ns, &sl); |
1280 | free (sl.buf); |
1258 | |
1281 | ns->anims_sent[anim_num] = 1; |
1259 | ns->anims_sent[anim_num] = 1; |
1282 | } |
1260 | } |
1283 | |
1261 | |
1284 | |
1262 | |
1285 | /****************************************************************************** |
1263 | /****************************************************************************** |
… | |
… | |
1299 | { |
1277 | { |
1300 | 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); |
1301 | return; |
1279 | return; |
1302 | abort (); |
1280 | abort (); |
1303 | } |
1281 | } |
|
|
1282 | |
1304 | 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; |
1305 | newmap->cells[x][y].count++; |
1284 | newmap->cells[x][y].count++; |
|
|
1285 | |
1306 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1286 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1307 | esrv_send_face (ns, face_num, 0); |
1287 | esrv_send_face (ns, face_num, 0); |
1308 | } |
1288 | } |
1309 | |
1289 | |
1310 | struct LayerCell |
1290 | struct LayerCell |
… | |
… | |
1417 | static void |
1397 | static void |
1418 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1398 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1419 | { |
1399 | { |
1420 | static long frames, bytes, tbytes, tframes; |
1400 | static long frames, bytes, tbytes, tframes; |
1421 | char *cur; |
1401 | char *cur; |
1422 | SockList sl; |
|
|
1423 | |
1402 | |
1424 | |
1403 | packet sl; |
1425 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1404 | sl << "map "; |
1426 | strcpy ((char *) sl.buf, "map "); |
|
|
1427 | sl.len = strlen ((char *) sl.buf); |
|
|
1428 | |
1405 | |
1429 | 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); |
1430 | sl.len = cur - (char *) sl.buf; |
1407 | sl.len = cur - (char *) sl.buf; |
1431 | |
1408 | |
1432 | /* LOG(llevDebug, "Sending map command.\n");*/ |
1409 | /* LOG(llevDebug, "Sending map command.\n");*/ |
… | |
… | |
1444 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1421 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1445 | Send_With_Handling (ns, &sl); |
1422 | Send_With_Handling (ns, &sl); |
1446 | ns->sent_scroll = 0; |
1423 | ns->sent_scroll = 0; |
1447 | } |
1424 | } |
1448 | |
1425 | |
1449 | free (sl.buf); |
|
|
1450 | } |
1426 | } |
1451 | |
1427 | |
1452 | |
1428 | |
1453 | /** Clears a map cell */ |
1429 | /** Clears a map cell */ |
1454 | static void |
1430 | static void |
… | |
… | |
1496 | * 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 |
1497 | * 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 |
1498 | * sent, it returns zero. |
1474 | * sent, it returns zero. |
1499 | */ |
1475 | */ |
1500 | static int |
1476 | static int |
1501 | 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) |
1502 | { |
1478 | { |
1503 | short face_num; |
1479 | short face_num; |
1504 | |
1480 | |
1505 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1481 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1506 | 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; |
1507 | else |
1483 | else |
1508 | face_num = 0; |
1484 | face_num = 0; |
1509 | |
1485 | |
1510 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1486 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1511 | { |
1487 | { |
1512 | SockList_AddShort (&sl, face_num); |
1488 | sl << uint16 (face_num); |
1513 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1489 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1514 | esrv_send_face (&ns, face_num, 0); |
1490 | esrv_send_face (&ns, face_num, 0); |
|
|
1491 | |
1515 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1492 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1516 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1493 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1517 | return 1; |
1494 | return 1; |
1518 | } |
1495 | } |
1519 | |
1496 | |
… | |
… | |
1539 | * 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 |
1540 | * actually match. |
1517 | * actually match. |
1541 | */ |
1518 | */ |
1542 | |
1519 | |
1543 | static int |
1520 | static int |
1544 | 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) |
1545 | { |
1522 | { |
1546 | object *ob, *head; |
1523 | object *ob, *head; |
1547 | uint16 face_num; |
1524 | uint16 face_num; |
1548 | int bx, by, i; |
1525 | int bx, by, i; |
1549 | |
1526 | |
1550 | /* 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. |
1551 | * If not, then do the normal processing. |
1528 | * If not, then do the normal processing. |
1552 | */ |
1529 | */ |
1553 | |
|
|
1554 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1530 | head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; |
1555 | |
1531 | |
1556 | /* 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 |
1557 | * we would normally send for this space. If so, then |
1533 | * we would normally send for this space. If so, then |
1558 | * 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 |
… | |
… | |
1723 | |
1699 | |
1724 | /* 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 |
1725 | * 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 |
1726 | * this one. |
1702 | * this one. |
1727 | */ |
1703 | */ |
1728 | 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) |
1729 | { |
|
|
1730 | face_num = 0; |
1705 | face_num = 0; |
1731 | } |
|
|
1732 | |
1706 | |
1733 | /* 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 |
1734 | * 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. |
1735 | */ |
1709 | */ |
1736 | if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) |
1710 | if (ns.lastmap.cells[sx][sy].faces[layer] != face_num) |
1737 | { |
1711 | { |
1738 | ns->lastmap.cells[sx][sy].faces[layer] = face_num; |
1712 | ns.lastmap.cells[sx][sy].faces[layer] = face_num; |
1739 | if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) |
1713 | if (!(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1740 | esrv_send_face (ns, face_num, 0); |
1714 | esrv_send_face (&ns, face_num, 0); |
1741 | SockList_AddShort (sl, face_num); |
1715 | |
|
|
1716 | sl << uint16 (face_num); |
1742 | return 1; |
1717 | return 1; |
1743 | } |
1718 | } |
|
|
1719 | |
1744 | /* Nothing changed */ |
1720 | /* Nothing changed */ |
1745 | return 0; |
1721 | return 0; |
1746 | } |
1722 | } |
1747 | |
1723 | |
1748 | /** |
1724 | /** |
… | |
… | |
1763 | * 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 |
1764 | * take. |
1740 | * take. |
1765 | */ |
1741 | */ |
1766 | |
1742 | |
1767 | static inline int |
1743 | static inline int |
1768 | 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) |
1769 | { |
1745 | { |
1770 | object *ob; |
1746 | object *ob; |
1771 | int smoothlevel; /* old face_num; */ |
1747 | int smoothlevel; /* old face_num; */ |
1772 | |
1748 | |
1773 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1749 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1778 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) |
1754 | if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) |
1779 | smoothlevel = 0; |
1755 | smoothlevel = 0; |
1780 | else |
1756 | else |
1781 | { |
1757 | { |
1782 | smoothlevel = ob->smoothlevel; |
1758 | smoothlevel = ob->smoothlevel; |
1783 | if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1759 | if (smoothlevel && !(ns.faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) |
1784 | SendSmooth (ns, ob->face->number); |
1760 | SendSmooth (&ns, ob->face->number); |
1785 | } /* else not already head object or blank face */ |
1761 | } /* else not already head object or blank face */ |
1786 | |
1762 | |
1787 | /* 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 |
1788 | * 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. |
1789 | */ |
1765 | */ |
1790 | if (smoothlevel > 255) |
1766 | if (smoothlevel > 255) |
1791 | smoothlevel = 255; |
1767 | smoothlevel = 255; |
1792 | else if (smoothlevel < 0) |
1768 | else if (smoothlevel < 0) |
1793 | smoothlevel = 0; |
1769 | smoothlevel = 0; |
|
|
1770 | |
1794 | if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) |
1771 | if (ns.lastmap.cells[sx][sy].smooth[layer] != smoothlevel) |
1795 | { |
1772 | { |
1796 | ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1773 | ns.lastmap.cells[sx][sy].smooth[layer] = smoothlevel; |
1797 | SockList_AddChar (sl, (uint8) (smoothlevel & 0xFF)); |
1774 | sl << uint8 (smoothlevel); |
1798 | return 1; |
1775 | return 1; |
1799 | } |
1776 | } |
|
|
1777 | |
1800 | /* Nothing changed */ |
1778 | /* Nothing changed */ |
1801 | return 0; |
1779 | return 0; |
1802 | } |
1780 | } |
1803 | |
1781 | |
1804 | /** |
1782 | /** |
… | |
… | |
1845 | draw_client_map1 (object *pl) |
1823 | draw_client_map1 (object *pl) |
1846 | { |
1824 | { |
1847 | 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; |
1848 | sint16 nx, ny; |
1826 | sint16 nx, ny; |
1849 | int estartlen, eoldlen; |
1827 | int estartlen, eoldlen; |
1850 | SockList sl; |
|
|
1851 | SockList esl; /*For extended Map info */ |
|
|
1852 | uint16 mask, emask; |
1828 | uint16 mask, emask; |
1853 | uint8 eentrysize; |
1829 | uint8 eentrysize; |
1854 | uint16 ewhatstart, ewhatflag; |
1830 | uint16 ewhatstart, ewhatflag; |
1855 | uint8 extendedinfos; |
1831 | uint8 extendedinfos; |
1856 | maptile *m; |
1832 | maptile *m; |
1857 | |
1833 | |
1858 | NewSocket & socket = pl->contr->socket; |
1834 | NewSocket &socket = pl->contr->socket; |
1859 | |
1835 | |
1860 | check_map_change (pl->contr); |
1836 | check_map_change (pl->contr); |
1861 | |
1837 | |
1862 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
1838 | packet sl; |
1863 | if (socket.mapmode == Map1Cmd) |
1839 | packet esl; |
1864 | strcpy ((char *) sl.buf, "map1 "); |
1840 | |
1865 | else |
1841 | sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); |
1866 | strcpy ((char *) sl.buf, "map1a "); |
|
|
1867 | sl.len = strlen ((char *) sl.buf); |
|
|
1868 | startlen = sl.len; |
1842 | startlen = sl.len; |
1869 | |
1843 | |
1870 | /*Extendedmapinfo structure initialisation */ |
1844 | /*Extendedmapinfo structure initialisation */ |
1871 | if (socket.ext_mapinfos) |
1845 | if (socket.ext_mapinfos) |
1872 | { |
1846 | { |
1873 | esl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
1874 | strcpy ((char *) esl.buf, "mapextended "); |
|
|
1875 | esl.len = strlen ((char *) esl.buf); |
|
|
1876 | extendedinfos = EMI_NOREDRAW; |
1847 | extendedinfos = EMI_NOREDRAW; |
1877 | |
1848 | |
1878 | if (socket.EMI_smooth) |
1849 | if (socket.EMI_smooth) |
1879 | extendedinfos |= EMI_SMOOTH; |
1850 | extendedinfos |= EMI_SMOOTH; |
1880 | |
1851 | |
1881 | ewhatstart = esl.len; |
1852 | ewhatstart = esl.len; |
1882 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1853 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1883 | could need to be taken away */ |
1854 | could need to be taken away */ |
1884 | SockList_AddChar (&esl, extendedinfos); |
|
|
1885 | eentrysize = getExtendedMapInfoSize (&socket); |
1855 | eentrysize = getExtendedMapInfoSize (&socket); |
1886 | SockList_AddChar (&esl, eentrysize); |
1856 | esl << "mapextended " |
|
|
1857 | << uint8 (extendedinfos) |
|
|
1858 | << uint8 (eentrysize); |
1887 | estartlen = esl.len; |
1859 | estartlen = esl.len; |
1888 | } |
1860 | } |
1889 | else |
1861 | else |
1890 | { |
1862 | { |
1891 | /* suppress compiler warnings */ |
1863 | /* suppress compiler warnings */ |
… | |
… | |
1932 | { |
1904 | { |
1933 | int i, got_one; |
1905 | int i, got_one; |
1934 | |
1906 | |
1935 | oldlen = sl.len; |
1907 | oldlen = sl.len; |
1936 | |
1908 | |
1937 | SockList_AddShort (&sl, mask); |
1909 | sl << uint16 (mask); |
1938 | |
1910 | |
1939 | if (check_head (sl, socket, ax, ay, 2)) |
1911 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
1940 | mask |= 0x4; |
|
|
1941 | if (check_head (sl, socket, ax, ay, 1)) |
1912 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
1942 | mask |= 0x2; |
|
|
1943 | if (check_head (sl, socket, ax, ay, 0)) |
1913 | if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; |
1944 | mask |= 0x1; |
|
|
1945 | |
1914 | |
1946 | /* 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 |
1947 | * actually need to send that - just the coordinates |
1916 | * actually need to send that - just the coordinates |
1948 | * with no faces tells the client to blank out the |
1917 | * with no faces tells the client to blank out the |
1949 | * space. |
1918 | * space. |
… | |
… | |
1986 | * 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 |
1987 | * of the map, it shouldn't have a head |
1956 | * of the map, it shouldn't have a head |
1988 | */ |
1957 | */ |
1989 | if (lastcell.count != -1) |
1958 | if (lastcell.count != -1) |
1990 | { |
1959 | { |
1991 | SockList_AddShort (&sl, mask); |
1960 | sl << uint16 (mask); |
1992 | map_clearcell (&lastcell, 0, 0, 0, -1); |
1961 | map_clearcell (&lastcell, 0, 0, 0, -1); |
1993 | } |
1962 | } |
1994 | } |
1963 | } |
1995 | else if (d > 3) |
1964 | else if (d > 3) |
1996 | { |
1965 | { |
… | |
… | |
2000 | * reason. Still may need to send the head for this space. |
1969 | * reason. Still may need to send the head for this space. |
2001 | */ |
1970 | */ |
2002 | |
1971 | |
2003 | oldlen = sl.len; |
1972 | oldlen = sl.len; |
2004 | |
1973 | |
2005 | SockList_AddShort (&sl, mask); |
1974 | sl << uint16 (mask); |
2006 | |
1975 | |
2007 | if (lastcell.count != -1) |
1976 | if (lastcell.count != -1) |
2008 | need_send = 1; |
1977 | need_send = 1; |
2009 | |
1978 | |
2010 | count = -1; |
1979 | count = -1; |
2011 | |
1980 | |
2012 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
1981 | if (socket.mapmode == Map1aCmd && have_head (ax, ay)) |
2013 | { |
1982 | { |
2014 | /* Now check to see if any heads need to be sent */ |
1983 | /* Now check to see if any heads need to be sent */ |
2015 | |
1984 | |
2016 | if (check_head (sl, socket, ax, ay, 2)) |
1985 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
2017 | mask |= 0x4; |
|
|
2018 | if (check_head (sl, socket, ax, ay, 1)) |
1986 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
2019 | mask |= 0x2; |
|
|
2020 | if (check_head (sl, socket, ax, ay, 0)) |
1987 | if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1; |
2021 | mask |= 0x1; |
|
|
2022 | |
1988 | |
2023 | lastcell.count = count; |
1989 | lastcell.count = count; |
2024 | } |
1990 | } |
2025 | else |
1991 | else |
2026 | { |
1992 | { |
… | |
… | |
2055 | */ |
2021 | */ |
2056 | oldlen = sl.len; |
2022 | oldlen = sl.len; |
2057 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2023 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2058 | eoldlen = esl.len; |
2024 | eoldlen = esl.len; |
2059 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2025 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2060 | SockList_AddShort (&sl, mask); |
2026 | sl << uint16 (mask); |
2061 | |
2027 | |
2062 | if (socket.ext_mapinfos) |
2028 | if (socket.ext_mapinfos) |
2063 | SockList_AddShort (&esl, emask); |
2029 | esl << uint16 (emask); |
2064 | |
2030 | |
2065 | unsigned char dummy; |
2031 | unsigned char dummy; |
2066 | unsigned char *last_ext = &dummy; |
2032 | unsigned char *last_ext = &dummy; |
2067 | |
2033 | |
2068 | /* Darkness changed */ |
2034 | /* Darkness changed */ |
… | |
… | |
2072 | |
2038 | |
2073 | if (socket.extmap) |
2039 | if (socket.extmap) |
2074 | { |
2040 | { |
2075 | *last_ext |= 0x80; |
2041 | *last_ext |= 0x80; |
2076 | last_ext = sl.buf + sl.len; |
2042 | last_ext = sl.buf + sl.len; |
2077 | SockList_AddChar (&sl, d); |
2043 | sl << uint8 (d); |
2078 | } |
2044 | } |
2079 | else |
2045 | else |
2080 | SockList_AddChar (&sl, 255 - 64 * d); |
2046 | sl << uint8 (255 - 64 * d); |
2081 | } |
2047 | } |
2082 | |
2048 | |
2083 | lastcell.count = d; |
2049 | lastcell.count = d; |
2084 | |
2050 | |
2085 | if (socket.extmap) |
2051 | if (socket.extmap) |
… | |
… | |
2152 | sl << uint8 (8) << uint8 (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) |
… | |
… | |
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 "); |
|
|
2470 | sl.len = strlen ((char *) sl.buf); |
|
|
2471 | |
2429 | |
|
|
2430 | sl << "updspell " |
|
|
2431 | << uint8 (flags) |
2472 | sl << uint8 (flags) << uint32 (spell->count); |
2432 | << uint32 (spell->count); |
2473 | |
2433 | |
2474 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2434 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2475 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2435 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2476 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2436 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2477 | |
2437 | |
2478 | flags = 0; |
|
|
2479 | Send_With_Handling (&pl->socket, &sl); |
2438 | Send_With_Handling (&pl->socket, &sl); |
2480 | free (sl.buf); |
|
|
2481 | } |
2439 | } |
2482 | } |
2440 | } |
2483 | } |
2441 | } |
2484 | } |
2442 | } |
2485 | |
2443 | |
2486 | void |
2444 | void |
2487 | esrv_remove_spell (player *pl, object *spell) |
2445 | esrv_remove_spell (player *pl, object *spell) |
2488 | { |
2446 | { |
2489 | SockList sl; |
|
|
2490 | |
|
|
2491 | if (!pl->socket.monitor_spells) |
2447 | if (!pl->socket.monitor_spells) |
2492 | return; |
2448 | return; |
|
|
2449 | |
2493 | if (!pl || !spell || spell->env != pl->ob) |
2450 | if (!pl || !spell || spell->env != pl->ob) |
2494 | { |
2451 | { |
2495 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2452 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2496 | return; |
2453 | return; |
2497 | } |
2454 | } |
2498 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
|
|
2499 | strcpy ((char *) sl.buf, "delspell "); |
|
|
2500 | sl.len = strlen ((char *) sl.buf); |
|
|
2501 | |
2455 | |
|
|
2456 | packet sl; |
|
|
2457 | |
|
|
2458 | sl << "delspell " |
2502 | sl << uint32 (spell->count); |
2459 | << uint32 (spell->count); |
2503 | |
2460 | |
2504 | Send_With_Handling (&pl->socket, &sl); |
2461 | Send_With_Handling (&pl->socket, &sl); |
2505 | free (sl.buf); |
|
|
2506 | } |
2462 | } |
2507 | |
2463 | |
2508 | /* 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. */ |
2509 | static void |
2465 | static void |
2510 | append_spell (player *pl, SockList &sl, object *spell) |
2466 | append_spell (player *pl, packet &sl, object *spell) |
2511 | { |
2467 | { |
2512 | int len, i, skill = 0; |
2468 | int len, i, skill = 0; |
2513 | |
2469 | |
2514 | if (!(spell->name)) |
2470 | if (!(spell->name)) |
2515 | { |
2471 | { |
… | |
… | |
2552 | * all spells in the player's inventory. |
2508 | * all spells in the player's inventory. |
2553 | */ |
2509 | */ |
2554 | void |
2510 | void |
2555 | esrv_add_spells (player *pl, object *spell) |
2511 | esrv_add_spells (player *pl, object *spell) |
2556 | { |
2512 | { |
2557 | SockList sl; |
|
|
2558 | |
|
|
2559 | if (!pl) |
2513 | if (!pl) |
2560 | { |
2514 | { |
2561 | 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"); |
2562 | return; |
2516 | return; |
2563 | } |
2517 | } |
|
|
2518 | |
2564 | if (!pl->socket.monitor_spells) |
2519 | if (!pl->socket.monitor_spells) |
2565 | return; |
2520 | return; |
2566 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
2521 | |
2567 | strcpy ((char *) sl.buf, "addspell "); |
2522 | packet sl; |
2568 | sl.len = strlen ((char *) sl.buf); |
2523 | |
|
|
2524 | sl << "addspell "; |
|
|
2525 | |
2569 | if (!spell) |
2526 | if (!spell) |
2570 | { |
2527 | { |
2571 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2528 | for (spell = pl->ob->inv; spell != NULL; spell = spell->below) |
2572 | { |
2529 | { |
2573 | /* were we to simply keep appending data here, we could exceed |
2530 | /* were we to simply keep appending data here, we could exceed |
… | |
… | |
2602 | return; |
2559 | return; |
2603 | } |
2560 | } |
2604 | else |
2561 | else |
2605 | append_spell (pl, sl, spell); |
2562 | append_spell (pl, sl, spell); |
2606 | |
2563 | |
2607 | if (sl.len >= MAXSOCKBUF) |
2564 | if (sl.length () >= MAXSOCKBUF) |
2608 | { |
2565 | { |
2609 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2566 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
2610 | fatal (0); |
2567 | fatal (0); |
2611 | } |
2568 | } |
2612 | |
2569 | |
2613 | /* finally, we can send the packet */ |
2570 | /* finally, we can send the packet */ |
2614 | Send_With_Handling (&pl->socket, &sl); |
2571 | Send_With_Handling (&pl->socket, &sl); |
2615 | free (sl.buf); |
2572 | |
2616 | } |
2573 | } |
|
|
2574 | |