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.33 by root, Thu Dec 14 01:21:58 2006 UTC

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 */
323void 323void
324SetUp (char *buf, int len, NewSocket * ns) 324SetUp (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 */
561void 567void
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 */
683static void 689static void
684SendSmooth (NewSocket * ns, uint16 face) 690SendSmooth (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 "); 711
708 sl.len = strlen ((char *) sl.buf); 712 sl << "smooth "
709 SockList_AddShort (&sl, face); 713 << uint16 (face)
710 SockList_AddShort (&sl, smoothface); 714 << uint16 (smoothface);
715
711 Send_With_Handling (ns, &sl); 716 Send_With_Handling (ns, &sl);
712} 717}
713 718
714 /** 719 /**
715 * Tells client the picture it has to use 720 * Tells client the picture it has to use
722 727
723 facenbr = atoi (buf); 728 facenbr = atoi (buf);
724 SendSmooth (ns, facenbr); 729 SendSmooth (ns, facenbr);
725} 730}
726 731
727
728
729
730
731/** 732/**
732 * 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,
733 * etc.) 734 * etc.)
734 */ 735 */
735void 736void
788 */ 789 */
789void 790void
790NewPlayerCmd (uint8 * buf, int len, player *pl) 791NewPlayerCmd (uint8 * buf, int len, player *pl)
791{ 792{
792 int time, repeat; 793 int time, repeat;
793 short packet;
794 unsigned char command[MAX_BUF]; 794 char command[MAX_BUF];
795 SockList sl; 795 int pktlen;
796 796
797 if (len < 7) 797 if (len < 7)
798 { 798 {
799 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);
800 return; 800 return;
801 } 801 }
802 802
803 packet = GetShort_String (buf); 803 pktlen = net_uint16 (buf);
804 repeat = GetInt_String (buf + 2); 804 repeat = net_uint32 (buf + 2);
805
805 /* -1 is special - no repeat, but don't update */ 806 /* -1 is special - no repeat, but don't update */
806 if (repeat != -1) 807 if (repeat != -1)
807 {
808 pl->count = repeat; 808 pl->count = repeat;
809 } 809
810 if ((len - 4) >= MAX_BUF) 810 if ((len - 4) >= MAX_BUF)
811 len = MAX_BUF - 5; 811 len = MAX_BUF - 5;
812 812
813 strncpy ((char *) command, (char *) buf + 6, len - 4); 813 strncpy ((char *) command, (char *) buf + 6, len - 4);
814 command[len - 4] = '\0'; 814 command[len - 4] = '\0';
824 return; 824 return;
825 } 825 }
826 826
827 /* This should not happen anymore. */ 827 /* This should not happen anymore. */
828 if (pl->ob->speed_left < -1.0) 828 if (pl->ob->speed_left < -1.0)
829 {
830 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 829 LOG (llevError, "Player has negative time - shouldn't do command.\n");
831 } 830
832 /* In c_new.c */ 831 /* In c_new.c */
833 execute_newserver_command (pl->ob, (char *) command); 832 execute_newserver_command (pl->ob, (char *) command);
834 /* Perhaps something better should be done with a left over count. 833 /* Perhaps something better should be done with a left over count.
835 * Cleaning up the input should probably be done first - all actions 834 * 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 835 * for the command that issued the count should be done before any other
837 * commands. 836 * commands.
838 */ 837 */
839 pl->count = 0; 838 pl->count = 0;
840 839
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) 840 if (FABS (pl->ob->speed) < 0.001)
847 time = MAX_TIME * 100; 841 time = MAX_TIME * 100;
848 else 842 else
849 time = (int) (MAX_TIME / FABS (pl->ob->speed)); 843 time = (int) (MAX_TIME / FABS (pl->ob->speed));
850 SockList_AddInt (&sl, time); 844
845 /* Send confirmation of command execution now */
846
847 packet sl;
848 sl << "comc " << uint16 (pktlen) << uint32 (time);
851 Send_With_Handling (&pl->socket, &sl); 849 Send_With_Handling (&pl->socket, &sl);
852} 850}
853 851
854 852
855/** This is a reply to a previous query. */ 853/** This is a reply to a previous query. */
968 /* these are old dxclients */ 966 /* these are old dxclients */
969 /* Version 1024 added support for singular + plural name values - 967 /* Version 1024 added support for singular + plural name values -
970 * requiing this minimal value reduces complexity of that code, and it 968 * requiing this minimal value reduces complexity of that code, and it
971 * has been around for a long time. 969 * has been around for a long time.
972 */ 970 */
973 if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) 971 if (ns->sc_version < 1026)
974 { 972 {
975 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 973 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
976 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 974 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
977 Write_String_To_Socket (ns, version_warning, strlen (version_warning)); 975 ns->send_packet (version_warning);
978 } 976 }
979 977
980 } 978 }
981} 979}
982 980
1054send_query (NewSocket * ns, uint8 flags, char *text) 1052send_query (NewSocket * ns, uint8 flags, char *text)
1055{ 1053{
1056 char buf[MAX_BUF]; 1054 char buf[MAX_BUF];
1057 1055
1058 sprintf (buf, "query %d %s", flags, text ? text : ""); 1056 sprintf (buf, "query %d %s", flags, text ? text : "");
1059 Write_String_To_Socket (ns, buf, strlen (buf)); 1057 ns->send_packet (buf);
1060} 1058}
1061 1059
1062#define AddIfInt64(Old,New,Type) if (Old != New) {\ 1060#define AddIfInt64(Old,New,Type) if (Old != New) {\
1063 Old = New; \ 1061 Old = New; \
1064 SockList_AddChar(&sl, Type); \ 1062 sl << uint8 (Type) << uint64 (New); \
1065 SockList_AddInt64(&sl, New); \
1066 } 1063 }
1067 1064
1068#define AddIfInt(Old,New,Type) if (Old != New) {\ 1065#define AddIfInt(Old,New,Type) if (Old != New) {\
1069 Old = New; \ 1066 Old = New; \
1070 SockList_AddChar(&sl, Type); \ 1067 sl << uint8 (Type) << uint32 (New); \
1071 SockList_AddInt(&sl, New); \
1072 } 1068 }
1073 1069
1074#define AddIfShort(Old,New,Type) if (Old != New) {\ 1070#define AddIfShort(Old,New,Type) if (Old != New) {\
1075 Old = New; \ 1071 Old = New; \
1076 SockList_AddChar(&sl, Type); \ 1072 sl << uint8 (Type) << uint16 (New); \
1077 SockList_AddShort(&sl, New); \
1078 } 1073 }
1079 1074
1080#define AddIfFloat(Old,New,Type) if (Old != New) {\ 1075#define AddIfFloat(Old,New,Type) if (Old != New) {\
1081 Old = New; \ 1076 Old = New; \
1082 SockList_AddChar(&sl, Type); \ 1077 sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \
1083 SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\
1084 } 1078 }
1085 1079
1086#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ 1080#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\
1087 if (Old) free(Old);\
1088 Old = strdup_local(New);\ 1081 free(Old); Old = strdup (New);\
1089 SockList_AddChar(&sl, Type); \ 1082 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 } 1083 }
1094 1084
1095/** 1085/**
1096 * Sends a statistics update. We look at the old values, 1086 * Sends a statistics update. We look at the old values,
1097 * 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
1099 * commands for now. 1089 * commands for now.
1100 */ 1090 */
1101void 1091void
1102esrv_update_stats (player *pl) 1092esrv_update_stats (player *pl)
1103{ 1093{
1104 SockList sl;
1105 char buf[MAX_BUF]; 1094 char buf[MAX_BUF];
1106 uint16 flags; 1095 uint16 flags;
1107 1096
1108 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1097 packet sl;
1109 strcpy ((char *) sl.buf, "stats "); 1098 sl << "stats ";
1110 sl.len = strlen ((char *) sl.buf);
1111 1099
1112 if (pl->ob != NULL) 1100 if (pl->ob != NULL)
1113 { 1101 {
1114 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);
1115 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);
1132 1120
1133 for (s = 0; s < NUM_SKILLS; s++) 1121 for (s = 0; s < NUM_SKILLS; s++)
1134 { 1122 {
1135 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)
1136 { 1124 {
1137
1138 /* Always send along the level if exp changes. This is only 1125 /* Always send along the level if exp changes. This is only
1139 * 1 extra byte, but keeps processing simpler. 1126 * 1 extra byte, but keeps processing simpler.
1140 */ 1127 */
1141 SockList_AddChar (&sl, (char) (s + CS_STAT_SKILLINFO)); 1128 sl << uint8 (s + CS_STAT_SKILLINFO)
1142 SockList_AddChar (&sl, (char) pl->last_skill_ob[s]->level); 1129 << uint8 (pl->last_skill_ob[s]->level)
1143 SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); 1130 << uint64 (pl->last_skill_ob[s]->stats.exp);
1131
1144 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;
1145 } 1133 }
1146 } 1134 }
1147 } 1135 }
1148 1136
1204 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); 1192 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len);
1205#endif 1193#endif
1206 Send_With_Handling (&pl->socket, &sl); 1194 Send_With_Handling (&pl->socket, &sl);
1207 } 1195 }
1208 1196
1209 free (sl.buf);
1210} 1197}
1211 1198
1212/** 1199/**
1213 * 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.
1214 */ 1201 */
1215void 1202void
1216esrv_new_player (player *pl, uint32 weight) 1203esrv_new_player (player *pl, uint32 weight)
1217{ 1204{
1218 SockList sl;
1219
1220 pl->last_weight = weight; 1205 pl->last_weight = weight;
1221 1206
1222 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1207 packet sl;
1208 sl << "player ";
1223 1209
1224 strcpy ((char *) sl.buf, "player "); 1210 sl << uint32 (pl->ob->count)
1225 sl.len = strlen ((char *) sl.buf); 1211 << uint32 (weight)
1226 SockList_AddInt (&sl, pl->ob->count); 1212 << uint32 (pl->ob->face->number)
1227 SockList_AddInt (&sl, weight); 1213 << 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 1214
1234 Send_With_Handling (&pl->socket, &sl); 1215 Send_With_Handling (&pl->socket, &sl);
1235 free (sl.buf);
1236 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1216 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1237} 1217}
1238 1218
1239/** 1219/**
1240 * Need to send an animation sequence to the client. 1220 * Need to send an animation sequence to the client.
1244 * when the player logs in and picks stuff up. 1224 * when the player logs in and picks stuff up.
1245 */ 1225 */
1246void 1226void
1247esrv_send_animation (NewSocket * ns, short anim_num) 1227esrv_send_animation (NewSocket * ns, short anim_num)
1248{ 1228{
1249 SockList sl;
1250 int i; 1229 int i;
1251 1230
1252 /* 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
1253 * 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
1254 * range, it must be a valid animation. 1233 * range, it must be a valid animation.
1257 { 1236 {
1258 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);
1259 return; 1238 return;
1260 } 1239 }
1261 1240
1262 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1241 packet sl;
1263 strcpy ((char *) sl.buf, "anim "); 1242
1264 sl.len = 5; 1243 sl << "anim "
1265 SockList_AddShort (&sl, anim_num); 1244 << uint16 (anim_num)
1266 SockList_AddShort (&sl, 0); /* flags - not used right now */ 1245 << uint16 (0); /* flags - not used right now */
1246
1267 /* 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
1268 * the face itself) down to the client. 1248 * the face itself) down to the client.
1269 */ 1249 */
1270 for (i = 0; i < animations[anim_num].num_animations; i++) 1250 for (i = 0; i < animations[anim_num].num_animations; i++)
1271 { 1251 {
1272 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))
1273 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1253 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1274 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 */
1275 } 1255 }
1256
1276 Send_With_Handling (ns, &sl); 1257 Send_With_Handling (ns, &sl);
1277 free (sl.buf); 1258
1278 ns->anims_sent[anim_num] = 1; 1259 ns->anims_sent[anim_num] = 1;
1279} 1260}
1280 1261
1281 1262
1282/****************************************************************************** 1263/******************************************************************************
1296 { 1277 {
1297 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);
1298 return; 1279 return;
1299 abort (); 1280 abort ();
1300 } 1281 }
1282
1301 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;
1302 newmap->cells[x][y].count++; 1284 newmap->cells[x][y].count++;
1285
1303 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) 1286 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE))
1304 esrv_send_face (ns, face_num, 0); 1287 esrv_send_face (ns, face_num, 0);
1305} 1288}
1306 1289
1307struct LayerCell 1290struct LayerCell
1414static void 1397static void
1415esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) 1398esrv_map_doneredraw (NewSocket * ns, struct Map *newmap)
1416{ 1399{
1417 static long frames, bytes, tbytes, tframes; 1400 static long frames, bytes, tbytes, tframes;
1418 char *cur; 1401 char *cur;
1419 SockList sl;
1420 1402
1421 1403 packet sl;
1422 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1404 sl << "map ";
1423 strcpy ((char *) sl.buf, "map ");
1424 sl.len = strlen ((char *) sl.buf);
1425 1405
1426 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);
1427 sl.len = cur - (char *) sl.buf; 1407 sl.len = cur - (char *) sl.buf;
1428 1408
1429/* LOG(llevDebug, "Sending map command.\n");*/ 1409/* LOG(llevDebug, "Sending map command.\n");*/
1441 memcpy (&ns->lastmap, newmap, sizeof (struct Map)); 1421 memcpy (&ns->lastmap, newmap, sizeof (struct Map));
1442 Send_With_Handling (ns, &sl); 1422 Send_With_Handling (ns, &sl);
1443 ns->sent_scroll = 0; 1423 ns->sent_scroll = 0;
1444 } 1424 }
1445 1425
1446 free (sl.buf);
1447} 1426}
1448 1427
1449 1428
1450/** Clears a map cell */ 1429/** Clears a map cell */
1451static void 1430static void
1493 * 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
1494 * 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
1495 * sent, it returns zero. 1474 * sent, it returns zero.
1496 */ 1475 */
1497static int 1476static int
1498check_head (SockList & sl, NewSocket & ns, int ax, int ay, int layer) 1477check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer)
1499{ 1478{
1500 short face_num; 1479 short face_num;
1501 1480
1502 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1481 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1503 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;
1504 else 1483 else
1505 face_num = 0; 1484 face_num = 0;
1506 1485
1507 if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) 1486 if (face_num != ns.lastmap.cells[ax][ay].faces[layer])
1508 { 1487 {
1509 SockList_AddShort (&sl, face_num); 1488 sl << uint16 (face_num);
1510 if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) 1489 if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE))
1511 esrv_send_face (&ns, face_num, 0); 1490 esrv_send_face (&ns, face_num, 0);
1491
1512 heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; 1492 heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL;
1513 ns.lastmap.cells[ax][ay].faces[layer] = face_num; 1493 ns.lastmap.cells[ax][ay].faces[layer] = face_num;
1514 return 1; 1494 return 1;
1515 } 1495 }
1516 1496
1536 * 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
1537 * actually match. 1517 * actually match.
1538 */ 1518 */
1539 1519
1540static int 1520static int
1541update_space (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1521update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1542{ 1522{
1543 object *ob, *head; 1523 object *ob, *head;
1544 uint16 face_num; 1524 uint16 face_num;
1545 int bx, by, i; 1525 int bx, by, i;
1546 1526
1547 /* 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.
1548 * If not, then do the normal processing. 1528 * If not, then do the normal processing.
1549 */ 1529 */
1550
1551 head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; 1530 head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer];
1552 1531
1553 /* 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
1554 * we would normally send for this space. If so, then 1533 * we would normally send for this space. If so, then
1555 * 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
1720 1699
1721 /* 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
1722 * 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
1723 * this one. 1702 * this one.
1724 */ 1703 */
1725 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)
1726 {
1727 face_num = 0; 1705 face_num = 0;
1728 }
1729 1706
1730 /* 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
1731 * 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.
1732 */ 1709 */
1733 if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) 1710 if (ns.lastmap.cells[sx][sy].faces[layer] != face_num)
1734 { 1711 {
1735 ns->lastmap.cells[sx][sy].faces[layer] = face_num; 1712 ns.lastmap.cells[sx][sy].faces[layer] = face_num;
1736 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) 1713 if (!(ns.faces_sent[face_num] & NS_FACESENT_FACE))
1737 esrv_send_face (ns, face_num, 0); 1714 esrv_send_face (&ns, face_num, 0);
1738 SockList_AddShort (sl, face_num); 1715
1716 sl << uint16 (face_num);
1739 return 1; 1717 return 1;
1740 } 1718 }
1719
1741 /* Nothing changed */ 1720 /* Nothing changed */
1742 return 0; 1721 return 0;
1743} 1722}
1744 1723
1745/** 1724/**
1760 * 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
1761 * take. 1740 * take.
1762 */ 1741 */
1763 1742
1764static inline int 1743static inline int
1765update_smooth (SockList * sl, NewSocket * ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1744update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1766{ 1745{
1767 object *ob; 1746 object *ob;
1768 int smoothlevel; /* old face_num; */ 1747 int smoothlevel; /* old face_num; */
1769 1748
1770 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1749 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1775 if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) 1754 if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp))
1776 smoothlevel = 0; 1755 smoothlevel = 0;
1777 else 1756 else
1778 { 1757 {
1779 smoothlevel = ob->smoothlevel; 1758 smoothlevel = ob->smoothlevel;
1780 if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) 1759 if (smoothlevel && !(ns.faces_sent[ob->face->number] & NS_FACESENT_SMOOTH))
1781 SendSmooth (ns, ob->face->number); 1760 SendSmooth (&ns, ob->face->number);
1782 } /* else not already head object or blank face */ 1761 } /* else not already head object or blank face */
1783 1762
1784 /* 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
1785 * 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.
1786 */ 1765 */
1787 if (smoothlevel > 255) 1766 if (smoothlevel > 255)
1788 smoothlevel = 255; 1767 smoothlevel = 255;
1789 else if (smoothlevel < 0) 1768 else if (smoothlevel < 0)
1790 smoothlevel = 0; 1769 smoothlevel = 0;
1770
1791 if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) 1771 if (ns.lastmap.cells[sx][sy].smooth[layer] != smoothlevel)
1792 { 1772 {
1793 ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; 1773 ns.lastmap.cells[sx][sy].smooth[layer] = smoothlevel;
1794 SockList_AddChar (sl, (uint8) (smoothlevel & 0xFF)); 1774 sl << uint8 (smoothlevel);
1795 return 1; 1775 return 1;
1796 } 1776 }
1777
1797 /* Nothing changed */ 1778 /* Nothing changed */
1798 return 0; 1779 return 0;
1799} 1780}
1800 1781
1801/** 1782/**
1842draw_client_map1 (object *pl) 1823draw_client_map1 (object *pl)
1843{ 1824{
1844 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;
1845 sint16 nx, ny; 1826 sint16 nx, ny;
1846 int estartlen, eoldlen; 1827 int estartlen, eoldlen;
1847 SockList sl;
1848 SockList esl; /*For extended Map info */
1849 uint16 mask, emask; 1828 uint16 mask, emask;
1850 uint8 eentrysize; 1829 uint8 eentrysize;
1851 uint16 ewhatstart, ewhatflag; 1830 uint16 ewhatstart, ewhatflag;
1852 uint8 extendedinfos; 1831 uint8 extendedinfos;
1853 maptile *m; 1832 maptile *m;
1854 1833
1855 NewSocket & socket = pl->contr->socket; 1834 NewSocket &socket = pl->contr->socket;
1856 1835
1857 check_map_change (pl->contr); 1836 check_map_change (pl->contr);
1858 1837
1859 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1838 packet sl;
1860 if (socket.mapmode == Map1Cmd) 1839 packet esl;
1861 strcpy ((char *) sl.buf, "map1 "); 1840
1862 else 1841 sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a ");
1863 strcpy ((char *) sl.buf, "map1a ");
1864 sl.len = strlen ((char *) sl.buf);
1865 startlen = sl.len; 1842 startlen = sl.len;
1866 1843
1867 /*Extendedmapinfo structure initialisation */ 1844 /*Extendedmapinfo structure initialisation */
1868 if (socket.ext_mapinfos) 1845 if (socket.ext_mapinfos)
1869 { 1846 {
1870 esl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1871 strcpy ((char *) esl.buf, "mapextended ");
1872 esl.len = strlen ((char *) esl.buf);
1873 extendedinfos = EMI_NOREDRAW; 1847 extendedinfos = EMI_NOREDRAW;
1874 1848
1875 if (socket.EMI_smooth) 1849 if (socket.EMI_smooth)
1876 extendedinfos |= EMI_SMOOTH; 1850 extendedinfos |= EMI_SMOOTH;
1877 1851
1878 ewhatstart = esl.len; 1852 ewhatstart = esl.len;
1879 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit 1853 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1880 could need to be taken away */ 1854 could need to be taken away */
1881 SockList_AddChar (&esl, extendedinfos);
1882 eentrysize = getExtendedMapInfoSize (&socket); 1855 eentrysize = getExtendedMapInfoSize (&socket);
1883 SockList_AddChar (&esl, eentrysize); 1856 esl << "mapextended "
1857 << uint8 (extendedinfos)
1858 << uint8 (eentrysize);
1884 estartlen = esl.len; 1859 estartlen = esl.len;
1885 } 1860 }
1886 else 1861 else
1887 { 1862 {
1888 /* suppress compiler warnings */ 1863 /* suppress compiler warnings */
1929 { 1904 {
1930 int i, got_one; 1905 int i, got_one;
1931 1906
1932 oldlen = sl.len; 1907 oldlen = sl.len;
1933 1908
1934 SockList_AddShort (&sl, mask); 1909 sl << uint16 (mask);
1935 1910
1936 if (check_head (sl, socket, ax, ay, 2)) 1911 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4;
1937 mask |= 0x4;
1938 if (check_head (sl, socket, ax, ay, 1)) 1912 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2;
1939 mask |= 0x2;
1940 if (check_head (sl, socket, ax, ay, 0)) 1913 if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1;
1941 mask |= 0x1;
1942 1914
1943 /* 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
1944 * actually need to send that - just the coordinates 1916 * actually need to send that - just the coordinates
1945 * with no faces tells the client to blank out the 1917 * with no faces tells the client to blank out the
1946 * space. 1918 * space.
1983 * 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
1984 * of the map, it shouldn't have a head 1956 * of the map, it shouldn't have a head
1985 */ 1957 */
1986 if (lastcell.count != -1) 1958 if (lastcell.count != -1)
1987 { 1959 {
1988 SockList_AddShort (&sl, mask); 1960 sl << uint16 (mask);
1989 map_clearcell (&lastcell, 0, 0, 0, -1); 1961 map_clearcell (&lastcell, 0, 0, 0, -1);
1990 } 1962 }
1991 } 1963 }
1992 else if (d > 3) 1964 else if (d > 3)
1993 { 1965 {
1997 * reason. Still may need to send the head for this space. 1969 * reason. Still may need to send the head for this space.
1998 */ 1970 */
1999 1971
2000 oldlen = sl.len; 1972 oldlen = sl.len;
2001 1973
2002 SockList_AddShort (&sl, mask); 1974 sl << uint16 (mask);
2003 1975
2004 if (lastcell.count != -1) 1976 if (lastcell.count != -1)
2005 need_send = 1; 1977 need_send = 1;
2006 1978
2007 count = -1; 1979 count = -1;
2008 1980
2009 if (socket.mapmode == Map1aCmd && have_head (ax, ay)) 1981 if (socket.mapmode == Map1aCmd && have_head (ax, ay))
2010 { 1982 {
2011 /* Now check to see if any heads need to be sent */ 1983 /* Now check to see if any heads need to be sent */
2012 1984
2013 if (check_head (sl, socket, ax, ay, 2)) 1985 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4;
2014 mask |= 0x4;
2015 if (check_head (sl, socket, ax, ay, 1)) 1986 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2;
2016 mask |= 0x2;
2017 if (check_head (sl, socket, ax, ay, 0)) 1987 if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1;
2018 mask |= 0x1;
2019 1988
2020 lastcell.count = count; 1989 lastcell.count = count;
2021 } 1990 }
2022 else 1991 else
2023 { 1992 {
2052 */ 2021 */
2053 oldlen = sl.len; 2022 oldlen = sl.len;
2054 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 2023 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2055 eoldlen = esl.len; 2024 eoldlen = esl.len;
2056 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 2025 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2057 SockList_AddShort (&sl, mask); 2026 sl << uint16 (mask);
2058 2027
2059 if (socket.ext_mapinfos) 2028 if (socket.ext_mapinfos)
2060 SockList_AddShort (&esl, emask); 2029 esl << uint16 (emask);
2061 2030
2062 unsigned char dummy; 2031 unsigned char dummy;
2063 unsigned char *last_ext = &dummy; 2032 unsigned char *last_ext = &dummy;
2064 2033
2065 /* Darkness changed */ 2034 /* Darkness changed */
2069 2038
2070 if (socket.extmap) 2039 if (socket.extmap)
2071 { 2040 {
2072 *last_ext |= 0x80; 2041 *last_ext |= 0x80;
2073 last_ext = sl.buf + sl.len; 2042 last_ext = sl.buf + sl.len;
2074 SockList_AddChar (&sl, d); 2043 sl << uint8 (d);
2075 } 2044 }
2076 else 2045 else
2077 SockList_AddChar (&sl, 255 - 64 * d); 2046 sl << uint8 (255 - 64 * d);
2078 } 2047 }
2079 2048
2080 lastcell.count = d; 2049 lastcell.count = d;
2081 2050
2082 if (socket.extmap) 2051 if (socket.extmap)
2083 { 2052 {
2084 uint8 stat_hp = 0; 2053 uint8 stat_hp = 0;
2085 uint8 stat_width = 0; 2054 uint8 stat_width = 0;
2086 uint8 flags = 0; 2055 uint8 flags = 0;
2087 tag_t player = 0; 2056 UUID player = 0;
2088 2057
2089 // send hp information, if applicable 2058 // send hp information, if applicable
2090 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0)) 2059 if (object *op = GET_MAP_FACE_OBJ (m, nx, ny, 0))
2091 { 2060 {
2092 if (op->head || op->invisible) 2061 if (op->head || op->invisible)
2113 lastcell.stat_hp = stat_hp; 2082 lastcell.stat_hp = stat_hp;
2114 2083
2115 mask |= 0x8; 2084 mask |= 0x8;
2116 *last_ext |= 0x80; 2085 *last_ext |= 0x80;
2117 last_ext = sl.buf + sl.len; 2086 last_ext = sl.buf + sl.len;
2118 SockList_AddChar (&sl, 5); 2087
2119 SockList_AddChar (&sl, stat_hp); 2088 sl << uint8 (5) << uint8 (stat_hp);
2120 2089
2121 if (stat_width > 1) 2090 if (stat_width > 1)
2122 { 2091 {
2123 *last_ext |= 0x80; 2092 *last_ext |= 0x80;
2124 last_ext = sl.buf + sl.len; 2093 last_ext = sl.buf + sl.len;
2125 SockList_AddChar (&sl, 6); 2094
2126 SockList_AddChar (&sl, stat_width); 2095 sl << uint8 (6) << uint8 (stat_width);
2127 } 2096 }
2128 } 2097 }
2129 2098
2130 if (lastcell.player != player) 2099 if (lastcell.player != player)
2131 { 2100 {
2132 lastcell.player = player; 2101 lastcell.player = player;
2133 2102
2134 mask |= 0x8; 2103 mask |= 0x8;
2135 *last_ext |= 0x80; 2104 *last_ext |= 0x80;
2136 last_ext = sl.buf + sl.len; 2105 last_ext = sl.buf + sl.len;
2137 SockList_AddChar (&sl, 0x47); 2106
2138 SockList_AddChar (&sl, 4); 2107 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2139 SockList_AddInt (&sl, player);
2140 } 2108 }
2141 2109
2142 if (lastcell.flags != flags) 2110 if (lastcell.flags != flags)
2143 { 2111 {
2144 lastcell.flags = flags; 2112 lastcell.flags = flags;
2145 2113
2146 mask |= 0x8; 2114 mask |= 0x8;
2147 *last_ext |= 0x80; 2115 *last_ext |= 0x80;
2148 last_ext = sl.buf + sl.len; 2116 last_ext = sl.buf + sl.len;
2149 SockList_AddChar (&sl, 8); 2117
2150 SockList_AddChar (&sl, flags); 2118 sl << uint8 (8) << uint8 (flags);
2151 } 2119 }
2152 } 2120 }
2153 2121
2154 /* Floor face */ 2122 /* Floor face */
2155 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) 2123 if (update_space (sl, socket, m, nx, ny, ax, ay, 2))
2156 mask |= 0x4; 2124 mask |= 0x4;
2157 2125
2158 if (socket.EMI_smooth) 2126 if (socket.EMI_smooth)
2159 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 2)) 2127 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 2))
2160 emask |= 0x4; 2128 emask |= 0x4;
2161 2129
2162 /* Middle face */ 2130 /* Middle face */
2163 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 1)) 2131 if (update_space (sl, socket, m, nx, ny, ax, ay, 1))
2164 mask |= 0x2; 2132 mask |= 0x2;
2165 2133
2166 if (socket.EMI_smooth) 2134 if (socket.EMI_smooth)
2167 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 1)) 2135 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 1))
2168 emask |= 0x2; 2136 emask |= 0x2;
2169 2137
2170 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))
2171 { 2139 {
2172 if (lastcell.faces[0] != pl->face->number) 2140 if (lastcell.faces[0] != pl->face->number)
2175 mask |= 0x1; 2143 mask |= 0x1;
2176 2144
2177 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE)) 2145 if (!(socket.faces_sent[pl->face->number] & NS_FACESENT_FACE))
2178 esrv_send_face (&socket, pl->face->number, 0); 2146 esrv_send_face (&socket, pl->face->number, 0);
2179 2147
2180 SockList_AddShort (&sl, pl->face->number); 2148 sl << uint16 (pl->face->number);
2181 } 2149 }
2182 } 2150 }
2183 else 2151 else
2184 { 2152 {
2185 /* Top face */ 2153 /* Top face */
2186 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) 2154 if (update_space (sl, socket, m, nx, ny, ax, ay, 0))
2187 mask |= 0x1; 2155 mask |= 0x1;
2188 2156
2189 if (socket.EMI_smooth) 2157 if (socket.EMI_smooth)
2190 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) 2158 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 0))
2191 emask |= 0x1; 2159 emask |= 0x1;
2192 } 2160 }
2193 2161
2194 /* 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
2195 * space by checking the mask. If so, update the mask. 2163 * space by checking the mask. If so, update the mask.
2221 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2189 esl.buf[ewhatstart + 1] = ewhatflag & 0xff;
2222 } 2190 }
2223 2191
2224 if (esl.len > estartlen) 2192 if (esl.len > estartlen)
2225 Send_With_Handling (&socket, &esl); 2193 Send_With_Handling (&socket, &esl);
2226
2227 free (esl.buf);
2228 } 2194 }
2229 2195
2230 if (sl.len > startlen || socket.sent_scroll) 2196 if (sl.len > startlen || socket.sent_scroll)
2231 { 2197 {
2232 Send_With_Handling (&socket, &sl); 2198 Send_With_Handling (&socket, &sl);
2233 socket.sent_scroll = 0; 2199 socket.sent_scroll = 0;
2234 } 2200 }
2235
2236 free (sl.buf);
2237} 2201}
2238 2202
2239/** 2203/**
2240 * Draws client map. 2204 * Draws client map.
2241 */ 2205 */
2355 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap); 2319 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap);
2356 } 2320 }
2357 } /* Is a valid space */ 2321 } /* Is a valid space */
2358 } 2322 }
2359 } 2323 }
2324
2360 esrv_map_doneredraw (&pl->contr->socket, &newmap); 2325 esrv_map_doneredraw (&pl->contr->socket, &newmap);
2361 2326
2362 check_map_change (pl->contr); 2327 check_map_change (pl->contr);
2363} 2328}
2364 2329
2373 2338
2374/*****************************************************************************/ 2339/*****************************************************************************/
2375void 2340void
2376send_plugin_custom_message (object *pl, char *buf) 2341send_plugin_custom_message (object *pl, char *buf)
2377{ 2342{
2378 cs_write_string (&pl->contr->socket, buf, strlen (buf)); 2343 pl->contr->socket.send_packet (buf);
2379} 2344}
2380 2345
2381/** 2346/**
2382 * This sends the skill number to name mapping. We ignore 2347 * This sends the skill number to name mapping. We ignore
2383 * the params - we always send the same info no matter what. 2348 * the params - we always send the same info no matter what.
2384 */ 2349 */
2385void 2350void
2386send_skill_info (NewSocket * ns, char *params) 2351send_skill_info (NewSocket *ns, char *params)
2387{ 2352{
2388 SockList sl; 2353 packet sl;
2389 int i; 2354 sl << "replyinfo skill_info\n";
2390 2355
2391 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2392 strcpy ((char *) sl.buf, "replyinfo skill_info\n");
2393 for (i = 1; i < NUM_SKILLS; i++) 2356 for (int i = 1; i < NUM_SKILLS; i++)
2394 { 2357 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]); 2358
2396 }
2397 sl.len = strlen ((char *) sl.buf);
2398 if (sl.len >= MAXSOCKBUF) 2359 if (sl.len >= MAXSOCKBUF)
2399 { 2360 {
2400 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2361 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2401 fatal (0); 2362 fatal (0);
2402 } 2363 }
2364
2403 Send_With_Handling (ns, &sl); 2365 Send_With_Handling (ns, &sl);
2404 free (sl.buf);
2405} 2366}
2406 2367
2407/** 2368/**
2408 * This sends the spell path to name mapping. We ignore 2369 * This sends the spell path to name mapping. We ignore
2409 * the params - we always send the same info no matter what. 2370 * the params - we always send the same info no matter what.
2410 */ 2371 */
2411void 2372void
2412send_spell_paths (NewSocket * ns, char *params) 2373send_spell_paths (NewSocket * ns, char *params)
2413{ 2374{
2414 SockList sl; 2375 packet sl;
2415 int i;
2416 2376
2417 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2377 sl << "replyinfo spell_paths\n";
2418 strcpy ((char *) sl.buf, "replyinfo spell_paths\n"); 2378
2419 for (i = 0; i < NRSPELLPATHS; i++) 2379 for (int i = 0; i < NRSPELLPATHS; i++)
2420 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]);
2421 sl.len = strlen ((char *) sl.buf); 2381
2422 if (sl.len >= MAXSOCKBUF) 2382 if (sl.len >= MAXSOCKBUF)
2423 { 2383 {
2424 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2384 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2425 fatal (0); 2385 fatal (0);
2426 } 2386 }
2387
2427 Send_With_Handling (ns, &sl); 2388 Send_With_Handling (ns, &sl);
2428 free (sl.buf);
2429} 2389}
2430 2390
2431/** 2391/**
2432 * 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.
2433 * 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
2434 */ 2394 */
2435void 2395void
2436esrv_update_spells (player *pl) 2396esrv_update_spells (player *pl)
2437{ 2397{
2438 SockList sl;
2439 int flags = 0;
2440 object *spell;
2441
2442 if (!pl->socket.monitor_spells) 2398 if (!pl->socket.monitor_spells)
2443 return; 2399 return;
2400
2444 for (spell = pl->ob->inv; spell != NULL; spell = spell->below) 2401 for (object *spell = pl->ob->inv; spell; spell = spell->below)
2445 { 2402 {
2446 if (spell->type == SPELL) 2403 if (spell->type == SPELL)
2447 { 2404 {
2405 int flags = 0;
2406
2448 /* check if we need to update it */ 2407 /* check if we need to update it */
2449 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))
2450 { 2409 {
2451 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);
2452 flags |= UPD_SP_MANA; 2411 flags |= UPD_SP_MANA;
2453 } 2412 }
2413
2454 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))
2455 { 2415 {
2456 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);
2457 flags |= UPD_SP_GRACE; 2417 flags |= UPD_SP_GRACE;
2458 } 2418 }
2419
2459 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))
2460 { 2421 {
2461 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);
2462 flags |= UPD_SP_DAMAGE; 2423 flags |= UPD_SP_DAMAGE;
2463 } 2424 }
2425
2464 if (flags != 0) 2426 if (flags)
2465 { 2427 {
2466 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2428 packet sl;
2467 strcpy ((char *) sl.buf, "updspell "); 2429
2468 sl.len = strlen ((char *) sl.buf); 2430 sl << "updspell "
2469 SockList_AddChar (&sl, flags); 2431 << uint8 (flags)
2470 SockList_AddInt (&sl, spell->count); 2432 << uint32 (spell->count);
2471 if (flags & UPD_SP_MANA) 2433
2472 SockList_AddShort (&sl, spell->last_sp); 2434 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2473 if (flags & UPD_SP_GRACE) 2435 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2474 SockList_AddShort (&sl, spell->last_grace); 2436 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2475 if (flags & UPD_SP_DAMAGE) 2437
2476 SockList_AddShort (&sl, spell->last_eat);
2477 flags = 0;
2478 Send_With_Handling (&pl->socket, &sl); 2438 Send_With_Handling (&pl->socket, &sl);
2479 free (sl.buf);
2480 } 2439 }
2481 } 2440 }
2482 } 2441 }
2483} 2442}
2484 2443
2485void 2444void
2486esrv_remove_spell (player *pl, object *spell) 2445esrv_remove_spell (player *pl, object *spell)
2487{ 2446{
2488 SockList sl;
2489
2490 if (!pl->socket.monitor_spells) 2447 if (!pl->socket.monitor_spells)
2491 return; 2448 return;
2449
2492 if (!pl || !spell || spell->env != pl->ob) 2450 if (!pl || !spell || spell->env != pl->ob)
2493 { 2451 {
2494 LOG (llevError, "Invalid call to esrv_remove_spell"); 2452 LOG (llevError, "Invalid call to esrv_remove_spell");
2495 return; 2453 return;
2496 } 2454 }
2497 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2455
2498 strcpy ((char *) sl.buf, "delspell "); 2456 packet sl;
2499 sl.len = strlen ((char *) sl.buf); 2457
2500 SockList_AddInt (&sl, spell->count); 2458 sl << "delspell "
2459 << uint32 (spell->count);
2460
2501 Send_With_Handling (&pl->socket, &sl); 2461 Send_With_Handling (&pl->socket, &sl);
2502 free (sl.buf);
2503} 2462}
2504 2463
2505/* 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. */
2506static void 2465static void
2507append_spell (player *pl, SockList * sl, object *spell) 2466append_spell (player *pl, packet &sl, object *spell)
2508{ 2467{
2509 int len, i, skill = 0; 2468 int len, i, skill = 0;
2510 2469
2511 if (!(spell->name)) 2470 if (!(spell->name))
2512 { 2471 {
2513 LOG (llevError, "item number %d is a spell with no name.\n", spell->count); 2472 LOG (llevError, "item number %d is a spell with no name.\n", spell->count);
2514 return; 2473 return;
2515 } 2474 }
2516 SockList_AddInt (sl, spell->count); 2475
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 */ 2476 /* 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); 2477 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); 2478 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); 2479 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 2480
2528 /* figure out which skill it uses, if it uses one */ 2481 /* figure out which skill it uses, if it uses one */
2529 if (spell->skill) 2482 if (spell->skill)
2530 { 2483 {
2531 for (i = 1; i < NUM_SKILLS; i++) 2484 for (i = 1; i < NUM_SKILLS; i++)
2533 { 2486 {
2534 skill = i + CS_STAT_SKILLINFO; 2487 skill = i + CS_STAT_SKILLINFO;
2535 break; 2488 break;
2536 } 2489 }
2537 } 2490 }
2538 SockList_AddChar (sl, skill);
2539 2491
2540 SockList_AddInt (sl, spell->path_attuned); 2492 /* send the current values */
2493 sl << uint32 (spell->count)
2494 << uint16 (spell->level)
2495 << uint16 (spell->casting_time)
2496 << uint16 (spell->last_sp)
2497 << uint16 (spell->last_grace)
2498 << uint16 (spell->last_eat)
2499 << uint8 (skill)
2500 << uint32 (spell->path_attuned)
2541 SockList_AddInt (sl, (spell->face) ? spell->face->number : 0); 2501 << uint32 (spell->face ? spell->face->number : 0)
2542 2502 << data8 (spell->name)
2543 len = strlen (spell->name); 2503 << 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} 2504}
2560 2505
2561/** 2506/**
2562 * This tells the client to add the spell *ob, if *ob is NULL, then add 2507 * This tells the client to add the spell *ob, if *ob is NULL, then add
2563 * all spells in the player's inventory. 2508 * all spells in the player's inventory.
2564 */ 2509 */
2565void 2510void
2566esrv_add_spells (player *pl, object *spell) 2511esrv_add_spells (player *pl, object *spell)
2567{ 2512{
2568 SockList sl;
2569
2570 if (!pl) 2513 if (!pl)
2571 { 2514 {
2572 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");
2573 return; 2516 return;
2574 } 2517 }
2518
2575 if (!pl->socket.monitor_spells) 2519 if (!pl->socket.monitor_spells)
2576 return; 2520 return;
2577 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2521
2578 strcpy ((char *) sl.buf, "addspell "); 2522 packet sl;
2579 sl.len = strlen ((char *) sl.buf); 2523
2524 sl << "addspell ";
2525
2580 if (!spell) 2526 if (!spell)
2581 { 2527 {
2582 for (spell = pl->ob->inv; spell != NULL; spell = spell->below) 2528 for (spell = pl->ob->inv; spell != NULL; spell = spell->below)
2583 { 2529 {
2584 /* were we to simply keep appending data here, we could exceed 2530 /* 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 2540 * is hundreds of bytes off, so correcting 22 vs 26 doesn't seem
2595 * like it will fix this 2541 * like it will fix this
2596 */ 2542 */
2597 if (spell->type != SPELL) 2543 if (spell->type != SPELL)
2598 continue; 2544 continue;
2545
2599 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0)))) 2546 if (sl.len >= (MAXSOCKBUF - (26 + strlen (spell->name) + (spell->msg ? strlen (spell->msg) : 0))))
2600 { 2547 {
2601 Send_With_Handling (&pl->socket, &sl); 2548 Send_With_Handling (&pl->socket, &sl);
2602 strcpy ((char *) sl.buf, "addspell "); 2549 strcpy ((char *) sl.buf, "addspell ");
2603 sl.len = strlen ((char *) sl.buf); 2550 sl.len = strlen ((char *) sl.buf);
2604 } 2551 }
2552
2605 append_spell (pl, &sl, spell); 2553 append_spell (pl, sl, spell);
2606 } 2554 }
2607 } 2555 }
2608 else if (spell->type != SPELL) 2556 else if (spell->type != SPELL)
2609 { 2557 {
2610 LOG (llevError, "Asked to send a non-spell object as a spell"); 2558 LOG (llevError, "Asked to send a non-spell object as a spell");
2611 return; 2559 return;
2612 } 2560 }
2613 else 2561 else
2614 append_spell (pl, &sl, spell); 2562 append_spell (pl, sl, spell);
2563
2615 if (sl.len >= MAXSOCKBUF) 2564 if (sl.length () >= MAXSOCKBUF)
2616 { 2565 {
2617 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2566 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2618 fatal (0); 2567 fatal (0);
2619 } 2568 }
2569
2620 /* finally, we can send the packet */ 2570 /* finally, we can send the packet */
2621 Send_With_Handling (&pl->socket, &sl); 2571 Send_With_Handling (&pl->socket, &sl);
2622 free (sl.buf); 2572
2623} 2573}
2574

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines