--- deliantra/server/socket/request.C 2007/01/06 14:42:31 1.59 +++ deliantra/server/socket/request.C 2007/03/01 12:28:17 1.67 @@ -1,26 +1,26 @@ /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - Copyright (C) 2001 Mark Wedel - Copyright (C) 1992 Frank Tore Johansen - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - The author can be reached via e-mail to -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2001 Mark Wedel + * Copyright (C) 1992 Frank Tore Johansen + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * The author can be reached via e-mail to + */ /** * \file @@ -38,9 +38,6 @@ * * esrv_map_new starts updating the map * - * esrv_map_setbelow allows filling in all of the faces for the map. - * if a face has not already been sent to the client, it is sent now. - * */ #include @@ -149,7 +146,7 @@ pl->ns->floorbox_reset (); } -/** check for map change and send new map data */ +/** check for map/region change and send new map data */ static void check_map_change (player *pl) { @@ -203,6 +200,13 @@ socket.current_x = ob->x; socket.current_y = ob->y; + + region *reg = ob->region (); + if (socket.current_region != reg) + { + socket.current_region = reg; + socket.send_packet_printf ("drawinfo 0 You are now %s.\n(use whereami for more details)", ®->longname); + } } /** @@ -800,9 +804,9 @@ pl->count = 0; //TODO: schmorp thinks whatever this calculates, it makes no sense at all - int time = FABS (pl->ob->speed) < 0.001 + int time = fabs (pl->ob->speed) < 0.001 ? time = MAX_TIME * 100 - : time = (int) (MAX_TIME / FABS (pl->ob->speed)); + : time = (int) (MAX_TIME / fabs (pl->ob->speed)); /* Send confirmation of command execution now */ packet sl ("comc"); @@ -848,10 +852,6 @@ key_change_class (pl->ob, buf[0]); break; - case ST_CONFIRM_QUIT: - key_confirm_quit (pl->ob, buf[0]); - break; - case ST_GET_PARTY_PASSWORD: /* Get password for party */ receive_party_password (pl->ob, 13); break; @@ -1013,50 +1013,54 @@ char buf[MAX_BUF]; uint16 flags; - if (!pl->ns) + client *ns = pl->ns; + if (!ns) + return; + + object *ob = pl->ob; + if (!ob) return; packet sl ("stats"); - if (pl->ob) - { - AddIfShort (pl->last_stats.hp, pl->ob->stats.hp, CS_STAT_HP); - AddIfShort (pl->last_stats.maxhp, pl->ob->stats.maxhp, CS_STAT_MAXHP); - AddIfShort (pl->last_stats.sp, pl->ob->stats.sp, CS_STAT_SP); - AddIfShort (pl->last_stats.maxsp, pl->ob->stats.maxsp, CS_STAT_MAXSP); - AddIfShort (pl->last_stats.grace, pl->ob->stats.grace, CS_STAT_GRACE); - AddIfShort (pl->last_stats.maxgrace, pl->ob->stats.maxgrace, CS_STAT_MAXGRACE); - AddIfShort (pl->last_stats.Str, pl->ob->stats.Str, CS_STAT_STR); - AddIfShort (pl->last_stats.Dex, pl->ob->stats.Dex, CS_STAT_DEX); - AddIfShort (pl->last_stats.Con, pl->ob->stats.Con, CS_STAT_CON); - AddIfShort (pl->last_stats.Int, pl->ob->stats.Int, CS_STAT_INT); - AddIfShort (pl->last_stats.Wis, pl->ob->stats.Wis, CS_STAT_WIS); - AddIfShort (pl->last_stats.Pow, pl->ob->stats.Pow, CS_STAT_POW); - AddIfShort (pl->last_stats.Cha, pl->ob->stats.Cha, CS_STAT_CHA); - } + AddIfShort (ns->last_stats.hp, ob->stats.hp, CS_STAT_HP); + AddIfShort (ns->last_stats.maxhp, ob->stats.maxhp, CS_STAT_MAXHP); + AddIfShort (ns->last_stats.sp, ob->stats.sp, CS_STAT_SP); + AddIfShort (ns->last_stats.maxsp, ob->stats.maxsp, CS_STAT_MAXSP); + AddIfShort (ns->last_stats.grace, ob->stats.grace, CS_STAT_GRACE); + AddIfShort (ns->last_stats.maxgrace, ob->stats.maxgrace, CS_STAT_MAXGRACE); + AddIfShort (ns->last_stats.Str, ob->stats.Str, CS_STAT_STR); + AddIfShort (ns->last_stats.Dex, ob->stats.Dex, CS_STAT_DEX); + AddIfShort (ns->last_stats.Con, ob->stats.Con, CS_STAT_CON); + AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); + AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); + 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++) - if (pl->last_skill_ob[s] && pl->last_skill_exp[s] != pl->last_skill_ob[s]->stats.exp) - { - /* Always send along the level if exp changes. This is only - * 1 extra byte, but keeps processing simpler. - */ - sl << uint8 (s + CS_STAT_SKILLINFO) - << uint8 (pl->last_skill_ob[s]->level) - << uint64 (pl->last_skill_ob[s]->stats.exp); + if (object *skill = pl->last_skill_ob[s]) + if (skill->stats.exp != ns->last_skill_exp [s]) + { + ns->last_skill_exp [s] = skill->stats.exp; - pl->last_skill_exp[s] = pl->last_skill_ob[s]->stats.exp; - } + /* Always send along the level if exp changes. This is only + * 1 extra byte, but keeps processing simpler. + */ + sl << uint8 (s + CS_STAT_SKILLINFO) + << uint8 (skill->level) + << uint64 (skill->stats.exp); + } + + AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); + AddIfShort (ns->last_level, ob->level, CS_STAT_LEVEL); + AddIfShort (ns->last_stats.wc, ob->stats.wc, CS_STAT_WC); + AddIfShort (ns->last_stats.ac, ob->stats.ac, CS_STAT_AC); + AddIfShort (ns->last_stats.dam, ob->stats.dam, CS_STAT_DAM); + AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED); + AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); + AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); + AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); - AddIfInt64 (pl->last_stats.exp, pl->ob->stats.exp, CS_STAT_EXP64); - AddIfShort (pl->last_level, (char) pl->ob->level, CS_STAT_LEVEL); - AddIfShort (pl->last_stats.wc, pl->ob->stats.wc, CS_STAT_WC); - AddIfShort (pl->last_stats.ac, pl->ob->stats.ac, CS_STAT_AC); - AddIfShort (pl->last_stats.dam, pl->ob->stats.dam, CS_STAT_DAM); - AddIfFloat (pl->last_speed, pl->ob->speed, CS_STAT_SPEED); - AddIfShort (pl->last_stats.food, pl->ob->stats.food, CS_STAT_FOOD); - AddIfFloat (pl->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP); - AddIfInt (pl->last_weight_limit, (sint32) weight_limit[pl->ob->stats.Str], CS_STAT_WEIGHT_LIM); flags = 0; if (pl->fire_on) @@ -1065,10 +1069,10 @@ if (pl->run_on) flags |= SF_RUNON; - AddIfShort (pl->last_flags, flags, CS_STAT_FLAGS); + AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); - if (pl->ns->sc_version < 1025) - { AddIfShort (pl->last_resist[ATNR_PHYSICAL], pl->ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } + if (ns->sc_version < 1025) + { AddIfShort (ns->last_resist[ATNR_PHYSICAL], ob->resist[ATNR_PHYSICAL], CS_STAT_ARMOUR) } else for (int i = 0; i < NROFATTACKS; i++) { @@ -1076,24 +1080,24 @@ if (atnr_cs_stat[i] == -1) continue; - AddIfShort (pl->last_resist[i], pl->ob->resist[i], (char) atnr_cs_stat[i]); + AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); } if (pl->ns->monitor_spells) { - AddIfInt (pl->last_path_attuned, pl->ob->path_attuned, CS_STAT_SPELL_ATTUNE); - AddIfInt (pl->last_path_repelled, pl->ob->path_repelled, CS_STAT_SPELL_REPEL); - AddIfInt (pl->last_path_denied, pl->ob->path_denied, CS_STAT_SPELL_DENY); + AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); + AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); + AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); } - rangetostring (pl->ob, buf); /* we want use the new fire & run system in new client */ - AddIfString (pl->ns->stats.range, buf, CS_STAT_RANGE); - set_title (pl->ob, buf); - AddIfString (pl->ns->stats.title, buf, CS_STAT_TITLE); + rangetostring (ob, buf); /* we want use the new fire & run system in new client */ + AddIfString (ns->stats.range, buf, CS_STAT_RANGE); + set_title (ob, buf); + AddIfString (ns->stats.title, buf, CS_STAT_TITLE); /* Only send it away if we have some actual data */ if (sl.length () > 6) - pl->ns->send_packet (sl); + ns->send_packet (sl); } /** @@ -1102,8 +1106,6 @@ void esrv_new_player (player *pl, uint32 weight) { - pl->last_weight = weight; - packet sl ("player"); sl << uint32 (pl->ob->count) @@ -1111,6 +1113,7 @@ << uint32 (pl->ob->face->number) << data8 (pl->ob->name); + pl->ns->last_weight = weight; pl->ns->send_packet (sl); SET_FLAG (pl->ob, FLAG_CLIENT_SENT); } @@ -1163,28 +1166,6 @@ * ******************************************************************************/ -/** - * This adds face_num to a map cell at x,y. If the client doesn't have - * the face yet, we will also send it. - */ -static void -esrv_map_setbelow (client * ns, int x, int y, short face_num, struct Map *newmap) -{ - if (newmap->cells[x][y].count >= MAP_LAYERS) - { - //TODO: one or the other, can't both have abort and return, verify and act - LOG (llevError, "Too many faces in map cell %d %d\n", x, y); - return; - abort (); - } - - newmap->cells[x][y].faces[newmap->cells[x][y].count] = face_num; - newmap->cells[x][y].count++; - - if (!(ns->faces_sent[face_num] & NS_FACESENT_FACE)) - esrv_send_face (ns, face_num, 0); -} - /** Clears a map cell */ static void map_clearcell (struct MapCell *cell, int face0, int face1, int face2, int count) @@ -1555,6 +1536,28 @@ return result; } +// prefetch (and touch) all maps within a specific distancd +static void +prefetch_surrounding_maps (maptile *map, int distance) +{ + map->last_access = runtime; + + 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); +} + +// prefetch a generous area around the player +static void +prefetch_surrounding_maps (object *op) +{ + prefetch_surrounding_maps (op->map, 3); +} + /** * This function uses the new map1 protocol command to send the map * to the client. It is necessary because the old map command supports @@ -1591,10 +1594,11 @@ client &socket = *pl->contr->ns; - if (!pl->active ()) + if (!pl->active) return; check_map_change (pl->contr); + prefetch_surrounding_maps (pl); packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); packet esl; @@ -1971,10 +1975,8 @@ draw_client_map (object *pl) { int i, j; - sint16 ax, ay, nx, ny; /* ax and ay goes from 0 to max-size of arrays */ - New_Face *face, *floor; - New_Face *floor2; - int d, mflags; + sint16 ax, ay; /* ax and ay goes from 0 to max-size of arrays */ + int mflags; struct Map newmap; maptile *m, *pm; @@ -2165,7 +2167,7 @@ static void append_spell (player *pl, packet &sl, object *spell) { - int len, i, skill = 0; + int i, skill = 0; if (!(spell->name)) {