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.189 by root, Wed Oct 31 09:17:14 2012 UTC vs.
Revision 1.198 by root, Wed Dec 5 19:03:27 2018 UTC

1/* 1/*
2 * This file is part of Deliantra, the Roguelike Realtime MMORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel 6 * Copyright (©) 2001 Mark Wedel
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 10 * the terms of the Affero GNU General Public License as published by the
28 * \file 29 * \file
29 * Client handling. 30 * Client handling.
30 * 31 *
31 * \date 2003-12-02 32 * \date 2003-12-02
32 * 33 *
33 * This file implements all of the goo on the server side for handling 34 * This file implements all of the goo on the server side for handling
34 * clients. It's got a bunch of global variables for keeping track of 35 * clients. It's got a bunch of global variables for keeping track of
35 * each of the clients. 36 * each of the clients.
36 * 37 *
37 * Note: All functions that are used to process data from the client 38 * Note: All functions that are used to process data from the client
38 * have the prototype of (char *data, int datalen, int client_num). This 39 * have the prototype of (char *data, int datalen, int client_num). This
39 * way, we can use one dispatch table. 40 * way, we can use one dispatch table.
40 * 41 *
276 277
277/** 278/**
278 * RequestInfo is sort of a meta command. There is some specific 279 * RequestInfo is sort of a meta command. There is some specific
279 * request of information, but we call other functions to provide 280 * request of information, but we call other functions to provide
280 * that information. 281 * that information.
282 * requestinfo is completely deprecated, use resource exti request
283 * and the fxix or http protocols.
281 */ 284 */
282void 285void
283RequestInfo (char *buf, int len, client *ns) 286RequestInfo (char *buf, int len, client *ns)
284{ 287{
285 char *params; 288 char *params;
323//-GPL 326//-GPL
324 327
325void 328void
326client::mapinfo_queue_clear () 329client::mapinfo_queue_clear ()
327{ 330{
328 for (auto (i, mapinfo_queue.begin ()); i != mapinfo_queue.end (); ++i) 331 for (auto &&i : mapinfo_queue)
329 free (*i); 332 free (i);
330 333
331 mapinfo_queue.clear (); 334 mapinfo_queue.clear ();
332} 335}
333 336
334bool 337bool
349 352
350 // due to historical glitches, the mapinfo index and tile index differs 353 // due to historical glitches, the mapinfo index and tile index differs
351 static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN }; 354 static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN };
352 355
353 // maybe we should only allow the four flat directions 356 // maybe we should only allow the four flat directions
354 if (IN_RANGE_EXC (dir, 0, array_length (dirmap))) 357 if (IN_RANGE_EXC (dir, 0, ecb_array_length (dirmap)))
355 { 358 {
356 dir = dirmap [dir]; 359 dir = dirmap [dir];
357 360
358 if (!map->tile_path [dir]) 361 if (!map->tile_path [dir])
359 map = 0; 362 map = 0;
494 * Cleaning up the input should probably be done first - all actions 497 * Cleaning up the input should probably be done first - all actions
495 * for the command that issued the count should be done before any other 498 * for the command that issued the count should be done before any other
496 * commands. 499 * commands.
497 */ 500 */
498 pl->count = 0; 501 pl->count = 0;
499}
500
501/**
502 * This handles the general commands from the client (ie, north, fire, cast,
503 * etc.). It is a lot like PlayerCmd above, but is called with the
504 * 'ncom' method which gives more information back to the client so it
505 * can throttle.
506 */
507void
508NewPlayerCmd (char *buf, int len, player *pl)
509{
510 if (len <= 6)
511 {
512 LOG (llevDebug, "%s: corrupt ncom command <%s>: not long enough (%d) - discarding\n", pl->ns->host, buf, len);
513 return;
514 }
515
516 uint16 cmdid = net_uint16 ((uint8 *)buf);
517 sint32 repeat = net_sint32 ((uint8 *)buf + 2);
518
519 /* -1 is special - no repeat, but don't update */
520 if (repeat != -1)
521 pl->count = repeat;
522
523 buf += 6; //len -= 6;
524
525 execute_newserver_command (pl->ob, buf);
526
527 /* Perhaps something better should be done with a left over count.
528 * Cleaning up the input should probably be done first - all actions
529 * for the command that issued the count should be done before any other
530 * commands.
531 */
532 pl->count = 0;
533
534 //TODO: schmorp thinks whatever this calculates, it makes no sense at all
535 int time = pl->ob->has_active_speed ()
536 ? (int) (MAX_TIME / pl->ob->speed)
537 : MAX_TIME * 100;
538
539 /* Send confirmation of command execution now */
540 packet sl ("comc");
541 sl << uint16 (cmdid) << uint32 (time);
542 pl->ns->send_packet (sl);
543} 502}
544 503
545/** This is a reply to a previous query. */ 504/** This is a reply to a previous query. */
546void 505void
547ReplyCmd (char *buf, int len, client *ns) 506ReplyCmd (char *buf, int len, client *ns)
982 { 941 {
983 /* This block deals with spaces that are not visible for whatever 942 /* This block deals with spaces that are not visible for whatever
984 * reason. Still may need to send the head for this space. 943 * reason. Still may need to send the head for this space.
985 */ 944 */
986 if (lastcell.count != -1 945 if (lastcell.count != -1
987 || lastcell.faces[0] 946 || lastcell.faces[0]
988 || lastcell.faces[1] 947 || lastcell.faces[1]
989 || lastcell.faces[2] 948 || lastcell.faces[2]
990 || lastcell.stat_hp 949 || lastcell.stat_hp
991 || lastcell.flags 950 || lastcell.flags
992 || lastcell.player) 951 || lastcell.player)
993 sl << uint16 (mask); 952 sl << uint16 (mask);
994 953
995 /* properly clear a previously sent big face */ 954 /* properly clear a previously sent big face */
996 map_clearcell (&lastcell, -1); 955 map_clearcell (&lastcell, -1);
1052 { 1011 {
1053 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; 1012 stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp;
1054 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge 1013 stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge
1055 } 1014 }
1056 1015
1057 if (expect_false (op->has_dialogue ())) 1016 if (ecb_expect_false (op->has_dialogue ()))
1058 flags |= 1; 1017 flags |= 1;
1059 1018
1060 if (expect_false (op->type == PLAYER)) 1019 if (ecb_expect_false (op->type == PLAYER))
1061 player = op == ob ? pl->ob->count 1020 player = op == ob ? pl->ob->count
1062 : op == pl->ob ? ob->count 1021 : op == pl->ob ? ob->count
1063 : op->count; 1022 : op->count;
1064 } 1023 }
1065 1024
1066 if (expect_false (lastcell.stat_hp != stat_hp)) 1025 if (ecb_expect_false (lastcell.stat_hp != stat_hp))
1067 { 1026 {
1068 lastcell.stat_hp = stat_hp; 1027 lastcell.stat_hp = stat_hp;
1069 1028
1070 mask |= 0x8; 1029 mask |= 0x8;
1071 *last_ext |= 0x80; 1030 *last_ext |= 0x80;
1080 1039
1081 sl << uint8 (6) << uint8 (stat_width); 1040 sl << uint8 (6) << uint8 (stat_width);
1082 } 1041 }
1083 } 1042 }
1084 1043
1085 if (expect_false (lastcell.player != player)) 1044 if (ecb_expect_false (lastcell.player != player))
1086 { 1045 {
1087 lastcell.player = player; 1046 lastcell.player = player;
1088 1047
1089 mask |= 0x8; 1048 mask |= 0x8;
1090 *last_ext |= 0x80; 1049 *last_ext |= 0x80;
1091 last_ext = &sl[sl.length ()]; 1050 last_ext = &sl[sl.length ()];
1092 1051
1093 sl << uint8 (0x47) << uint8 (4) << (uint32)player; 1052 sl << uint8 (0x47) << uint8 (4) << (uint32)player;
1094 } 1053 }
1095 1054
1096 if (expect_false (lastcell.flags != flags)) 1055 if (ecb_expect_false (lastcell.flags != flags))
1097 { 1056 {
1098 lastcell.flags = flags; 1057 lastcell.flags = flags;
1099 1058
1100 mask |= 0x8; 1059 mask |= 0x8;
1101 *last_ext |= 0x80; 1060 *last_ext |= 0x80;
1112 1071
1113 /* Middle face */ 1072 /* Middle face */
1114 if (update_space (sl, socket, ms, lastcell, 1)) 1073 if (update_space (sl, socket, ms, lastcell, 1))
1115 mask |= 0x2; 1074 mask |= 0x2;
1116 1075
1117 if (expect_false (ob->invisible) 1076 if (ecb_expect_false (ob->invisible)
1118 && ob->invisible & (ob->invisible < 50 ? 1 : 7) 1077 && ob->invisible & (ob->invisible < 50 ? 1 : 7)
1119 && ms.player () == ob) 1078 && ms.player () == ob)
1120 { 1079 {
1121 // force player to be visible to himself if invisible 1080 // force player to be visible to himself if invisible
1122 if (lastcell.faces[0] != ob->face) 1081 if (lastcell.faces[0] != ob->face)
1272 << uint16 (spell->cached_grace) 1231 << uint16 (spell->cached_grace)
1273 << uint16 (spell->cached_eat) 1232 << uint16 (spell->cached_eat)
1274 << uint8 (skill) 1233 << uint8 (skill)
1275 << uint32 (spell->path_attuned) 1234 << uint32 (spell->path_attuned)
1276 << uint32 (spell->face) 1235 << uint32 (spell->face)
1277 << data8 (spell->name) 1236 << data8 (spell->name);
1237
1238 if (pl->ns->monitor_spells < 2)
1278 << data16 (spell->msg); 1239 sl << data16 (spell->msg);
1279} 1240}
1280 1241
1281/** 1242/**
1282 * This tells the client to add the spell *ob, if *ob is NULL, then add 1243 * This tells the client to add the spell *ob, if *ob is NULL, then add
1283 * all spells in the player's inventory. 1244 * all spells in the player's inventory.
1284 */ 1245 */
1285void 1246void
1286esrv_add_spells (player *pl, object *spell) 1247esrv_add_spells (player *pl, object *spell)
1287{ 1248{
1298 1259
1299 if (!spell) 1260 if (!spell)
1300 { 1261 {
1301 for (spell = pl->ob->inv; spell; spell = spell->below) 1262 for (spell = pl->ob->inv; spell; spell = spell->below)
1302 { 1263 {
1303 /* were we to simply keep appending data here, we could exceed 1264 /* were we to simply keep appending data here, we could exceed
1304 * MAXSOCKBUF if the player has enough spells to add, we know that 1265 * MAXSOCKBUF if the player has enough spells to add, we know that
1305 * append_spells will always append 19 data bytes, plus 4 length 1266 * append_spells will always append 19 data bytes, plus 4 length
1306 * bytes and 3 strings (because that is the spec) so we need to 1267 * bytes and 3 strings (because that is the spec) so we need to
1307 * check that the length of those 3 strings, plus the 23 bytes, 1268 * check that the length of those 3 strings, plus the 23 bytes,
1308 * won't take us over the length limit for the socket, if it does, 1269 * won't take us over the length limit for the socket, if it does,
1309 * we need to send what we already have, and restart packet formation 1270 * we need to send what we already have, and restart packet formation
1310 */ 1271 */
1311 if (spell->type != SPELL) 1272 if (spell->type != SPELL)
1312 continue; 1273 continue;
1313 1274
1314 /* Seeing crashes by overflowed buffers. Quick arithemetic seems 1275 /* Seeing crashes by overflowed buffers. Quick arithemetic seems

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines