… | |
… | |
46 | */ |
46 | */ |
47 | |
47 | |
48 | #include <global.h> |
48 | #include <global.h> |
49 | #include <sproto.h> |
49 | #include <sproto.h> |
50 | |
50 | |
51 | #include <newclient.h> |
|
|
52 | #include <newserver.h> |
|
|
53 | #include <living.h> |
51 | #include <living.h> |
54 | #include <commands.h> |
52 | #include <commands.h> |
55 | |
53 | |
56 | /* This block is basically taken from socket.c - I assume if it works there, |
54 | /* This block is basically taken from socket.c - I assume if it works there, |
57 | * it should work here. |
55 | * it should work here. |
… | |
… | |
88 | -1, /* life stealing */ |
86 | -1, /* life stealing */ |
89 | -1 /* Disease - not fully done yet */ |
87 | -1 /* Disease - not fully done yet */ |
90 | }; |
88 | }; |
91 | |
89 | |
92 | static void |
90 | static void |
93 | socket_map_scroll (client_socket * ns, int dx, int dy) |
91 | socket_map_scroll (client * ns, int dx, int dy) |
94 | { |
92 | { |
95 | struct Map newmap; |
93 | struct Map newmap; |
96 | int x, y, mx, my; |
94 | int x, y, mx, my; |
97 | |
95 | |
98 | { |
96 | { |
… | |
… | |
148 | } |
146 | } |
149 | |
147 | |
150 | static void |
148 | static void |
151 | clear_map (player *pl) |
149 | clear_map (player *pl) |
152 | { |
150 | { |
153 | client_socket &socket = *pl->socket; |
151 | client &socket = *pl->socket; |
154 | |
152 | |
155 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
153 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
156 | |
154 | |
157 | if (socket.newmapcmd == 1) |
155 | if (socket.newmapcmd == 1) |
158 | socket.send_packet ("newmap"); |
156 | socket.send_packet ("newmap"); |
… | |
… | |
163 | |
161 | |
164 | /** check for map change and send new map data */ |
162 | /** check for map change and send new map data */ |
165 | static void |
163 | static void |
166 | check_map_change (player *pl) |
164 | check_map_change (player *pl) |
167 | { |
165 | { |
168 | client_socket &socket = *pl->socket; |
166 | client &socket = *pl->socket; |
169 | object *ob = pl->ob; |
167 | object *ob = pl->ob; |
170 | char buf[MAX_BUF]; /* eauugggh */ |
168 | char buf[MAX_BUF]; /* eauugggh */ |
171 | |
169 | |
172 | if (socket.current_map != ob->map) |
170 | if (socket.current_map != ob->map) |
173 | { |
171 | { |
… | |
… | |
214 | } |
212 | } |
215 | } |
213 | } |
216 | |
214 | |
217 | socket.current_x = ob->x; |
215 | socket.current_x = ob->x; |
218 | socket.current_y = ob->y; |
216 | socket.current_y = ob->y; |
|
|
217 | } |
|
|
218 | |
|
|
219 | /** |
|
|
220 | * RequestInfo is sort of a meta command. There is some specific |
|
|
221 | * request of information, but we call other functions to provide |
|
|
222 | * that information. |
|
|
223 | */ |
|
|
224 | void |
|
|
225 | RequestInfo (char *buf, int len, client * ns) |
|
|
226 | { |
|
|
227 | char *params = NULL, *cp; |
|
|
228 | |
|
|
229 | /* No match */ |
|
|
230 | char bigbuf[MAX_BUF]; |
|
|
231 | int slen; |
|
|
232 | |
|
|
233 | /* Set up replyinfo before we modify any of the buffers - this is used |
|
|
234 | * if we don't find a match. |
|
|
235 | */ |
|
|
236 | strcpy (bigbuf, "replyinfo "); |
|
|
237 | slen = strlen (bigbuf); |
|
|
238 | safe_strcat (bigbuf, buf, &slen, MAX_BUF); |
|
|
239 | |
|
|
240 | /* find the first space, make it null, and update the |
|
|
241 | * params pointer. |
|
|
242 | */ |
|
|
243 | for (cp = buf; *cp != '\0'; cp++) |
|
|
244 | if (*cp == ' ') |
|
|
245 | { |
|
|
246 | *cp = '\0'; |
|
|
247 | params = cp + 1; |
|
|
248 | break; |
|
|
249 | } |
|
|
250 | |
|
|
251 | if (!strcmp (buf, "image_info")) |
|
|
252 | send_image_info (ns, params); |
|
|
253 | else if (!strcmp (buf, "image_sums")) |
|
|
254 | send_image_sums (ns, params); |
|
|
255 | else if (!strcmp (buf, "skill_info")) |
|
|
256 | send_skill_info (ns, params); |
|
|
257 | else if (!strcmp (buf, "spell_paths")) |
|
|
258 | send_spell_paths (ns, params); |
|
|
259 | else |
|
|
260 | ns->send_packet (bigbuf, len); |
219 | } |
261 | } |
220 | |
262 | |
221 | void |
263 | void |
222 | ExtCmd (char *buf, int len, player *pl) |
264 | ExtCmd (char *buf, int len, player *pl) |
223 | { |
265 | { |
… | |
… | |
311 | pl->socket->send_packet (bigbuf); |
353 | pl->socket->send_packet (bigbuf); |
312 | } |
354 | } |
313 | |
355 | |
314 | /** This is the Setup cmd - easy first implementation */ |
356 | /** This is the Setup cmd - easy first implementation */ |
315 | void |
357 | void |
316 | SetUp (char *buf, int len, client_socket * ns) |
358 | SetUp (char *buf, int len, client * ns) |
317 | { |
359 | { |
318 | int s, slen; |
360 | int s, slen; |
319 | char *cmd, *param, cmdback[HUGE_BUF]; |
361 | char *cmd, *param, cmdback[HUGE_BUF]; |
320 | |
362 | |
321 | /* run through the cmds of setup |
363 | /* run through the cmds of setup |
… | |
… | |
531 | * This is what takes care of it. We tell the client how things worked out. |
573 | * This is what takes care of it. We tell the client how things worked out. |
532 | * I am not sure if this file is the best place for this function. however, |
574 | * I am not sure if this file is the best place for this function. however, |
533 | * it either has to be here or init_sockets needs to be exported. |
575 | * it either has to be here or init_sockets needs to be exported. |
534 | */ |
576 | */ |
535 | void |
577 | void |
536 | AddMeCmd (char *buf, int len, client_socket * ns) |
578 | AddMeCmd (char *buf, int len, client * ns) |
537 | { |
579 | { |
538 | Settings oldsettings; |
580 | Settings oldsettings; |
539 | |
581 | |
540 | oldsettings = settings; |
582 | oldsettings = settings; |
541 | if (ns->status != Ns_Add || add_player (ns)) |
583 | if (ns->status != Ns_Add || add_player (ns)) |
… | |
… | |
546 | settings = oldsettings; |
588 | settings = oldsettings; |
547 | } |
589 | } |
548 | |
590 | |
549 | /** Reply to ExtendedInfos command */ |
591 | /** Reply to ExtendedInfos command */ |
550 | void |
592 | void |
551 | ToggleExtendedInfos (char *buf, int len, client_socket * ns) |
593 | ToggleExtendedInfos (char *buf, int len, client * ns) |
552 | { |
594 | { |
553 | char cmdback[MAX_BUF]; |
595 | char cmdback[MAX_BUF]; |
554 | char command[50]; |
596 | char command[50]; |
555 | int info, nextinfo; |
597 | int info, nextinfo; |
556 | |
598 | |
… | |
… | |
607 | #define MSG_TYPE_MONUMENT 5 |
649 | #define MSG_TYPE_MONUMENT 5 |
608 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
650 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
609 | |
651 | |
610 | /** Reply to ExtendedInfos command */ |
652 | /** Reply to ExtendedInfos command */ |
611 | void |
653 | void |
612 | ToggleExtendedText (char *buf, int len, client_socket * ns) |
654 | ToggleExtendedText (char *buf, int len, client * ns) |
613 | { |
655 | { |
614 | char cmdback[MAX_BUF]; |
656 | char cmdback[MAX_BUF]; |
615 | char temp[10]; |
657 | char temp[10]; |
616 | char command[50]; |
658 | char command[50]; |
617 | int info, nextinfo, i, flag; |
659 | int info, nextinfo, i, flag; |
… | |
… | |
668 | * a piece of data from us that we know the client wants. So |
710 | * a piece of data from us that we know the client wants. So |
669 | * if we know the client wants it, might as well push it to the |
711 | * if we know the client wants it, might as well push it to the |
670 | * client. |
712 | * client. |
671 | */ |
713 | */ |
672 | static void |
714 | static void |
673 | SendSmooth (client_socket * ns, uint16 face) |
715 | SendSmooth (client * ns, uint16 face) |
674 | { |
716 | { |
675 | uint16 smoothface; |
717 | uint16 smoothface; |
676 | |
718 | |
677 | /* If we can't find a face, return and set it so we won't try to send this |
719 | /* If we can't find a face, return and set it so we won't try to send this |
678 | * again. |
720 | * again. |
… | |
… | |
702 | /** |
744 | /** |
703 | * Tells client the picture it has to use |
745 | * Tells client the picture it has to use |
704 | * to smooth a picture number given as argument. |
746 | * to smooth a picture number given as argument. |
705 | */ |
747 | */ |
706 | void |
748 | void |
707 | AskSmooth (char *buf, int len, client_socket * ns) |
749 | AskSmooth (char *buf, int len, client * ns) |
708 | { |
750 | { |
709 | uint16 facenbr; |
751 | uint16 facenbr; |
710 | |
752 | |
711 | facenbr = atoi (buf); |
753 | facenbr = atoi (buf); |
712 | SendSmooth (ns, facenbr); |
754 | SendSmooth (ns, facenbr); |
… | |
… | |
893 | * something older than the server. If we assume the client will be |
935 | * something older than the server. If we assume the client will be |
894 | * backwards compatible, having it be a later version should not be a |
936 | * backwards compatible, having it be a later version should not be a |
895 | * problem. |
937 | * problem. |
896 | */ |
938 | */ |
897 | void |
939 | void |
898 | VersionCmd (char *buf, int len, client_socket * ns) |
940 | VersionCmd (char *buf, int len, client * ns) |
899 | { |
941 | { |
900 | char *cp; |
942 | char *cp; |
901 | char version_warning[256]; |
943 | char version_warning[256]; |
902 | |
944 | |
903 | if (!buf) |
945 | if (!buf) |
… | |
… | |
927 | cp = strchr (cp + 1, ' '); |
969 | cp = strchr (cp + 1, ' '); |
928 | if (cp) |
970 | if (cp) |
929 | { |
971 | { |
930 | LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
972 | LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
931 | |
973 | |
932 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
974 | assign (ns->version, cp + 1); |
933 | |
975 | |
934 | /* This is first implementation - i skip all beta DX clients with it |
|
|
935 | * Add later stuff here for other clients |
|
|
936 | */ |
|
|
937 | |
|
|
938 | /* these are old dxclients */ |
|
|
939 | /* Version 1024 added support for singular + plural name values - |
|
|
940 | * requiing this minimal value reduces complexity of that code, and it |
|
|
941 | * has been around for a long time. |
|
|
942 | */ |
|
|
943 | if (ns->sc_version < 1026) |
976 | if (ns->sc_version < 1026) |
944 | { |
977 | { |
945 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
978 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
946 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
979 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
947 | ns->send_packet (version_warning); |
980 | ns->send_packet (version_warning); |
… | |
… | |
949 | |
982 | |
950 | } |
983 | } |
951 | } |
984 | } |
952 | |
985 | |
953 | /** sound related functions. */ |
986 | /** sound related functions. */ |
954 | |
|
|
955 | void |
987 | void |
956 | SetSound (char *buf, int len, client_socket * ns) |
988 | SetSound (char *buf, int len, client * ns) |
957 | { |
989 | { |
958 | ns->sound = atoi (buf); |
990 | ns->sound = atoi (buf); |
959 | } |
991 | } |
960 | |
992 | |
961 | /** client wants the map resent */ |
993 | /** client wants the map resent */ |
… | |
… | |
1019 | /** |
1051 | /** |
1020 | * Asks the client to query the user. This way, the client knows |
1052 | * Asks the client to query the user. This way, the client knows |
1021 | * it needs to send something back (vs just printing out a message) |
1053 | * it needs to send something back (vs just printing out a message) |
1022 | */ |
1054 | */ |
1023 | void |
1055 | void |
1024 | send_query (client_socket * ns, uint8 flags, char *text) |
1056 | send_query (client * ns, uint8 flags, char *text) |
1025 | { |
1057 | { |
1026 | char buf[MAX_BUF]; |
1058 | char buf[MAX_BUF]; |
1027 | |
1059 | |
1028 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1060 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1029 | ns->send_packet (buf); |
1061 | ns->send_packet (buf); |
… | |
… | |
1188 | * sent them the face yet (this can become quite costly in terms of |
1220 | * sent them the face yet (this can become quite costly in terms of |
1189 | * how much we are sending - on the other hand, this should only happen |
1221 | * how much we are sending - on the other hand, this should only happen |
1190 | * when the player logs in and picks stuff up. |
1222 | * when the player logs in and picks stuff up. |
1191 | */ |
1223 | */ |
1192 | void |
1224 | void |
1193 | esrv_send_animation (client_socket * ns, short anim_num) |
1225 | esrv_send_animation (client * ns, short anim_num) |
1194 | { |
1226 | { |
1195 | int i; |
1227 | int i; |
1196 | |
1228 | |
1197 | /* Do some checking on the anim_num we got. Note that the animations |
1229 | /* Do some checking on the anim_num we got. Note that the animations |
1198 | * are added in contigous order, so if the number is in the valid |
1230 | * are added in contigous order, so if the number is in the valid |
… | |
… | |
1235 | /** |
1267 | /** |
1236 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1268 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1237 | * the face yet, we will also send it. |
1269 | * the face yet, we will also send it. |
1238 | */ |
1270 | */ |
1239 | static void |
1271 | static void |
1240 | esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap) |
1272 | esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap) |
1241 | { |
1273 | { |
1242 | if (newmap->cells[x][y].count >= MAP_LAYERS) |
1274 | if (newmap->cells[x][y].count >= MAP_LAYERS) |
1243 | { |
1275 | { |
1244 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1276 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1245 | return; |
1277 | return; |
… | |
… | |
1265 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1297 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1266 | }; |
1298 | }; |
1267 | |
1299 | |
1268 | /** Checkes if map cells have changed */ |
1300 | /** Checkes if map cells have changed */ |
1269 | static int |
1301 | static int |
1270 | mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap) |
1302 | mapcellchanged (client * ns, int i, int j, struct Map *newmap) |
1271 | { |
1303 | { |
1272 | int k; |
1304 | int k; |
1273 | |
1305 | |
1274 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1306 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1275 | return 1; |
1307 | return 1; |
… | |
… | |
1288 | * cnum is the client number, cur is the the buffer we put all of |
1320 | * cnum is the client number, cur is the the buffer we put all of |
1289 | * this data into. we return the end of the data. layers is |
1321 | * this data into. we return the end of the data. layers is |
1290 | * how many layers of data we should back. |
1322 | * how many layers of data we should back. |
1291 | */ |
1323 | */ |
1292 | static uint8 * |
1324 | static uint8 * |
1293 | compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap) |
1325 | compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap) |
1294 | { |
1326 | { |
1295 | int x, y, k; |
1327 | int x, y, k; |
1296 | int face; |
1328 | int face; |
1297 | unsigned char *fcur; |
1329 | unsigned char *fcur; |
1298 | struct MapLayer layers[MAP_LAYERS]; |
1330 | struct MapLayer layers[MAP_LAYERS]; |
… | |
… | |
1406 | * needs to get sent - if so, it adds the data, sending the head |
1438 | * needs to get sent - if so, it adds the data, sending the head |
1407 | * if needed, and returning 1. If this no data needs to get |
1439 | * if needed, and returning 1. If this no data needs to get |
1408 | * sent, it returns zero. |
1440 | * sent, it returns zero. |
1409 | */ |
1441 | */ |
1410 | static int |
1442 | static int |
1411 | check_head (packet &sl, client_socket &ns, int ax, int ay, int layer) |
1443 | check_head (packet &sl, client &ns, int ax, int ay, int layer) |
1412 | { |
1444 | { |
1413 | short face_num; |
1445 | short face_num; |
1414 | |
1446 | |
1415 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1447 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1416 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1448 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
… | |
… | |
1450 | * the case, it seems to make more sense to have these layer values |
1482 | * the case, it seems to make more sense to have these layer values |
1451 | * actually match. |
1483 | * actually match. |
1452 | */ |
1484 | */ |
1453 | |
1485 | |
1454 | static int |
1486 | static int |
1455 | update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1487 | update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1456 | { |
1488 | { |
1457 | object *ob, *head; |
1489 | object *ob, *head; |
1458 | uint16 face_num; |
1490 | uint16 face_num; |
1459 | int bx, by, i; |
1491 | int bx, by, i; |
1460 | |
1492 | |
… | |
… | |
1673 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1705 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1674 | * take. |
1706 | * take. |
1675 | */ |
1707 | */ |
1676 | |
1708 | |
1677 | static inline int |
1709 | static inline int |
1678 | update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1710 | update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1679 | { |
1711 | { |
1680 | object *ob; |
1712 | object *ob; |
1681 | int smoothlevel; /* old face_num; */ |
1713 | int smoothlevel; /* old face_num; */ |
1682 | |
1714 | |
1683 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1715 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1717 | * Returns the size of a data for a map square as returned by |
1749 | * Returns the size of a data for a map square as returned by |
1718 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1750 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1719 | * available. |
1751 | * available. |
1720 | */ |
1752 | */ |
1721 | int |
1753 | int |
1722 | getExtendedMapInfoSize (client_socket * ns) |
1754 | getExtendedMapInfoSize (client * ns) |
1723 | { |
1755 | { |
1724 | int result = 0; |
1756 | int result = 0; |
1725 | |
1757 | |
1726 | if (ns->ext_mapinfos) |
1758 | if (ns->ext_mapinfos) |
1727 | { |
1759 | { |
… | |
… | |
1763 | uint8 eentrysize; |
1795 | uint8 eentrysize; |
1764 | uint16 ewhatstart, ewhatflag; |
1796 | uint16 ewhatstart, ewhatflag; |
1765 | uint8 extendedinfos; |
1797 | uint8 extendedinfos; |
1766 | maptile *m; |
1798 | maptile *m; |
1767 | |
1799 | |
1768 | client_socket &socket = *pl->contr->socket; |
1800 | client &socket = *pl->contr->socket; |
1769 | |
1801 | |
1770 | check_map_change (pl->contr); |
1802 | check_map_change (pl->contr); |
1771 | |
1803 | |
1772 | packet sl; |
1804 | packet sl; |
1773 | packet esl; |
1805 | packet esl; |
… | |
… | |
2216 | /** |
2248 | /** |
2217 | * This sends the skill number to name mapping. We ignore |
2249 | * This sends the skill number to name mapping. We ignore |
2218 | * the params - we always send the same info no matter what. |
2250 | * the params - we always send the same info no matter what. |
2219 | */ |
2251 | */ |
2220 | void |
2252 | void |
2221 | send_skill_info (client_socket *ns, char *params) |
2253 | send_skill_info (client *ns, char *params) |
2222 | { |
2254 | { |
2223 | packet sl; |
2255 | packet sl; |
2224 | sl << "replyinfo skill_info\n"; |
2256 | sl << "replyinfo skill_info\n"; |
2225 | |
2257 | |
2226 | for (int i = 1; i < NUM_SKILLS; i++) |
2258 | for (int i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2238 | /** |
2270 | /** |
2239 | * This sends the spell path to name mapping. We ignore |
2271 | * This sends the spell path to name mapping. We ignore |
2240 | * the params - we always send the same info no matter what. |
2272 | * the params - we always send the same info no matter what. |
2241 | */ |
2273 | */ |
2242 | void |
2274 | void |
2243 | send_spell_paths (client_socket * ns, char *params) |
2275 | send_spell_paths (client * ns, char *params) |
2244 | { |
2276 | { |
2245 | packet sl; |
2277 | packet sl; |
2246 | |
2278 | |
2247 | sl << "replyinfo spell_paths\n"; |
2279 | sl << "replyinfo spell_paths\n"; |
2248 | |
2280 | |