ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/request.C
(Generate patch)

Comparing deliantra/server/socket/request.C (file contents):
Revision 1.26 by pippijn, Mon Dec 11 19:46:47 2006 UTC vs.
Revision 1.34 by root, Thu Dec 14 01:59:10 2006 UTC

41 * if a face has not already been sent to the client, it is sent now. 41 * if a face has not already been sent to the client, it is sent now.
42 * 42 *
43 * mapcellchanged, compactlayer, compactstack, perform the map compressing 43 * mapcellchanged, compactlayer, compactstack, perform the map compressing
44 * operations 44 * operations
45 * 45 *
46 * esrv_map_doneredraw finishes the map update, and ships across the
47 * map updates.
48 *
49 */ 46 */
50 47
51#include <global.h> 48#include <global.h>
52#include <sproto.h> 49#include <sproto.h>
53 50
102{ 99{
103 struct Map newmap; 100 struct Map newmap;
104 int x, y, mx, my; 101 int x, y, mx, my;
105 102
106 { 103 {
107 char buf[MAXSOCKBUF]; 104 packet sl;
108 105
109 sprintf (buf, "map_scroll %d %d", dx, dy); 106 sl.printf ("map_scroll %d %d", dx, dy);
110 Write_String_To_Socket (ns, buf, strlen (buf)); 107 ns->send_packet (sl);
111 } 108 }
112 109
113 /* If we are using the Map1aCmd, we may in fact send 110 /* If we are using the Map1aCmd, we may in fact send
114 * head information that is outside the viewable map. 111 * head information that is outside the viewable map.
115 * So set the mx,my to the max value we want to 112 * So set the mx,my to the max value we want to
161 NewSocket & socket = pl->socket; 158 NewSocket & socket = pl->socket;
162 159
163 memset (&socket.lastmap, 0, sizeof (socket.lastmap)); 160 memset (&socket.lastmap, 0, sizeof (socket.lastmap));
164 161
165 if (socket.newmapcmd == 1) 162 if (socket.newmapcmd == 1)
166 Write_String_To_Socket (&socket, "newmap", 6); 163 socket.send_packet ("newmap");
167 164
168 socket.update_look = 1; 165 socket.update_look = 1;
169 socket.look_position = 0; 166 socket.look_position = 0;
170} 167}
171 168
202 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, ob->map->width, ob->map->height, ob->map->path); 199 flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, ob->map->width, ob->map->height, ob->map->path);
203 } 200 }
204 else 201 else
205 snprintf (buf, MAX_BUF, "mapinfo current"); 202 snprintf (buf, MAX_BUF, "mapinfo current");
206 203
207 Write_String_To_Socket (&socket, buf, strlen (buf)); 204 socket.send_packet (buf);
208 } 205 }
209 } 206 }
210 else if (socket.current_x != ob->x || socket.current_y != ob->y) 207 else if (socket.current_x != ob->x || socket.current_y != ob->y)
211 { 208 {
212 int dx = ob->x - socket.current_x; 209 int dx = ob->x - socket.current_x;
314 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token); 311 snprintf (bigbuf, MAX_BUF, "mapinfo %s nomap", token);
315 } 312 }
316 else 313 else
317 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token); 314 snprintf (bigbuf, MAX_BUF, "mapinfo %s unsupported", token);
318 315
319 Write_String_To_Socket (&pl->socket, bigbuf, strlen (bigbuf)); 316 pl->socket.send_packet (bigbuf);
320} 317}
321 318
322/** This is the Setup cmd - easy first implementation */ 319/** This is the Setup cmd - easy first implementation */
323void 320void
324SetUp (char *buf, int len, NewSocket * ns) 321SetUp (char *buf, int len, NewSocket * ns)
331 * 328 *
332 * we send the status of the cmd back, or a FALSE is the cmd is the server unknown 329 * 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 330 * The client then must sort this out
334 */ 331 */
335 332
336 LOG (llevInfo, "Get SetupCmd:: %s\n", buf); 333 //LOG (llevInfo, "Get SetupCmd:: %s\n", buf);
334
337 strcpy (cmdback, "setup"); 335 strcpy (cmdback, "setup");
338 for (s = 0; s < len;) 336 for (s = 0; s < len; )
339 { 337 {
340
341 cmd = &buf[s]; 338 cmd = &buf[s];
342 339
343 /* find the next space, and put a null there */ 340 /* find the next space, and put a null there */
344 for (; buf[s] && buf[s] != ' '; s++); 341 for (; buf[s] && buf[s] != ' '; s++)
342 ;
343
345 buf[s++] = 0; 344 buf[s++] = 0;
345
346 while (buf[s] == ' ') 346 while (buf[s] == ' ')
347 s++; 347 s++;
348 348
349 if (s >= len) 349 if (s >= len)
350 break; 350 break;
351 351
352 param = &buf[s]; 352 param = &buf[s];
353 353
354 for (; buf[s] && buf[s] != ' '; s++); 354 for (; buf[s] && buf[s] != ' '; s++)
355 ;
356
355 buf[s++] = 0; 357 buf[s++] = 0;
358
356 while (buf[s] == ' ') 359 while (buf[s] == ' ')
357 s++; 360 s++;
358 361
359 slen = strlen (cmdback); 362 slen = strlen (cmdback);
360 safe_strcat (cmdback, " ", &slen, HUGE_BUF); 363 safe_strcat (cmdback, " ", &slen, HUGE_BUF);
521 * report a failure to the client. 524 * report a failure to the client.
522 */ 525 */
523 safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF); 526 safe_strcat (cmdback, "FALSE", &slen, HUGE_BUF);
524 } 527 }
525 } /* for processing all the setup commands */ 528 } /* for processing all the setup commands */
529
526 LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback); 530 LOG (llevInfo, "SendBack SetupCmd:: %s\n", cmdback);
527 Write_String_To_Socket (ns, cmdback, strlen (cmdback)); 531 ns->send_packet (cmdback);
528} 532}
529 533
530/** 534/**
531 * The client has requested to be added to the game. 535 * 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. 536 * This is what takes care of it. We tell the client how things worked out.
538{ 542{
539 Settings oldsettings; 543 Settings oldsettings;
540 544
541 oldsettings = settings; 545 oldsettings = settings;
542 if (ns->status != Ns_Add || add_player (ns)) 546 if (ns->status != Ns_Add || add_player (ns))
543 { 547 ns->send_packet ("addme_failed");
544 Write_String_To_Socket (ns, "addme_failed", 12);
545 }
546 else 548 else
547 { 549 {
548 /* Basically, the add_player copies the socket structure into 550 /* Basically, the add_player copies the socket structure into
549 * the player structure, so this one (which is from init_sockets) 551 * the player structure, so this one (which is from init_sockets)
550 * is not needed anymore. The write below should still work, as the 552 * is not needed anymore. The write below should still work, as the
551 * stuff in ns is still relevant. 553 * stuff in ns is still relevant.
552 */ 554 */
553 Write_String_To_Socket (ns, "addme_success", 13); 555 ns->send_packet ("addme_success");
554 socket_info.nconns--; 556 socket_info.nconns--;
555 ns->status = Ns_Avail; 557 ns->status = Ns_Avail;
556 } 558 }
559
557 settings = oldsettings; 560 settings = oldsettings;
558} 561}
559 562
560/** Reply to ExtendedInfos command */ 563/** Reply to ExtendedInfos command */
561void 564void
605 { 608 {
606 strcat (cmdback, " "); 609 strcat (cmdback, " ");
607 strcat (cmdback, "smoothing"); 610 strcat (cmdback, "smoothing");
608 } 611 }
609 612
610 Write_String_To_Socket (ns, cmdback, strlen (cmdback)); 613 ns->send_packet (cmdback);
611} 614}
612 615
613/* 616/*
614#define MSG_TYPE_BOOK 1 617#define MSG_TYPE_BOOK 1
615#define MSG_TYPE_CARD 2 618#define MSG_TYPE_CARD 2
668 strcat (cmdback, " "); 671 strcat (cmdback, " ");
669 snprintf (temp, sizeof (temp), "%d", i); 672 snprintf (temp, sizeof (temp), "%d", i);
670 strcat (cmdback, temp); 673 strcat (cmdback, temp);
671 } 674 }
672 675
673 Write_String_To_Socket (ns, cmdback, strlen (cmdback)); 676 ns->send_packet (cmdback);
674} 677}
675 678
676/** 679/**
677 * A lot like the old AskSmooth (in fact, now called by AskSmooth). 680 * 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 681 * Basically, it makes no sense to wait for the client to request a
682 */ 685 */
683static void 686static void
684SendSmooth (NewSocket * ns, uint16 face) 687SendSmooth (NewSocket * ns, uint16 face)
685{ 688{
686 uint16 smoothface; 689 uint16 smoothface;
687 unsigned char reply[MAX_BUF];
688 SockList sl;
689 690
690 /* If we can't find a face, return and set it so we won't try to send this 691 /* If we can't find a face, return and set it so we won't try to send this
691 * again. 692 * again.
692 */ 693 */
693 if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface))) 694 if ((!FindSmooth (face, &smoothface)) && (!FindSmooth (smooth_face->number, &smoothface)))
701 if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) 702 if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE))
702 esrv_send_face (ns, smoothface, 0); 703 esrv_send_face (ns, smoothface, 0);
703 704
704 ns->faces_sent[face] |= NS_FACESENT_SMOOTH; 705 ns->faces_sent[face] |= NS_FACESENT_SMOOTH;
705 706
706 sl.buf = reply; 707 packet sl;
707 strcpy ((char *) sl.buf, "smooth "); 708
708 sl.len = strlen ((char *) sl.buf); 709 sl << "smooth "
709 SockList_AddShort (&sl, face); 710 << uint16 (face)
710 SockList_AddShort (&sl, smoothface); 711 << uint16 (smoothface);
712
711 Send_With_Handling (ns, &sl); 713 Send_With_Handling (ns, &sl);
712} 714}
713 715
714 /** 716 /**
715 * Tells client the picture it has to use 717 * Tells client the picture it has to use
721 uint16 facenbr; 723 uint16 facenbr;
722 724
723 facenbr = atoi (buf); 725 facenbr = atoi (buf);
724 SendSmooth (ns, facenbr); 726 SendSmooth (ns, facenbr);
725} 727}
726
727
728
729
730 728
731/** 729/**
732 * This handles the general commands from the client (ie, north, fire, cast, 730 * This handles the general commands from the client (ie, north, fire, cast,
733 * etc.) 731 * etc.)
734 */ 732 */
788 */ 786 */
789void 787void
790NewPlayerCmd (uint8 * buf, int len, player *pl) 788NewPlayerCmd (uint8 * buf, int len, player *pl)
791{ 789{
792 int time, repeat; 790 int time, repeat;
793 short packet;
794 unsigned char command[MAX_BUF]; 791 char command[MAX_BUF];
795 SockList sl; 792 int pktlen;
796 793
797 if (len < 7) 794 if (len < 7)
798 { 795 {
799 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); 796 LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf);
800 return; 797 return;
801 } 798 }
802 799
803 packet = GetShort_String (buf); 800 pktlen = net_uint16 (buf);
804 repeat = GetInt_String (buf + 2); 801 repeat = net_uint32 (buf + 2);
802
805 /* -1 is special - no repeat, but don't update */ 803 /* -1 is special - no repeat, but don't update */
806 if (repeat != -1) 804 if (repeat != -1)
807 {
808 pl->count = repeat; 805 pl->count = repeat;
809 } 806
810 if ((len - 4) >= MAX_BUF) 807 if ((len - 4) >= MAX_BUF)
811 len = MAX_BUF - 5; 808 len = MAX_BUF - 5;
812 809
813 strncpy ((char *) command, (char *) buf + 6, len - 4); 810 strncpy ((char *) command, (char *) buf + 6, len - 4);
814 command[len - 4] = '\0'; 811 command[len - 4] = '\0';
824 return; 821 return;
825 } 822 }
826 823
827 /* This should not happen anymore. */ 824 /* This should not happen anymore. */
828 if (pl->ob->speed_left < -1.0) 825 if (pl->ob->speed_left < -1.0)
829 {
830 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 826 LOG (llevError, "Player has negative time - shouldn't do command.\n");
831 } 827
832 /* In c_new.c */ 828 /* In c_new.c */
833 execute_newserver_command (pl->ob, (char *) command); 829 execute_newserver_command (pl->ob, (char *) command);
834 /* Perhaps something better should be done with a left over count. 830 /* Perhaps something better should be done with a left over count.
835 * Cleaning up the input should probably be done first - all actions 831 * Cleaning up the input should probably be done first - all actions
836 * for the command that issued the count should be done before any other 832 * for the command that issued the count should be done before any other
837 * commands. 833 * commands.
838 */ 834 */
839 pl->count = 0; 835 pl->count = 0;
840 836
841 /* Send confirmation of command execution now */
842 sl.buf = command;
843 strcpy ((char *) sl.buf, "comc ");
844 sl.len = 5;
845 SockList_AddShort (&sl, packet);
846 if (FABS (pl->ob->speed) < 0.001) 837 if (FABS (pl->ob->speed) < 0.001)
847 time = MAX_TIME * 100; 838 time = MAX_TIME * 100;
848 else 839 else
849 time = (int) (MAX_TIME / FABS (pl->ob->speed)); 840 time = (int) (MAX_TIME / FABS (pl->ob->speed));
850 SockList_AddInt (&sl, time); 841
842 /* Send confirmation of command execution now */
843
844 packet sl;
845 sl << "comc " << uint16 (pktlen) << uint32 (time);
851 Send_With_Handling (&pl->socket, &sl); 846 Send_With_Handling (&pl->socket, &sl);
852} 847}
853 848
854 849
855/** This is a reply to a previous query. */ 850/** This is a reply to a previous query. */
968 /* these are old dxclients */ 963 /* these are old dxclients */
969 /* Version 1024 added support for singular + plural name values - 964 /* Version 1024 added support for singular + plural name values -
970 * requiing this minimal value reduces complexity of that code, and it 965 * requiing this minimal value reduces complexity of that code, and it
971 * has been around for a long time. 966 * has been around for a long time.
972 */ 967 */
973 if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) 968 if (ns->sc_version < 1026)
974 { 969 {
975 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 970 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
976 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 971 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
977 Write_String_To_Socket (ns, version_warning, strlen (version_warning)); 972 ns->send_packet (version_warning);
978 } 973 }
979 974
980 } 975 }
981} 976}
982 977
1054send_query (NewSocket * ns, uint8 flags, char *text) 1049send_query (NewSocket * ns, uint8 flags, char *text)
1055{ 1050{
1056 char buf[MAX_BUF]; 1051 char buf[MAX_BUF];
1057 1052
1058 sprintf (buf, "query %d %s", flags, text ? text : ""); 1053 sprintf (buf, "query %d %s", flags, text ? text : "");
1059 Write_String_To_Socket (ns, buf, strlen (buf)); 1054 ns->send_packet (buf);
1060} 1055}
1061 1056
1062#define AddIfInt64(Old,New,Type) if (Old != New) {\ 1057#define AddIfInt64(Old,New,Type) if (Old != New) {\
1063 Old = New; \ 1058 Old = New; \
1064 SockList_AddChar(&sl, Type); \ 1059 sl << uint8 (Type) << uint64 (New); \
1065 SockList_AddInt64(&sl, New); \
1066 } 1060 }
1067 1061
1068#define AddIfInt(Old,New,Type) if (Old != New) {\ 1062#define AddIfInt(Old,New,Type) if (Old != New) {\
1069 Old = New; \ 1063 Old = New; \
1070 SockList_AddChar(&sl, Type); \ 1064 sl << uint8 (Type) << uint32 (New); \
1071 SockList_AddInt(&sl, New); \
1072 } 1065 }
1073 1066
1074#define AddIfShort(Old,New,Type) if (Old != New) {\ 1067#define AddIfShort(Old,New,Type) if (Old != New) {\
1075 Old = New; \ 1068 Old = New; \
1076 SockList_AddChar(&sl, Type); \ 1069 sl << uint8 (Type) << uint16 (New); \
1077 SockList_AddShort(&sl, New); \
1078 } 1070 }
1079 1071
1080#define AddIfFloat(Old,New,Type) if (Old != New) {\ 1072#define AddIfFloat(Old,New,Type) if (Old != New) {\
1081 Old = New; \ 1073 Old = New; \
1082 SockList_AddChar(&sl, Type); \ 1074 sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \
1083 SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\
1084 } 1075 }
1085 1076
1086#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ 1077#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\
1087 if (Old) free(Old);\
1088 Old = strdup_local(New);\ 1078 free(Old); Old = strdup (New);\
1089 SockList_AddChar(&sl, Type); \ 1079 sl << uint8 (Type) << data8 (New); \
1090 SockList_AddChar(&sl, ( char )strlen(New)); \
1091 strcpy((char*)sl.buf + sl.len, New); \
1092 sl.len += strlen(New); \
1093 } 1080 }
1094 1081
1095/** 1082/**
1096 * Sends a statistics update. We look at the old values, 1083 * Sends a statistics update. We look at the old values,
1097 * and only send what has changed. Stat mapping values are in newclient.h 1084 * and only send what has changed. Stat mapping values are in newclient.h
1099 * commands for now. 1086 * commands for now.
1100 */ 1087 */
1101void 1088void
1102esrv_update_stats (player *pl) 1089esrv_update_stats (player *pl)
1103{ 1090{
1104 SockList sl;
1105 char buf[MAX_BUF]; 1091 char buf[MAX_BUF];
1106 uint16 flags; 1092 uint16 flags;
1107 1093
1108 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1094 packet sl;
1109 strcpy ((char *) sl.buf, "stats "); 1095 sl << "stats ";
1110 sl.len = strlen ((char *) sl.buf);
1111 1096
1112 if (pl->ob != NULL) 1097 if (pl->ob != NULL)
1113 { 1098 {
1114 AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); 1099 AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP);
1115 AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); 1100 AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP);
1132 1117
1133 for (s = 0; s < NUM_SKILLS; s++) 1118 for (s = 0; s < NUM_SKILLS; s++)
1134 { 1119 {
1135 if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) 1120 if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp)
1136 { 1121 {
1137
1138 /* Always send along the level if exp changes. This is only 1122 /* Always send along the level if exp changes. This is only
1139 * 1 extra byte, but keeps processing simpler. 1123 * 1 extra byte, but keeps processing simpler.
1140 */ 1124 */
1141 SockList_AddChar (&sl, (char) (s + CS_STAT_SKILLINFO)); 1125 sl << uint8 (s + CS_STAT_SKILLINFO)
1142 SockList_AddChar (&sl, (char) pl->last_skill_ob[s]->level); 1126 << uint8 (pl->last_skill_ob[s]->level)
1143 SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); 1127 << uint64 (pl->last_skill_ob[s]->stats.exp);
1128
1144 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; 1129 pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp;
1145 } 1130 }
1146 } 1131 }
1147 } 1132 }
1148 1133
1196 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); 1181 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE);
1197 set_title (pl->ob, buf); 1182 set_title (pl->ob, buf);
1198 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1183 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE);
1199 1184
1200 /* Only send it away if we have some actual data */ 1185 /* Only send it away if we have some actual data */
1201 if (sl.len > 6) 1186 if (sl.length () > 6)
1202 {
1203#ifdef ESRV_DEBUG
1204 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len);
1205#endif
1206 Send_With_Handling (&pl->socket, &sl); 1187 Send_With_Handling (&pl->socket, &sl);
1207 }
1208
1209 free (sl.buf);
1210} 1188}
1211 1189
1212/** 1190/**
1213 * Tells the client that here is a player it should start using. 1191 * Tells the client that here is a player it should start using.
1214 */ 1192 */
1215void 1193void
1216esrv_new_player (player *pl, uint32 weight) 1194esrv_new_player (player *pl, uint32 weight)
1217{ 1195{
1218 SockList sl;
1219
1220 pl->last_weight = weight; 1196 pl->last_weight = weight;
1221 1197
1222 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1198 packet sl;
1199 sl << "player ";
1223 1200
1224 strcpy ((char *) sl.buf, "player "); 1201 sl << uint32 (pl->ob->count)
1225 sl.len = strlen ((char *) sl.buf); 1202 << uint32 (weight)
1226 SockList_AddInt (&sl, pl->ob->count); 1203 << uint32 (pl->ob->face->number)
1227 SockList_AddInt (&sl, weight); 1204 << data8 (pl->ob->name);
1228 SockList_AddInt (&sl, pl->ob->face->number);
1229
1230 SockList_AddChar (&sl, (char) strlen (pl->ob->name));
1231 strcpy ((char *) sl.buf + sl.len, pl->ob->name);
1232 sl.len += strlen (pl->ob->name);
1233 1205
1234 Send_With_Handling (&pl->socket, &sl); 1206 Send_With_Handling (&pl->socket, &sl);
1235 free (sl.buf);
1236 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1207 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1237} 1208}
1238 1209
1239/** 1210/**
1240 * Need to send an animation sequence to the client. 1211 * Need to send an animation sequence to the client.
1244 * when the player logs in and picks stuff up. 1215 * when the player logs in and picks stuff up.
1245 */ 1216 */
1246void 1217void
1247esrv_send_animation (NewSocket * ns, short anim_num) 1218esrv_send_animation (NewSocket * ns, short anim_num)
1248{ 1219{
1249 SockList sl;
1250 int i; 1220 int i;
1251 1221
1252 /* Do some checking on the anim_num we got. Note that the animations 1222 /* Do some checking on the anim_num we got. Note that the animations
1253 * are added in contigous order, so if the number is in the valid 1223 * are added in contigous order, so if the number is in the valid
1254 * range, it must be a valid animation. 1224 * range, it must be a valid animation.
1257 { 1227 {
1258 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); 1228 LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num);
1259 return; 1229 return;
1260 } 1230 }
1261 1231
1262 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1232 packet sl;
1263 strcpy ((char *) sl.buf, "anim "); 1233
1264 sl.len = 5; 1234 sl << "anim "
1265 SockList_AddShort (&sl, anim_num); 1235 << uint16 (anim_num)
1266 SockList_AddShort (&sl, 0); /* flags - not used right now */ 1236 << uint16 (0); /* flags - not used right now */
1237
1267 /* Build up the list of faces. Also, send any information (ie, the 1238 /* Build up the list of faces. Also, send any information (ie, the
1268 * the face itself) down to the client. 1239 * the face itself) down to the client.
1269 */ 1240 */
1270 for (i = 0; i < animations[anim_num].num_animations; i++) 1241 for (i = 0; i < animations[anim_num].num_animations; i++)
1271 { 1242 {
1272 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE)) 1243 if (!(ns->faces_sent[animations[anim_num].faces[i]] & NS_FACESENT_FACE))
1273 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1244 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1274 SockList_AddShort (&sl, animations[anim_num].faces[i]); /* flags - not used right now */ 1245 sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */
1275 } 1246 }
1247
1276 Send_With_Handling (ns, &sl); 1248 Send_With_Handling (ns, &sl);
1277 free (sl.buf); 1249
1278 ns->anims_sent[anim_num] = 1; 1250 ns->anims_sent[anim_num] = 1;
1279} 1251}
1280 1252
1281 1253
1282/****************************************************************************** 1254/******************************************************************************
1296 { 1268 {
1297 LOG (llevError, "Too many faces in map cell %d %d\n", x, y); 1269 LOG (llevError, "Too many faces in map cell %d %d\n", x, y);
1298 return; 1270 return;
1299 abort (); 1271 abort ();
1300 } 1272 }
1273
1301 newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; 1274 newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num;
1302 newmap->cells[x][y].count++; 1275 newmap->cells[x][y].count++;
1276
1303 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) 1277 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE))
1304 esrv_send_face (ns, face_num, 0); 1278 esrv_send_face (ns, face_num, 0);
1305} 1279}
1306 1280
1307struct LayerCell 1281struct LayerCell
1409 *fcur = *fcur | 128; /* mark for end of faces at this layer */ 1383 *fcur = *fcur | 128; /* mark for end of faces at this layer */
1410 } 1384 }
1411 return cur; 1385 return cur;
1412} 1386}
1413 1387
1414static void
1415esrv_map_doneredraw (NewSocket * ns, struct Map *newmap)
1416{
1417 static long frames, bytes, tbytes, tframes;
1418 char *cur;
1419 SockList sl;
1420
1421
1422 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1423 strcpy ((char *) sl.buf, "map ");
1424 sl.len = strlen ((char *) sl.buf);
1425
1426 cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap);
1427 sl.len = cur - (char *) sl.buf;
1428
1429/* LOG(llevDebug, "Sending map command.\n");*/
1430
1431 if (sl.len > (int) strlen ("map ") || ns->sent_scroll)
1432 {
1433 /* All of this is just accounting stuff */
1434 if (tframes > 100)
1435 tframes = tbytes = 0;
1436
1437 tframes++;
1438 frames++;
1439 tbytes += sl.len;
1440 bytes += sl.len;
1441 memcpy (&ns->lastmap, newmap, sizeof (struct Map));
1442 Send_With_Handling (ns, &sl);
1443 ns->sent_scroll = 0;
1444 }
1445
1446 free (sl.buf);
1447}
1448
1449
1450/** Clears a map cell */ 1388/** Clears a map cell */
1451static void 1389static void
1452map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) 1390map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count)
1453{ 1391{
1454 cell->faces[0] = face0; 1392 cell->faces[0] = face0;
1493 * needs to get sent - if so, it adds the data, sending the head 1431 * needs to get sent - if so, it adds the data, sending the head
1494 * if needed, and returning 1. If this no data needs to get 1432 * if needed, and returning 1. If this no data needs to get
1495 * sent, it returns zero. 1433 * sent, it returns zero.
1496 */ 1434 */
1497static int 1435static int
1498check_head (SockList & sl, NewSocket & ns, int ax, int ay, int layer) 1436check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer)
1499{ 1437{
1500 short face_num; 1438 short face_num;
1501 1439
1502 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1440 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1503 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1441 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number;
1504 else 1442 else
1505 face_num = 0; 1443 face_num = 0;
1506 1444
1507 if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) 1445 if (face_num != ns.lastmap.cells[ax][ay].faces[layer])
1508 { 1446 {
1509 SockList_AddShort (&sl, face_num); 1447 sl << uint16 (face_num);
1510 if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) 1448 if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE))
1511 esrv_send_face (&ns, face_num, 0); 1449 esrv_send_face (&ns, face_num, 0);
1450
1512 heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; 1451 heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL;
1513 ns.lastmap.cells[ax][ay].faces[layer] = face_num; 1452 ns.lastmap.cells[ax][ay].faces[layer] = face_num;
1514 return 1; 1453 return 1;
1515 } 1454 }
1516 1455
1536 * the case, it seems to make more sense to have these layer values 1475 * the case, it seems to make more sense to have these layer values
1537 * actually match. 1476 * actually match.
1538 */ 1477 */
1539 1478
1540static int 1479static int
1541update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1480update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1542{ 1481{
1543 object *ob, *head; 1482 object *ob, *head;
1544 uint16 face_num; 1483 uint16 face_num;
1545 int bx, by, i; 1484 int bx, by, i;
1546 1485
1547 /* If there is a multipart object stored away, treat that as more important. 1486 /* If there is a multipart object stored away, treat that as more important.
1548 * If not, then do the normal processing. 1487 * If not, then do the normal processing.
1549 */ 1488 */
1550
1551 head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; 1489 head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer];
1552 1490
1553 /* Check to see if this head is part of the set of objects 1491 /* Check to see if this head is part of the set of objects
1554 * we would normally send for this space. If so, then 1492 * we would normally send for this space. If so, then
1555 * don't use the head value. We need to do the check 1493 * don't use the head value. We need to do the check
1720 1658
1721 /* Another hack - because of heads and whatnot, this face may match one 1659 /* Another hack - because of heads and whatnot, this face may match one
1722 * we already sent for a lower layer. In that case, don't send 1660 * we already sent for a lower layer. In that case, don't send
1723 * this one. 1661 * this one.
1724 */ 1662 */
1725 if (face_num && layer + 1 < MAP_LAYERS && ns->lastmap.cells[sx][sy].faces[layer + 1] == face_num) 1663 if (face_num && layer + 1 < MAP_LAYERS && ns.lastmap.cells[sx][sy].faces[layer + 1] == face_num)
1726 {
1727 face_num = 0; 1664 face_num = 0;
1728 }
1729 1665
1730 /* We've gotten what face we want to use for the object. Now see if 1666 /* We've gotten what face we want to use for the object. Now see if
1731 * if it has changed since we last sent it to the client. 1667 * if it has changed since we last sent it to the client.
1732 */ 1668 */
1733 if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) 1669 if (ns.lastmap.cells[sx][sy].faces[layer] != face_num)
1734 { 1670 {
1735 ns->lastmap.cells[sx][sy].faces[layer] = face_num; 1671 ns.lastmap.cells[sx][sy].faces[layer] = face_num;
1736 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) 1672 if (!(ns.faces_sent[face_num] & NS_FACESENT_FACE))
1737 esrv_send_face (ns, face_num, 0); 1673 esrv_send_face (&ns, face_num, 0);
1738 SockList_AddShort (sl, face_num); 1674
1675 sl << uint16 (face_num);
1739 return 1; 1676 return 1;
1740 } 1677 }
1678
1741 /* Nothing changed */ 1679 /* Nothing changed */
1742 return 0; 1680 return 0;
1743} 1681}
1744 1682
1745/** 1683/**
1760 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1698 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1761 * take. 1699 * take.
1762 */ 1700 */
1763 1701
1764static inline int 1702static inline int
1765update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1703update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1766{ 1704{
1767 object *ob; 1705 object *ob;
1768 int smoothlevel; /* old face_num; */ 1706 int smoothlevel; /* old face_num; */
1769 1707
1770 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1708 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1775 if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) 1713 if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp))
1776 smoothlevel = 0; 1714 smoothlevel = 0;
1777 else 1715 else
1778 { 1716 {
1779 smoothlevel = ob->smoothlevel; 1717 smoothlevel = ob->smoothlevel;
1780 if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) 1718 if (smoothlevel && !(ns.faces_sent[ob->face->number] & NS_FACESENT_SMOOTH))
1781 SendSmooth (ns, ob->face->number); 1719 SendSmooth (&ns, ob->face->number);
1782 } /* else not already head object or blank face */ 1720 } /* else not already head object or blank face */
1783 1721
1784 /* We've gotten what face we want to use for the object. Now see if 1722 /* We've gotten what face we want to use for the object. Now see if
1785 * if it has changed since we last sent it to the client. 1723 * if it has changed since we last sent it to the client.
1786 */ 1724 */
1787 if (smoothlevel > 255) 1725 if (smoothlevel > 255)
1788 smoothlevel = 255; 1726 smoothlevel = 255;
1789 else if (smoothlevel < 0) 1727 else if (smoothlevel < 0)
1790 smoothlevel = 0; 1728 smoothlevel = 0;
1729
1791 if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) 1730 if (ns.lastmap.cells[sx][sy].smooth[layer] != smoothlevel)
1792 { 1731 {
1793 ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; 1732 ns.lastmap.cells[sx][sy].smooth[layer] = smoothlevel;
1794 SockList_AddChar (sl, (uint8) (smoothlevel & 0xFF)); 1733 sl << uint8 (smoothlevel);
1795 return 1; 1734 return 1;
1796 } 1735 }
1736
1797 /* Nothing changed */ 1737 /* Nothing changed */
1798 return 0; 1738 return 0;
1799} 1739}
1800 1740
1801/** 1741/**
1842draw_client_map1 (object *pl) 1782draw_client_map1 (object *pl)
1843{ 1783{
1844 int x, y, ax, ay, d, startlen, max_x, max_y, oldlen; 1784 int x, y, ax, ay, d, startlen, max_x, max_y, oldlen;
1845 sint16 nx, ny; 1785 sint16 nx, ny;
1846 int estartlen, eoldlen; 1786 int estartlen, eoldlen;
1847 SockList sl;
1848 SockList esl; /*For extended Map info */
1849 uint16 mask, emask; 1787 uint16 mask, emask;
1850 uint8 eentrysize; 1788 uint8 eentrysize;
1851 uint16 ewhatstart, ewhatflag; 1789 uint16 ewhatstart, ewhatflag;
1852 uint8 extendedinfos; 1790 uint8 extendedinfos;
1853 maptile *m; 1791 maptile *m;
1854 1792
1855 NewSocket & socket = pl->contr->socket; 1793 NewSocket &socket = pl->contr->socket;
1856 1794
1857 check_map_change (pl->contr); 1795 check_map_change (pl->contr);
1858 1796
1859 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1797 packet sl;
1860 if (socket.mapmode == Map1Cmd) 1798 packet esl;
1861 strcpy ((char *) sl.buf, "map1 "); 1799
1862 else 1800 sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a ");
1863 strcpy ((char *) sl.buf, "map1a ");
1864 sl.len = strlen ((char *) sl.buf);
1865 startlen = sl.len; 1801 startlen = sl.length ();
1866 1802
1867 /*Extendedmapinfo structure initialisation */ 1803 /*Extendedmapinfo structure initialisation */
1868 if (socket.ext_mapinfos) 1804 if (socket.ext_mapinfos)
1869 { 1805 {
1870 esl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1871 strcpy ((char *) esl.buf, "mapextended ");
1872 esl.len = strlen ((char *) esl.buf);
1873 extendedinfos = EMI_NOREDRAW; 1806 extendedinfos = EMI_NOREDRAW;
1874 1807
1875 if (socket.EMI_smooth) 1808 if (socket.EMI_smooth)
1876 extendedinfos |= EMI_SMOOTH; 1809 extendedinfos |= EMI_SMOOTH;
1877 1810
1878 ewhatstart = esl.len; 1811 ewhatstart = esl.length ();
1879 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit 1812 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1880 could need to be taken away */ 1813 could need to be taken away */
1881 SockList_AddChar (&esl, extendedinfos);
1882 eentrysize = getExtendedMapInfoSize (&socket); 1814 eentrysize = getExtendedMapInfoSize (&socket);
1883 SockList_AddChar (&esl, eentrysize); 1815 esl << "mapextended "
1816 << uint8 (extendedinfos)
1817 << uint8 (eentrysize);
1818
1884 estartlen = esl.len; 1819 estartlen = esl.length ();
1885 } 1820 }
1886 else 1821 else
1887 { 1822 {
1888 /* suppress compiler warnings */ 1823 /* suppress compiler warnings */
1889 ewhatstart = 0; 1824 ewhatstart = 0;
1927 */ 1862 */
1928 if (ax >= socket.mapx || ay >= socket.mapy) 1863 if (ax >= socket.mapx || ay >= socket.mapy)
1929 { 1864 {
1930 int i, got_one; 1865 int i, got_one;
1931 1866
1932 oldlen = sl.len; 1867 oldlen = sl.length ();
1933 1868
1934 SockList_AddShort (&sl, mask); 1869 sl << uint16 (mask);
1935 1870
1936 if (check_head (sl, socket, ax, ay, 2)) 1871 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4;
1937 mask |= 0x4;
1938 if (check_head (sl, socket, ax, ay, 1)) 1872 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2;
1939 mask |= 0x2;
1940 if (check_head (sl, socket, ax, ay, 0)) 1873 if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1;
1941 mask |= 0x1;
1942 1874
1943 /* If all we are doing is sending 0 (blank) faces, we don't 1875 /* If all we are doing is sending 0 (blank) faces, we don't
1944 * actually need to send that - just the coordinates 1876 * actually need to send that - just the coordinates
1945 * with no faces tells the client to blank out the 1877 * with no faces tells the client to blank out the
1946 * space. 1878 * space.
1947 */ 1879 */
1948 got_one = 0; 1880 got_one = 0;
1949 for (i = oldlen + 2; i < sl.len; i++) 1881 for (i = oldlen + 2; i < sl.length (); i++)
1950 if (sl.buf[i]) 1882 if (sl.buf[i])
1951 got_one = 1; 1883 got_one = 1;
1952 1884
1953 if (got_one && (mask & 0xf)) 1885 if (got_one && (mask & 0xf))
1954 sl.buf[oldlen + 1] = mask & 0xff; 1886 sl.buf[oldlen + 1] = mask & 0xff;
1955 else 1887 else
1956 { /*either all faces blank, either no face at all */ 1888 { /*either all faces blank, either no face at all */
1957 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */ 1889 if (mask & 0xf) /*at least 1 face, we know it's blank, only send coordinates */
1958 sl.len = oldlen + 2; 1890 sl.reset (oldlen + 2);
1959 else 1891 else
1960 sl.len = oldlen; 1892 sl.reset (oldlen);
1961 } 1893 }
1962 1894
1963 /*What concerns extendinfos, nothing to be done for now 1895 /*What concerns extendinfos, nothing to be done for now
1964 * (perhaps effects layer later) 1896 * (perhaps effects layer later)
1965 */ 1897 */
1983 * if this hasn't already been done. If the space is out 1915 * if this hasn't already been done. If the space is out
1984 * of the map, it shouldn't have a head 1916 * of the map, it shouldn't have a head
1985 */ 1917 */
1986 if (lastcell.count != -1) 1918 if (lastcell.count != -1)
1987 { 1919 {
1988 SockList_AddShort (&sl, mask); 1920 sl << uint16 (mask);
1989 map_clearcell (&lastcell, 0, 0, 0, -1); 1921 map_clearcell (&lastcell, 0, 0, 0, -1);
1990 } 1922 }
1991 } 1923 }
1992 else if (d > 3) 1924 else if (d > 3)
1993 { 1925 {
1995 1927
1996 /* This block deals with spaces that are not visible for whatever 1928 /* This block deals with spaces that are not visible for whatever
1997 * reason. Still may need to send the head for this space. 1929 * reason. Still may need to send the head for this space.
1998 */ 1930 */
1999 1931
2000 oldlen = sl.len; 1932 oldlen = sl.length ();
2001 1933
2002 SockList_AddShort (&sl, mask); 1934 sl << uint16 (mask);
2003 1935
2004 if (lastcell.count != -1) 1936 if (lastcell.count != -1)
2005 need_send = 1; 1937 need_send = 1;
2006 1938
2007 count = -1; 1939 count = -1;
2008 1940
2009 if (socket.mapmode == Map1aCmd && have_head (ax, ay)) 1941 if (socket.mapmode == Map1aCmd && have_head (ax, ay))
2010 { 1942 {
2011 /* Now check to see if any heads need to be sent */ 1943 /* Now check to see if any heads need to be sent */
2012 1944
2013 if (check_head (sl, socket, ax, ay, 2)) 1945 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4;
2014 mask |= 0x4;
2015 if (check_head (sl, socket, ax, ay, 1)) 1946 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2;
2016 mask |= 0x2;
2017 if (check_head (sl, socket, ax, ay, 0)) 1947 if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1;
2018 mask |= 0x1;
2019 1948
2020 lastcell.count = count; 1949 lastcell.count = count;
2021 } 1950 }
2022 else 1951 else
2023 { 1952 {
2030 } 1959 }
2031 1960
2032 if ((mask & 0xf) || need_send) 1961 if ((mask & 0xf) || need_send)
2033 sl.buf[oldlen + 1] = mask & 0xff; 1962 sl.buf[oldlen + 1] = mask & 0xff;
2034 else 1963 else
2035 sl.len = oldlen; 1964 sl.reset (oldlen);
2036 } 1965 }
2037 else 1966 else
2038 { 1967 {
2039 /* In this block, the space is visible or there are head objects 1968 /* In this block, the space is visible or there are head objects
2040 * we need to send. 1969 * we need to send.
2042 1971
2043 /* Rather than try to figure out what everything that we might 1972 /* Rather than try to figure out what everything that we might
2044 * need to send is, then form the packet after that, 1973 * need to send is, then form the packet after that,
2045 * we presume that we will in fact form a packet, and update 1974 * we presume that we will in fact form a packet, and update
2046 * the bits by what we do actually send. If we send nothing, 1975 * the bits by what we do actually send. If we send nothing,
2047 * we just back out sl.len to the old value, and no harm 1976 * we just back out sl.length () to the old value, and no harm
2048 * is done. 1977 * is done.
2049 * I think this is simpler than doing a bunch of checks to see 1978 * I think this is simpler than doing a bunch of checks to see
2050 * what if anything we need to send, setting the bits, then 1979 * what if anything we need to send, setting the bits, then
2051 * doing those checks again to add the real data. 1980 * doing those checks again to add the real data.
2052 */ 1981 */
2053 oldlen = sl.len; 1982 oldlen = sl.length ();
2054 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1983 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2055 eoldlen = esl.len; 1984 eoldlen = esl.length ();
2056 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1985 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2057 SockList_AddShort (&sl, mask); 1986 sl << uint16 (mask);
2058 1987
2059 if (socket.ext_mapinfos) 1988 if (socket.ext_mapinfos)
2060 SockList_AddShort (&esl, emask); 1989 esl << uint16 (emask);
2061 1990
2062 unsigned char dummy; 1991 unsigned char dummy;
2063 unsigned char *last_ext = &dummy; 1992 unsigned char *last_ext = &dummy;
2064 1993
2065 /* Darkness changed */ 1994 /* Darkness changed */
2068 mask |= 0x8; 1997 mask |= 0x8;
2069 1998
2070 if (socket.extmap) 1999 if (socket.extmap)
2071 { 2000 {
2072 *last_ext |= 0x80; 2001 *last_ext |= 0x80;
2073 last_ext = sl.buf + sl.len; 2002 last_ext = sl.buf + sl.length ();
2074 SockList_AddChar (&sl, d); 2003 sl << uint8 (d);
2075 } 2004 }
2076 else 2005 else
2077 SockList_AddChar (&sl, 255 - 64 * d); 2006 sl << uint8 (255 - 64 * d);
2078 } 2007 }
2079 2008
2080 lastcell.count = d; 2009 lastcell.count = d;
2081 2010
2082 if (socket.extmap) 2011 if (socket.extmap)
2083 { 2012 {
2084 uint8 stat_hp = 0; 2013 uint8 stat_hp = 0;
2085 uint8 stat_width = 0; 2014 uint8 stat_width = 0;
2086 uint8 flags = 0; 2015 uint8 flags = 0;
2087 tag_t player = 0; 2016 UUID player = 0;
2088 2017
2089 // send hp information, if applicable 2018 // send hp information, if applicable
2090 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) 2019 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0))
2091 { 2020 {
2092 if (op->head || op->invisible) 2021 if (op->head || op->invisible)
2112 { 2041 {
2113 lastcell.stat_hp = stat_hp; 2042 lastcell.stat_hp = stat_hp;
2114 2043
2115 mask |= 0x8; 2044 mask |= 0x8;
2116 *last_ext |= 0x80; 2045 *last_ext |= 0x80;
2117 last_ext = sl.buf + sl.len; 2046 last_ext = sl.buf + sl.length ();
2118 SockList_AddChar (&sl, 5); 2047
2119 SockList_AddChar (&sl, stat_hp); 2048 sl << uint8 (5) << uint8 (stat_hp);
2120 2049
2121 if (stat_width > 1) 2050 if (stat_width > 1)
2122 { 2051 {
2123 *last_ext |= 0x80; 2052 *last_ext |= 0x80;
2124 last_ext = sl.buf + sl.len; 2053 last_ext = sl.buf + sl.length ();
2125 SockList_AddChar (&sl, 6); 2054
2126 SockList_AddChar (&sl, stat_width); 2055 sl << uint8 (6) << uint8 (stat_width);
2127 } 2056 }
2128 } 2057 }
2129 2058
2130 if (lastcell.player != player) 2059 if (lastcell.player != player)
2131 { 2060 {
2132 lastcell.player = player; 2061 lastcell.player = player;
2133 2062
2134 mask |= 0x8; 2063 mask |= 0x8;
2135 *last_ext |= 0x80; 2064 *last_ext |= 0x80;
2136 last_ext = sl.buf + sl.len; 2065 last_ext = sl.buf + sl.length ();
2137 SockList_AddChar (&sl, 0x47); 2066
2138 SockList_AddChar (&sl, 4); 2067 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2139 SockList_AddInt (&sl, player);
2140 } 2068 }
2141 2069
2142 if (lastcell.flags != flags) 2070 if (lastcell.flags != flags)
2143 { 2071 {
2144 lastcell.flags = flags; 2072 lastcell.flags = flags;
2145 2073
2146 mask |= 0x8; 2074 mask |= 0x8;
2147 *last_ext |= 0x80; 2075 *last_ext |= 0x80;
2148 last_ext = sl.buf + sl.len; 2076 last_ext = sl.buf + sl.length ();
2149 SockList_AddChar (&sl, 8); 2077
2150 SockList_AddChar (&sl, flags); 2078 sl << uint8 (8) << uint8 (flags);
2151 } 2079 }
2152 } 2080 }
2153 2081
2154 /* Floor face */ 2082 /* Floor face */
2155 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) 2083 if (update_space (sl, socket, m, nx, ny, ax, ay, 2))
2156 mask |= 0x4; 2084 mask |= 0x4;
2157 2085
2158 if (socket.EMI_smooth) 2086 if (socket.EMI_smooth)
2159 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 2)) 2087 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 2))
2160 emask |= 0x4; 2088 emask |= 0x4;
2161 2089
2162 /* Middle face */ 2090 /* Middle face */
2163 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 1)) 2091 if (update_space (sl, socket, m, nx, ny, ax, ay, 1))
2164 mask |= 0x2; 2092 mask |= 0x2;
2165 2093
2166 if (socket.EMI_smooth) 2094 if (socket.EMI_smooth)
2167 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 1)) 2095 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 1))
2168 emask |= 0x2; 2096 emask |= 0x2;
2169 2097
2170 if (nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1)) 2098 if (nx == pl->x && ny == pl->y && pl->invisible & (pl->invisible < 50 ? 4 : 1))
2171 { 2099 {
2172 if (lastcell.faces[0] != pl->face->number) 2100 if (lastcell.faces[0] != pl->face->number)
2175 mask |= 0x1; 2103 mask |= 0x1;
2176 2104
2177 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) 2105 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE))
2178 esrv_send_face (&socket, pl->face->number, 0); 2106 esrv_send_face (&socket, pl->face->number, 0);
2179 2107
2180 SockList_AddShort (&sl, pl->face->number); 2108 sl << uint16 (pl->face->number);
2181 } 2109 }
2182 } 2110 }
2183 else 2111 else
2184 { 2112 {
2185 /* Top face */ 2113 /* Top face */
2186 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) 2114 if (update_space (sl, socket, m, nx, ny, ax, ay, 0))
2187 mask |= 0x1; 2115 mask |= 0x1;
2188 2116
2189 if (socket.EMI_smooth) 2117 if (socket.EMI_smooth)
2190 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) 2118 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 0))
2191 emask |= 0x1; 2119 emask |= 0x1;
2192 } 2120 }
2193 2121
2194 /* Check to see if we are in fact sending anything for this 2122 /* Check to see if we are in fact sending anything for this
2195 * space by checking the mask. If so, update the mask. 2123 * space by checking the mask. If so, update the mask.
2197 * value, so we don't send those bits. 2125 * value, so we don't send those bits.
2198 */ 2126 */
2199 if (mask & 0xf) 2127 if (mask & 0xf)
2200 sl.buf[oldlen + 1] = mask & 0xff; 2128 sl.buf[oldlen + 1] = mask & 0xff;
2201 else 2129 else
2202 sl.len = oldlen; 2130 sl.reset (oldlen);
2203 2131
2204 if (emask & 0xf) 2132 if (emask & 0xf)
2205 esl.buf[eoldlen + 1] = emask & 0xff; 2133 esl.buf[eoldlen + 1] = emask & 0xff;
2206 else 2134 else
2207 esl.len = eoldlen; 2135 esl.reset (eoldlen);
2208 } /* else this is a viewable space */ 2136 } /* else this is a viewable space */
2209 } /* for x loop */ 2137 } /* for x loop */
2210 } /* for y loop */ 2138 } /* for y loop */
2211 2139
2212 /* Verify that we in fact do need to send this */ 2140 /* Verify that we in fact do need to send this */
2213 if (socket.ext_mapinfos) 2141 if (socket.ext_mapinfos)
2214 { 2142 {
2215 if (!(sl.len > startlen || socket.sent_scroll)) 2143 if (!(sl.length () > startlen || socket.sent_scroll))
2216 { 2144 {
2217 /* No map data will follow, so don't say the client 2145 /* No map data will follow, so don't say the client
2218 * it doesn't need draw! 2146 * it doesn't need draw!
2219 */ 2147 */
2220 ewhatflag &= (~EMI_NOREDRAW); 2148 ewhatflag &= (~EMI_NOREDRAW);
2221 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2149 esl.buf[ewhatstart + 1] = ewhatflag & 0xff;
2222 } 2150 }
2223 2151
2224 if (esl.len > estartlen) 2152 if (esl.length () > estartlen)
2225 Send_With_Handling (&socket, &esl); 2153 Send_With_Handling (&socket, &esl);
2226
2227 free (esl.buf);
2228 } 2154 }
2229 2155
2230 if (sl.len > startlen || socket.sent_scroll) 2156 if (sl.length () > startlen || socket.sent_scroll)
2231 { 2157 {
2232 Send_With_Handling (&socket, &sl); 2158 Send_With_Handling (&socket, &sl);
2233 socket.sent_scroll = 0; 2159 socket.sent_scroll = 0;
2234 } 2160 }
2235
2236 free (sl.buf);
2237} 2161}
2238 2162
2239/** 2163/**
2240 * Draws client map. 2164 * Draws client map.
2241 */ 2165 */
2292 { 2216 {
2293 update_los (pl); 2217 update_los (pl);
2294 pl->contr->do_los = 0; 2218 pl->contr->do_los = 0;
2295 } 2219 }
2296 2220
2297 if (pl->contr->socket.mapmode == Map1Cmd || pl->contr->socket.mapmode == Map1aCmd)
2298 {
2299 /* Big maps need a different drawing mechanism to work */ 2221 /* Big maps need a different drawing mechanism to work */
2300 draw_client_map1 (pl); 2222 draw_client_map1 (pl);
2301 return;
2302 }
2303
2304 if (pl->invisible & (pl->invisible < 50 ? 4 : 1))
2305 {
2306 esrv_map_setbelow (&pl->contr->socket, pl->contr->socket.mapx / 2, pl->contr->socket.mapy / 2, pl->face->number, &newmap);
2307 }
2308
2309 /* j and i are the y and x coordinates of the real map (which is
2310 * basically some number of spaces around the player)
2311 * ax and ay are values from within the viewport (ie, 0, 0 is upper
2312 * left corner) and are thus disconnected from the map values.
2313 * Subtract 1 from the max values so that we properly handle cases where
2314 * player has specified an even map. Otherwise, we try to send them too
2315 * much, ie, if mapx is 10, we would try to send from -5 to 5, which is actually
2316 * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is
2317 * odd, this still works fine.
2318 */
2319 ay = 0;
2320 for (j = pl->y - pl->contr->socket.mapy / 2; j <= pl->y + (pl->contr->socket.mapy - 1) / 2; j++, ay++)
2321 {
2322 ax = 0;
2323 for (i = pl->x - pl->contr->socket.mapx / 2; i <= pl->x + (pl->contr->socket.mapx - 1) / 2; i++, ax++)
2324 {
2325
2326 d = pl->contr->blocked_los[ax][ay];
2327 /* note the out_of_map and d>3 checks are both within the same
2328 * negation check.
2329 */
2330 nx = i;
2331 ny = j;
2332 m = get_map_from_coord (pm, &nx, &ny);
2333 if (m && d < 4)
2334 {
2335 face = GET_MAP_FACE (m, nx, ny, 0);
2336 floor2 = GET_MAP_FACE (m, nx, ny, 1);
2337 floor = GET_MAP_FACE (m, nx, ny, 2);
2338
2339 /* If all is blank, send a blank face. */
2340 if ((!face || face == blank_face) && (!floor2 || floor2 == blank_face) && (!floor || floor == blank_face))
2341 {
2342 esrv_map_setbelow (&pl->contr->socket, ax, ay, blank_face->number, &newmap);
2343 }
2344 else
2345 { /* actually have something interesting */
2346 /* send the darkness mask, if any. */
2347 if (d && pl->contr->socket.darkness)
2348 esrv_map_setbelow (&pl->contr->socket, ax, ay, dark_faces[d - 1]->number, &newmap);
2349
2350 if (face && face != blank_face)
2351 esrv_map_setbelow (&pl->contr->socket, ax, ay, face->number, &newmap);
2352 if (floor2 && floor2 != blank_face)
2353 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor2->number, &newmap);
2354 if (floor && floor != blank_face)
2355 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap);
2356 }
2357 } /* Is a valid space */
2358 }
2359 }
2360 esrv_map_doneredraw (&pl->contr->socket, &newmap);
2361
2362 check_map_change (pl->contr);
2363} 2223}
2364 2224
2365 2225
2366/*****************************************************************************/ 2226/*****************************************************************************/
2367 2227
2373 2233
2374/*****************************************************************************/ 2234/*****************************************************************************/
2375void 2235void
2376send_plugin_custom_message (object *pl, char *buf) 2236send_plugin_custom_message (object *pl, char *buf)
2377{ 2237{
2378 cs_write_string (&pl->contr->socket, buf, strlen (buf)); 2238 pl->contr->socket.send_packet (buf);
2379} 2239}
2380 2240
2381/** 2241/**
2382 * This sends the skill number to name mapping. We ignore 2242 * This sends the skill number to name mapping. We ignore
2383 * the params - we always send the same info no matter what. 2243 * the params - we always send the same info no matter what.
2384 */ 2244 */
2385void 2245void
2386send_skill_info (NewSocket * ns, char *params) 2246send_skill_info (NewSocket *ns, char *params)
2387{ 2247{
2388 SockList sl; 2248 packet sl;
2389 int i; 2249 sl << "replyinfo skill_info\n";
2390 2250
2391 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2392 strcpy ((char *) sl.buf, "replyinfo skill_info\n");
2393 for (i = 1; i < NUM_SKILLS; i++) 2251 for (int i = 1; i < NUM_SKILLS; i++)
2394 { 2252 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]);
2395 sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); 2253
2396 }
2397 sl.len = strlen ((char *) sl.buf);
2398 if (sl.len >= MAXSOCKBUF) 2254 if (sl.length () >= MAXSOCKBUF)
2399 { 2255 {
2400 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2256 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2401 fatal (0); 2257 fatal (0);
2402 } 2258 }
2259
2403 Send_With_Handling (ns, &sl); 2260 Send_With_Handling (ns, &sl);
2404 free (sl.buf);
2405} 2261}
2406 2262
2407/** 2263/**
2408 * This sends the spell path to name mapping. We ignore 2264 * This sends the spell path to name mapping. We ignore
2409 * the params - we always send the same info no matter what. 2265 * the params - we always send the same info no matter what.
2410 */ 2266 */
2411void 2267void
2412send_spell_paths (NewSocket * ns, char *params) 2268send_spell_paths (NewSocket * ns, char *params)
2413{ 2269{
2414 SockList sl; 2270 packet sl;
2415 int i;
2416 2271
2417 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2272 sl << "replyinfo spell_paths\n";
2418 strcpy ((char *) sl.buf, "replyinfo spell_paths\n"); 2273
2419 for (i = 0; i < NRSPELLPATHS; i++) 2274 for (int i = 0; i < NRSPELLPATHS; i++)
2420 sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", 1 << i, spellpathnames[i]); 2275 sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
2421 sl.len = strlen ((char *) sl.buf); 2276
2422 if (sl.len >= MAXSOCKBUF) 2277 if (sl.length () >= MAXSOCKBUF)
2423 { 2278 {
2424 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2279 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2425 fatal (0); 2280 fatal (0);
2426 } 2281 }
2282
2427 Send_With_Handling (ns, &sl); 2283 Send_With_Handling (ns, &sl);
2428 free (sl.buf);
2429} 2284}
2430 2285
2431/** 2286/**
2432 * This looks for any spells the player may have that have changed their stats. 2287 * This looks for any spells the player may have that have changed their stats.
2433 * it then sends an updspell packet for each spell that has changed in this way 2288 * it then sends an updspell packet for each spell that has changed in this way
2434 */ 2289 */
2435void 2290void
2436esrv_update_spells (player *pl) 2291esrv_update_spells (player *pl)
2437{ 2292{
2438 SockList sl;
2439 int flags = 0;
2440 object *spell;
2441
2442 if (!pl->socket.monitor_spells) 2293 if (!pl->socket.monitor_spells)
2443 return; 2294 return;
2295
2444 for (spell = pl->ob->inv; spell != NULL; spell = spell->below) 2296 for (object *spell = pl->ob->inv; spell; spell = spell->below)
2445 { 2297 {
2446 if (spell->type == SPELL) 2298 if (spell->type == SPELL)
2447 { 2299 {
2300 int flags = 0;
2301
2448 /* check if we need to update it */ 2302 /* check if we need to update it */
2449 if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA)) 2303 if (spell->last_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA))
2450 { 2304 {
2451 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 2305 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
2452 flags |= UPD_SP_MANA; 2306 flags |= UPD_SP_MANA;
2453 } 2307 }
2308
2454 if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE)) 2309 if (spell->last_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE))
2455 { 2310 {
2456 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 2311 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
2457 flags |= UPD_SP_GRACE; 2312 flags |= UPD_SP_GRACE;
2458 } 2313 }
2314
2459 if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell)) 2315 if (spell->last_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell))
2460 { 2316 {
2461 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 2317 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
2462 flags |= UPD_SP_DAMAGE; 2318 flags |= UPD_SP_DAMAGE;
2463 } 2319 }
2320
2464 if (flags != 0) 2321 if (flags)
2465 { 2322 {
2466 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2323 packet sl;
2467 strcpy ((char *) sl.buf, "updspell "); 2324
2468 sl.len = strlen ((char *) sl.buf); 2325 sl << "updspell "
2469 SockList_AddChar (&sl, flags); 2326 << uint8 (flags)
2470 SockList_AddInt (&sl, spell->count); 2327 << uint32 (spell->count);
2471 if (flags & UPD_SP_MANA) 2328
2472 SockList_AddShort (&sl, spell->last_sp); 2329 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2473 if (flags & UPD_SP_GRACE) 2330 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2474 SockList_AddShort (&sl, spell->last_grace); 2331 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2475 if (flags & UPD_SP_DAMAGE) 2332
2476 SockList_AddShort (&sl, spell->last_eat);
2477 flags = 0;
2478 Send_With_Handling (&pl->socket, &sl); 2333 Send_With_Handling (&pl->socket, &sl);
2479 free (sl.buf);
2480 } 2334 }
2481 } 2335 }
2482 } 2336 }
2483} 2337}
2484 2338
2485void 2339void
2486esrv_remove_spell (player *pl, object *spell) 2340esrv_remove_spell (player *pl, object *spell)
2487{ 2341{
2488 SockList sl;
2489
2490 if (!pl->socket.monitor_spells) 2342 if (!pl->socket.monitor_spells)
2491 return; 2343 return;
2344
2492 if (!pl || !spell || spell->env != pl->ob) 2345 if (!pl || !spell || spell->env != pl->ob)
2493 { 2346 {
2494 LOG (llevError, "Invalid call to esrv_remove_spell"); 2347 LOG (llevError, "Invalid call to esrv_remove_spell");
2495 return; 2348 return;
2496 } 2349 }
2497 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2350
2498 strcpy ((char *) sl.buf, "delspell "); 2351 packet sl;
2499 sl.len = strlen ((char *) sl.buf); 2352
2500 SockList_AddInt (&sl, spell->count); 2353 sl << "delspell "
2354 << uint32 (spell->count);
2355
2501 Send_With_Handling (&pl->socket, &sl); 2356 Send_With_Handling (&pl->socket, &sl);
2502 free (sl.buf);
2503} 2357}
2504 2358
2505/* appends the spell *spell to the Socklist we will send the data to. */ 2359/* appends the spell *spell to the Socklist we will send the data to. */
2506static void 2360static void
2507append_spell (player *pl, SockList * sl, object *spell) 2361append_spell (player *pl, packet &sl, object *spell)
2508{ 2362{
2509 int len, i, skill = 0; 2363 int len, i, skill = 0;
2510 2364
2511 if (!(spell->name)) 2365 if (!(spell->name))
2512 { 2366 {
2513 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 2367 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
2514 return; 2368 return;
2515 } 2369 }
2516 SockList_AddInt (sl, spell->count); 2370
2517 SockList_AddShort (sl, spell->level);
2518 SockList_AddShort (sl, spell->casting_time);
2519 /* store costs and damage in the object struct, to compare to later */ 2371 /* store costs and damage in the object struct, to compare to later */
2520 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA); 2372 spell->last_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
2521 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE); 2373 spell->last_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
2522 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell); 2374 spell->last_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
2523 /* send the current values */
2524 SockList_AddShort (sl, spell->last_sp);
2525 SockList_AddShort (sl, spell->last_grace);
2526 SockList_AddShort (sl, spell->last_eat);
2527 2375
2528 /* figure out which skill it uses, if it uses one */ 2376 /* figure out which skill it uses, if it uses one */
2529 if (spell->skill) 2377 if (spell->skill)
2530 { 2378 {
2531 for (i = 1; i < NUM_SKILLS; i++) 2379 for (i = 1; i < NUM_SKILLS; i++)
2533 { 2381 {
2534 skill = i + CS_STAT_SKILLINFO; 2382 skill = i + CS_STAT_SKILLINFO;
2535 break; 2383 break;
2536 } 2384 }
2537 } 2385 }
2538 SockList_AddChar (sl, skill);
2539 2386
2540 SockList_AddInt (sl, spell->path_attuned); 2387 /* send the current values */
2388 sl << uint32 (spell->count)
2389 << uint16 (spell->level)
2390 << uint16 (spell->casting_time)
2391 << uint16 (spell->last_sp)
2392 << uint16 (spell->last_grace)
2393 << uint16 (spell->last_eat)
2394 << uint8 (skill)
2395 << uint32 (spell->path_attuned)
2541 SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); 2396 << uint32 (spell->face ? spell->face->number : 0)
2542 2397 << data8 (spell->name)
2543 len = strlen (spell->name); 2398 << data16 (spell->msg);
2544 SockList_AddChar (sl, (char) len);
2545 memcpy (sl->buf + sl->len, spell->name, len);
2546 sl->len += len;
2547
2548 if (!spell->msg)
2549 {
2550 SockList_AddShort (sl, 0);
2551 }
2552 else
2553 {
2554 len = strlen (spell->msg);
2555 SockList_AddShort (sl, len);
2556 memcpy (sl->buf + sl->len, spell->msg, len);
2557 sl->len += len;
2558 }
2559} 2399}
2560 2400
2561/** 2401/**
2562 * This tells the client to add the spell *ob, if *ob is NULL, then add 2402 * This tells the client to add the spell *ob, if *ob is NULL, then add
2563 * all spells in the player's inventory. 2403 * all spells in the player's inventory.
2564 */ 2404 */
2565void 2405void
2566esrv_add_spells (player *pl, object *spell) 2406esrv_add_spells (player *pl, object *spell)
2567{ 2407{
2568 SockList sl;
2569
2570 if (!pl) 2408 if (!pl)
2571 { 2409 {
2572 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player"); 2410 LOG (llevError, "esrv_add_spells, tried to add a spell to a NULL player");
2573 return; 2411 return;
2574 } 2412 }
2413
2575 if (!pl->socket.monitor_spells) 2414 if (!pl->socket.monitor_spells)
2576 return; 2415 return;
2577 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2416
2578 strcpy ((char *) sl.buf, "addspell "); 2417 packet sl;
2579 sl.len = strlen ((char *) sl.buf); 2418
2419 sl << "addspell ";
2420
2580 if (!spell) 2421 if (!spell)
2581 { 2422 {
2582 for (spell = pl->ob->inv; spell != NULL; spell = spell->below) 2423 for (spell = pl->ob->inv; spell != NULL; spell = spell->below)
2583 { 2424 {
2584 /* were we to simply keep appending data here, we could exceed 2425 /* were we to simply keep appending data here, we could exceed
2594 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem 2435 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem
2595 * like it will fix this 2436 * like it will fix this
2596 */ 2437 */
2597 if (spell->type != SPELL) 2438 if (spell->type != SPELL)
2598 continue; 2439 continue;
2440
2599 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2441 if (sl.length () >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2600 { 2442 {
2601 Send_With_Handling (&pl->socket, &sl); 2443 Send_With_Handling (&pl->socket, &sl);
2602 strcpy ((char *) sl.buf, "addspell "); 2444
2603 sl.len = strlen ((char *) sl.buf); 2445 sl.reset ();
2446 sl << "addspell ";
2604 } 2447 }
2448
2605 append_spell (pl, &sl, spell); 2449 append_spell (pl, sl, spell);
2606 } 2450 }
2607 } 2451 }
2608 else if (spell->type != SPELL) 2452 else if (spell->type != SPELL)
2609 { 2453 {
2610 LOG (llevError, "Asked to send a non-spell object as a spell"); 2454 LOG (llevError, "Asked to send a non-spell object as a spell");
2611 return; 2455 return;
2612 } 2456 }
2613 else 2457 else
2614 append_spell (pl, &sl, spell); 2458 append_spell (pl, sl, spell);
2459
2615 if (sl.len >= MAXSOCKBUF) 2460 if (sl.length () >= MAXSOCKBUF)
2616 { 2461 {
2617 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2462 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2618 fatal (0); 2463 fatal (0);
2619 } 2464 }
2465
2620 /* finally, we can send the packet */ 2466 /* finally, we can send the packet */
2621 Send_With_Handling (&pl->socket, &sl); 2467 Send_With_Handling (&pl->socket, &sl);
2622 free (sl.buf); 2468
2623} 2469}
2470

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines