… | |
… | |
102 | { |
102 | { |
103 | struct Map newmap; |
103 | struct Map newmap; |
104 | int x, y, mx, my; |
104 | int x, y, mx, my; |
105 | |
105 | |
106 | { |
106 | { |
107 | SockList sl (MAXSOCKBUF); |
107 | packet sl; |
108 | |
108 | |
109 | sl.printf ("map_scroll %d %d", dx, dy); |
109 | sl.printf ("map_scroll %d %d", dx, dy); |
110 | ns->send_packet (sl); |
110 | ns->send_packet (sl); |
111 | sl.free (); |
|
|
112 | } |
111 | } |
113 | |
112 | |
114 | /* If we are using the Map1aCmd, we may in fact send |
113 | /* If we are using the Map1aCmd, we may in fact send |
115 | * head information that is outside the viewable map. |
114 | * head information that is outside the viewable map. |
116 | * So set the mx,my to the max value we want to |
115 | * So set the mx,my to the max value we want to |
… | |
… | |
706 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
705 | if (!(ns->faces_sent[smoothface] & NS_FACESENT_FACE)) |
707 | esrv_send_face (ns, smoothface, 0); |
706 | esrv_send_face (ns, smoothface, 0); |
708 | |
707 | |
709 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
708 | ns->faces_sent[face] |= NS_FACESENT_SMOOTH; |
710 | |
709 | |
711 | SockList sl (MAXSOCKBUF); |
710 | packet sl; |
712 | |
711 | |
713 | sl << "smooth " |
712 | sl << "smooth " |
714 | << uint16 (face) |
713 | << uint16 (face) |
715 | << uint16 (smoothface); |
714 | << uint16 (smoothface); |
716 | |
715 | |
717 | Send_With_Handling (ns, &sl); |
716 | Send_With_Handling (ns, &sl); |
718 | sl.free (); |
|
|
719 | } |
717 | } |
720 | |
718 | |
721 | /** |
719 | /** |
722 | * Tells client the picture it has to use |
720 | * Tells client the picture it has to use |
723 | * to smooth a picture number given as argument. |
721 | * to smooth a picture number given as argument. |
… | |
… | |
792 | void |
790 | void |
793 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
791 | NewPlayerCmd (uint8 * buf, int len, player *pl) |
794 | { |
792 | { |
795 | int time, repeat; |
793 | int time, repeat; |
796 | char command[MAX_BUF]; |
794 | char command[MAX_BUF]; |
797 | short packet; |
795 | int pktlen; |
798 | |
796 | |
799 | if (len < 7) |
797 | if (len < 7) |
800 | { |
798 | { |
801 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
799 | LOG (llevDebug, "Corrupt ncom command <%s> not long enough - discarding\n", buf); |
802 | return; |
800 | return; |
803 | } |
801 | } |
804 | |
802 | |
805 | packet = net_uint16 (buf); |
803 | pktlen = net_uint16 (buf); |
806 | repeat = net_uint32 (buf + 2); |
804 | repeat = net_uint32 (buf + 2); |
807 | |
805 | |
808 | /* -1 is special - no repeat, but don't update */ |
806 | /* -1 is special - no repeat, but don't update */ |
809 | if (repeat != -1) |
807 | if (repeat != -1) |
810 | pl->count = repeat; |
808 | pl->count = repeat; |
… | |
… | |
844 | else |
842 | else |
845 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
843 | time = (int) (MAX_TIME / FABS (pl->ob->speed)); |
846 | |
844 | |
847 | /* Send confirmation of command execution now */ |
845 | /* Send confirmation of command execution now */ |
848 | |
846 | |
849 | SockList sl (MAXSOCKBUF); |
847 | packet sl; |
850 | sl << "comc " << uint16 (packet) << uint32 (time); |
848 | sl << "comc " << uint16 (pktlen) << uint32 (time); |
851 | Send_With_Handling (&pl->socket, &sl); |
849 | Send_With_Handling (&pl->socket, &sl); |
852 | sl.free (); |
|
|
853 | } |
850 | } |
854 | |
851 | |
855 | |
852 | |
856 | /** This is a reply to a previous query. */ |
853 | /** This is a reply to a previous query. */ |
857 | void |
854 | void |
… | |
… | |
1095 | esrv_update_stats (player *pl) |
1092 | esrv_update_stats (player *pl) |
1096 | { |
1093 | { |
1097 | char buf[MAX_BUF]; |
1094 | char buf[MAX_BUF]; |
1098 | uint16 flags; |
1095 | uint16 flags; |
1099 | |
1096 | |
1100 | SockList sl (MAXSOCKBUF); |
1097 | packet sl; |
1101 | sl << "stats "; |
1098 | sl << "stats "; |
1102 | |
1099 | |
1103 | if (pl->ob != NULL) |
1100 | if (pl->ob != NULL) |
1104 | { |
1101 | { |
1105 | AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
1102 | AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); |
… | |
… | |
1195 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1192 | LOG (llevDebug, "Sending stats command, %d bytes long.\n", sl.len); |
1196 | #endif |
1193 | #endif |
1197 | Send_With_Handling (&pl->socket, &sl); |
1194 | Send_With_Handling (&pl->socket, &sl); |
1198 | } |
1195 | } |
1199 | |
1196 | |
1200 | sl.free (); |
|
|
1201 | } |
1197 | } |
1202 | |
1198 | |
1203 | /** |
1199 | /** |
1204 | * Tells the client that here is a player it should start using. |
1200 | * Tells the client that here is a player it should start using. |
1205 | */ |
1201 | */ |
1206 | void |
1202 | void |
1207 | esrv_new_player (player *pl, uint32 weight) |
1203 | esrv_new_player (player *pl, uint32 weight) |
1208 | { |
1204 | { |
1209 | pl->last_weight = weight; |
1205 | pl->last_weight = weight; |
1210 | |
1206 | |
1211 | SockList sl (MAXSOCKBUF); |
1207 | packet sl; |
1212 | sl << "player "; |
1208 | sl << "player "; |
1213 | |
1209 | |
1214 | sl << uint32 (pl->ob->count) |
1210 | sl << uint32 (pl->ob->count) |
1215 | << uint32 (weight) |
1211 | << uint32 (weight) |
1216 | << uint32 (pl->ob->face->number) |
1212 | << uint32 (pl->ob->face->number) |
1217 | << data8 (pl->ob->name); |
1213 | << data8 (pl->ob->name); |
1218 | |
1214 | |
1219 | Send_With_Handling (&pl->socket, &sl); |
1215 | Send_With_Handling (&pl->socket, &sl); |
1220 | sl.free (); |
|
|
1221 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1216 | SET_FLAG (pl->ob, FLAG_CLIENT_SENT); |
1222 | } |
1217 | } |
1223 | |
1218 | |
1224 | /** |
1219 | /** |
1225 | * Need to send an animation sequence to the client. |
1220 | * Need to send an animation sequence to the client. |
… | |
… | |
1241 | { |
1236 | { |
1242 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
1237 | LOG (llevError, "esrv_send_anim (%d) out of bounds??\n", anim_num); |
1243 | return; |
1238 | return; |
1244 | } |
1239 | } |
1245 | |
1240 | |
1246 | SockList sl (MAXSOCKBUF); |
1241 | packet sl; |
1247 | |
1242 | |
1248 | sl << "anim " |
1243 | sl << "anim " |
1249 | << uint16 (anim_num) |
1244 | << uint16 (anim_num) |
1250 | << uint16 (0); /* flags - not used right now */ |
1245 | << uint16 (0); /* flags - not used right now */ |
1251 | |
1246 | |
… | |
… | |
1258 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1253 | esrv_send_face (ns, animations[anim_num].faces[i], 0); |
1259 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1254 | sl << uint16 (animations[anim_num].faces[i]); /* flags - not used right now */ |
1260 | } |
1255 | } |
1261 | |
1256 | |
1262 | Send_With_Handling (ns, &sl); |
1257 | Send_With_Handling (ns, &sl); |
1263 | sl.free (); |
|
|
1264 | |
1258 | |
1265 | ns->anims_sent[anim_num] = 1; |
1259 | ns->anims_sent[anim_num] = 1; |
1266 | } |
1260 | } |
1267 | |
1261 | |
1268 | |
1262 | |
… | |
… | |
1404 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1398 | esrv_map_doneredraw (NewSocket * ns, struct Map *newmap) |
1405 | { |
1399 | { |
1406 | static long frames, bytes, tbytes, tframes; |
1400 | static long frames, bytes, tbytes, tframes; |
1407 | char *cur; |
1401 | char *cur; |
1408 | |
1402 | |
1409 | SockList sl (MAXSOCKBUF); |
1403 | packet sl; |
1410 | sl << "map "; |
1404 | sl << "map "; |
1411 | |
1405 | |
1412 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
1406 | cur = (char *) compactlayer (ns, (unsigned char *) sl.buf + sl.len, MAP_LAYERS, newmap); |
1413 | sl.len = cur - (char *) sl.buf; |
1407 | sl.len = cur - (char *) sl.buf; |
1414 | |
1408 | |
… | |
… | |
1427 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1421 | memcpy (&ns->lastmap, newmap, sizeof (struct Map)); |
1428 | Send_With_Handling (ns, &sl); |
1422 | Send_With_Handling (ns, &sl); |
1429 | ns->sent_scroll = 0; |
1423 | ns->sent_scroll = 0; |
1430 | } |
1424 | } |
1431 | |
1425 | |
1432 | sl.free (); |
|
|
1433 | } |
1426 | } |
1434 | |
1427 | |
1435 | |
1428 | |
1436 | /** Clears a map cell */ |
1429 | /** Clears a map cell */ |
1437 | static void |
1430 | static void |
… | |
… | |
1479 | * needs to get sent - if so, it adds the data, sending the head |
1472 | * needs to get sent - if so, it adds the data, sending the head |
1480 | * if needed, and returning 1. If this no data needs to get |
1473 | * if needed, and returning 1. If this no data needs to get |
1481 | * sent, it returns zero. |
1474 | * sent, it returns zero. |
1482 | */ |
1475 | */ |
1483 | static int |
1476 | static int |
1484 | check_head (SockList &sl, NewSocket &ns, int ax, int ay, int layer) |
1477 | check_head (packet &sl, NewSocket &ns, int ax, int ay, int layer) |
1485 | { |
1478 | { |
1486 | short face_num; |
1479 | short face_num; |
1487 | |
1480 | |
1488 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1481 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1489 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1482 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
… | |
… | |
1523 | * the case, it seems to make more sense to have these layer values |
1516 | * the case, it seems to make more sense to have these layer values |
1524 | * actually match. |
1517 | * actually match. |
1525 | */ |
1518 | */ |
1526 | |
1519 | |
1527 | static int |
1520 | static int |
1528 | update_space (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1521 | update_space (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1529 | { |
1522 | { |
1530 | object *ob, *head; |
1523 | object *ob, *head; |
1531 | uint16 face_num; |
1524 | uint16 face_num; |
1532 | int bx, by, i; |
1525 | int bx, by, i; |
1533 | |
1526 | |
… | |
… | |
1746 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1739 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1747 | * take. |
1740 | * take. |
1748 | */ |
1741 | */ |
1749 | |
1742 | |
1750 | static inline int |
1743 | static inline int |
1751 | update_smooth (SockList &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1744 | update_smooth (packet &sl, NewSocket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1752 | { |
1745 | { |
1753 | object *ob; |
1746 | object *ob; |
1754 | int smoothlevel; /* old face_num; */ |
1747 | int smoothlevel; /* old face_num; */ |
1755 | |
1748 | |
1756 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1749 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1840 | |
1833 | |
1841 | NewSocket &socket = pl->contr->socket; |
1834 | NewSocket &socket = pl->contr->socket; |
1842 | |
1835 | |
1843 | check_map_change (pl->contr); |
1836 | check_map_change (pl->contr); |
1844 | |
1837 | |
1845 | SockList sl (MAXSOCKBUF); |
1838 | packet sl; |
1846 | SockList esl (MAXSOCKBUF); |
1839 | packet esl; |
1847 | |
1840 | |
1848 | sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); |
1841 | sl << (socket.mapmode == Map1Cmd ? "map1 " : "map1a "); |
1849 | startlen = sl.len; |
1842 | startlen = sl.len; |
1850 | |
1843 | |
1851 | /*Extendedmapinfo structure initialisation */ |
1844 | /*Extendedmapinfo structure initialisation */ |
… | |
… | |
2203 | if (sl.len > startlen || socket.sent_scroll) |
2196 | if (sl.len > startlen || socket.sent_scroll) |
2204 | { |
2197 | { |
2205 | Send_With_Handling (&socket, &sl); |
2198 | Send_With_Handling (&socket, &sl); |
2206 | socket.sent_scroll = 0; |
2199 | socket.sent_scroll = 0; |
2207 | } |
2200 | } |
2208 | |
|
|
2209 | sl.free (); |
|
|
2210 | esl.free (); |
|
|
2211 | } |
2201 | } |
2212 | |
2202 | |
2213 | /** |
2203 | /** |
2214 | * Draws client map. |
2204 | * Draws client map. |
2215 | */ |
2205 | */ |
… | |
… | |
2358 | * the params - we always send the same info no matter what. |
2348 | * the params - we always send the same info no matter what. |
2359 | */ |
2349 | */ |
2360 | void |
2350 | void |
2361 | send_skill_info (NewSocket *ns, char *params) |
2351 | send_skill_info (NewSocket *ns, char *params) |
2362 | { |
2352 | { |
2363 | SockList sl (MAXSOCKBUF); |
2353 | packet sl; |
2364 | sl << "replyinfo skill_info\n"; |
2354 | sl << "replyinfo skill_info\n"; |
2365 | |
2355 | |
2366 | for (int i = 1; i < NUM_SKILLS; i++) |
2356 | for (int i = 1; i < NUM_SKILLS; i++) |
2367 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2357 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names[i]); |
2368 | |
2358 | |
… | |
… | |
2371 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2361 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
2372 | fatal (0); |
2362 | fatal (0); |
2373 | } |
2363 | } |
2374 | |
2364 | |
2375 | Send_With_Handling (ns, &sl); |
2365 | Send_With_Handling (ns, &sl); |
2376 | sl.free (); |
|
|
2377 | } |
2366 | } |
2378 | |
2367 | |
2379 | /** |
2368 | /** |
2380 | * This sends the spell path to name mapping. We ignore |
2369 | * This sends the spell path to name mapping. We ignore |
2381 | * the params - we always send the same info no matter what. |
2370 | * the params - we always send the same info no matter what. |
2382 | */ |
2371 | */ |
2383 | void |
2372 | void |
2384 | send_spell_paths (NewSocket * ns, char *params) |
2373 | send_spell_paths (NewSocket * ns, char *params) |
2385 | { |
2374 | { |
2386 | SockList sl (MAXSOCKBUF); |
2375 | packet sl; |
2387 | |
2376 | |
2388 | sl << "replyinfo spell_paths\n"; |
2377 | sl << "replyinfo spell_paths\n"; |
2389 | |
2378 | |
2390 | for (int i = 0; i < NRSPELLPATHS; i++) |
2379 | for (int i = 0; i < NRSPELLPATHS; i++) |
2391 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
2380 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
… | |
… | |
2395 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2384 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
2396 | fatal (0); |
2385 | fatal (0); |
2397 | } |
2386 | } |
2398 | |
2387 | |
2399 | Send_With_Handling (ns, &sl); |
2388 | Send_With_Handling (ns, &sl); |
2400 | sl.free (); |
|
|
2401 | } |
2389 | } |
2402 | |
2390 | |
2403 | /** |
2391 | /** |
2404 | * This looks for any spells the player may have that have changed their stats. |
2392 | * This looks for any spells the player may have that have changed their stats. |
2405 | * it then sends an updspell packet for each spell that has changed in this way |
2393 | * it then sends an updspell packet for each spell that has changed in this way |
… | |
… | |
2435 | flags |= UPD_SP_DAMAGE; |
2423 | flags |= UPD_SP_DAMAGE; |
2436 | } |
2424 | } |
2437 | |
2425 | |
2438 | if (flags) |
2426 | if (flags) |
2439 | { |
2427 | { |
2440 | SockList sl (MAXSOCKBUF); |
2428 | packet sl; |
2441 | |
2429 | |
2442 | sl << "updspell " |
2430 | sl << "updspell " |
2443 | << uint8 (flags) |
2431 | << uint8 (flags) |
2444 | << uint32 (spell->count); |
2432 | << uint32 (spell->count); |
2445 | |
2433 | |
2446 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2434 | if (flags & UPD_SP_MANA ) sl << uint16 (spell->last_sp); |
2447 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2435 | if (flags & UPD_SP_GRACE ) sl << uint16 (spell->last_grace); |
2448 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2436 | if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->last_eat); |
2449 | |
2437 | |
2450 | Send_With_Handling (&pl->socket, &sl); |
2438 | Send_With_Handling (&pl->socket, &sl); |
2451 | sl.free (); |
|
|
2452 | } |
2439 | } |
2453 | } |
2440 | } |
2454 | } |
2441 | } |
2455 | } |
2442 | } |
2456 | |
2443 | |
… | |
… | |
2464 | { |
2451 | { |
2465 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2452 | LOG (llevError, "Invalid call to esrv_remove_spell"); |
2466 | return; |
2453 | return; |
2467 | } |
2454 | } |
2468 | |
2455 | |
2469 | SockList sl (MAXSOCKBUF); |
2456 | packet sl; |
2470 | |
2457 | |
2471 | sl << "delspell " |
2458 | sl << "delspell " |
2472 | << uint32 (spell->count); |
2459 | << uint32 (spell->count); |
2473 | |
2460 | |
2474 | Send_With_Handling (&pl->socket, &sl); |
2461 | Send_With_Handling (&pl->socket, &sl); |
2475 | sl.free (); |
|
|
2476 | } |
2462 | } |
2477 | |
2463 | |
2478 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2464 | /* appends the spell *spell to the Socklist we will send the data to. */ |
2479 | static void |
2465 | static void |
2480 | append_spell (player *pl, SockList &sl, object *spell) |
2466 | append_spell (player *pl, packet &sl, object *spell) |
2481 | { |
2467 | { |
2482 | int len, i, skill = 0; |
2468 | int len, i, skill = 0; |
2483 | |
2469 | |
2484 | if (!(spell->name)) |
2470 | if (!(spell->name)) |
2485 | { |
2471 | { |
… | |
… | |
2531 | } |
2517 | } |
2532 | |
2518 | |
2533 | if (!pl->socket.monitor_spells) |
2519 | if (!pl->socket.monitor_spells) |
2534 | return; |
2520 | return; |
2535 | |
2521 | |
2536 | SockList sl (MAXSOCKBUF); |
2522 | packet sl; |
2537 | |
2523 | |
2538 | sl << "addspell "; |
2524 | sl << "addspell "; |
2539 | |
2525 | |
2540 | if (!spell) |
2526 | if (!spell) |
2541 | { |
2527 | { |
… | |
… | |
2582 | } |
2568 | } |
2583 | |
2569 | |
2584 | /* finally, we can send the packet */ |
2570 | /* finally, we can send the packet */ |
2585 | Send_With_Handling (&pl->socket, &sl); |
2571 | Send_With_Handling (&pl->socket, &sl); |
2586 | |
2572 | |
2587 | sl.free (); |
|
|
2588 | } |
2573 | } |
2589 | |
2574 | |