… | |
… | |
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 | { |
|
|
99 | packet sl; |
|
|
100 | |
|
|
101 | sl.printf ("map_scroll %d %d", dx, dy); |
96 | ns->send_packet_printf ("map_scroll %d %d", dx, dy); |
102 | ns->send_packet (sl); |
|
|
103 | } |
|
|
104 | |
97 | |
105 | /* If we are using the Map1aCmd, we may in fact send |
98 | /* If we are using the Map1aCmd, we may in fact send |
106 | * head information that is outside the viewable map. |
99 | * head information that is outside the viewable map. |
107 | * So set the mx,my to the max value we want to |
100 | * So set the mx,my to the max value we want to |
108 | * look for. Removed code to do so - it caused extra |
101 | * look for. Removed code to do so - it caused extra |
… | |
… | |
148 | } |
141 | } |
149 | |
142 | |
150 | static void |
143 | static void |
151 | clear_map (player *pl) |
144 | clear_map (player *pl) |
152 | { |
145 | { |
153 | client_socket &socket = *pl->socket; |
146 | client &socket = *pl->socket; |
154 | |
147 | |
155 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
148 | memset (&socket.lastmap, 0, sizeof (socket.lastmap)); |
156 | |
149 | |
157 | if (socket.newmapcmd == 1) |
150 | if (socket.newmapcmd == 1) |
158 | socket.send_packet ("newmap"); |
151 | socket.send_packet ("newmap"); |
… | |
… | |
163 | |
156 | |
164 | /** check for map change and send new map data */ |
157 | /** check for map change and send new map data */ |
165 | static void |
158 | static void |
166 | check_map_change (player *pl) |
159 | check_map_change (player *pl) |
167 | { |
160 | { |
168 | client_socket &socket = *pl->socket; |
161 | client &socket = *pl->socket; |
169 | object *ob = pl->ob; |
162 | object *ob = pl->ob; |
170 | char buf[MAX_BUF]; /* eauugggh */ |
163 | char buf[MAX_BUF]; /* eauugggh */ |
171 | |
164 | |
172 | if (socket.current_map != ob->map) |
165 | if (socket.current_map != ob->map) |
173 | { |
166 | { |
… | |
… | |
222 | * RequestInfo is sort of a meta command. There is some specific |
215 | * RequestInfo is sort of a meta command. There is some specific |
223 | * request of information, but we call other functions to provide |
216 | * request of information, but we call other functions to provide |
224 | * that information. |
217 | * that information. |
225 | */ |
218 | */ |
226 | void |
219 | void |
227 | RequestInfo (char *buf, int len, client_socket * ns) |
220 | RequestInfo (char *buf, int len, client * ns) |
228 | { |
221 | { |
229 | char *params = NULL, *cp; |
222 | char *params = NULL, *cp; |
230 | |
223 | |
231 | /* No match */ |
224 | /* No match */ |
232 | char bigbuf[MAX_BUF]; |
225 | char bigbuf[MAX_BUF]; |
… | |
… | |
355 | pl->socket->send_packet (bigbuf); |
348 | pl->socket->send_packet (bigbuf); |
356 | } |
349 | } |
357 | |
350 | |
358 | /** This is the Setup cmd - easy first implementation */ |
351 | /** This is the Setup cmd - easy first implementation */ |
359 | void |
352 | void |
360 | SetUp (char *buf, int len, client_socket * ns) |
353 | SetUp (char *buf, int len, client * ns) |
361 | { |
354 | { |
362 | int s, slen; |
355 | int s, slen; |
363 | char *cmd, *param, cmdback[HUGE_BUF]; |
356 | char *cmd, *param, cmdback[HUGE_BUF]; |
364 | |
357 | |
365 | /* run through the cmds of setup |
358 | /* run through the cmds of setup |
… | |
… | |
575 | * This is what takes care of it. We tell the client how things worked out. |
568 | * This is what takes care of it. We tell the client how things worked out. |
576 | * I am not sure if this file is the best place for this function. however, |
569 | * I am not sure if this file is the best place for this function. however, |
577 | * it either has to be here or init_sockets needs to be exported. |
570 | * it either has to be here or init_sockets needs to be exported. |
578 | */ |
571 | */ |
579 | void |
572 | void |
580 | AddMeCmd (char *buf, int len, client_socket * ns) |
573 | AddMeCmd (char *buf, int len, client * ns) |
581 | { |
574 | { |
582 | Settings oldsettings; |
575 | Settings oldsettings; |
583 | |
576 | |
584 | oldsettings = settings; |
577 | oldsettings = settings; |
585 | if (ns->status != Ns_Add || add_player (ns)) |
578 | if (ns->status != Ns_Add || add_player (ns)) |
… | |
… | |
590 | settings = oldsettings; |
583 | settings = oldsettings; |
591 | } |
584 | } |
592 | |
585 | |
593 | /** Reply to ExtendedInfos command */ |
586 | /** Reply to ExtendedInfos command */ |
594 | void |
587 | void |
595 | ToggleExtendedInfos (char *buf, int len, client_socket * ns) |
588 | ToggleExtendedInfos (char *buf, int len, client * ns) |
596 | { |
589 | { |
597 | char cmdback[MAX_BUF]; |
590 | char cmdback[MAX_BUF]; |
598 | char command[50]; |
591 | char command[50]; |
599 | int info, nextinfo; |
592 | int info, nextinfo; |
600 | |
593 | |
… | |
… | |
651 | #define MSG_TYPE_MONUMENT 5 |
644 | #define MSG_TYPE_MONUMENT 5 |
652 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
645 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
653 | |
646 | |
654 | /** Reply to ExtendedInfos command */ |
647 | /** Reply to ExtendedInfos command */ |
655 | void |
648 | void |
656 | ToggleExtendedText (char *buf, int len, client_socket * ns) |
649 | ToggleExtendedText (char *buf, int len, client * ns) |
657 | { |
650 | { |
658 | char cmdback[MAX_BUF]; |
651 | char cmdback[MAX_BUF]; |
659 | char temp[10]; |
652 | char temp[10]; |
660 | char command[50]; |
653 | char command[50]; |
661 | int info, nextinfo, i, flag; |
654 | int info, nextinfo, i, flag; |
… | |
… | |
712 | * a piece of data from us that we know the client wants. So |
705 | * a piece of data from us that we know the client wants. So |
713 | * if we know the client wants it, might as well push it to the |
706 | * if we know the client wants it, might as well push it to the |
714 | * client. |
707 | * client. |
715 | */ |
708 | */ |
716 | static void |
709 | static void |
717 | SendSmooth (client_socket * ns, uint16 face) |
710 | SendSmooth (client * ns, uint16 face) |
718 | { |
711 | { |
719 | uint16 smoothface; |
712 | uint16 smoothface; |
720 | |
713 | |
721 | /* If we can't find a face, return and set it so we won't try to send this |
714 | /* If we can't find a face, return and set it so we won't try to send this |
722 | * again. |
715 | * again. |
… | |
… | |
746 | /** |
739 | /** |
747 | * Tells client the picture it has to use |
740 | * Tells client the picture it has to use |
748 | * to smooth a picture number given as argument. |
741 | * to smooth a picture number given as argument. |
749 | */ |
742 | */ |
750 | void |
743 | void |
751 | AskSmooth (char *buf, int len, client_socket * ns) |
744 | AskSmooth (char *buf, int len, client * ns) |
752 | { |
745 | { |
753 | uint16 facenbr; |
746 | uint16 facenbr; |
754 | |
747 | |
755 | facenbr = atoi (buf); |
748 | facenbr = atoi (buf); |
756 | SendSmooth (ns, facenbr); |
749 | SendSmooth (ns, facenbr); |
… | |
… | |
937 | * something older than the server. If we assume the client will be |
930 | * something older than the server. If we assume the client will be |
938 | * backwards compatible, having it be a later version should not be a |
931 | * backwards compatible, having it be a later version should not be a |
939 | * problem. |
932 | * problem. |
940 | */ |
933 | */ |
941 | void |
934 | void |
942 | VersionCmd (char *buf, int len, client_socket * ns) |
935 | VersionCmd (char *buf, int len, client * ns) |
943 | { |
936 | { |
944 | char *cp; |
937 | char *cp; |
945 | char version_warning[256]; |
938 | char version_warning[256]; |
946 | |
939 | |
947 | if (!buf) |
940 | if (!buf) |
… | |
… | |
971 | cp = strchr (cp + 1, ' '); |
964 | cp = strchr (cp + 1, ' '); |
972 | if (cp) |
965 | if (cp) |
973 | { |
966 | { |
974 | LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
967 | LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); |
975 | |
968 | |
976 | snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); |
969 | assign (ns->version, cp + 1); |
977 | |
970 | |
978 | /* This is first implementation - i skip all beta DX clients with it |
|
|
979 | * Add later stuff here for other clients |
|
|
980 | */ |
|
|
981 | |
|
|
982 | /* these are old dxclients */ |
|
|
983 | /* Version 1024 added support for singular + plural name values - |
|
|
984 | * requiing this minimal value reduces complexity of that code, and it |
|
|
985 | * has been around for a long time. |
|
|
986 | */ |
|
|
987 | if (ns->sc_version < 1026) |
971 | if (ns->sc_version < 1026) |
988 | { |
972 | { |
989 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
973 | sprintf (version_warning, "drawinfo %d %s", NDI_RED, |
990 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
974 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
991 | ns->send_packet (version_warning); |
975 | ns->send_packet (version_warning); |
… | |
… | |
993 | |
977 | |
994 | } |
978 | } |
995 | } |
979 | } |
996 | |
980 | |
997 | /** sound related functions. */ |
981 | /** sound related functions. */ |
998 | |
|
|
999 | void |
982 | void |
1000 | SetSound (char *buf, int len, client_socket * ns) |
983 | SetSound (char *buf, int len, client * ns) |
1001 | { |
984 | { |
1002 | ns->sound = atoi (buf); |
985 | ns->sound = atoi (buf); |
1003 | } |
986 | } |
1004 | |
987 | |
1005 | /** client wants the map resent */ |
988 | /** client wants the map resent */ |
… | |
… | |
1063 | /** |
1046 | /** |
1064 | * Asks the client to query the user. This way, the client knows |
1047 | * Asks the client to query the user. This way, the client knows |
1065 | * it needs to send something back (vs just printing out a message) |
1048 | * it needs to send something back (vs just printing out a message) |
1066 | */ |
1049 | */ |
1067 | void |
1050 | void |
1068 | send_query (client_socket * ns, uint8 flags, char *text) |
1051 | send_query (client * ns, uint8 flags, char *text) |
1069 | { |
1052 | { |
1070 | char buf[MAX_BUF]; |
1053 | char buf[MAX_BUF]; |
1071 | |
1054 | |
1072 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1055 | sprintf (buf, "query %d %s", flags, text ? text : ""); |
1073 | ns->send_packet (buf); |
1056 | ns->send_packet (buf); |
… | |
… | |
1232 | * sent them the face yet (this can become quite costly in terms of |
1215 | * sent them the face yet (this can become quite costly in terms of |
1233 | * how much we are sending - on the other hand, this should only happen |
1216 | * how much we are sending - on the other hand, this should only happen |
1234 | * when the player logs in and picks stuff up. |
1217 | * when the player logs in and picks stuff up. |
1235 | */ |
1218 | */ |
1236 | void |
1219 | void |
1237 | esrv_send_animation (client_socket * ns, short anim_num) |
1220 | esrv_send_animation (client * ns, short anim_num) |
1238 | { |
1221 | { |
1239 | int i; |
1222 | int i; |
1240 | |
1223 | |
1241 | /* Do some checking on the anim_num we got. Note that the animations |
1224 | /* Do some checking on the anim_num we got. Note that the animations |
1242 | * are added in contigous order, so if the number is in the valid |
1225 | * are added in contigous order, so if the number is in the valid |
… | |
… | |
1279 | /** |
1262 | /** |
1280 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1263 | * This adds face_num to a map cell at x,y. If the client doesn't have |
1281 | * the face yet, we will also send it. |
1264 | * the face yet, we will also send it. |
1282 | */ |
1265 | */ |
1283 | static void |
1266 | static void |
1284 | esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap) |
1267 | esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap) |
1285 | { |
1268 | { |
1286 | if (newmap->cells[x][y].count >= MAP_LAYERS) |
1269 | if (newmap->cells[x][y].count >= MAP_LAYERS) |
1287 | { |
1270 | { |
1288 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1271 | LOG (llevError, "Too many faces in map cell %d %d\n", x, y); |
1289 | return; |
1272 | return; |
… | |
… | |
1309 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1292 | struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; |
1310 | }; |
1293 | }; |
1311 | |
1294 | |
1312 | /** Checkes if map cells have changed */ |
1295 | /** Checkes if map cells have changed */ |
1313 | static int |
1296 | static int |
1314 | mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap) |
1297 | mapcellchanged (client * ns, int i, int j, struct Map *newmap) |
1315 | { |
1298 | { |
1316 | int k; |
1299 | int k; |
1317 | |
1300 | |
1318 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1301 | if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) |
1319 | return 1; |
1302 | return 1; |
… | |
… | |
1332 | * cnum is the client number, cur is the the buffer we put all of |
1315 | * cnum is the client number, cur is the the buffer we put all of |
1333 | * this data into. we return the end of the data. layers is |
1316 | * this data into. we return the end of the data. layers is |
1334 | * how many layers of data we should back. |
1317 | * how many layers of data we should back. |
1335 | */ |
1318 | */ |
1336 | static uint8 * |
1319 | static uint8 * |
1337 | compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap) |
1320 | compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap) |
1338 | { |
1321 | { |
1339 | int x, y, k; |
1322 | int x, y, k; |
1340 | int face; |
1323 | int face; |
1341 | unsigned char *fcur; |
1324 | unsigned char *fcur; |
1342 | struct MapLayer layers[MAP_LAYERS]; |
1325 | struct MapLayer layers[MAP_LAYERS]; |
… | |
… | |
1450 | * needs to get sent - if so, it adds the data, sending the head |
1433 | * needs to get sent - if so, it adds the data, sending the head |
1451 | * if needed, and returning 1. If this no data needs to get |
1434 | * if needed, and returning 1. If this no data needs to get |
1452 | * sent, it returns zero. |
1435 | * sent, it returns zero. |
1453 | */ |
1436 | */ |
1454 | static int |
1437 | static int |
1455 | check_head (packet &sl, client_socket &ns, int ax, int ay, int layer) |
1438 | check_head (packet &sl, client &ns, int ax, int ay, int layer) |
1456 | { |
1439 | { |
1457 | short face_num; |
1440 | short face_num; |
1458 | |
1441 | |
1459 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1442 | if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) |
1460 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
1443 | face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; |
… | |
… | |
1494 | * the case, it seems to make more sense to have these layer values |
1477 | * the case, it seems to make more sense to have these layer values |
1495 | * actually match. |
1478 | * actually match. |
1496 | */ |
1479 | */ |
1497 | |
1480 | |
1498 | static int |
1481 | static int |
1499 | update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1482 | update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1500 | { |
1483 | { |
1501 | object *ob, *head; |
1484 | object *ob, *head; |
1502 | uint16 face_num; |
1485 | uint16 face_num; |
1503 | int bx, by, i; |
1486 | int bx, by, i; |
1504 | |
1487 | |
… | |
… | |
1717 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1700 | * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ |
1718 | * take. |
1701 | * take. |
1719 | */ |
1702 | */ |
1720 | |
1703 | |
1721 | static inline int |
1704 | static inline int |
1722 | update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1705 | update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) |
1723 | { |
1706 | { |
1724 | object *ob; |
1707 | object *ob; |
1725 | int smoothlevel; /* old face_num; */ |
1708 | int smoothlevel; /* old face_num; */ |
1726 | |
1709 | |
1727 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
1710 | ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); |
… | |
… | |
1761 | * Returns the size of a data for a map square as returned by |
1744 | * Returns the size of a data for a map square as returned by |
1762 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1745 | * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries |
1763 | * available. |
1746 | * available. |
1764 | */ |
1747 | */ |
1765 | int |
1748 | int |
1766 | getExtendedMapInfoSize (client_socket * ns) |
1749 | getExtendedMapInfoSize (client * ns) |
1767 | { |
1750 | { |
1768 | int result = 0; |
1751 | int result = 0; |
1769 | |
1752 | |
1770 | if (ns->ext_mapinfos) |
1753 | if (ns->ext_mapinfos) |
1771 | { |
1754 | { |
… | |
… | |
1807 | uint8 eentrysize; |
1790 | uint8 eentrysize; |
1808 | uint16 ewhatstart, ewhatflag; |
1791 | uint16 ewhatstart, ewhatflag; |
1809 | uint8 extendedinfos; |
1792 | uint8 extendedinfos; |
1810 | maptile *m; |
1793 | maptile *m; |
1811 | |
1794 | |
1812 | client_socket &socket = *pl->contr->socket; |
1795 | client &socket = *pl->contr->socket; |
1813 | |
1796 | |
1814 | check_map_change (pl->contr); |
1797 | check_map_change (pl->contr); |
1815 | |
1798 | |
1816 | packet sl; |
1799 | packet sl; |
1817 | packet esl; |
1800 | packet esl; |
… | |
… | |
2260 | /** |
2243 | /** |
2261 | * This sends the skill number to name mapping. We ignore |
2244 | * This sends the skill number to name mapping. We ignore |
2262 | * the params - we always send the same info no matter what. |
2245 | * the params - we always send the same info no matter what. |
2263 | */ |
2246 | */ |
2264 | void |
2247 | void |
2265 | send_skill_info (client_socket *ns, char *params) |
2248 | send_skill_info (client *ns, char *params) |
2266 | { |
2249 | { |
2267 | packet sl; |
2250 | packet sl; |
2268 | sl << "replyinfo skill_info\n"; |
2251 | sl << "replyinfo skill_info\n"; |
2269 | |
2252 | |
2270 | for (int i = 1; i < NUM_SKILLS; i++) |
2253 | for (int i = 1; i < NUM_SKILLS; i++) |
… | |
… | |
2282 | /** |
2265 | /** |
2283 | * This sends the spell path to name mapping. We ignore |
2266 | * This sends the spell path to name mapping. We ignore |
2284 | * the params - we always send the same info no matter what. |
2267 | * the params - we always send the same info no matter what. |
2285 | */ |
2268 | */ |
2286 | void |
2269 | void |
2287 | send_spell_paths (client_socket * ns, char *params) |
2270 | send_spell_paths (client * ns, char *params) |
2288 | { |
2271 | { |
2289 | packet sl; |
2272 | packet sl; |
2290 | |
2273 | |
2291 | sl << "replyinfo spell_paths\n"; |
2274 | sl << "replyinfo spell_paths\n"; |
2292 | |
2275 | |