… | |
… | |
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 */ |
323 | void |
320 | void |
324 | SetUp (char *buf, int len, NewSocket * ns) |
321 | SetUp (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 */ |
561 | void |
564 | void |
… | |
… | |
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 |
… | |
… | |
699 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
702 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
700 | esrv_send_face (ns, smoothface, 0); |
703 | esrv_send_face (ns, smoothface, 0); |
701 | |
704 | |
702 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
705 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
703 | |
706 | |
704 | SockList sl (MAXSOCKBUF); |
707 | packet sl; |
705 | |
708 | |
706 | sl << "smooth " |
709 | sl << "smooth " |
707 | << uint16 (face) |
710 | << uint16 (face) |
708 | << uint16 (smoothface); |
711 | << uint16 (smoothface); |
709 | |
712 | |
710 | Send_With_Handling (ns, &sl); |
713 | Send_With_Handling (ns, &sl); |
711 | sl.free (); |
|
|
712 | } |
714 | } |
713 | |
715 | |
714 | /** |
716 | /** |
715 | * Tells client the picture it has to use |
717 | * Tells client the picture it has to use |
716 | * to smooth a picture number given as argument. |
718 | * to smooth a picture number given as argument. |
… | |
… | |
785 | void |
787 | void |
786 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
788 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
787 | { |
789 | { |
788 | int time, repeat; |
790 | int time, repeat; |
789 | char command[MAX_BUF]; |
791 | char command[MAX_BUF]; |
790 | short packet; |
792 | int pktlen; |
791 | |
793 | |
792 | if (len < 7) |
794 | if (len < 7) |
793 | { |
795 | { |
794 | 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); |
795 | return; |
797 | return; |
796 | } |
798 | } |
797 | |
799 | |
798 | packet = GetShort_String (buf); |
800 | pktlen = net_uint16 (buf); |
799 | repeat = GetInt_String (buf + 2); |
801 | repeat = net_uint32 (buf + 2); |
|
|
802 | |
800 | /* -1 is special - no repeat, but don't update */ |
803 | /* -1 is special - no repeat, but don't update */ |
801 | if (repeat != -1) |
804 | if (repeat != -1) |
802 | pl->count = repeat; |
805 | pl->count = repeat; |
803 | |
806 | |
804 | if ((len - 4) >= MAX_BUF) |
807 | if ((len - 4) >= MAX_BUF) |
… | |
… | |
836 | else |
839 | else |
837 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
840 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
838 | |
841 | |
839 | /* Send confirmation of command execution now */ |
842 | /* Send confirmation of command execution now */ |
840 | |
843 | |
841 | SockList sl (MAXSOCKBUF); |
844 | packet sl; |
842 | sl << "comc " << uint16 (packet) << uint32 (time); |
845 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
843 | Send_With_Handling (&pl->socket, &sl); |
846 | Send_With_Handling (&pl->socket, &sl); |
844 | sl.free (); |
|
|
845 | } |
847 | } |
846 | |
848 | |
847 | |
849 | |
848 | /** This is a reply to a previous query. */ |
850 | /** This is a reply to a previous query. */ |
849 | void |
851 | void |
… | |
… | |
965 | */ |
967 | */ |
966 | if (ns->sc_version < 1026) |
968 | if (ns->sc_version < 1026) |
967 | { |
969 | { |
968 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
970 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
969 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
971 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
970 | Write_String_To_Socket (ns, version_warning, strlen (version_warning)); |
972 | ns->send_packet (version_warning); |
971 | } |
973 | } |
972 | |
974 | |
973 | } |
975 | } |
974 | } |
976 | } |
975 | |
977 | |
… | |
… | |
1047 | send_query (NewSocket * ns, uint8 flags, char *text) |
1049 | send_query (NewSocket * ns, uint8 flags, char *text) |
1048 | { |
1050 | { |
1049 | char buf[MAX_BUF]; |
1051 | char buf[MAX_BUF]; |
1050 | |
1052 | |
1051 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1053 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1052 | Write_String_To_Socket (ns, buf, strlen (buf)); |
1054 | ns->send_packet (buf); |
1053 | } |
1055 | } |
1054 | |
1056 | |
1055 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1057 | #define AddIfInt64(Old,New,Type) if (Old != New) {\ |
1056 | Old = New; \ |
1058 | Old = New; \ |
1057 | sl << uint8 (Type) << uint64 (New); \ |
1059 | sl << uint8 (Type) << uint64 (New); \ |
… | |
… | |
1087 | esrv_update_stats (player *pl) |
1089 | esrv_update_stats (player *pl) |
1088 | { |
1090 | { |
1089 | char buf[MAX_BUF]; |
1091 | char buf[MAX_BUF]; |
1090 | uint16 flags; |
1092 | uint16 flags; |
1091 | |
1093 | |
1092 | SockList sl (MAXSOCKBUF); |
1094 | packet sl; |
1093 | sl << "stats "; |
1095 | sl << "stats "; |
1094 | |
1096 | |
1095 | if (pl->ob != NULL) |
1097 | if (pl->ob != NULL) |
1096 | { |
1098 | { |
1097 | 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); |
… | |
… | |
1179 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1181 | AddIfString (pl->socket.stats.range, buf, CS_STAT_RANGE); |
1180 | set_title (pl->ob, buf); |
1182 | set_title (pl->ob, buf); |
1181 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1183 | AddIfString (pl->socket.stats.title, buf, CS_STAT_TITLE); |
1182 | |
1184 | |
1183 | /* Only send it away if we have some actual data */ |
1185 | /* Only send it away if we have some actual data */ |
1184 | if (sl.len > 6) |
1186 | if (sl.length () > 6) |
1185 | { |
|
|
1186 | #ifdef ESRV_DEBUG |
|
|
1187 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
|
|
1188 | #endif |
|
|
1189 | Send_With_Handling (&pl->socket, &sl); |
1187 | Send_With_Handling (&pl->socket, &sl); |
1190 | } |
|
|
1191 | |
|
|
1192 | sl.free (); |
|
|
1193 | } |
1188 | } |
1194 | |
1189 | |
1195 | /** |
1190 | /** |
1196 | * 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. |
1197 | */ |
1192 | */ |
1198 | void |
1193 | void |
1199 | esrv_new_player (player *pl, uint32 weight) |
1194 | esrv_new_player (player *pl, uint32 weight) |
1200 | { |
1195 | { |
1201 | pl->last_weight = weight; |
1196 | pl->last_weight = weight; |
1202 | |
1197 | |
1203 | SockList sl (MAXSOCKBUF); |
1198 | packet sl; |
1204 | sl << "player "; |
1199 | sl << "player "; |
1205 | |
1200 | |
1206 | sl << uint32 (pl->ob->count) |
1201 | sl << uint32 (pl->ob->count) |
1207 | << uint32 (weight) |
1202 | << uint32 (weight) |
1208 | << uint32 (pl->ob->face->number) |
1203 | << uint32 (pl->ob->face->number) |
1209 | << data8 (pl->ob->name); |
1204 | << data8 (pl->ob->name); |
1210 | |
1205 | |
1211 | Send_With_Handling (&pl->socket, &sl); |
1206 | Send_With_Handling (&pl->socket, &sl); |
1212 | sl.free (); |
|
|
1213 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1207 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1214 | } |
1208 | } |
1215 | |
1209 | |
1216 | /** |
1210 | /** |
1217 | * Need to send an animation sequence to the client. |
1211 | * Need to send an animation sequence to the client. |
… | |
… | |
1233 | { |
1227 | { |
1234 | 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); |
1235 | return; |
1229 | return; |
1236 | } |
1230 | } |
1237 | |
1231 | |
1238 | SockList sl (MAXSOCKBUF); |
1232 | packet sl; |
1239 | |
1233 | |
1240 | sl << "anim " |
1234 | sl << "anim " |
1241 | << uint16 (anim_num) |
1235 | << uint16 (anim_num) |
1242 | << uint16 (0); /* flags - not used right now */ |
1236 | << uint16 (0); /* flags - not used right now */ |
1243 | |
1237 | |
… | |
… | |
1250 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1244 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1251 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1245 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1252 | } |
1246 | } |
1253 | |
1247 | |
1254 | Send_With_Handling (ns, &sl); |
1248 | Send_With_Handling (ns, &sl); |
1255 | sl.free (); |
|
|
1256 | |
1249 | |
1257 | ns->anims_sent[anim_num] = 1; |
1250 | ns->anims_sent[anim_num] = 1; |
1258 | } |
1251 | } |
1259 | |
1252 | |
1260 | |
1253 | |
… | |
… | |
1390 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1383 | *fcur = *fcur | 128; /* mark for end of faces at this layer */ |
1391 | } |
1384 | } |
1392 | return cur; |
1385 | return cur; |
1393 | } |
1386 | } |
1394 | |
1387 | |
1395 | static void |
|
|
1396 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
|
|
1397 | { |
|
|
1398 | static long frames, bytes, tbytes, tframes; |
|
|
1399 | char *cur; |
|
|
1400 | |
|
|
1401 | SockList sl (MAXSOCKBUF); |
|
|
1402 | sl << "map "; |
|
|
1403 | |
|
|
1404 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
|
|
1405 | sl.len = cur - (char *) sl.buf; |
|
|
1406 | |
|
|
1407 | /* LOG(llevDebug, "Sending map command.\n");*/ |
|
|
1408 | |
|
|
1409 | if (sl.len > (int) strlen ("map ") || ns->sent_scroll) |
|
|
1410 | { |
|
|
1411 | /* All of this is just accounting stuff */ |
|
|
1412 | if (tframes > 100) |
|
|
1413 | tframes = tbytes = 0; |
|
|
1414 | |
|
|
1415 | tframes++; |
|
|
1416 | frames++; |
|
|
1417 | tbytes += sl.len; |
|
|
1418 | bytes += sl.len; |
|
|
1419 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
|
|
1420 | Send_With_Handling (ns, &sl); |
|
|
1421 | ns->sent_scroll = 0; |
|
|
1422 | } |
|
|
1423 | |
|
|
1424 | sl.free (); |
|
|
1425 | } |
|
|
1426 | |
|
|
1427 | |
|
|
1428 | /** Clears a map cell */ |
1388 | /** Clears a map cell */ |
1429 | static void |
1389 | static void |
1430 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1390 | map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) |
1431 | { |
1391 | { |
1432 | cell->faces[0] = face0; |
1392 | cell->faces[0] = face0; |
… | |
… | |
1471 | * 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 |
1472 | * 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 |
1473 | * sent, it returns zero. |
1433 | * sent, it returns zero. |
1474 | */ |
1434 | */ |
1475 | static int |
1435 | static int |
1476 | check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) |
1436 | check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer) |
1477 | { |
1437 | { |
1478 | short face_num; |
1438 | short face_num; |
1479 | |
1439 | |
1480 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1440 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1481 | 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; |
1482 | else |
1442 | else |
1483 | face_num = 0; |
1443 | face_num = 0; |
1484 | |
1444 | |
1485 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1445 | if (face_num != ns.lastmap.cells[ax][ay].faces[layer]) |
1486 | { |
1446 | { |
1487 | SockList_AddShort (&sl, face_num); |
1447 | sl << uint16 (face_num); |
1488 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1448 | if (face_num && !(ns.faces_sent[face_num] & NS_FACESENT_FACE)) |
1489 | esrv_send_face (&ns, face_num, 0); |
1449 | esrv_send_face (&ns, face_num, 0); |
1490 | |
1450 | |
1491 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1451 | heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer] = NULL; |
1492 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
1452 | ns.lastmap.cells[ax][ay].faces[layer] = face_num; |
… | |
… | |
1515 | * 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 |
1516 | * actually match. |
1476 | * actually match. |
1517 | */ |
1477 | */ |
1518 | |
1478 | |
1519 | static int |
1479 | static int |
1520 | update_space (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1480 | update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1521 | { |
1481 | { |
1522 | object *ob, *head; |
1482 | object *ob, *head; |
1523 | uint16 face_num; |
1483 | uint16 face_num; |
1524 | int bx, by, i; |
1484 | int bx, by, i; |
1525 | |
1485 | |
… | |
… | |
1738 | * 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 |
1739 | * take. |
1699 | * take. |
1740 | */ |
1700 | */ |
1741 | |
1701 | |
1742 | static inline int |
1702 | static inline int |
1743 | update_smooth (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1703 | update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1744 | { |
1704 | { |
1745 | object *ob; |
1705 | object *ob; |
1746 | int smoothlevel; /* old face_num; */ |
1706 | int smoothlevel; /* old face_num; */ |
1747 | |
1707 | |
1748 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1708 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1832 | |
1792 | |
1833 | NewSocket &socket = pl->contr->socket; |
1793 | NewSocket &socket = pl->contr->socket; |
1834 | |
1794 | |
1835 | check_map_change (pl->contr); |
1795 | check_map_change (pl->contr); |
1836 | |
1796 | |
1837 | SockList sl (MAXSOCKBUF); |
1797 | packet sl; |
1838 | SockList esl (MAXSOCKBUF); |
1798 | packet esl; |
1839 | |
1799 | |
1840 | sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); |
1800 | sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); |
1841 | startlen = sl.len; |
1801 | startlen = sl.length (); |
1842 | |
1802 | |
1843 | /*Extendedmapinfo structure initialisation */ |
1803 | /*Extendedmapinfo structure initialisation */ |
1844 | if (socket.ext_mapinfos) |
1804 | if (socket.ext_mapinfos) |
1845 | { |
1805 | { |
1846 | extendedinfos = EMI_NOREDRAW; |
1806 | extendedinfos = EMI_NOREDRAW; |
1847 | |
1807 | |
1848 | if (socket.EMI_smooth) |
1808 | if (socket.EMI_smooth) |
1849 | extendedinfos |= EMI_SMOOTH; |
1809 | extendedinfos |= EMI_SMOOTH; |
1850 | |
1810 | |
1851 | ewhatstart = esl.len; |
1811 | ewhatstart = esl.length (); |
1852 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1812 | ewhatflag = extendedinfos; /*The EMI_NOREDRAW bit |
1853 | could need to be taken away */ |
1813 | could need to be taken away */ |
1854 | eentrysize = getExtendedMapInfoSize (&socket); |
1814 | eentrysize = getExtendedMapInfoSize (&socket); |
1855 | esl << "mapextended " |
1815 | esl << "mapextended " |
1856 | << uint8 (extendedinfos) |
1816 | << uint8 (extendedinfos) |
1857 | << uint8 (eentrysize); |
1817 | << uint8 (eentrysize); |
|
|
1818 | |
1858 | estartlen = esl.len; |
1819 | estartlen = esl.length (); |
1859 | } |
1820 | } |
1860 | else |
1821 | else |
1861 | { |
1822 | { |
1862 | /* suppress compiler warnings */ |
1823 | /* suppress compiler warnings */ |
1863 | ewhatstart = 0; |
1824 | ewhatstart = 0; |
… | |
… | |
1901 | */ |
1862 | */ |
1902 | if (ax >= socket.mapx || ay >= socket.mapy) |
1863 | if (ax >= socket.mapx || ay >= socket.mapy) |
1903 | { |
1864 | { |
1904 | int i, got_one; |
1865 | int i, got_one; |
1905 | |
1866 | |
1906 | oldlen = sl.len; |
1867 | oldlen = sl.length (); |
1907 | |
1868 | |
1908 | sl << uint16 (mask); |
1869 | sl << uint16 (mask); |
1909 | |
1870 | |
1910 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
1871 | if (check_head (sl, socket, ax, ay, 2)) mask |= 0x4; |
1911 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
1872 | if (check_head (sl, socket, ax, ay, 1)) mask |= 0x2; |
… | |
… | |
1915 | * actually need to send that - just the coordinates |
1876 | * actually need to send that - just the coordinates |
1916 | * with no faces tells the client to blank out the |
1877 | * with no faces tells the client to blank out the |
1917 | * space. |
1878 | * space. |
1918 | */ |
1879 | */ |
1919 | got_one = 0; |
1880 | got_one = 0; |
1920 | for (i = oldlen + 2; i < sl.len; i++) |
1881 | for (i = oldlen + 2; i < sl.length (); i++) |
1921 | if (sl.buf[i]) |
1882 | if (sl.buf[i]) |
1922 | got_one = 1; |
1883 | got_one = 1; |
1923 | |
1884 | |
1924 | if (got_one && (mask & 0xf)) |
1885 | if (got_one && (mask & 0xf)) |
1925 | sl.buf[oldlen + 1] = mask & 0xff; |
1886 | sl.buf[oldlen + 1] = mask & 0xff; |
1926 | else |
1887 | else |
1927 | { /*either all faces blank, either no face at all */ |
1888 | { /*either all faces blank, either no face at all */ |
1928 | 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 */ |
1929 | sl.len = oldlen + 2; |
1890 | sl.reset (oldlen + 2); |
1930 | else |
1891 | else |
1931 | sl.len = oldlen; |
1892 | sl.reset (oldlen); |
1932 | } |
1893 | } |
1933 | |
1894 | |
1934 | /*What concerns extendinfos, nothing to be done for now |
1895 | /*What concerns extendinfos, nothing to be done for now |
1935 | * (perhaps effects layer later) |
1896 | * (perhaps effects layer later) |
1936 | */ |
1897 | */ |
… | |
… | |
1966 | |
1927 | |
1967 | /* This block deals with spaces that are not visible for whatever |
1928 | /* This block deals with spaces that are not visible for whatever |
1968 | * reason. Still may need to send the head for this space. |
1929 | * reason. Still may need to send the head for this space. |
1969 | */ |
1930 | */ |
1970 | |
1931 | |
1971 | oldlen = sl.len; |
1932 | oldlen = sl.length (); |
1972 | |
1933 | |
1973 | sl << uint16 (mask); |
1934 | sl << uint16 (mask); |
1974 | |
1935 | |
1975 | if (lastcell.count != -1) |
1936 | if (lastcell.count != -1) |
1976 | need_send = 1; |
1937 | need_send = 1; |
… | |
… | |
1998 | } |
1959 | } |
1999 | |
1960 | |
2000 | if ((mask & 0xf) || need_send) |
1961 | if ((mask & 0xf) || need_send) |
2001 | sl.buf[oldlen + 1] = mask & 0xff; |
1962 | sl.buf[oldlen + 1] = mask & 0xff; |
2002 | else |
1963 | else |
2003 | sl.len = oldlen; |
1964 | sl.reset (oldlen); |
2004 | } |
1965 | } |
2005 | else |
1966 | else |
2006 | { |
1967 | { |
2007 | /* 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 |
2008 | * we need to send. |
1969 | * we need to send. |
… | |
… | |
2010 | |
1971 | |
2011 | /* Rather than try to figure out what everything that we might |
1972 | /* Rather than try to figure out what everything that we might |
2012 | * need to send is, then form the packet after that, |
1973 | * need to send is, then form the packet after that, |
2013 | * 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 |
2014 | * 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, |
2015 | * 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 |
2016 | * is done. |
1977 | * is done. |
2017 | * 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 |
2018 | * what if anything we need to send, setting the bits, then |
1979 | * what if anything we need to send, setting the bits, then |
2019 | * doing those checks again to add the real data. |
1980 | * doing those checks again to add the real data. |
2020 | */ |
1981 | */ |
2021 | oldlen = sl.len; |
1982 | oldlen = sl.length (); |
2022 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1983 | mask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2023 | eoldlen = esl.len; |
1984 | eoldlen = esl.length (); |
2024 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
1985 | emask = (ax & 0x3f) << 10 | (ay & 0x3f) << 4; |
2025 | sl << uint16 (mask); |
1986 | sl << uint16 (mask); |
2026 | |
1987 | |
2027 | if (socket.ext_mapinfos) |
1988 | if (socket.ext_mapinfos) |
2028 | esl << uint16 (emask); |
1989 | esl << uint16 (emask); |
… | |
… | |
2036 | mask |= 0x8; |
1997 | mask |= 0x8; |
2037 | |
1998 | |
2038 | if (socket.extmap) |
1999 | if (socket.extmap) |
2039 | { |
2000 | { |
2040 | *last_ext |= 0x80; |
2001 | *last_ext |= 0x80; |
2041 | last_ext = sl.buf + sl.len; |
2002 | last_ext = sl.buf + sl.length (); |
2042 | sl << uint8 (d); |
2003 | sl << uint8 (d); |
2043 | } |
2004 | } |
2044 | else |
2005 | else |
2045 | sl << uint8 (255 - 64 * d); |
2006 | sl << uint8 (255 - 64 * d); |
2046 | } |
2007 | } |
… | |
… | |
2080 | { |
2041 | { |
2081 | lastcell.stat_hp = stat_hp; |
2042 | lastcell.stat_hp = stat_hp; |
2082 | |
2043 | |
2083 | mask |= 0x8; |
2044 | mask |= 0x8; |
2084 | *last_ext |= 0x80; |
2045 | *last_ext |= 0x80; |
2085 | last_ext = sl.buf + sl.len; |
2046 | last_ext = sl.buf + sl.length (); |
2086 | |
2047 | |
2087 | sl << uint8 (5) << uint8 (stat_hp); |
2048 | sl << uint8 (5) << uint8 (stat_hp); |
2088 | |
2049 | |
2089 | if (stat_width > 1) |
2050 | if (stat_width > 1) |
2090 | { |
2051 | { |
2091 | *last_ext |= 0x80; |
2052 | *last_ext |= 0x80; |
2092 | last_ext = sl.buf + sl.len; |
2053 | last_ext = sl.buf + sl.length (); |
2093 | |
2054 | |
2094 | sl << uint8 (6) << uint8 (stat_width); |
2055 | sl << uint8 (6) << uint8 (stat_width); |
2095 | } |
2056 | } |
2096 | } |
2057 | } |
2097 | |
2058 | |
… | |
… | |
2099 | { |
2060 | { |
2100 | lastcell.player = player; |
2061 | lastcell.player = player; |
2101 | |
2062 | |
2102 | mask |= 0x8; |
2063 | mask |= 0x8; |
2103 | *last_ext |= 0x80; |
2064 | *last_ext |= 0x80; |
2104 | last_ext = sl.buf + sl.len; |
2065 | last_ext = sl.buf + sl.length (); |
2105 | |
2066 | |
2106 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2067 | sl << uint8 (0x47) << uint8 (8) << (uint64)player; |
2107 | } |
2068 | } |
2108 | |
2069 | |
2109 | if (lastcell.flags != flags) |
2070 | if (lastcell.flags != flags) |
2110 | { |
2071 | { |
2111 | lastcell.flags = flags; |
2072 | lastcell.flags = flags; |
2112 | |
2073 | |
2113 | mask |= 0x8; |
2074 | mask |= 0x8; |
2114 | *last_ext |= 0x80; |
2075 | *last_ext |= 0x80; |
2115 | last_ext = sl.buf + sl.len; |
2076 | last_ext = sl.buf + sl.length (); |
2116 | |
2077 | |
2117 | sl << uint8 (8) << uint8 (flags); |
2078 | sl << uint8 (8) << uint8 (flags); |
2118 | } |
2079 | } |
2119 | } |
2080 | } |
2120 | |
2081 | |
… | |
… | |
2164 | * value, so we don't send those bits. |
2125 | * value, so we don't send those bits. |
2165 | */ |
2126 | */ |
2166 | if (mask & 0xf) |
2127 | if (mask & 0xf) |
2167 | sl.buf[oldlen + 1] = mask & 0xff; |
2128 | sl.buf[oldlen + 1] = mask & 0xff; |
2168 | else |
2129 | else |
2169 | sl.len = oldlen; |
2130 | sl.reset (oldlen); |
2170 | |
2131 | |
2171 | if (emask & 0xf) |
2132 | if (emask & 0xf) |
2172 | esl.buf[eoldlen + 1] = emask & 0xff; |
2133 | esl.buf[eoldlen + 1] = emask & 0xff; |
2173 | else |
2134 | else |
2174 | esl.len = eoldlen; |
2135 | esl.reset (eoldlen); |
2175 | } /* else this is a viewable space */ |
2136 | } /* else this is a viewable space */ |
2176 | } /* for x loop */ |
2137 | } /* for x loop */ |
2177 | } /* for y loop */ |
2138 | } /* for y loop */ |
2178 | |
2139 | |
2179 | /* Verify that we in fact do need to send this */ |
2140 | /* Verify that we in fact do need to send this */ |
2180 | if (socket.ext_mapinfos) |
2141 | if (socket.ext_mapinfos) |
2181 | { |
2142 | { |
2182 | if (!(sl.len > startlen || socket.sent_scroll)) |
2143 | if (!(sl.length () > startlen || socket.sent_scroll)) |
2183 | { |
2144 | { |
2184 | /* No map data will follow, so don't say the client |
2145 | /* No map data will follow, so don't say the client |
2185 | * it doesn't need draw! |
2146 | * it doesn't need draw! |
2186 | */ |
2147 | */ |
2187 | ewhatflag &= (~EMI_NOREDRAW); |
2148 | ewhatflag &= (~EMI_NOREDRAW); |
2188 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2149 | esl.buf[ewhatstart + 1] = ewhatflag & 0xff; |
2189 | } |
2150 | } |
2190 | |
2151 | |
2191 | if (esl.len > estartlen) |
2152 | if (esl.length () > estartlen) |
2192 | Send_With_Handling (&socket, &esl); |
2153 | Send_With_Handling (&socket, &esl); |
2193 | } |
2154 | } |
2194 | |
2155 | |
2195 | if (sl.len > startlen || socket.sent_scroll) |
2156 | if (sl.length () > startlen || socket.sent_scroll) |
2196 | { |
2157 | { |
2197 | Send_With_Handling (&socket, &sl); |
2158 | Send_With_Handling (&socket, &sl); |
2198 | socket.sent_scroll = 0; |
2159 | socket.sent_scroll = 0; |
2199 | } |
2160 | } |
2200 | |
|
|
2201 | sl.free (); |
|
|
2202 | esl.free (); |
|
|
2203 | } |
2161 | } |
2204 | |
2162 | |
2205 | /** |
2163 | /** |
2206 | * Draws client map. |
2164 | * Draws client map. |
2207 | */ |
2165 | */ |
… | |
… | |
2258 | { |
2216 | { |
2259 | update_los (pl); |
2217 | update_los (pl); |
2260 | pl->contr->do_los = 0; |
2218 | pl->contr->do_los = 0; |
2261 | } |
2219 | } |
2262 | |
2220 | |
2263 | if (pl->contr->socket.mapmode == Map1Cmd || pl->contr->socket.mapmode == Map1aCmd) |
|
|
2264 | { |
|
|
2265 | /* Big maps need a different drawing mechanism to work */ |
2221 | /* Big maps need a different drawing mechanism to work */ |
2266 | draw_client_map1 (pl); |
2222 | draw_client_map1 (pl); |
2267 | return; |
|
|
2268 | } |
|
|
2269 | |
|
|
2270 | if (pl->invisible & (pl->invisible < 50 ? 4 : 1)) |
|
|
2271 | { |
|
|
2272 | esrv_map_setbelow (&pl->contr->socket, pl->contr->socket.mapx / 2, pl->contr->socket.mapy / 2, pl->face->number, &newmap); |
|
|
2273 | } |
|
|
2274 | |
|
|
2275 | /* j and i are the y and x coordinates of the real map (which is |
|
|
2276 | * basically some number of spaces around the player) |
|
|
2277 | * ax and ay are values from within the viewport (ie, 0, 0 is upper |
|
|
2278 | * left corner) and are thus disconnected from the map values. |
|
|
2279 | * Subtract 1 from the max values so that we properly handle cases where |
|
|
2280 | * player has specified an even map. Otherwise, we try to send them too |
|
|
2281 | * much, ie, if mapx is 10, we would try to send from -5 to 5, which is actually |
|
|
2282 | * 11 spaces. Now, we would send from -5 to 4, which is properly. If mapx is |
|
|
2283 | * odd, this still works fine. |
|
|
2284 | */ |
|
|
2285 | ay = 0; |
|
|
2286 | for (j = pl->y - pl->contr->socket.mapy / 2; j <= pl->y + (pl->contr->socket.mapy - 1) / 2; j++, ay++) |
|
|
2287 | { |
|
|
2288 | ax = 0; |
|
|
2289 | for (i = pl->x - pl->contr->socket.mapx / 2; i <= pl->x + (pl->contr->socket.mapx - 1) / 2; i++, ax++) |
|
|
2290 | { |
|
|
2291 | |
|
|
2292 | d = pl->contr->blocked_los[ax][ay]; |
|
|
2293 | /* note the out_of_map and d>3 checks are both within the same |
|
|
2294 | * negation check. |
|
|
2295 | */ |
|
|
2296 | nx = i; |
|
|
2297 | ny = j; |
|
|
2298 | m = get_map_from_coord (pm, &nx, &ny); |
|
|
2299 | if (m && d < 4) |
|
|
2300 | { |
|
|
2301 | face = GET_MAP_FACE (m, nx, ny, 0); |
|
|
2302 | floor2 = GET_MAP_FACE (m, nx, ny, 1); |
|
|
2303 | floor = GET_MAP_FACE (m, nx, ny, 2); |
|
|
2304 | |
|
|
2305 | /* If all is blank, send a blank face. */ |
|
|
2306 | if ((!face || face == blank_face) && (!floor2 || floor2 == blank_face) && (!floor || floor == blank_face)) |
|
|
2307 | { |
|
|
2308 | esrv_map_setbelow (&pl->contr->socket, ax, ay, blank_face->number, &newmap); |
|
|
2309 | } |
|
|
2310 | else |
|
|
2311 | { /* actually have something interesting */ |
|
|
2312 | /* send the darkness mask, if any. */ |
|
|
2313 | if (d && pl->contr->socket.darkness) |
|
|
2314 | esrv_map_setbelow (&pl->contr->socket, ax, ay, dark_faces[d - 1]->number, &newmap); |
|
|
2315 | |
|
|
2316 | if (face && face != blank_face) |
|
|
2317 | esrv_map_setbelow (&pl->contr->socket, ax, ay, face->number, &newmap); |
|
|
2318 | if (floor2 && floor2 != blank_face) |
|
|
2319 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor2->number, &newmap); |
|
|
2320 | if (floor && floor != blank_face) |
|
|
2321 | esrv_map_setbelow (&pl->contr->socket, ax, ay, floor->number, &newmap); |
|
|
2322 | } |
|
|
2323 | } /* Is a valid space */ |
|
|
2324 | } |
|
|
2325 | } |
|
|
2326 | |
|
|
2327 | esrv_map_doneredraw (&pl->contr->socket, &newmap); |
|
|
2328 | |
|
|
2329 | check_map_change (pl->contr); |
|
|
2330 | } |
2223 | } |
2331 | |
2224 | |
2332 | |
2225 | |
2333 | /*****************************************************************************/ |
2226 | /*****************************************************************************/ |
2334 | |
2227 | |
… | |
… | |
2340 | |
2233 | |
2341 | /*****************************************************************************/ |
2234 | /*****************************************************************************/ |
2342 | void |
2235 | void |
2343 | send_plugin_custom_message (object *pl, char *buf) |
2236 | send_plugin_custom_message (object *pl, char *buf) |
2344 | { |
2237 | { |
2345 | cs_write_string (&pl->contr->socket, buf, strlen (buf)); |
2238 | pl->contr->socket.send_packet (buf); |
2346 | } |
2239 | } |
2347 | |
2240 | |
2348 | /** |
2241 | /** |
2349 | * This sends the skill number to name mapping. We ignore |
2242 | * This sends the skill number to name mapping. We ignore |
2350 | * the params - we always send the same info no matter what. |
2243 | * the params - we always send the same info no matter what. |
2351 | */ |
2244 | */ |
2352 | void |
2245 | void |
2353 | send_skill_info (NewSocket *ns, char *params) |
2246 | send_skill_info (NewSocket *ns, char *params) |
2354 | { |
2247 | { |
2355 | SockList sl (MAXSOCKBUF); |
2248 | packet sl; |
2356 | sl << "replyinfo skill_info\n"; |
2249 | sl << "replyinfo skill_info\n"; |
2357 | |
2250 | |
2358 | for (int i = 1; i < NUM_SKILLS; i++) |
2251 | for (int i = 1; i < NUM_SKILLS; i++) |
2359 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2252 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2360 | |
2253 | |
2361 | if (sl.len >= MAXSOCKBUF) |
2254 | if (sl.length () >= MAXSOCKBUF) |
2362 | { |
2255 | { |
2363 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2256 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2364 | fatal (0); |
2257 | fatal (0); |
2365 | } |
2258 | } |
2366 | |
2259 | |
2367 | Send_With_Handling (ns, &sl); |
2260 | Send_With_Handling (ns, &sl); |
2368 | sl.free (); |
|
|
2369 | } |
2261 | } |
2370 | |
2262 | |
2371 | /** |
2263 | /** |
2372 | * This sends the spell path to name mapping. We ignore |
2264 | * This sends the spell path to name mapping. We ignore |
2373 | * the params - we always send the same info no matter what. |
2265 | * the params - we always send the same info no matter what. |
2374 | */ |
2266 | */ |
2375 | void |
2267 | void |
2376 | send_spell_paths (NewSocket * ns, char *params) |
2268 | send_spell_paths (NewSocket * ns, char *params) |
2377 | { |
2269 | { |
2378 | SockList sl (MAXSOCKBUF); |
2270 | packet sl; |
2379 | |
2271 | |
2380 | sl << "replyinfo spell_paths\n"; |
2272 | sl << "replyinfo spell_paths\n"; |
2381 | |
2273 | |
2382 | for (int i = 0; i < NRSPELLPATHS; i++) |
2274 | for (int i = 0; i < NRSPELLPATHS; i++) |
2383 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
2275 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
2384 | |
2276 | |
2385 | if (sl.len >= MAXSOCKBUF) |
2277 | if (sl.length () >= MAXSOCKBUF) |
2386 | { |
2278 | { |
2387 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2279 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2388 | fatal (0); |
2280 | fatal (0); |
2389 | } |
2281 | } |
2390 | |
2282 | |
2391 | Send_With_Handling (ns, &sl); |
2283 | Send_With_Handling (ns, &sl); |
2392 | sl.free (); |
|
|
2393 | } |
2284 | } |
2394 | |
2285 | |
2395 | /** |
2286 | /** |
2396 | * 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. |
2397 | * 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 |
… | |
… | |
2427 | flags |= UPD_SP_DAMAGE; |
2318 | flags |= UPD_SP_DAMAGE; |
2428 | } |
2319 | } |
2429 | |
2320 | |
2430 | if (flags) |
2321 | if (flags) |
2431 | { |
2322 | { |
2432 | SockList sl (MAXSOCKBUF); |
2323 | packet sl; |
2433 | |
2324 | |
2434 | sl << "updspell " |
2325 | sl << "updspell " |
2435 | << uint8 (flags) |
2326 | << uint8 (flags) |
2436 | << uint32 (spell->count); |
2327 | << uint32 (spell->count); |
2437 | |
2328 | |
2438 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2329 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2439 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2330 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2440 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2331 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2441 | |
2332 | |
2442 | Send_With_Handling (&pl->socket, &sl); |
2333 | Send_With_Handling (&pl->socket, &sl); |
2443 | sl.free (); |
|
|
2444 | } |
2334 | } |
2445 | } |
2335 | } |
2446 | } |
2336 | } |
2447 | } |
2337 | } |
2448 | |
2338 | |
… | |
… | |
2456 | { |
2346 | { |
2457 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2347 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2458 | return; |
2348 | return; |
2459 | } |
2349 | } |
2460 | |
2350 | |
2461 | SockList sl (MAXSOCKBUF); |
2351 | packet sl; |
2462 | |
2352 | |
2463 | sl << "delspell " |
2353 | sl << "delspell " |
2464 | << uint32 (spell->count); |
2354 | << uint32 (spell->count); |
2465 | |
2355 | |
2466 | Send_With_Handling (&pl->socket, &sl); |
2356 | Send_With_Handling (&pl->socket, &sl); |
2467 | sl.free (); |
|
|
2468 | } |
2357 | } |
2469 | |
2358 | |
2470 | /* 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. */ |
2471 | static void |
2360 | static void |
2472 | append_spell (player *pl, SockList &sl, object *spell) |
2361 | append_spell (player *pl, packet &sl, object *spell) |
2473 | { |
2362 | { |
2474 | int len, i, skill = 0; |
2363 | int len, i, skill = 0; |
2475 | |
2364 | |
2476 | if (!(spell->name)) |
2365 | if (!(spell->name)) |
2477 | { |
2366 | { |
… | |
… | |
2523 | } |
2412 | } |
2524 | |
2413 | |
2525 | if (!pl->socket.monitor_spells) |
2414 | if (!pl->socket.monitor_spells) |
2526 | return; |
2415 | return; |
2527 | |
2416 | |
2528 | SockList sl (MAXSOCKBUF); |
2417 | packet sl; |
2529 | |
2418 | |
2530 | sl << "addspell "; |
2419 | sl << "addspell "; |
2531 | |
2420 | |
2532 | if (!spell) |
2421 | if (!spell) |
2533 | { |
2422 | { |
… | |
… | |
2547 | * like it will fix this |
2436 | * like it will fix this |
2548 | */ |
2437 | */ |
2549 | if (spell->type != SPELL) |
2438 | if (spell->type != SPELL) |
2550 | continue; |
2439 | continue; |
2551 | |
2440 | |
2552 | 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)))) |
2553 | { |
2442 | { |
2554 | Send_With_Handling (&pl->socket, &sl); |
2443 | Send_With_Handling (&pl->socket, &sl); |
2555 | strcpy ((char *) sl.buf, "addspell "); |
2444 | |
2556 | sl.len = strlen ((char *) sl.buf); |
2445 | sl.reset (); |
|
|
2446 | sl << "addspell "; |
2557 | } |
2447 | } |
2558 | |
2448 | |
2559 | append_spell (pl, sl, spell); |
2449 | append_spell (pl, sl, spell); |
2560 | } |
2450 | } |
2561 | } |
2451 | } |
… | |
… | |
2574 | } |
2464 | } |
2575 | |
2465 | |
2576 | /* finally, we can send the packet */ |
2466 | /* finally, we can send the packet */ |
2577 | Send_With_Handling (&pl->socket, &sl); |
2467 | Send_With_Handling (&pl->socket, &sl); |
2578 | |
2468 | |
2579 | sl.free (); |
|
|
2580 | } |
2469 | } |
2581 | |
2470 | |