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.40 by root, Fri Dec 15 04:21:29 2006 UTC vs.
Revision 1.41 by root, Fri Dec 15 19:59:20 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 { 96 {
148} 146}
149 147
150static void 148static void
151clear_map (player *pl) 149clear_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 */
165static void 163static void
166check_map_change (player *pl) 164check_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 {
222 * RequestInfo is sort of a meta command. There is some specific 220 * RequestInfo is sort of a meta command. There is some specific
223 * request of information, but we call other functions to provide 221 * request of information, but we call other functions to provide
224 * that information. 222 * that information.
225 */ 223 */
226void 224void
227RequestInfo (char *buf, int len, client_socket * ns) 225RequestInfo (char *buf, int len, client * ns)
228{ 226{
229 char *params = NULL, *cp; 227 char *params = NULL, *cp;
230 228
231 /* No match */ 229 /* No match */
232 char bigbuf[MAX_BUF]; 230 char bigbuf[MAX_BUF];
355 pl->socket->send_packet (bigbuf); 353 pl->socket->send_packet (bigbuf);
356} 354}
357 355
358/** This is the Setup cmd - easy first implementation */ 356/** This is the Setup cmd - easy first implementation */
359void 357void
360SetUp (char *buf, int len, client_socket * ns) 358SetUp (char *buf, int len, client * ns)
361{ 359{
362 int s, slen; 360 int s, slen;
363 char *cmd, *param, cmdback[HUGE_BUF]; 361 char *cmd, *param, cmdback[HUGE_BUF];
364 362
365 /* run through the cmds of setup 363 /* run through the cmds of setup
575 * 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.
576 * 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,
577 * 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.
578 */ 576 */
579void 577void
580AddMeCmd (char *buf, int len, client_socket * ns) 578AddMeCmd (char *buf, int len, client * ns)
581{ 579{
582 Settings oldsettings; 580 Settings oldsettings;
583 581
584 oldsettings = settings; 582 oldsettings = settings;
585 if (ns->status != Ns_Add || add_player (ns)) 583 if (ns->status != Ns_Add || add_player (ns))
590 settings = oldsettings; 588 settings = oldsettings;
591} 589}
592 590
593/** Reply to ExtendedInfos command */ 591/** Reply to ExtendedInfos command */
594void 592void
595ToggleExtendedInfos (char *buf, int len, client_socket * ns) 593ToggleExtendedInfos (char *buf, int len, client * ns)
596{ 594{
597 char cmdback[MAX_BUF]; 595 char cmdback[MAX_BUF];
598 char command[50]; 596 char command[50];
599 int info, nextinfo; 597 int info, nextinfo;
600 598
651#define MSG_TYPE_MONUMENT 5 649#define MSG_TYPE_MONUMENT 5
652#define MSG_TYPE_SCRIPTED_DIALOG 6*/ 650#define MSG_TYPE_SCRIPTED_DIALOG 6*/
653 651
654/** Reply to ExtendedInfos command */ 652/** Reply to ExtendedInfos command */
655void 653void
656ToggleExtendedText (char *buf, int len, client_socket * ns) 654ToggleExtendedText (char *buf, int len, client * ns)
657{ 655{
658 char cmdback[MAX_BUF]; 656 char cmdback[MAX_BUF];
659 char temp[10]; 657 char temp[10];
660 char command[50]; 658 char command[50];
661 int info, nextinfo, i, flag; 659 int info, nextinfo, i, flag;
712 * 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
713 * 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
714 * client. 712 * client.
715 */ 713 */
716static void 714static void
717SendSmooth (client_socket * ns, uint16 face) 715SendSmooth (client * ns, uint16 face)
718{ 716{
719 uint16 smoothface; 717 uint16 smoothface;
720 718
721 /* 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
722 * again. 720 * again.
746 /** 744 /**
747 * Tells client the picture it has to use 745 * Tells client the picture it has to use
748 * to smooth a picture number given as argument. 746 * to smooth a picture number given as argument.
749 */ 747 */
750void 748void
751AskSmooth (char *buf, int len, client_socket * ns) 749AskSmooth (char *buf, int len, client * ns)
752{ 750{
753 uint16 facenbr; 751 uint16 facenbr;
754 752
755 facenbr = atoi (buf); 753 facenbr = atoi (buf);
756 SendSmooth (ns, facenbr); 754 SendSmooth (ns, facenbr);
937 * 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
938 * 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
939 * problem. 937 * problem.
940 */ 938 */
941void 939void
942VersionCmd (char *buf, int len, client_socket * ns) 940VersionCmd (char *buf, int len, client * ns)
943{ 941{
944 char *cp; 942 char *cp;
945 char version_warning[256]; 943 char version_warning[256];
946 944
947 if (!buf) 945 if (!buf)
971 cp = strchr (cp + 1, ' '); 969 cp = strchr (cp + 1, ' ');
972 if (cp) 970 if (cp)
973 { 971 {
974 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);
975 973
976 snprintf (ns->client, sizeof (ns->client), "%s", cp + 1); 974 assign (ns->version, cp + 1);
977 975
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) 976 if (ns->sc_version < 1026)
988 { 977 {
989 sprintf (version_warning, "drawinfo %d %s", NDI_RED, 978 sprintf (version_warning, "drawinfo %d %s", NDI_RED,
990 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); 979 "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****");
991 ns->send_packet (version_warning); 980 ns->send_packet (version_warning);
993 982
994 } 983 }
995} 984}
996 985
997/** sound related functions. */ 986/** sound related functions. */
998
999void 987void
1000SetSound (char *buf, int len, client_socket * ns) 988SetSound (char *buf, int len, client * ns)
1001{ 989{
1002 ns->sound = atoi (buf); 990 ns->sound = atoi (buf);
1003} 991}
1004 992
1005/** client wants the map resent */ 993/** client wants the map resent */
1063/** 1051/**
1064 * 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
1065 * 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)
1066 */ 1054 */
1067void 1055void
1068send_query (client_socket * ns, uint8 flags, char *text) 1056send_query (client * ns, uint8 flags, char *text)
1069{ 1057{
1070 char buf[MAX_BUF]; 1058 char buf[MAX_BUF];
1071 1059
1072 sprintf (buf, "query %d %s", flags, text ? text : ""); 1060 sprintf (buf, "query %d %s", flags, text ? text : "");
1073 ns->send_packet (buf); 1061 ns->send_packet (buf);
1232 * 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
1233 * 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
1234 * when the player logs in and picks stuff up. 1222 * when the player logs in and picks stuff up.
1235 */ 1223 */
1236void 1224void
1237esrv_send_animation (client_socket * ns, short anim_num) 1225esrv_send_animation (client * ns, short anim_num)
1238{ 1226{
1239 int i; 1227 int i;
1240 1228
1241 /* 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
1242 * 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
1279/** 1267/**
1280 * 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
1281 * the face yet, we will also send it. 1269 * the face yet, we will also send it.
1282 */ 1270 */
1283static void 1271static void
1284esrv_map_setbelow (client_socket * ns, int x, int y, short face_num, struct Map *newmap) 1272esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap)
1285{ 1273{
1286 if (newmap->cells[x][y].count >= MAP_LAYERS) 1274 if (newmap->cells[x][y].count >= MAP_LAYERS)
1287 { 1275 {
1288 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);
1289 return; 1277 return;
1309 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y]; 1297 struct LayerCell lcells[MAP_CLIENT_X * MAP_CLIENT_Y];
1310}; 1298};
1311 1299
1312/** Checkes if map cells have changed */ 1300/** Checkes if map cells have changed */
1313static int 1301static int
1314mapcellchanged (client_socket * ns, int i, int j, struct Map *newmap) 1302mapcellchanged (client * ns, int i, int j, struct Map *newmap)
1315{ 1303{
1316 int k; 1304 int k;
1317 1305
1318 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)
1319 return 1; 1307 return 1;
1332 * 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
1333 * 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
1334 * how many layers of data we should back. 1322 * how many layers of data we should back.
1335 */ 1323 */
1336static uint8 * 1324static uint8 *
1337compactlayer (client_socket * ns, unsigned char *cur, int numlayers, struct Map *newmap) 1325compactlayer (client * ns, unsigned char *cur, int numlayers, struct Map *newmap)
1338{ 1326{
1339 int x, y, k; 1327 int x, y, k;
1340 int face; 1328 int face;
1341 unsigned char *fcur; 1329 unsigned char *fcur;
1342 struct MapLayer layers[MAP_LAYERS]; 1330 struct MapLayer layers[MAP_LAYERS];
1450 * 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
1451 * 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
1452 * sent, it returns zero. 1440 * sent, it returns zero.
1453 */ 1441 */
1454static int 1442static int
1455check_head (packet &sl, client_socket &ns, int ax, int ay, int layer) 1443check_head (packet &sl, client &ns, int ax, int ay, int layer)
1456{ 1444{
1457 short face_num; 1445 short face_num;
1458 1446
1459 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer]) 1447 if (heads[(ay * MAX_HEAD_POS + ax) * MAX_LAYERS + layer])
1460 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;
1494 * 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
1495 * actually match. 1483 * actually match.
1496 */ 1484 */
1497 1485
1498static int 1486static int
1499update_space (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1487update_space (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1500{ 1488{
1501 object *ob, *head; 1489 object *ob, *head;
1502 uint16 face_num; 1490 uint16 face_num;
1503 int bx, by, i; 1491 int bx, by, i;
1504 1492
1717 * 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
1718 * take. 1706 * take.
1719 */ 1707 */
1720 1708
1721static inline int 1709static inline int
1722update_smooth (packet &sl, client_socket &ns, maptile *mp, int mx, int my, int sx, int sy, int layer) 1710update_smooth (packet &sl, client &ns, maptile *mp, int mx, int my, int sx, int sy, int layer)
1723{ 1711{
1724 object *ob; 1712 object *ob;
1725 int smoothlevel; /* old face_num; */ 1713 int smoothlevel; /* old face_num; */
1726 1714
1727 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer); 1715 ob = GET_MAP_FACE_OBJ (mp, mx, my, layer);
1761 * 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
1762 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries 1750 * mapextended. There are CLIENTMAPX*CLIENTMAPY*LAYERS entries
1763 * available. 1751 * available.
1764 */ 1752 */
1765int 1753int
1766getExtendedMapInfoSize (client_socket * ns) 1754getExtendedMapInfoSize (client * ns)
1767{ 1755{
1768 int result = 0; 1756 int result = 0;
1769 1757
1770 if (ns->ext_mapinfos) 1758 if (ns->ext_mapinfos)
1771 { 1759 {
1807 uint8 eentrysize; 1795 uint8 eentrysize;
1808 uint16 ewhatstart, ewhatflag; 1796 uint16 ewhatstart, ewhatflag;
1809 uint8 extendedinfos; 1797 uint8 extendedinfos;
1810 maptile *m; 1798 maptile *m;
1811 1799
1812 client_socket &socket = *pl->contr->socket; 1800 client &socket = *pl->contr->socket;
1813 1801
1814 check_map_change (pl->contr); 1802 check_map_change (pl->contr);
1815 1803
1816 packet sl; 1804 packet sl;
1817 packet esl; 1805 packet esl;
2260/** 2248/**
2261 * This sends the skill number to name mapping. We ignore 2249 * This sends the skill number to name mapping. We ignore
2262 * the params - we always send the same info no matter what. 2250 * the params - we always send the same info no matter what.
2263 */ 2251 */
2264void 2252void
2265send_skill_info (client_socket *ns, char *params) 2253send_skill_info (client *ns, char *params)
2266{ 2254{
2267 packet sl; 2255 packet sl;
2268 sl << "replyinfo skill_info\n"; 2256 sl << "replyinfo skill_info\n";
2269 2257
2270 for (int i = 1; i < NUM_SKILLS; i++) 2258 for (int i = 1; i < NUM_SKILLS; i++)
2282/** 2270/**
2283 * This sends the spell path to name mapping. We ignore 2271 * This sends the spell path to name mapping. We ignore
2284 * the params - we always send the same info no matter what. 2272 * the params - we always send the same info no matter what.
2285 */ 2273 */
2286void 2274void
2287send_spell_paths (client_socket * ns, char *params) 2275send_spell_paths (client * ns, char *params)
2288{ 2276{
2289 packet sl; 2277 packet sl;
2290 2278
2291 sl << "replyinfo spell_paths\n"; 2279 sl << "replyinfo spell_paths\n";
2292 2280

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines