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.27 by root, Wed Dec 13 18:08:02 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 sl.len = strlen ((char *) sl.buf);
709 708
710 sl << uint16 (face) << uint16 (smoothface); 709 sl << "smooth "
710 << uint16 (face)
711 << uint16 (smoothface);
711 712
712 Send_With_Handling (ns, &sl); 713 Send_With_Handling (ns, &sl);
713} 714}
714 715
715 /** 716 /**
722 uint16 facenbr; 723 uint16 facenbr;
723 724
724 facenbr = atoi (buf); 725 facenbr = atoi (buf);
725 SendSmooth (ns, facenbr); 726 SendSmooth (ns, facenbr);
726} 727}
727
728
729
730
731 728
732/** 729/**
733 * 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,
734 * etc.) 731 * etc.)
735 */ 732 */
789 */ 786 */
790void 787void
791NewPlayerCmd (uint8 * buf, int len, player *pl) 788NewPlayerCmd (uint8 * buf, int len, player *pl)
792{ 789{
793 int time, repeat; 790 int time, repeat;
794 short packet;
795 unsigned char command[MAX_BUF]; 791 char command[MAX_BUF];
796 SockList sl; 792 int pktlen;
797 793
798 if (len < 7) 794 if (len < 7)
799 { 795 {
800 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);
801 return; 797 return;
802 } 798 }
803 799
804 packet = GetShort_String (buf); 800 pktlen = net_uint16 (buf);
805 repeat = GetInt_String (buf + 2); 801 repeat = net_uint32 (buf + 2);
802
806 /* -1 is special - no repeat, but don't update */ 803 /* -1 is special - no repeat, but don't update */
807 if (repeat != -1) 804 if (repeat != -1)
808 {
809 pl->count = repeat; 805 pl->count = repeat;
810 } 806
811 if ((len - 4) >= MAX_BUF) 807 if ((len - 4) >= MAX_BUF)
812 len = MAX_BUF - 5; 808 len = MAX_BUF - 5;
813 809
814 strncpy ((char *) command, (char *) buf + 6, len - 4); 810 strncpy ((char *) command, (char *) buf + 6, len - 4);
815 command[len - 4] = '\0'; 811 command[len - 4] = '\0';
825 return; 821 return;
826 } 822 }
827 823
828 /* This should not happen anymore. */ 824 /* This should not happen anymore. */
829 if (pl->ob->speed_left < -1.0) 825 if (pl->ob->speed_left < -1.0)
830 {
831 LOG (llevError, "Player has negative time - shouldn't do command.\n"); 826 LOG (llevError, "Player has negative time - shouldn't do command.\n");
832 } 827
833 /* In c_new.c */ 828 /* In c_new.c */
834 execute_newserver_command (pl->ob, (char *) command); 829 execute_newserver_command (pl->ob, (char *) command);
835 /* Perhaps something better should be done with a left over count. 830 /* Perhaps something better should be done with a left over count.
836 * Cleaning up the input should probably be done first - all actions 831 * Cleaning up the input should probably be done first - all actions
837 * for the command that issued the count should be done before any other 832 * for the command that issued the count should be done before any other
838 * commands. 833 * commands.
839 */ 834 */
840 pl->count = 0; 835 pl->count = 0;
841 836
842 /* Send confirmation of command execution now */
843 sl.buf = command;
844 strcpy ((char *) sl.buf, "comc ");
845 sl.len = 5;
846
847 if (FABS (pl->ob->speed) < 0.001) 837 if (FABS (pl->ob->speed) < 0.001)
848 time = MAX_TIME * 100; 838 time = MAX_TIME * 100;
849 else 839 else
850 time = (int) (MAX_TIME / FABS (pl->ob->speed)); 840 time = (int) (MAX_TIME / FABS (pl->ob->speed));
851 841
842 /* Send confirmation of command execution now */
843
844 packet sl;
852 sl << uint16 (packet) << uint32 (time); 845 sl << "comc " << uint16 (pktlen) << uint32 (time);
853
854 Send_With_Handling (&pl->socket, &sl); 846 Send_With_Handling (&pl->socket, &sl);
855} 847}
856 848
857 849
858/** This is a reply to a previous query. */ 850/** This is a reply to a previous query. */
971 /* these are old dxclients */ 963 /* these are old dxclients */
972 /* Version 1024 added support for singular + plural name values - 964 /* Version 1024 added support for singular + plural name values -
973 * requiing this minimal value reduces complexity of that code, and it 965 * requiing this minimal value reduces complexity of that code, and it
974 * has been around for a long time. 966 * has been around for a long time.
975 */ 967 */
976 if (!strcmp (" CF DX CLIENT", cp) || ns->sc_version < 1024) 968 if (ns->sc_version < 1026)
977 { 969 {
978 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 970 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
979 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 971 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
980 Write_String_To_Socket (ns, version_warning, strlen (version_warning)); 972 ns->send_packet (version_warning);
981 } 973 }
982 974
983 } 975 }
984} 976}
985 977
1057send_query (NewSocket * ns, uint8 flags, char *text) 1049send_query (NewSocket * ns, uint8 flags, char *text)
1058{ 1050{
1059 char buf[MAX_BUF]; 1051 char buf[MAX_BUF];
1060 1052
1061 sprintf (buf, "query %d %s", flags, text ? text : ""); 1053 sprintf (buf, "query %d %s", flags, text ? text : "");
1062 Write_String_To_Socket (ns, buf, strlen (buf)); 1054 ns->send_packet (buf);
1063} 1055}
1064 1056
1065#define AddIfInt64(Old,New,Type) if (Old != New) {\ 1057#define AddIfInt64(Old,New,Type) if (Old != New) {\
1066 Old = New; \ 1058 Old = New; \
1067 SockList_AddChar(&sl, Type); \ 1059 sl << uint8 (Type) << uint64 (New); \
1068 SockList_AddInt64(&sl, New); \
1069 } 1060 }
1070 1061
1071#define AddIfInt(Old,New,Type) if (Old != New) {\ 1062#define AddIfInt(Old,New,Type) if (Old != New) {\
1072 Old = New; \ 1063 Old = New; \
1073 SockList_AddChar(&sl, Type); \ 1064 sl << uint8 (Type) << uint32 (New); \
1074 SockList_AddInt(&sl, New); \
1075 } 1065 }
1076 1066
1077#define AddIfShort(Old,New,Type) if (Old != New) {\ 1067#define AddIfShort(Old,New,Type) if (Old != New) {\
1078 Old = New; \ 1068 Old = New; \
1079 SockList_AddChar(&sl, Type); \ 1069 sl << uint8 (Type) << uint16 (New); \
1080 SockList_AddShort(&sl, New); \
1081 } 1070 }
1082 1071
1083#define AddIfFloat(Old,New,Type) if (Old != New) {\ 1072#define AddIfFloat(Old,New,Type) if (Old != New) {\
1084 Old = New; \ 1073 Old = New; \
1085 SockList_AddChar(&sl, Type); \ 1074 sl << uint8 (Type) << uint32 (New*FLOAT_MULTI); \
1086 SockList_AddInt(&sl,(long)(New*FLOAT_MULTI));\
1087 } 1075 }
1088 1076
1089#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\ 1077#define AddIfString(Old,New,Type) if (Old == NULL || strcmp(Old,New)) {\
1090 if (Old) free(Old);\
1091 Old = strdup_local(New);\ 1078 free(Old); Old = strdup (New);\
1092 SockList_AddChar(&sl, Type); \ 1079 sl << uint8 (Type) << data8 (New); \
1093 SockList_AddChar(&sl, ( char )strlen(New)); \
1094 strcpy((char*)sl.buf + sl.len, New); \
1095 sl.len += strlen(New); \
1096 } 1080 }
1097 1081
1098/** 1082/**
1099 * Sends a statistics update. We look at the old values, 1083 * Sends a statistics update. We look at the old values,
1100 * 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
1102 * commands for now. 1086 * commands for now.
1103 */ 1087 */
1104void 1088void
1105esrv_update_stats (player *pl) 1089esrv_update_stats (player *pl)
1106{ 1090{
1107 SockList sl;
1108 char buf[MAX_BUF]; 1091 char buf[MAX_BUF];
1109 uint16 flags; 1092 uint16 flags;
1110 1093
1111 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1094 packet sl;
1112 strcpy ((char *) sl.buf, "stats "); 1095 sl << "stats ";
1113 sl.len = strlen ((char *) sl.buf);
1114 1096
1115 if (pl->ob != NULL) 1097 if (pl->ob != NULL)
1116 { 1098 {
1117 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);
1118 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);
1135 1117
1136 for (s = 0; s < NUM_SKILLS; s++) 1118 for (s = 0; s < NUM_SKILLS; s++)
1137 { 1119 {
1138 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)
1139 { 1121 {
1140
1141 /* Always send along the level if exp changes. This is only 1122 /* Always send along the level if exp changes. This is only
1142 * 1 extra byte, but keeps processing simpler. 1123 * 1 extra byte, but keeps processing simpler.
1143 */ 1124 */
1144 SockList_AddChar (&sl, (char) (s + CS_STAT_SKILLINFO)); 1125 sl << uint8 (s + CS_STAT_SKILLINFO)
1145 SockList_AddChar (&sl, (char) pl->last_skill_ob[s]->level); 1126 << uint8 (pl->last_skill_ob[s]->level)
1146 SockList_AddInt64 (&sl, pl->last_skill_ob[s]->stats.exp); 1127 << uint64 (pl->last_skill_ob[s]->stats.exp);
1128
1147 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;
1148 } 1130 }
1149 } 1131 }
1150 } 1132 }
1151 1133
1199 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); 1181 AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE);
1200 set_title (pl->ob, buf); 1182 set_title (pl->ob, buf);
1201 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); 1183 AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE);
1202 1184
1203 /* Only send it away if we have some actual data */ 1185 /* Only send it away if we have some actual data */
1204 if (sl.len > 6) 1186 if (sl.length () > 6)
1205 {
1206#ifdef ESRV_DEBUG
1207 LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len);
1208#endif
1209 Send_With_Handling (&pl->socket, &sl); 1187 Send_With_Handling (&pl->socket, &sl);
1210 }
1211
1212 free (sl.buf);
1213} 1188}
1214 1189
1215/** 1190/**
1216 * 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.
1217 */ 1192 */
1218void 1193void
1219esrv_new_player (player *pl, uint32 weight) 1194esrv_new_player (player *pl, uint32 weight)
1220{ 1195{
1221 SockList sl;
1222
1223 pl->last_weight = weight; 1196 pl->last_weight = weight;
1224 1197
1225 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1198 packet sl;
1199 sl << "player ";
1226 1200
1227 strcpy ((char *) sl.buf, "player "); 1201 sl << uint32 (pl->ob->count)
1228 sl.len = strlen ((char *) sl.buf); 1202 << uint32 (weight)
1229 SockList_AddInt (&sl, pl->ob->count); 1203 << uint32 (pl->ob->face->number)
1230 SockList_AddInt (&sl, weight); 1204 << data8 (pl->ob->name);
1231 SockList_AddInt (&sl, pl->ob->face->number);
1232
1233 SockList_AddChar (&sl, (char) strlen (pl->ob->name));
1234 strcpy ((char *) sl.buf + sl.len, pl->ob->name);
1235 sl.len += strlen (pl->ob->name);
1236 1205
1237 Send_With_Handling (&pl->socket, &sl); 1206 Send_With_Handling (&pl->socket, &sl);
1238 free (sl.buf);
1239 SET_FLAG (pl->ob, FLAG_CLIENT_SENT); 1207 SET_FLAG (pl->ob, FLAG_CLIENT_SENT);
1240} 1208}
1241 1209
1242/** 1210/**
1243 * Need to send an animation sequence to the client. 1211 * Need to send an animation sequence to the client.
1247 * when the player logs in and picks stuff up. 1215 * when the player logs in and picks stuff up.
1248 */ 1216 */
1249void 1217void
1250esrv_send_animation (NewSocket * ns, short anim_num) 1218esrv_send_animation (NewSocket * ns, short anim_num)
1251{ 1219{
1252 SockList sl;
1253 int i; 1220 int i;
1254 1221
1255 /* 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
1256 * 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
1257 * range, it must be a valid animation. 1224 * range, it must be a valid animation.
1260 { 1227 {
1261 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);
1262 return; 1229 return;
1263 } 1230 }
1264 1231
1265 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1232 packet sl;
1266 strcpy ((char *) sl.buf, "anim "); 1233
1267 sl.len = 5; 1234 sl << "anim "
1268 SockList_AddShort (&sl, anim_num); 1235 << uint16 (anim_num)
1269 SockList_AddShort (&sl, 0); /* flags - not used right now */ 1236 << uint16 (0); /* flags - not used right now */
1237
1270 /* 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
1271 * the face itself) down to the client. 1239 * the face itself) down to the client.
1272 */ 1240 */
1273 for (i = 0; i < animations[anim_num].num_animations; i++) 1241 for (i = 0; i < animations[anim_num].num_animations; i++)
1274 { 1242 {
1275 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))
1276 esrv_send_face (ns, animations[anim_num].faces[i], 0); 1244 esrv_send_face (ns, animations[anim_num].faces[i], 0);
1277 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 */
1278 } 1246 }
1247
1279 Send_With_Handling (ns, &sl); 1248 Send_With_Handling (ns, &sl);
1280 free (sl.buf); 1249
1281 ns->anims_sent[anim_num] = 1; 1250 ns->anims_sent[anim_num] = 1;
1282} 1251}
1283 1252
1284 1253
1285/****************************************************************************** 1254/******************************************************************************
1299 { 1268 {
1300 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);
1301 return; 1270 return;
1302 abort (); 1271 abort ();
1303 } 1272 }
1273
1304 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;
1305 newmap->cells[x][y].count++; 1275 newmap->cells[x][y].count++;
1276
1306 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) 1277 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE))
1307 esrv_send_face (ns, face_num, 0); 1278 esrv_send_face (ns, face_num, 0);
1308} 1279}
1309 1280
1310struct LayerCell 1281struct LayerCell
1412 *fcur = *fcur | 128; /* mark for end of faces at this layer */ 1383 *fcur = *fcur | 128; /* mark for end of faces at this layer */
1413 } 1384 }
1414 return cur; 1385 return cur;
1415} 1386}
1416 1387
1417static void
1418esrv_map_doneredraw (NewSocket * ns, struct Map *newmap)
1419{
1420 static long frames, bytes, tbytes, tframes;
1421 char *cur;
1422 SockList sl;
1423
1424
1425 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1426 strcpy ((char *) sl.buf, "map ");
1427 sl.len = strlen ((char *) sl.buf);
1428
1429 cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap);
1430 sl.len = cur - (char *) sl.buf;
1431
1432/* LOG(llevDebug, "Sending map command.\n");*/
1433
1434 if (sl.len > (int) strlen ("map ") || ns->sent_scroll)
1435 {
1436 /* All of this is just accounting stuff */
1437 if (tframes > 100)
1438 tframes = tbytes = 0;
1439
1440 tframes++;
1441 frames++;
1442 tbytes += sl.len;
1443 bytes += sl.len;
1444 memcpy (&ns->lastmap, newmap, sizeof (struct Map));
1445 Send_With_Handling (ns, &sl);
1446 ns->sent_scroll = 0;
1447 }
1448
1449 free (sl.buf);
1450}
1451
1452
1453/** Clears a map cell */ 1388/** Clears a map cell */
1454static void 1389static void
1455map_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)
1456{ 1391{
1457 cell->faces[0] = face0; 1392 cell->faces[0] = face0;
1496 * 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
1497 * 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
1498 * sent, it returns zero. 1433 * sent, it returns zero.
1499 */ 1434 */
1500static int 1435static int
1501check_head (SockList & sl, NewSocket & ns, int ax, int ay, int layer) 1436check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer)
1502{ 1437{
1503 short face_num; 1438 short face_num;
1504 1439
1505 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1440 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1506 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;
1507 else 1442 else
1508 face_num = 0; 1443 face_num = 0;
1509 1444
1510 if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) 1445 if (face_num != ns.lastmap.cells[ax][ay].faces[layer])
1511 { 1446 {
1512 SockList_AddShort (&sl, face_num); 1447 sl << uint16 (face_num);
1513 if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) 1448 if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE))
1514 esrv_send_face (&ns, face_num, 0); 1449 esrv_send_face (&ns, face_num, 0);
1450
1515 heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; 1451 heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL;
1516 ns.lastmap.cells[ax][ay].faces[layer] = face_num; 1452 ns.lastmap.cells[ax][ay].faces[layer] = face_num;
1517 return 1; 1453 return 1;
1518 } 1454 }
1519 1455
1539 * 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
1540 * actually match. 1476 * actually match.
1541 */ 1477 */
1542 1478
1543static int 1479static int
1544update_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)
1545{ 1481{
1546 object *ob, *head; 1482 object *ob, *head;
1547 uint16 face_num; 1483 uint16 face_num;
1548 int bx, by, i; 1484 int bx, by, i;
1549 1485
1550 /* 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.
1551 * If not, then do the normal processing. 1487 * If not, then do the normal processing.
1552 */ 1488 */
1553
1554 head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer]; 1489 head = heads[(sy * MAX_HEAD_POS + sx) * MAX_LAYERS + layer];
1555 1490
1556 /* 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
1557 * we would normally send for this space. If so, then 1492 * we would normally send for this space. If so, then
1558 * 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
1723 1658
1724 /* 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
1725 * 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
1726 * this one. 1661 * this one.
1727 */ 1662 */
1728 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)
1729 {
1730 face_num = 0; 1664 face_num = 0;
1731 }
1732 1665
1733 /* 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
1734 * 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.
1735 */ 1668 */
1736 if (ns->lastmap.cells[sx][sy].faces[layer] != face_num) 1669 if (ns.lastmap.cells[sx][sy].faces[layer] != face_num)
1737 { 1670 {
1738 ns->lastmap.cells[sx][sy].faces[layer] = face_num; 1671 ns.lastmap.cells[sx][sy].faces[layer] = face_num;
1739 if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) 1672 if (!(ns.faces_sent[face_num] & NS_FACESENT_FACE))
1740 esrv_send_face (ns, face_num, 0); 1673 esrv_send_face (&ns, face_num, 0);
1741 SockList_AddShort (sl, face_num); 1674
1675 sl << uint16 (face_num);
1742 return 1; 1676 return 1;
1743 } 1677 }
1678
1744 /* Nothing changed */ 1679 /* Nothing changed */
1745 return 0; 1680 return 0;
1746} 1681}
1747 1682
1748/** 1683/**
1763 * 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
1764 * take. 1699 * take.
1765 */ 1700 */
1766 1701
1767static inline int 1702static inline int
1768update_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)
1769{ 1704{
1770 object *ob; 1705 object *ob;
1771 int smoothlevel; /* old face_num; */ 1706 int smoothlevel; /* old face_num; */
1772 1707
1773 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1708 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1778 if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp)) 1713 if (!ob || ob->face == blank_face || MAP_NOSMOOTH (mp))
1779 smoothlevel = 0; 1714 smoothlevel = 0;
1780 else 1715 else
1781 { 1716 {
1782 smoothlevel = ob->smoothlevel; 1717 smoothlevel = ob->smoothlevel;
1783 if (smoothlevel && !(ns->faces_sent[ob->face->number] & NS_FACESENT_SMOOTH)) 1718 if (smoothlevel && !(ns.faces_sent[ob->face->number] & NS_FACESENT_SMOOTH))
1784 SendSmooth (ns, ob->face->number); 1719 SendSmooth (&ns, ob->face->number);
1785 } /* else not already head object or blank face */ 1720 } /* else not already head object or blank face */
1786 1721
1787 /* 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
1788 * 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.
1789 */ 1724 */
1790 if (smoothlevel > 255) 1725 if (smoothlevel > 255)
1791 smoothlevel = 255; 1726 smoothlevel = 255;
1792 else if (smoothlevel < 0) 1727 else if (smoothlevel < 0)
1793 smoothlevel = 0; 1728 smoothlevel = 0;
1729
1794 if (ns->lastmap.cells[sx][sy].smooth[layer] != smoothlevel) 1730 if (ns.lastmap.cells[sx][sy].smooth[layer] != smoothlevel)
1795 { 1731 {
1796 ns->lastmap.cells[sx][sy].smooth[layer] = smoothlevel; 1732 ns.lastmap.cells[sx][sy].smooth[layer] = smoothlevel;
1797 SockList_AddChar (sl, (uint8) (smoothlevel & 0xFF)); 1733 sl << uint8 (smoothlevel);
1798 return 1; 1734 return 1;
1799 } 1735 }
1736
1800 /* Nothing changed */ 1737 /* Nothing changed */
1801 return 0; 1738 return 0;
1802} 1739}
1803 1740
1804/** 1741/**
1845draw_client_map1 (object *pl) 1782draw_client_map1 (object *pl)
1846{ 1783{
1847 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;
1848 sint16 nx, ny; 1785 sint16 nx, ny;
1849 int estartlen, eoldlen; 1786 int estartlen, eoldlen;
1850 SockList sl;
1851 SockList esl; /*For extended Map info */
1852 uint16 mask, emask; 1787 uint16 mask, emask;
1853 uint8 eentrysize; 1788 uint8 eentrysize;
1854 uint16 ewhatstart, ewhatflag; 1789 uint16 ewhatstart, ewhatflag;
1855 uint8 extendedinfos; 1790 uint8 extendedinfos;
1856 maptile *m; 1791 maptile *m;
1857 1792
1858 NewSocket & socket = pl->contr->socket; 1793 NewSocket &socket = pl->contr->socket;
1859 1794
1860 check_map_change (pl->contr); 1795 check_map_change (pl->contr);
1861 1796
1862 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 1797 packet sl;
1863 if (socket.mapmode == Map1Cmd) 1798 packet esl;
1864 strcpy ((char *) sl.buf, "map1 "); 1799
1865 else 1800 sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a ");
1866 strcpy ((char *) sl.buf, "map1a ");
1867 sl.len = strlen ((char *) sl.buf);
1868 startlen = sl.len; 1801 startlen = sl.length ();
1869 1802
1870 /*Extendedmapinfo structure initialisation */ 1803 /*Extendedmapinfo structure initialisation */
1871 if (socket.ext_mapinfos) 1804 if (socket.ext_mapinfos)
1872 { 1805 {
1873 esl.buf = (unsigned char *) malloc (MAXSOCKBUF);
1874 strcpy ((char *) esl.buf, "mapextended ");
1875 esl.len = strlen ((char *) esl.buf);
1876 extendedinfos = EMI_NOREDRAW; 1806 extendedinfos = EMI_NOREDRAW;
1877 1807
1878 if (socket.EMI_smooth) 1808 if (socket.EMI_smooth)
1879 extendedinfos |= EMI_SMOOTH; 1809 extendedinfos |= EMI_SMOOTH;
1880 1810
1881 ewhatstart = esl.len; 1811 ewhatstart = esl.length ();
1882 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit 1812 ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit
1883 could need to be taken away */ 1813 could need to be taken away */
1884 SockList_AddChar (&esl, extendedinfos);
1885 eentrysize = getExtendedMapInfoSize (&socket); 1814 eentrysize = getExtendedMapInfoSize (&socket);
1886 SockList_AddChar (&esl, eentrysize); 1815 esl << "mapextended "
1816 << uint8 (extendedinfos)
1817 << uint8 (eentrysize);
1818
1887 estartlen = esl.len; 1819 estartlen = esl.length ();
1888 } 1820 }
1889 else 1821 else
1890 { 1822 {
1891 /* suppress compiler warnings */ 1823 /* suppress compiler warnings */
1892 ewhatstart = 0; 1824 ewhatstart = 0;
1930 */ 1862 */
1931 if (ax >= socket.mapx || ay >= socket.mapy) 1863 if (ax >= socket.mapx || ay >= socket.mapy)
1932 { 1864 {
1933 int i, got_one; 1865 int i, got_one;
1934 1866
1935 oldlen = sl.len; 1867 oldlen = sl.length ();
1936 1868
1937 SockList_AddShort (&sl, mask); 1869 sl << uint16 (mask);
1938 1870
1939 if (check_head (sl, socket, ax, ay, 2)) 1871 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4;
1940 mask |= 0x4;
1941 if (check_head (sl, socket, ax, ay, 1)) 1872 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2;
1942 mask |= 0x2;
1943 if (check_head (sl, socket, ax, ay, 0)) 1873 if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1;
1944 mask |= 0x1;
1945 1874
1946 /* 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
1947 * actually need to send that - just the coordinates 1876 * actually need to send that - just the coordinates
1948 * with no faces tells the client to blank out the 1877 * with no faces tells the client to blank out the
1949 * space. 1878 * space.
1950 */ 1879 */
1951 got_one = 0; 1880 got_one = 0;
1952 for (i = oldlen + 2; i < sl.len; i++) 1881 for (i = oldlen + 2; i < sl.length (); i++)
1953 if (sl.buf[i]) 1882 if (sl.buf[i])
1954 got_one = 1; 1883 got_one = 1;
1955 1884
1956 if (got_one && (mask & 0xf)) 1885 if (got_one && (mask & 0xf))
1957 sl.buf[oldlen + 1] = mask & 0xff; 1886 sl.buf[oldlen + 1] = mask & 0xff;
1958 else 1887 else
1959 { /*either all faces blank, either no face at all */ 1888 { /*either all faces blank, either no face at all */
1960 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 */
1961 sl.len = oldlen + 2; 1890 sl.reset (oldlen + 2);
1962 else 1891 else
1963 sl.len = oldlen; 1892 sl.reset (oldlen);
1964 } 1893 }
1965 1894
1966 /*What concerns extendinfos, nothing to be done for now 1895 /*What concerns extendinfos, nothing to be done for now
1967 * (perhaps effects layer later) 1896 * (perhaps effects layer later)
1968 */ 1897 */
1986 * 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
1987 * of the map, it shouldn't have a head 1916 * of the map, it shouldn't have a head
1988 */ 1917 */
1989 if (lastcell.count != -1) 1918 if (lastcell.count != -1)
1990 { 1919 {
1991 SockList_AddShort (&sl, mask); 1920 sl << uint16 (mask);
1992 map_clearcell (&lastcell, 0, 0, 0, -1); 1921 map_clearcell (&lastcell, 0, 0, 0, -1);
1993 } 1922 }
1994 } 1923 }
1995 else if (d > 3) 1924 else if (d > 3)
1996 { 1925 {
1998 1927
1999 /* This block deals with spaces that are not visible for whatever 1928 /* This block deals with spaces that are not visible for whatever
2000 * reason. Still may need to send the head for this space. 1929 * reason. Still may need to send the head for this space.
2001 */ 1930 */
2002 1931
2003 oldlen = sl.len; 1932 oldlen = sl.length ();
2004 1933
2005 SockList_AddShort (&sl, mask); 1934 sl << uint16 (mask);
2006 1935
2007 if (lastcell.count != -1) 1936 if (lastcell.count != -1)
2008 need_send = 1; 1937 need_send = 1;
2009 1938
2010 count = -1; 1939 count = -1;
2011 1940
2012 if (socket.mapmode == Map1aCmd && have_head (ax, ay)) 1941 if (socket.mapmode == Map1aCmd && have_head (ax, ay))
2013 { 1942 {
2014 /* Now check to see if any heads need to be sent */ 1943 /* Now check to see if any heads need to be sent */
2015 1944
2016 if (check_head (sl, socket, ax, ay, 2)) 1945 if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4;
2017 mask |= 0x4;
2018 if (check_head (sl, socket, ax, ay, 1)) 1946 if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2;
2019 mask |= 0x2;
2020 if (check_head (sl, socket, ax, ay, 0)) 1947 if (check_head (sl, socket, ax, ay, 0)) mask |= 0x1;
2021 mask |= 0x1;
2022 1948
2023 lastcell.count = count; 1949 lastcell.count = count;
2024 } 1950 }
2025 else 1951 else
2026 { 1952 {
2033 } 1959 }
2034 1960
2035 if ((mask & 0xf) || need_send) 1961 if ((mask & 0xf) || need_send)
2036 sl.buf[oldlen + 1] = mask & 0xff; 1962 sl.buf[oldlen + 1] = mask & 0xff;
2037 else 1963 else
2038 sl.len = oldlen; 1964 sl.reset (oldlen);
2039 } 1965 }
2040 else 1966 else
2041 { 1967 {
2042 /* 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
2043 * we need to send. 1969 * we need to send.
2045 1971
2046 /* Rather than try to figure out what everything that we might 1972 /* Rather than try to figure out what everything that we might
2047 * need to send is, then form the packet after that, 1973 * need to send is, then form the packet after that,
2048 * 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
2049 * 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,
2050 * 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
2051 * is done. 1977 * is done.
2052 * 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
2053 * what if anything we need to send, setting the bits, then 1979 * what if anything we need to send, setting the bits, then
2054 * doing those checks again to add the real data. 1980 * doing those checks again to add the real data.
2055 */ 1981 */
2056 oldlen = sl.len; 1982 oldlen = sl.length ();
2057 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1983 mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2058 eoldlen = esl.len; 1984 eoldlen = esl.length ();
2059 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; 1985 emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4;
2060 SockList_AddShort (&sl, mask); 1986 sl << uint16 (mask);
2061 1987
2062 if (socket.ext_mapinfos) 1988 if (socket.ext_mapinfos)
2063 SockList_AddShort (&esl, emask); 1989 esl << uint16 (emask);
2064 1990
2065 unsigned char dummy; 1991 unsigned char dummy;
2066 unsigned char *last_ext = &dummy; 1992 unsigned char *last_ext = &dummy;
2067 1993
2068 /* Darkness changed */ 1994 /* Darkness changed */
2071 mask |= 0x8; 1997 mask |= 0x8;
2072 1998
2073 if (socket.extmap) 1999 if (socket.extmap)
2074 { 2000 {
2075 *last_ext |= 0x80; 2001 *last_ext |= 0x80;
2076 last_ext = sl.buf + sl.len; 2002 last_ext = sl.buf + sl.length ();
2077 SockList_AddChar (&sl, d); 2003 sl << uint8 (d);
2078 } 2004 }
2079 else 2005 else
2080 SockList_AddChar (&sl, 255 - 64 * d); 2006 sl << uint8 (255 - 64 * d);
2081 } 2007 }
2082 2008
2083 lastcell.count = d; 2009 lastcell.count = d;
2084 2010
2085 if (socket.extmap) 2011 if (socket.extmap)
2115 { 2041 {
2116 lastcell.stat_hp = stat_hp; 2042 lastcell.stat_hp = stat_hp;
2117 2043
2118 mask |= 0x8; 2044 mask |= 0x8;
2119 *last_ext |= 0x80; 2045 *last_ext |= 0x80;
2120 last_ext = sl.buf + sl.len; 2046 last_ext = sl.buf + sl.length ();
2121 2047
2122 sl << uint8 (5) << uint8 (stat_hp); 2048 sl << uint8 (5) << uint8 (stat_hp);
2123 2049
2124 if (stat_width > 1) 2050 if (stat_width > 1)
2125 { 2051 {
2126 *last_ext |= 0x80; 2052 *last_ext |= 0x80;
2127 last_ext = sl.buf + sl.len; 2053 last_ext = sl.buf + sl.length ();
2128 2054
2129 sl << uint8 (6) << uint8 (stat_width); 2055 sl << uint8 (6) << uint8 (stat_width);
2130 } 2056 }
2131 } 2057 }
2132 2058
2134 { 2060 {
2135 lastcell.player = player; 2061 lastcell.player = player;
2136 2062
2137 mask |= 0x8; 2063 mask |= 0x8;
2138 *last_ext |= 0x80; 2064 *last_ext |= 0x80;
2139 last_ext = sl.buf + sl.len; 2065 last_ext = sl.buf + sl.length ();
2140 2066
2141 sl << uint8 (0x47) << uint8 (8) << (uint64)player; 2067 sl << uint8 (0x47) << uint8 (8) << (uint64)player;
2142 } 2068 }
2143 2069
2144 if (lastcell.flags != flags) 2070 if (lastcell.flags != flags)
2145 { 2071 {
2146 lastcell.flags = flags; 2072 lastcell.flags = flags;
2147 2073
2148 mask |= 0x8; 2074 mask |= 0x8;
2149 *last_ext |= 0x80; 2075 *last_ext |= 0x80;
2150 last_ext = sl.buf + sl.len; 2076 last_ext = sl.buf + sl.length ();
2151 2077
2152 sl << uint8 (8) << uint8 (flags); 2078 sl << uint8 (8) << uint8 (flags);
2153 } 2079 }
2154 } 2080 }
2155 2081
2156 /* Floor face */ 2082 /* Floor face */
2157 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 2)) 2083 if (update_space (sl, socket, m, nx, ny, ax, ay, 2))
2158 mask |= 0x4; 2084 mask |= 0x4;
2159 2085
2160 if (socket.EMI_smooth) 2086 if (socket.EMI_smooth)
2161 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 2)) 2087 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 2))
2162 emask |= 0x4; 2088 emask |= 0x4;
2163 2089
2164 /* Middle face */ 2090 /* Middle face */
2165 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 1)) 2091 if (update_space (sl, socket, m, nx, ny, ax, ay, 1))
2166 mask |= 0x2; 2092 mask |= 0x2;
2167 2093
2168 if (socket.EMI_smooth) 2094 if (socket.EMI_smooth)
2169 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 1)) 2095 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 1))
2170 emask |= 0x2; 2096 emask |= 0x2;
2171 2097
2172 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))
2173 { 2099 {
2174 if (lastcell.faces[0] != pl->face->number) 2100 if (lastcell.faces[0] != pl->face->number)
2183 } 2109 }
2184 } 2110 }
2185 else 2111 else
2186 { 2112 {
2187 /* Top face */ 2113 /* Top face */
2188 if (update_space (&sl, &socket, m, nx, ny, ax, ay, 0)) 2114 if (update_space (sl, socket, m, nx, ny, ax, ay, 0))
2189 mask |= 0x1; 2115 mask |= 0x1;
2190 2116
2191 if (socket.EMI_smooth) 2117 if (socket.EMI_smooth)
2192 if (update_smooth (&esl, &socket, m, nx, ny, ax, ay, 0)) 2118 if (update_smooth (esl, socket, m, nx, ny, ax, ay, 0))
2193 emask |= 0x1; 2119 emask |= 0x1;
2194 } 2120 }
2195 2121
2196 /* 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
2197 * space by checking the mask. If so, update the mask. 2123 * space by checking the mask. If so, update the mask.
2199 * value, so we don't send those bits. 2125 * value, so we don't send those bits.
2200 */ 2126 */
2201 if (mask & 0xf) 2127 if (mask & 0xf)
2202 sl.buf[oldlen + 1] = mask & 0xff; 2128 sl.buf[oldlen + 1] = mask & 0xff;
2203 else 2129 else
2204 sl.len = oldlen; 2130 sl.reset (oldlen);
2205 2131
2206 if (emask & 0xf) 2132 if (emask & 0xf)
2207 esl.buf[eoldlen + 1] = emask & 0xff; 2133 esl.buf[eoldlen + 1] = emask & 0xff;
2208 else 2134 else
2209 esl.len = eoldlen; 2135 esl.reset (eoldlen);
2210 } /* else this is a viewable space */ 2136 } /* else this is a viewable space */
2211 } /* for x loop */ 2137 } /* for x loop */
2212 } /* for y loop */ 2138 } /* for y loop */
2213 2139
2214 /* Verify that we in fact do need to send this */ 2140 /* Verify that we in fact do need to send this */
2215 if (socket.ext_mapinfos) 2141 if (socket.ext_mapinfos)
2216 { 2142 {
2217 if (!(sl.len > startlen || socket.sent_scroll)) 2143 if (!(sl.length () > startlen || socket.sent_scroll))
2218 { 2144 {
2219 /* No map data will follow, so don't say the client 2145 /* No map data will follow, so don't say the client
2220 * it doesn't need draw! 2146 * it doesn't need draw!
2221 */ 2147 */
2222 ewhatflag &= (~EMI_NOREDRAW); 2148 ewhatflag &= (~EMI_NOREDRAW);
2223 esl.buf[ewhatstart + 1] = ewhatflag & 0xff; 2149 esl.buf[ewhatstart + 1] = ewhatflag & 0xff;
2224 } 2150 }
2225 2151
2226 if (esl.len > estartlen) 2152 if (esl.length () > estartlen)
2227 Send_With_Handling (&socket, &esl); 2153 Send_With_Handling (&socket, &esl);
2228
2229 free (esl.buf);
2230 } 2154 }
2231 2155
2232 if (sl.len > startlen || socket.sent_scroll) 2156 if (sl.length () > startlen || socket.sent_scroll)
2233 { 2157 {
2234 Send_With_Handling (&socket, &sl); 2158 Send_With_Handling (&socket, &sl);
2235 socket.sent_scroll = 0; 2159 socket.sent_scroll = 0;
2236 } 2160 }
2237
2238 free (sl.buf);
2239} 2161}
2240 2162
2241/** 2163/**
2242 * Draws client map. 2164 * Draws client map.
2243 */ 2165 */
2294 { 2216 {
2295 update_los (pl); 2217 update_los (pl);
2296 pl->contr->do_los = 0; 2218 pl->contr->do_los = 0;
2297 } 2219 }
2298 2220
2299 if (pl->contr->socket.mapmode == Map1Cmd || pl->contr->socket.mapmode == Map1aCmd)
2300 {
2301 /* Big maps need a different drawing mechanism to work */ 2221 /* Big maps need a different drawing mechanism to work */
2302 draw_client_map1 (pl); 2222 draw_client_map1 (pl);
2303 return;
2304 }
2305
2306 if (pl->invisible & (pl->invisible < 50 ? 4 : 1))
2307 {
2308 esrv_map_setbelow (&pl->contr->socket, pl->contr->socket.mapx / 2, pl->contr->socket.mapy / 2, pl->face->number, &newmap);
2309 }
2310
2311 /* j and i are the y and x coordinates of the real map (which is
2312 * basically some number of spaces around the player)
2313 * ax and ay are values from within the viewport (ie, 0, 0 is upper
2314 * left corner) and are thus disconnected from the map values.
2315 * Subtract 1 from the max values so that we properly handle cases where
2316 * player has specified an even map. Otherwise, we try to send them too
2317 * much, ie, if mapx is 10, we would try to send from -5 to 5, which is actually
2318 * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is
2319 * odd, this still works fine.
2320 */
2321 ay = 0;
2322 for (j = pl->y - pl->contr->socket.mapy / 2; j <= pl->y + (pl->contr->socket.mapy - 1) / 2; j++, ay++)
2323 {
2324 ax = 0;
2325 for (i = pl->x - pl->contr->socket.mapx / 2; i <= pl->x + (pl->contr->socket.mapx - 1) / 2; i++, ax++)
2326 {
2327
2328 d = pl->contr->blocked_los[ax][ay];
2329 /* note the out_of_map and d>3 checks are both within the same
2330 * negation check.
2331 */
2332 nx = i;
2333 ny = j;
2334 m = get_map_from_coord (pm, &nx, &ny);
2335 if (m && d < 4)
2336 {
2337 face = GET_MAP_FACE (m, nx, ny, 0);
2338 floor2 = GET_MAP_FACE (m, nx, ny, 1);
2339 floor = GET_MAP_FACE (m, nx, ny, 2);
2340
2341 /* If all is blank, send a blank face. */
2342 if ((!face || face == blank_face) && (!floor2 || floor2 == blank_face) && (!floor || floor == blank_face))
2343 {
2344 esrv_map_setbelow (&pl->contr->socket, ax, ay, blank_face->number, &newmap);
2345 }
2346 else
2347 { /* actually have something interesting */
2348 /* send the darkness mask, if any. */
2349 if (d && pl->contr->socket.darkness)
2350 esrv_map_setbelow (&pl->contr->socket, ax, ay, dark_faces[d - 1]->number, &newmap);
2351
2352 if (face && face != blank_face)
2353 esrv_map_setbelow (&pl->contr->socket, ax, ay, face->number, &newmap);
2354 if (floor2 && floor2 != blank_face)
2355 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor2->number, &newmap);
2356 if (floor && floor != blank_face)
2357 esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap);
2358 }
2359 } /* Is a valid space */
2360 }
2361 }
2362 esrv_map_doneredraw (&pl->contr->socket, &newmap);
2363
2364 check_map_change (pl->contr);
2365} 2223}
2366 2224
2367 2225
2368/*****************************************************************************/ 2226/*****************************************************************************/
2369 2227
2375 2233
2376/*****************************************************************************/ 2234/*****************************************************************************/
2377void 2235void
2378send_plugin_custom_message (object *pl, char *buf) 2236send_plugin_custom_message (object *pl, char *buf)
2379{ 2237{
2380 cs_write_string (&pl->contr->socket, buf, strlen (buf)); 2238 pl->contr->socket.send_packet (buf);
2381} 2239}
2382 2240
2383/** 2241/**
2384 * This sends the skill number to name mapping. We ignore 2242 * This sends the skill number to name mapping. We ignore
2385 * the params - we always send the same info no matter what. 2243 * the params - we always send the same info no matter what.
2386 */ 2244 */
2387void 2245void
2388send_skill_info (NewSocket * ns, char *params) 2246send_skill_info (NewSocket *ns, char *params)
2389{ 2247{
2390 SockList sl; 2248 packet sl;
2391 int i; 2249 sl << "replyinfo skill_info\n";
2392 2250
2393 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2394 strcpy ((char *) sl.buf, "replyinfo skill_info\n");
2395 for (i = 1; i < NUM_SKILLS; i++) 2251 for (int i = 1; i < NUM_SKILLS; i++)
2396 { 2252 sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]);
2397 sprintf ((char *) sl.buf + strlen ((char *) sl.buf), "%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); 2253
2398 }
2399 sl.len = strlen ((char *) sl.buf);
2400 if (sl.len >= MAXSOCKBUF) 2254 if (sl.length () >= MAXSOCKBUF)
2401 { 2255 {
2402 LOG (llevError, "Buffer overflow in send_skill_info!\n"); 2256 LOG (llevError, "Buffer overflow in send_skill_info!\n");
2403 fatal (0); 2257 fatal (0);
2404 } 2258 }
2259
2405 Send_With_Handling (ns, &sl); 2260 Send_With_Handling (ns, &sl);
2406 free (sl.buf);
2407} 2261}
2408 2262
2409/** 2263/**
2410 * This sends the spell path to name mapping. We ignore 2264 * This sends the spell path to name mapping. We ignore
2411 * the params - we always send the same info no matter what. 2265 * the params - we always send the same info no matter what.
2412 */ 2266 */
2413void 2267void
2414send_spell_paths (NewSocket * ns, char *params) 2268send_spell_paths (NewSocket * ns, char *params)
2415{ 2269{
2416 SockList sl; 2270 packet sl;
2417 int i;
2418 2271
2419 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2272 sl << "replyinfo spell_paths\n";
2420 strcpy ((char *) sl.buf, "replyinfo spell_paths\n"); 2273
2421 for (i = 0; i < NRSPELLPATHS; i++) 2274 for (int i = 0; i < NRSPELLPATHS; i++)
2422 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]);
2423 sl.len = strlen ((char *) sl.buf); 2276
2424 if (sl.len >= MAXSOCKBUF) 2277 if (sl.length () >= MAXSOCKBUF)
2425 { 2278 {
2426 LOG (llevError, "Buffer overflow in send_spell_paths!\n"); 2279 LOG (llevError, "Buffer overflow in send_spell_paths!\n");
2427 fatal (0); 2280 fatal (0);
2428 } 2281 }
2282
2429 Send_With_Handling (ns, &sl); 2283 Send_With_Handling (ns, &sl);
2430 free (sl.buf);
2431} 2284}
2432 2285
2433/** 2286/**
2434 * 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.
2435 * 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
2436 */ 2289 */
2437void 2290void
2438esrv_update_spells (player *pl) 2291esrv_update_spells (player *pl)
2439{ 2292{
2440 SockList sl;
2441 int flags = 0;
2442 object *spell;
2443
2444 if (!pl->socket.monitor_spells) 2293 if (!pl->socket.monitor_spells)
2445 return; 2294 return;
2295
2446 for (spell = pl->ob->inv; spell != NULL; spell = spell->below) 2296 for (object *spell = pl->ob->inv; spell; spell = spell->below)
2447 { 2297 {
2448 if (spell->type == SPELL) 2298 if (spell->type == SPELL)
2449 { 2299 {
2300 int flags = 0;
2301
2450 /* check if we need to update it */ 2302 /* check if we need to update it */
2451 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))
2452 { 2304 {
2453 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);
2454 flags |= UPD_SP_MANA; 2306 flags |= UPD_SP_MANA;
2455 } 2307 }
2308
2456 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))
2457 { 2310 {
2458 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);
2459 flags |= UPD_SP_GRACE; 2312 flags |= UPD_SP_GRACE;
2460 } 2313 }
2314
2461 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))
2462 { 2316 {
2463 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);
2464 flags |= UPD_SP_DAMAGE; 2318 flags |= UPD_SP_DAMAGE;
2465 } 2319 }
2320
2466 if (flags != 0) 2321 if (flags)
2467 { 2322 {
2468 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2323 packet sl;
2469 strcpy ((char *) sl.buf, "updspell ");
2470 sl.len = strlen ((char *) sl.buf);
2471 2324
2325 sl << "updspell "
2326 << uint8 (flags)
2472 sl << uint8 (flags) << uint32 (spell->count); 2327 << uint32 (spell->count);
2473 2328
2474 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); 2329 if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp);
2475 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); 2330 if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace);
2476 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); 2331 if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat);
2477 2332
2478 flags = 0;
2479 Send_With_Handling (&pl->socket, &sl); 2333 Send_With_Handling (&pl->socket, &sl);
2480 free (sl.buf);
2481 } 2334 }
2482 } 2335 }
2483 } 2336 }
2484} 2337}
2485 2338
2486void 2339void
2487esrv_remove_spell (player *pl, object *spell) 2340esrv_remove_spell (player *pl, object *spell)
2488{ 2341{
2489 SockList sl;
2490
2491 if (!pl->socket.monitor_spells) 2342 if (!pl->socket.monitor_spells)
2492 return; 2343 return;
2344
2493 if (!pl || !spell || spell->env != pl->ob) 2345 if (!pl || !spell || spell->env != pl->ob)
2494 { 2346 {
2495 LOG (llevError, "Invalid call to esrv_remove_spell"); 2347 LOG (llevError, "Invalid call to esrv_remove_spell");
2496 return; 2348 return;
2497 } 2349 }
2498 sl.buf = (unsigned char *) malloc (MAXSOCKBUF);
2499 strcpy ((char *) sl.buf, "delspell ");
2500 sl.len = strlen ((char *) sl.buf);
2501 2350
2351 packet sl;
2352
2353 sl << "delspell "
2502 sl << uint32 (spell->count); 2354 << uint32 (spell->count);
2503 2355
2504 Send_With_Handling (&pl->socket, &sl); 2356 Send_With_Handling (&pl->socket, &sl);
2505 free (sl.buf);
2506} 2357}
2507 2358
2508/* 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. */
2509static void 2360static void
2510append_spell (player *pl, SockList &sl, object *spell) 2361append_spell (player *pl, packet &sl, object *spell)
2511{ 2362{
2512 int len, i, skill = 0; 2363 int len, i, skill = 0;
2513 2364
2514 if (!(spell->name)) 2365 if (!(spell->name))
2515 { 2366 {
2552 * all spells in the player's inventory. 2403 * all spells in the player's inventory.
2553 */ 2404 */
2554void 2405void
2555esrv_add_spells (player *pl, object *spell) 2406esrv_add_spells (player *pl, object *spell)
2556{ 2407{
2557 SockList sl;
2558
2559 if (!pl) 2408 if (!pl)
2560 { 2409 {
2561 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");
2562 return; 2411 return;
2563 } 2412 }
2413
2564 if (!pl->socket.monitor_spells) 2414 if (!pl->socket.monitor_spells)
2565 return; 2415 return;
2566 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 2416
2567 strcpy ((char *) sl.buf, "addspell "); 2417 packet sl;
2568 sl.len = strlen ((char *) sl.buf); 2418
2419 sl << "addspell ";
2420
2569 if (!spell) 2421 if (!spell)
2570 { 2422 {
2571 for (spell = pl->ob->inv; spell != NULL; spell = spell->below) 2423 for (spell = pl->ob->inv; spell != NULL; spell = spell->below)
2572 { 2424 {
2573 /* were we to simply keep appending data here, we could exceed 2425 /* were we to simply keep appending data here, we could exceed
2584 * like it will fix this 2436 * like it will fix this
2585 */ 2437 */
2586 if (spell->type != SPELL) 2438 if (spell->type != SPELL)
2587 continue; 2439 continue;
2588 2440
2589 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))))
2590 { 2442 {
2591 Send_With_Handling (&pl->socket, &sl); 2443 Send_With_Handling (&pl->socket, &sl);
2592 strcpy ((char *) sl.buf, "addspell "); 2444
2593 sl.len = strlen ((char *) sl.buf); 2445 sl.reset ();
2446 sl << "addspell ";
2594 } 2447 }
2595 2448
2596 append_spell (pl, sl, spell); 2449 append_spell (pl, sl, spell);
2597 } 2450 }
2598 } 2451 }
2602 return; 2455 return;
2603 } 2456 }
2604 else 2457 else
2605 append_spell (pl, sl, spell); 2458 append_spell (pl, sl, spell);
2606 2459
2607 if (sl.len >= MAXSOCKBUF) 2460 if (sl.length () >= MAXSOCKBUF)
2608 { 2461 {
2609 LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); 2462 LOG (llevError, "Buffer overflow in esrv_add_spells!\n");
2610 fatal (0); 2463 fatal (0);
2611 } 2464 }
2612 2465
2613 /* finally, we can send the packet */ 2466 /* finally, we can send the packet */
2614 Send_With_Handling (&pl->socket, &sl); 2467 Send_With_Handling (&pl->socket, &sl);
2615 free (sl.buf); 2468
2616} 2469}
2470

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines