--- deliantra/server/socket/request.C 2008/12/26 10:44:17 1.145
+++ deliantra/server/socket/request.C 2010/03/26 01:04:45 1.165
@@ -1,26 +1,29 @@
/*
* 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 GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * 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
+ * Free Software Foundation, either version 3 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, see .
+ * You should have received a copy of the Affero GNU General Public License
+ * and the GNU General Public License along with this program. If not, see
+ * .
*
* The authors can be reached via e-mail to
*/
+//+GPL
+
/**
* \file
* Client handling.
@@ -65,7 +68,7 @@
* client. If a value is -1, then we don't send that to the
* client.
*/
-short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS,
+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 */ ,
@@ -143,7 +146,7 @@
send_map_info (player *pl)
{
client &socket = *pl->ns;
- object *ob = pl->observe;
+ object *ob = pl->viewpoint;
if (socket.mapinfocmd)
{
@@ -170,7 +173,7 @@
check_map_change (player *pl)
{
client &socket = *pl->ns;
- object *ob = pl->observe;
+ object *ob = pl->viewpoint;
region *reg = ob->region ();
if (socket.current_region != reg)
@@ -210,13 +213,8 @@
int dx = ob->x - socket.current_x;
int dy = ob->y - socket.current_y;
- if (socket.buggy_mapscroll && (abs (dx) > 8 || abs (dy) > 8))
- clear_map (pl); // current (<= 1.9.1) clients have unchecked buffer overflows
- else
- {
- socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y);
- socket.floorbox_reset ();
- }
+ socket_map_scroll (&socket, ob->x - socket.current_x, ob->y - socket.current_y);
+ socket.floorbox_reset ();
}
socket.current_x = ob->x;
@@ -224,6 +222,51 @@
}
/**
+ * This sends the skill number to name mapping. We ignore
+ * the params - we always send the same info no matter what.
+ */
+static void
+send_skill_info (client *ns, char *params)
+{
+ 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]);
+
+ if (sl.length () > MAXSOCKBUF)
+ {
+ LOG (llevError, "Buffer overflow in send_skill_info!\n");
+ fatal (0);
+ }
+
+ ns->send_packet (sl);
+}
+
+/**
+ * This sends the spell path to name mapping. We ignore
+ * the params - we always send the same info no matter what.
+ */
+static void
+send_spell_paths (client * ns, char *params)
+{
+ packet sl;
+
+ sl << "replyinfo spell_paths\n";
+
+ for (int i = 0; i < NRSPELLPATHS; i++)
+ sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
+
+ if (sl.length () > MAXSOCKBUF)
+ {
+ LOG (llevError, "Buffer overflow in send_spell_paths!\n");
+ fatal (0);
+ }
+
+ ns->send_packet (sl);
+}
+
+/**
* RequestInfo is sort of a meta command. There is some specific
* request of information, but we call other functions to provide
* that information.
@@ -243,11 +286,7 @@
break;
}
- if (!strcmp (buf, "image_info"))
- send_image_info (ns, params);
- else if (!strcmp (buf, "image_sums"))
- send_image_sums (ns, params);
- else if (!strcmp (buf, "skill_info"))
+ if (!strcmp (buf, "skill_info"))
send_skill_info (ns, params);
else if (!strcmp (buf, "spell_paths"))
send_spell_paths (ns, params);
@@ -273,6 +312,8 @@
INVOKE_CLIENT (EXTICMD, ns, ARG_DATA (buf, len));
}
+//-GPL
+
void
client::mapinfo_queue_clear ()
{
@@ -289,9 +330,9 @@
buf += strlen (buf) + 9;
// initial map and its origin
- maptile *map = pl->observe->map;
- int mapx = pl->ns->mapx / 2 - pl->observe->x;
- int mapy = pl->ns->mapy / 2 - pl->observe->y;
+ maptile *map = pl->viewpoint->map;
+ int mapx = pl->ns->mapx / 2 - pl->viewpoint->x;
+ int mapy = pl->ns->mapy / 2 - pl->viewpoint->y;
int max_distance = 8; // limit maximum path length to something generous
while (*buf && map && max_distance)
@@ -406,6 +447,8 @@
INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len));
}
+//+GPL
+
/*
#define MSG_TYPE_BOOK 1
#define MSG_TYPE_CARD 2
@@ -431,7 +474,7 @@
/* 1. Extract an info */
info = nextinfo;
- while ((info < len) && (buf[info] == ' '))
+ while ((info < len) && (buf [info] == ' '))
info++;
if (info >= len)
@@ -439,14 +482,15 @@
nextinfo = info + 1;
- while ((nextinfo < len) && (buf[nextinfo] != ' '))
+ while ((nextinfo < len) && (buf [nextinfo] != ' '))
nextinfo++;
if (nextinfo - info >= 49) /*Erroneous info asked */
continue;
- strncpy (command, &(buf[info]), nextinfo - info);
- command[nextinfo - info] = '\0';
+ memcpy (command, buf + info, nextinfo - info);
+ command [nextinfo - info] = 0;
+
/* 2. Interpret info */
i = sscanf (command, "%d", &flag);
@@ -490,7 +534,7 @@
buf++;
}
- execute_newserver_command (pl->ob, (char *) buf);
+ execute_newserver_command (pl->ob, (char *)buf);
/* Perhaps something better should be done with a left over count.
* Cleaning up the input should probably be done first - all actions
@@ -534,9 +578,9 @@
pl->count = 0;
//TODO: schmorp thinks whatever this calculates, it makes no sense at all
- int time = fabs (pl->ob->speed) < 0.001
- ? time = MAX_TIME * 100
- : time = (int) (MAX_TIME / fabs (pl->ob->speed));
+ int time = pl->ob->has_active_speed ()
+ ? (int) (MAX_TIME / pl->ob->speed)
+ : MAX_TIME * 100;
/* Send confirmation of command execution now */
packet sl ("comc");
@@ -692,7 +736,7 @@
static void
rangetostring (player *pl, char *obuf)
{
- dynbuf_text buf;
+ dynbuf_text &buf = msg_dynbuf; buf.clear ();
if (pl->ranged_ob)
buf << " Range" << (pl->ob->current_weapon == pl->ranged_ob ? "*" : "") << ": " << pl->ranged_ob->name;
@@ -796,9 +840,9 @@
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, 1.f/TICK);
+ AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK);
AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD);
- AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f/TICK);
+ 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;
@@ -811,17 +855,14 @@
AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS);
- 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++)
- {
- /* Skip ones we won't send */
- if (atnr_cs_stat[i] == -1)
- continue;
+ for (int i = 0; i < NROFATTACKS; i++)
+ {
+ /* Skip ones we won't send */
+ if (atnr_cs_stat[i] == -1)
+ continue;
- AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]);
- }
+ AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]);
+ }
if (pl->ns->monitor_spells)
{
@@ -933,14 +974,16 @@
return 0;
}
+//-GPL
+
// prefetch (and touch) all maps within a specific distancd
static void
prefetch_surrounding_maps (maptile *map, int distance)
{
- map->last_access = runtime;
+ map->touch ();
if (--distance)
- for (int dir = 4; --dir; )
+ 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);
@@ -955,14 +998,16 @@
prefetch_surrounding_maps (op->map, 3);
}
+//+GPL
+
/**
* Draws client map.
*/
void
draw_client_map (player *pl)
{
- object *ob = pl->observe;
- if (!ob->active)
+ object *ob = pl->viewpoint;
+ if (!pl->observe->active)
return;
/* If player is just joining the game, he isn't here yet, so the map
@@ -979,7 +1024,7 @@
/* do LOS after calls to update_position */
/* unfortunately, we need to udpate los when observing, currently */
- if (pl->do_los || pl->observe != pl->ob)
+ if (pl->do_los || pl->viewpoint != pl->ob)
{
pl->do_los = 0;
pl->update_los ();
@@ -1041,7 +1086,7 @@
continue;
}
-
+
int d = pl->blocked_los_uc (dx, dy);
if (d > 3)
@@ -1084,18 +1129,13 @@
unsigned char *last_ext = &dummy;
/* Darkness changed */
- if (lastcell.count != d && socket.darkness)
+ if (lastcell.count != d)
{
mask |= 0x8;
- if (socket.extmap)
- {
- *last_ext |= 0x80;
- last_ext = &sl[sl.length ()];
- sl << uint8 (d);
- }
- else
- sl << uint8 (255 - 64 * d);
+ *last_ext |= 0x80;
+ last_ext = &sl[sl.length ()];
+ sl << uint8 (d);
}
lastcell.count = d;
@@ -1103,80 +1143,80 @@
mapspace &ms = m->at (nx, ny);
ms.update ();
- if (expect_true (socket.extmap))
- {
- uint8 stat_hp = 0;
- uint8 stat_width = 0;
- uint8 flags = 0;
- tag_t player = 0;
-
- // send hp information, if applicable
- if (object *op = ms.faces_obj [0])
- if (op->is_head () && !op->invisible)
+ // extmap handling
+ uint8 stat_hp = 0;
+ uint8 stat_width = 0;
+ uint8 flags = 0;
+ tag_t player = 0;
+
+ // send hp information, if applicable
+ if (object *op = ms.faces_obj [0])
+ if (op->is_head () && !op->invisible)
+ {
+ if (op->stats.maxhp > op->stats.hp
+ && 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)))
{
- if (op->stats.maxhp > op->stats.hp
- && 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)))
- {
- 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
- }
-
- if (expect_false (op->has_dialogue ()))
- flags |= 1;
-
- if (expect_false (op->type == PLAYER))
- player = op == ob ? pl->ob->count
- : op == pl->ob ? ob->count
- : op->count;
+ 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
}
- if (expect_false (lastcell.stat_hp != stat_hp))
- {
- lastcell.stat_hp = stat_hp;
+ if (expect_false (op->has_dialogue ()))
+ flags |= 1;
- mask |= 0x8;
- *last_ext |= 0x80;
- last_ext = &sl[sl.length ()];
+ if (expect_false (op->type == PLAYER))
+ player = op == ob ? pl->ob->count
+ : op == pl->ob ? ob->count
+ : op->count;
+ }
- sl << uint8 (5) << uint8 (stat_hp);
+ if (expect_false (lastcell.stat_hp != stat_hp))
+ {
+ lastcell.stat_hp = stat_hp;
- if (stat_width > 1)
- {
- *last_ext |= 0x80;
- last_ext = &sl[sl.length ()];
+ mask |= 0x8;
+ *last_ext |= 0x80;
+ last_ext = &sl[sl.length ()];
- sl << uint8 (6) << uint8 (stat_width);
- }
- }
+ sl << uint8 (5) << uint8 (stat_hp);
- if (expect_false (lastcell.player != player))
+ if (stat_width > 1)
{
- lastcell.player = player;
-
- mask |= 0x8;
*last_ext |= 0x80;
last_ext = &sl[sl.length ()];
- sl << uint8 (0x47) << uint8 (4) << (uint32)player;
+ sl << uint8 (6) << uint8 (stat_width);
}
+ }
- if (expect_false (lastcell.flags != flags))
- {
- lastcell.flags = flags;
+ if (expect_false (lastcell.player != player))
+ {
+ lastcell.player = player;
- mask |= 0x8;
- *last_ext |= 0x80;
- last_ext = &sl[sl.length ()];
+ mask |= 0x8;
+ *last_ext |= 0x80;
+ last_ext = &sl[sl.length ()];
- sl << uint8 (8) << uint8 (flags);
- }
+ sl << uint8 (0x47) << uint8 (4) << (uint32)player;
}
+ if (expect_false (lastcell.flags != flags))
+ {
+ lastcell.flags = flags;
+
+ mask |= 0x8;
+ *last_ext |= 0x80;
+ last_ext = &sl[sl.length ()];
+
+ sl << uint8 (8) << uint8 (flags);
+ }
+
+ // faces
+
/* Floor face */
if (update_space (sl, socket, ms, lastcell, 2))
mask |= 0x4;
@@ -1225,62 +1265,6 @@
}
}
-/*****************************************************************************/
-/* GROS: The following one is used to allow a plugin to send a generic cmd to*/
-/* a player. Of course, the client need to know the command to be able to */
-/* manage it ! */
-/*****************************************************************************/
-void
-send_plugin_custom_message (object *pl, char *buf)
-{
- pl->contr->ns->send_packet (buf);
-}
-
-/**
- * This sends the skill number to name mapping. We ignore
- * the params - we always send the same info no matter what.
- */
-void
-send_skill_info (client *ns, char *params)
-{
- 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]);
-
- if (sl.length () > MAXSOCKBUF)
- {
- LOG (llevError, "Buffer overflow in send_skill_info!\n");
- fatal (0);
- }
-
- ns->send_packet (sl);
-}
-
-/**
- * This sends the spell path to name mapping. We ignore
- * the params - we always send the same info no matter what.
- */
-void
-send_spell_paths (client * ns, char *params)
-{
- packet sl;
-
- sl << "replyinfo spell_paths\n";
-
- for (int i = 0; i < NRSPELLPATHS; i++)
- sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]);
-
- if (sl.length () > MAXSOCKBUF)
- {
- LOG (llevError, "Buffer overflow in send_spell_paths!\n");
- fatal (0);
- }
-
- ns->send_packet (sl);
-}
-
/**
* This looks for any spells the player may have that have changed their stats.
* it then sends an updspell packet for each spell that has changed in this way
@@ -1291,50 +1275,54 @@
if (!pl->ns)
return;
+ pl->ns->update_spells = false;
+
if (!pl->ns->monitor_spells)
return;
for (object *spell = pl->ob->inv; spell; spell = spell->below)
- {
- if (spell->type == SPELL)
- {
- int flags = 0;
+ if (spell->type == SPELL)
+ {
+ int flags = 0;
+ int val;
- /* check if we need to update it */
- if (spell->cached_sp != SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA))
- {
- spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
- flags |= UPD_SP_MANA;
- }
+ /* check if we need to update it */
+ val = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
+ if (spell->cached_sp != val)
+ {
+ spell->cached_sp = val;
+ flags |= UPD_SP_MANA;
+ }
- if (spell->cached_grace != SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE))
- {
- spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
- flags |= UPD_SP_GRACE;
- }
+ val = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
+ if (spell->cached_grace != val)
+ {
+ spell->cached_grace = val;
+ flags |= UPD_SP_GRACE;
+ }
- if (spell->cached_eat != spell->stats.dam + SP_level_dam_adjust (pl->ob, spell))
- {
- spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
- flags |= UPD_SP_DAMAGE;
- }
+ val = casting_level (pl->ob, spell);
+ if (spell->cached_eat != val)
+ {
+ spell->cached_eat = val;
+ flags |= UPD_SP_LEVEL;
+ }
- if (flags)
- {
- packet sl;
+ if (flags)
+ {
+ packet sl;
- sl << "updspell "
- << uint8 (flags)
- << uint32 (spell->count);
-
- if (flags & UPD_SP_MANA ) sl << uint16 (spell->cached_sp);
- if (flags & UPD_SP_GRACE ) sl << uint16 (spell->cached_grace);
- if (flags & UPD_SP_DAMAGE) sl << uint16 (spell->cached_eat);
+ sl << "updspell "
+ << uint8 (flags)
+ << uint32 (spell->count);
- pl->ns->send_packet (sl);
- }
- }
- }
+ if (flags & UPD_SP_MANA ) sl << uint16 (spell->cached_sp);
+ if (flags & UPD_SP_GRACE) sl << uint16 (spell->cached_grace);
+ if (flags & UPD_SP_LEVEL) sl << uint16 (spell->cached_eat);
+
+ pl->ns->send_packet (sl);
+ }
+ }
}
void
@@ -1371,7 +1359,7 @@
/* store costs and damage in the object struct, to compare to later */
spell->cached_sp = SP_level_spellpoint_cost (pl->ob, spell, SPELL_MANA);
spell->cached_grace = SP_level_spellpoint_cost (pl->ob, spell, SPELL_GRACE);
- spell->cached_eat = spell->stats.dam + SP_level_dam_adjust (pl->ob, spell);
+ spell->cached_eat = casting_level (pl->ob, spell);
/* figure out which skill it uses, if it uses one */
if (spell->skill)
@@ -1470,3 +1458,5 @@
pl->ns->send_packet (sl);
}
+//-GPL
+