ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/request.C
(Generate patch)

Comparing deliantra/server/socket/request.C (file contents):
Revision 1.39 by root, Fri Dec 15 03:53:44 2006 UTC vs.
Revision 1.43 by root, Sat Dec 16 20:16:37 2006 UTC

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
92static void 90static void
93socket_map_scroll (client_socket * ns, int dx, int dy) 91socket_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
150static void 143static void
151clear_map (player *pl) 144clear_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 */
165static void 158static void
166check_map_change (player *pl) 159check_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 {
214 } 207 }
215 } 208 }
216 209
217 socket.current_x = ob->x; 210 socket.current_x = ob->x;
218 socket.current_y = ob->y; 211 socket.current_y = ob->y;
212}
213
214/**
215 * RequestInfo is sort of a meta command. There is some specific
216 * request of information, but we call other functions to provide
217 * that information.
218 */
219void
220RequestInfo (char *buf, int len, client * ns)
221{
222 char *params = NULL, *cp;
223
224 /* No match */
225 char bigbuf[MAX_BUF];
226 int slen;
227
228 /* Set up replyinfo before we modify any of the buffers - this is used
229 * if we don't find a match.
230 */
231 strcpy (bigbuf, "replyinfo ");
232 slen = strlen (bigbuf);
233 safe_strcat (bigbuf, buf, &slen, MAX_BUF);
234
235 /* find the first space, make it null, and update the
236 * params pointer.
237 */
238 for (cp = buf; *cp != '\0'; cp++)
239 if (*cp == ' ')
240 {
241 *cp = '\0';
242 params = cp + 1;
243 break;
244 }
245
246 if (!strcmp (buf, "image_info"))
247 send_image_info (ns, params);
248 else if (!strcmp (buf, "image_sums"))
249 send_image_sums (ns, params);
250 else if (!strcmp (buf, "skill_info"))
251 send_skill_info (ns, params);
252 else if (!strcmp (buf, "spell_paths"))
253 send_spell_paths (ns, params);
254 else
255 ns->send_packet (bigbuf, len);
219} 256}
220 257
221void 258void
222ExtCmd (char *buf, int len, player *pl) 259ExtCmd (char *buf, int len, player *pl)
223{ 260{
311 pl->socket->send_packet (bigbuf); 348 pl->socket->send_packet (bigbuf);
312} 349}
313 350
314/** This is the Setup cmd - easy first implementation */ 351/** This is the Setup cmd - easy first implementation */
315void 352void
316SetUp (char *buf, int len, client_socket * ns) 353SetUp (char *buf, int len, client * ns)
317{ 354{
318 int s, slen; 355 int s, slen;
319 char *cmd, *param, cmdback[HUGE_BUF]; 356 char *cmd, *param, cmdback[HUGE_BUF];
320 357
321 /* run through the cmds of setup 358 /* run through the cmds of setup
531 * 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.
532 * 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,
533 * 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.
534 */ 571 */
535void 572void
536AddMeCmd (char *buf, int len, client_socket * ns) 573AddMeCmd (char *buf, int len, client * ns)
537{ 574{
538 Settings oldsettings;
539
540 oldsettings = settings;
541 if (ns->status != Ns_Add || add_player (ns)) 575 if (ns->status != Ns_Add || add_player (ns))
542 ns->send_packet ("addme_failed"); 576 ns->send_packet ("addme_failed");
543 else 577 else
544 ns->send_packet ("addme_success"); 578 ns->send_packet ("addme_success");
545
546 settings = oldsettings;
547} 579}
548 580
549/** Reply to ExtendedInfos command */ 581/** Reply to ExtendedInfos command */
550void 582void
551ToggleExtendedInfos (char *buf, int len, client_socket * ns) 583ToggleExtendedInfos (char *buf, int len, client * ns)
552{ 584{
553 char cmdback[MAX_BUF]; 585 char cmdback[MAX_BUF];
554 char command[50]; 586 char command[50];
555 int info, nextinfo; 587 int info, nextinfo;
556 588
607#define MSG_TYPE_MONUMENT 5 639#define MSG_TYPE_MONUMENT 5
608#define MSG_TYPE_SCRIPTED_DIALOG 6*/ 640#define MSG_TYPE_SCRIPTED_DIALOG 6*/
609 641
610/** Reply to ExtendedInfos command */ 642/** Reply to ExtendedInfos command */
611void 643void
612ToggleExtendedText (char *buf, int len, client_socket * ns) 644ToggleExtendedText (char *buf, int len, client * ns)
613{ 645{
614 char cmdback[MAX_BUF]; 646 char cmdback[MAX_BUF];
615 char temp[10]; 647 char temp[10];
616 char command[50]; 648 char command[50];
617 int info, nextinfo, i, flag; 649 int info, nextinfo, i, flag;
668 * a piece of data from us that we know the client wants. So 700 * 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 701 * if we know the client wants it, might as well push it to the
670 * client. 702 * client.
671 */ 703 */
672static void 704static void
673SendSmooth (client_socket * ns, uint16 face) 705SendSmooth (client * ns, uint16 face)
674{ 706{
675 uint16 smoothface; 707 uint16 smoothface;
676 708
677 /* If we can't find a face, return and set it so we won't try to send this 709 /* If we can't find a face, return and set it so we won't try to send this
678 * again. 710 * again.
702 /** 734 /**
703 * Tells client the picture it has to use 735 * Tells client the picture it has to use
704 * to smooth a picture number given as argument. 736 * to smooth a picture number given as argument.
705 */ 737 */
706void 738void
707AskSmooth (char *buf, int len, client_socket * ns) 739AskSmooth (char *buf, int len, client * ns)
708{ 740{
709 uint16 facenbr; 741 uint16 facenbr;
710 742
711 facenbr = atoi (buf); 743 facenbr = atoi (buf);
712 SendSmooth (ns, facenbr); 744 SendSmooth (ns, facenbr);
893 * something older than the server. If we assume the client will be 925 * 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 926 * backwards compatible, having it be a later version should not be a
895 * problem. 927 * problem.
896 */ 928 */
897void 929void
898VersionCmd (char *buf, int len, client_socket * ns) 930VersionCmd (char *buf, int len, client * ns)
899{ 931{
900 char *cp; 932 char *cp;
901 char version_warning[256]; 933 char version_warning[256];
902 934
903 if (!buf) 935 if (!buf)
927 cp = strchr (cp + 1, ' '); 959 cp = strchr (cp + 1, ' ');
928 if (cp) 960 if (cp)
929 { 961 {
930 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host); 962 LOG (llevDebug, "CS: connection from client of type <%s>, ip %s\n", cp, ns->host);
931 963
932 snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); 964 assign (ns->version, cp + 1);
933 965
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) 966 if (ns->sc_version < 1026)
944 { 967 {
945 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 968 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
946 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 969 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
947 ns->send_packet (version_warning); 970 ns->send_packet (version_warning);
949 972
950 } 973 }
951} 974}
952 975
953/** sound related functions. */ 976/** sound related functions. */
954
955void 977void
956SetSound (char *buf, int len, client_socket * ns) 978SetSound (char *buf, int len, client * ns)
957{ 979{
958 ns->sound = atoi (buf); 980 ns->sound = atoi (buf);
959} 981}
960 982
961/** client wants the map resent */ 983/** client wants the map resent */
1019/** 1041/**
1020 * Asks the client to query the user. This way, the client knows 1042 * 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) 1043 * it needs to send something back (vs just printing out a message)
1022 */ 1044 */
1023void 1045void
1024send_query (client_socket * ns, uint8 flags, char *text) 1046send_query (client * ns, uint8 flags, char *text)
1025{ 1047{
1026 char buf[MAX_BUF]; 1048 char buf[MAX_BUF];
1027 1049
1028 sprintf (buf, "query %d %s", flags, text ? text : ""); 1050 sprintf (buf, "query %d %s", flags, text ? text : "");
1029 ns->send_packet (buf); 1051 ns->send_packet (buf);
1188 * sent them the face yet (this can become quite costly in terms of 1210 * 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 1211 * how much we are sending - on the other hand, this should only happen
1190 * when the player logs in and picks stuff up. 1212 * when the player logs in and picks stuff up.
1191 */ 1213 */
1192void 1214void
1193esrv_send_animation (client_socket * ns, short anim_num) 1215esrv_send_animation (client * ns, short anim_num)
1194{ 1216{
1195 int i; 1217 int i;
1196 1218
1197 /* Do some checking on the anim_num we got. Note that the animations 1219 /* 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 1220 * are added in contigous order, so if the number is in the valid
1235/** 1257/**
1236 * This adds face_num to a map cell at x,y. If the client doesn't have 1258 * 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. 1259 * the face yet, we will also send it.
1238 */ 1260 */
1239static void 1261static void
1240esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap) 1262esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap)
1241{ 1263{
1242 if (newmap->cells[x][y].count >= MAP_LAYERS) 1264 if (newmap->cells[x][y].count >= MAP_LAYERS)
1243 { 1265 {
1244 LOG (llevError, "Too many faces in map cell %d %d\n", x, y); 1266 LOG (llevError, "Too many faces in map cell %d %d\n", x, y);
1245 return; 1267 return;
1265 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; 1287 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y];
1266}; 1288};
1267 1289
1268/** Checkes if map cells have changed */ 1290/** Checkes if map cells have changed */
1269static int 1291static int
1270mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap) 1292mapcellchanged (client * ns, int i, int j, struct Map *newmap)
1271{ 1293{
1272 int k; 1294 int k;
1273 1295
1274 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count) 1296 if (ns->lastmap.cells[i][j].count != newmap->cells[i][j].count)
1275 return 1; 1297 return 1;
1288 * cnum is the client number, cur is the the buffer we put all of 1310 * 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 1311 * this data into. we return the end of the data. layers is
1290 * how many layers of data we should back. 1312 * how many layers of data we should back.
1291 */ 1313 */
1292static uint8 * 1314static uint8 *
1293compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap) 1315compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap)
1294{ 1316{
1295 int x, y, k; 1317 int x, y, k;
1296 int face; 1318 int face;
1297 unsigned char *fcur; 1319 unsigned char *fcur;
1298 struct MapLayer layers[MAP_LAYERS]; 1320 struct MapLayer layers[MAP_LAYERS];
1406 * needs to get sent - if so, it adds the data, sending the head 1428 * 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 1429 * if needed, and returning 1. If this no data needs to get
1408 * sent, it returns zero. 1430 * sent, it returns zero.
1409 */ 1431 */
1410static int 1432static int
1411check_head (packet &sl, client_socket &ns, int ax, int ay, int layer) 1433check_head (packet &sl, client &ns, int ax, int ay, int layer)
1412{ 1434{
1413 short face_num; 1435 short face_num;
1414 1436
1415 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1437 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1416 face_num = heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]->face->number; 1438 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 1472 * the case, it seems to make more sense to have these layer values
1451 * actually match. 1473 * actually match.
1452 */ 1474 */
1453 1475
1454static int 1476static int
1455update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1477update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1456{ 1478{
1457 object *ob, *head; 1479 object *ob, *head;
1458 uint16 face_num; 1480 uint16 face_num;
1459 int bx, by, i; 1481 int bx, by, i;
1460 1482
1673 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ 1695 * top layer (this matches what the GET_MAP_FACE and GET_MAP_FACE_OBJ
1674 * take. 1696 * take.
1675 */ 1697 */
1676 1698
1677static inline int 1699static inline int
1678update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1700update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1679{ 1701{
1680 object *ob; 1702 object *ob;
1681 int smoothlevel; /* old face_num; */ 1703 int smoothlevel; /* old face_num; */
1682 1704
1683 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1705 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1717 * Returns the size of a data for a map square as returned by 1739 * Returns the size of a data for a map square as returned by
1718 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries 1740 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
1719 * available. 1741 * available.
1720 */ 1742 */
1721int 1743int
1722getExtendedMapInfoSize (client_socket * ns) 1744getExtendedMapInfoSize (client * ns)
1723{ 1745{
1724 int result = 0; 1746 int result = 0;
1725 1747
1726 if (ns->ext_mapinfos) 1748 if (ns->ext_mapinfos)
1727 { 1749 {
1763 uint8 eentrysize; 1785 uint8 eentrysize;
1764 uint16 ewhatstart, ewhatflag; 1786 uint16 ewhatstart, ewhatflag;
1765 uint8 extendedinfos; 1787 uint8 extendedinfos;
1766 maptile *m; 1788 maptile *m;
1767 1789
1768 client_socket &socket = *pl->contr->socket; 1790 client &socket = *pl->contr->socket;
1769 1791
1770 check_map_change (pl->contr); 1792 check_map_change (pl->contr);
1771 1793
1772 packet sl; 1794 packet sl;
1773 packet esl; 1795 packet esl;
2216/** 2238/**
2217 * This sends the skill number to name mapping. We ignore 2239 * This sends the skill number to name mapping. We ignore
2218 * the params - we always send the same info no matter what. 2240 * the params - we always send the same info no matter what.
2219 */ 2241 */
2220void 2242void
2221send_skill_info (client_socket *ns, char *params) 2243send_skill_info (client *ns, char *params)
2222{ 2244{
2223 packet sl; 2245 packet sl;
2224 sl << "replyinfo skill_info\n"; 2246 sl << "replyinfo skill_info\n";
2225 2247
2226 for (int i = 1; i < NUM_SKILLS; i++) 2248 for (int i = 1; i < NUM_SKILLS; i++)
2238/** 2260/**
2239 * This sends the spell path to name mapping. We ignore 2261 * This sends the spell path to name mapping. We ignore
2240 * the params - we always send the same info no matter what. 2262 * the params - we always send the same info no matter what.
2241 */ 2263 */
2242void 2264void
2243send_spell_paths (client_socket * ns, char *params) 2265send_spell_paths (client * ns, char *params)
2244{ 2266{
2245 packet sl; 2267 packet sl;
2246 2268
2247 sl << "replyinfo spell_paths\n"; 2269 sl << "replyinfo spell_paths\n";
2248 2270

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines