--- deliantra/server/socket/request.C 2010/03/22 00:56:57 1.163 +++ deliantra/server/socket/request.C 2011/04/22 06:10:34 1.178 @@ -1,9 +1,9 @@ /* * This file is part of Deliantra, the Roguelike Realtime MMORPG. * - * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team - * Copyright (©) 2001,2007 Mark Wedel - * Copyright (©) 1992,2007 Frank Tore Johansen + * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team + * Copyright (©) 2001 Mark Wedel + * Copyright (©) 1992 Frank Tore Johansen * * Deliantra is free software: you can redistribute it and/or modify it under * the terms of the Affero GNU General Public License as published by the @@ -46,7 +46,6 @@ #include #include -#include /* This block is basically taken from socket.c - I assume if it works there, * it should work here. @@ -68,16 +67,30 @@ * client. If a value is -1, then we don't send that to the * client. */ -static short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, - CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, - CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, - CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , - CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, - CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, - CS_STAT_RES_FEAR, -1 /* Cancellation */ , - CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, - -1 /* Chaos */ , -1 /* Counterspell */ , - -1 /* Godpower */ , CS_STAT_RES_HOLYWORD, +static short atnr_cs_stat[NROFATTACKS] = +{ + CS_STAT_RES_PHYS, + CS_STAT_RES_MAG, + CS_STAT_RES_FIRE, + CS_STAT_RES_ELEC, + CS_STAT_RES_COLD, + CS_STAT_RES_CONF, + CS_STAT_RES_ACID, + CS_STAT_RES_DRAIN, + -1 /* weaponmagic */, + CS_STAT_RES_GHOSTHIT, + CS_STAT_RES_POISON, + CS_STAT_RES_SLOW, + CS_STAT_RES_PARA, + CS_STAT_TURN_UNDEAD, + CS_STAT_RES_FEAR, + -1 /* Cancellation */, + CS_STAT_RES_DEPLETE, + CS_STAT_RES_DEATH, + -1 /* Chaos */, + -1 /* Counterspell */, + -1 /* Godpower */, + CS_STAT_RES_HOLYWORD, CS_STAT_RES_BLIND, -1, /* Internal */ -1, /* life stealing */ @@ -135,10 +148,7 @@ memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); pl->ns->force_newmap = false; - - if (pl->ns->newmapcmd == 1) - pl->ns->send_packet ("newmap"); - + pl->ns->send_packet ("newmap"); pl->ns->floorbox_reset (); } @@ -154,10 +164,13 @@ { int flags = 0; - if (ob->map->tile_path[0]) flags |= 1; - if (ob->map->tile_path[1]) flags |= 2; - if (ob->map->tile_path[2]) flags |= 4; - if (ob->map->tile_path[3]) flags |= 8; + if (ob->map->tile_path[0]) flags |= 0x01; + if (ob->map->tile_path[1]) flags |= 0x02; + if (ob->map->tile_path[2]) flags |= 0x04; + if (ob->map->tile_path[3]) flags |= 0x08; + // these two are debatable + if (ob->map->tile_path[4]) flags |= 0x10; + if (ob->map->tile_path[5]) flags |= 0x20; socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, @@ -231,14 +244,11 @@ packet sl; sl << "replyinfo skill_info\n"; - for (int i = 1; i < NUM_SKILLS; i++) - sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); + for (int i = 0; i < skillvec.size (); ++i) + sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); if (sl.length () > MAXSOCKBUF) - { - LOG (llevError, "Buffer overflow in send_skill_info!\n"); - fatal (0); - } + cleanup ("buffer overflow in send_skill_info!"); ns->send_packet (sl); } @@ -258,10 +268,7 @@ sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); if (sl.length () > MAXSOCKBUF) - { - LOG (llevError, "Buffer overflow in send_spell_paths!\n"); - fatal (0); - } + cleanup ("buffer overflow in send_spell_paths!"); ns->send_packet (sl); } @@ -339,7 +346,8 @@ { int dir = *buf++ - '1'; - if (dir >= 0 && dir <= 3) + // maybe we should only allow the four flat directions + if (dir >= 0 && dir < TILE_NUM) { if (!map->tile_path [dir]) map = 0; @@ -373,10 +381,13 @@ { int flags = 0; - if (map->tile_path[0]) flags |= 1; - if (map->tile_path[1]) flags |= 2; - if (map->tile_path[2]) flags |= 4; - if (map->tile_path[3]) flags |= 8; + if (map->tile_path[0]) flags |= 0x01; + if (map->tile_path[1]) flags |= 0x02; + if (map->tile_path[2]) flags |= 0x04; + if (map->tile_path[3]) flags |= 0x08; + // these two are debatable + if (map->tile_path[4]) flags |= 0x10; + if (map->tile_path[5]) flags |= 0x20; send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); } @@ -449,70 +460,6 @@ //+GPL -/* -#define MSG_TYPE_BOOK 1 -#define MSG_TYPE_CARD 2 -#define MSG_TYPE_PAPER 3 -#define MSG_TYPE_SIGN 4 -#define MSG_TYPE_MONUMENT 5 -#define MSG_TYPE_SCRIPTED_DIALOG 6*/ - -/** Reply to ExtendedInfos command */ -void -ToggleExtendedText (char *buf, int len, client * ns) -{ - char cmdback[MAX_BUF]; - char temp[10]; - char command[50]; - int info, nextinfo, i, flag; - - cmdback[0] = '\0'; - - nextinfo = 0; - while (1) - { - /* 1. Extract an info */ - info = nextinfo; - - while ((info < len) && (buf [info] == ' ')) - info++; - - if (info >= len) - break; - - nextinfo = info + 1; - - while ((nextinfo < len) && (buf [nextinfo] != ' ')) - nextinfo++; - - if (nextinfo - info >= 49) /*Erroneous info asked */ - continue; - - memcpy (command, buf + info, nextinfo - info); - command [nextinfo - info] = 0; - - /* 2. Interpret info */ - i = sscanf (command, "%d", &flag); - - if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST)) - ns->supported_readables |= (1 << flag); - /*3. Next info */ - } - - /* Send resulting state */ - strcpy (cmdback, "ExtendedTextSet"); - - for (i = 0; i <= MSG_TYPE_LAST; i++) - if (ns->supported_readables & (1 << i)) - { - strcat (cmdback, " "); - snprintf (temp, sizeof (temp), "%d", i); - strcat (cmdback, temp); - } - - ns->send_packet (cmdback); -} - /** * This handles the general commands from the client (ie, north, fire, cast, * etc.) @@ -632,50 +579,12 @@ } /** - * Client tells its version. If there is a mismatch, we close the - * socket. In real life, all we should care about is the client having - * something older than the server. If we assume the client will be - * backwards compatible, having it be a later version should not be a - * problem. + * Client tells its version info. */ void -VersionCmd (char *buf, int len, client * ns) +VersionCmd (char *buf, int len, client *ns) { - if (!buf) - { - LOG (llevError, "CS: received corrupted version command\n"); - return; - } - - ns->cs_version = atoi (buf); - ns->sc_version = ns->cs_version; - - LOG (llevDebug, "connection from client <%s>\n", buf); - - //TODO: should log here just for statistics - - //if (VERSION_CS != ns->cs_version) - // unchecked; - - char *cp = strchr (buf + 1, ' '); - if (!cp) - return; - - ns->sc_version = atoi (cp); - - //if (VERSION_SC != ns->sc_version) - // unchecked; - - cp = strchr (cp + 1, ' '); - - if (cp) - { - ns->version = cp + 1; - - if (ns->sc_version < 1026) - ns->send_packet_printf ("drawinfo %d %s", NDI_RED, - "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); - } + INVOKE_CLIENT (VERSION, ns, ARG_DATA (buf, len)); } /** sound related functions. */ @@ -738,6 +647,16 @@ { dynbuf_text &buf = msg_dynbuf; buf.clear (); +#if 0 + // print ranged/chosen_skill etc. objects every call + printf ("%s %s => %s (%s)\n", + pl->ranged_ob ? &pl->ranged_ob->name : "-", + pl->combat_ob ? &pl->combat_ob->name : "-", + pl->ob->current_weapon ? &pl->ob->current_weapon->name : "-", + pl->ob->chosen_skill ? &pl->ob->chosen_skill->name : "-" + ); +#endif + if (pl->ranged_ob) buf << " Range" << (pl->ob->current_weapon == pl->ranged_ob ? "*" : "") << ": " << pl->ranged_ob->name; @@ -792,9 +711,6 @@ void esrv_update_stats (player *pl) { - char buf[MAX_BUF]; - uint16 flags; - client *ns = pl->ns; if (!ns) return; @@ -821,7 +737,7 @@ AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); - for (int s = 0; s < NUM_SKILLS; s++) + for (int s = 0; s < CS_NUM_SKILLS; s++) if (object *skill = opl->last_skill_ob [s]) if (skill->stats.exp != ns->last_skill_exp [s]) { @@ -830,7 +746,7 @@ /* Always send along the level if exp changes. This is only * 1 extra byte, but keeps processing simpler. */ - sl << uint8 (s + CS_STAT_SKILLINFO) + sl << uint8 (CS_STAT_SKILLINFO + s) << uint8 (skill->level) << uint64 (skill->stats.exp); } @@ -845,24 +761,15 @@ AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); - flags = 0; - - if (opl->fire_on) - flags |= SF_FIREON; - - if (opl->run_on) - flags |= SF_RUNON; + int flags = (opl->fire_on ? SF_FIREON : 0) + | (opl->run_on ? SF_RUNON : 0); AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); for (int i = 0; i < NROFATTACKS; i++) - { - /* Skip ones we won't send */ - if (atnr_cs_stat[i] == -1) - continue; - + /* Skip ones we won't send */ + if (atnr_cs_stat[i] >= 0) AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); - } if (pl->ns->monitor_spells) { @@ -871,6 +778,7 @@ AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); } + char buf[MAX_BUF]; rangetostring (opl, buf); /* we want use the new fire & run system in new client */ AddIfString (ns->stats.range, buf, CS_STAT_RANGE); set_title (ob, buf); @@ -976,26 +884,29 @@ //-GPL -// prefetch (and touch) all maps within a specific distancd +// prefetch some flat area around the player static void -prefetch_surrounding_maps (maptile *map, int distance) +prefetch_surrounding_area (object *op, maptile *map, int range) { - map->touch (); - - if (--distance) - for (int dir = 4; dir--; ) - if (const shstr &path = map->tile_path [dir]) - if (maptile *&neigh = map->tile_map [dir]) - prefetch_surrounding_maps (neigh, distance); - else - neigh = maptile::find_async (path, map); + for (maprect *rect = map->split_to_tiles (mapwalk_buf, + op->x - range , op->y - range , + op->x + range + 1, op->y + range + 1); + rect->m; + ++rect) + rect->m->touch (); } -// prefetch a generous area around the player +// prefetch a generous area around the player, also up and down static void prefetch_surrounding_maps (object *op) { - prefetch_surrounding_maps (op->map, 3); + prefetch_surrounding_area (op, op->map, 40); + + if (maptile *m = op->map->tile_available (TILE_DOWN)) + prefetch_surrounding_area (op, m, 20); + + if (maptile *m = op->map->tile_available (TILE_UP)) + prefetch_surrounding_area (op, m, 20); } //+GPL @@ -1055,7 +966,7 @@ client &socket = *pl->ns; - packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); + packet sl ("map1a"); startlen = sl.length (); @@ -1157,9 +1068,9 @@ && op->stats.maxhp > 0 && (op->type == PLAYER || op->type == DOOR // does not work, have maxhp 0 - || QUERY_FLAG (op, FLAG_MONSTER) - || QUERY_FLAG (op, FLAG_ALIVE) - || QUERY_FLAG (op, FLAG_GENERATOR))) + || op->flag [FLAG_MONSTER] + || op->flag [FLAG_ALIVE] + || op->flag [FLAG_GENERATOR])) { stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge @@ -1364,7 +1275,7 @@ /* figure out which skill it uses, if it uses one */ if (spell->skill) if (object *tmp = pl->find_skill (spell->skill)) - skill = tmp->subtype + CS_STAT_SKILLINFO; + skill = CS_STAT_SKILLINFO + SKILL_INDEX (tmp); // spells better have a face if (!spell->face) @@ -1448,10 +1359,7 @@ append_spell (pl, sl, spell); if (sl.length () > MAXSOCKBUF) - { - LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); - fatal (0); - } + cleanup ("buffer overflow in esrv_add_spells!"); /* finally, we can send the packet */ pl->ns->flush_fx ();