--- deliantra/server/socket/info.C 2007/01/20 13:47:17 1.33 +++ deliantra/server/socket/info.C 2007/07/01 05:00:20 1.46 @@ -1,25 +1,24 @@ /* - * CrossFire, A Multiplayer game for X-windows + * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. * - * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team - * Copyright (C) 2002 Mark Wedel & Crossfire Development Team - * Copyright (C) 1992 Frank Tore Johansen + * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team + * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team + * Copyright (©) 1992,2007 Frank Tore Johansen * - * This program is free software; you can redistribute it and/or modify + * Crossfire TRT 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 + * 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 + * 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 authors can be reached via e-mail at + * along with this program. If not, see . + * + * The authors can be reached via e-mail to */ /** @@ -38,6 +37,8 @@ #include #include +#include + /** * Draws a normal message on the client. It is pretty * much the same thing as the draw_info above, but takes a color @@ -47,7 +48,7 @@ static void esrv_print_msg (client *ns, int color, const char *str) { - ns->send_packet_printf ("drawinfo %d %s", color, str); + ns->send_msg (color, "info", str); } /** @@ -62,7 +63,7 @@ static void esrv_print_ext_msg (client *ns, int color, uint8 type, uint8 subtype, const char *message) { - ns->send_packet_printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); + ns->send_packet_printf ("drawextinfo %d %u %u %s", color, type, subtype, message); } /** @@ -85,84 +86,54 @@ return; if (pl->type == PLAYER) - esrv_print_msg (pl->contr->ns, colr, (char *) tmp); + esrv_print_msg (pl->contr->ns, colr, (char *)tmp); } -/** - * Prints out the contents of specified buffer structures, - * and clears the string. - */ -void -flush_output_element (const object *pl, Output_Buf * outputs) +bool +client::msg_suppressed (const char *msg) { - char tbuf[MAX_BUF]; + if (!pl) + return false; - if (outputs->buf == NULL) - return; - if (outputs->count > 1) - { - snprintf (tbuf, MAX_BUF, "%d times %s", outputs->count, &outputs->buf); - print_message (NDI_BLACK, pl, tbuf); - } - else - print_message (NDI_BLACK, pl, &outputs->buf); + if (pl->outputs_count <= 1 || !pl->outputs_sync) + return false; - outputs->buf = NULL; - outputs->first_update = 0; /* This way, it will be reused */ -} + int len = strlen (msg); -/** - * Sends message to player through output buffers. - * \param pl player to send message - * \param buf message to send - * - * If player's output_count is 1, sends message directly. - * - * Else checks output buffers for specified message. - * - * If found, checks if message should be sent now. - * - * If message not already in buffers, flushes olders buffer, - * and adds message to queue. - */ -static void -check_output_buffers (const object *pl, const char *buf) -{ - int i, oldest = 0; + if (len > MSG_BUF_SIZE) + return false; - if (pl->contr->outputs_count < 2) + msg_buf *lru = msgbuf; + for (msg_buf *buf = msgbuf; buf < msgbuf + MSG_BUF_COUNT; ++buf) { - print_message (NDI_BLACK, pl, buf); - return; - } - else - { - for (i = 0; i < NUM_OUTPUT_BUFS; i++) - { - if (pl->contr->outputs[i].buf && !strcmp (buf, pl->contr->outputs[i].buf)) - break; - else if (pl->contr->outputs[i].first_update < pl->contr->outputs[oldest].first_update) - oldest = i; - } - /* We found a match */ - if (i < NUM_OUTPUT_BUFS) + if (len == buf->len && !memcmp (msg, buf->msg, len)) { - pl->contr->outputs[i].count++; - if (pl->contr->outputs[i].count >= pl->contr->outputs_count) + // found matching buf, see if expired + if (buf->expire <= pticks || !buf->count) { - flush_output_element (pl, &pl->contr->outputs[i]); + // yes, take over matching buffer, print + buf->expire = pticks + pl->outputs_sync; + buf->count = pl->outputs_count; + + return false; } - } - /* No match - flush the oldest, and put the new one in */ - else - { - flush_output_element (pl, &pl->contr->outputs[oldest]); - pl->contr->outputs[oldest].first_update = pticks; - pl->contr->outputs[oldest].count = 1; - pl->contr->outputs[oldest].buf = buf; + // no, suppress + --buf->count; + return true; } + + if (lru->expire > buf->expire) + lru = buf; } + + // new message, evoke oldest buffer + lru->expire = pticks + pl->outputs_sync; + lru->count = pl->outputs_count; + lru->len = len; + memcpy (lru->msg, msg, len); + + return false; } /** @@ -181,28 +152,26 @@ * If message is black, and not NDI_UNIQUE, gets sent through output buffers. * */ - void -new_draw_info (int flags, int pri, const object *pl, const char *buf) +new_draw_info (int flags, int pri, const object *op, const char *buf) { if (flags & NDI_ALL) { for_all_players (pl) new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); - - return; } + else + { + if (!op || !op->contr || !op->contr->ns) + return; - if (!pl || pl->type != PLAYER || !pl->contr || !pl->contr->ns) - return; - - if (pri >= pl->contr->listening) - return; + if (pri >= op->contr->listening) + return; - if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) - check_output_buffers (pl, buf); - else - print_message (flags & NDI_COLOR_MASK, pl, buf); + if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK + || !op->contr->ns->msg_suppressed (buf)) + print_message (flags & NDI_COLOR_MASK, op, buf); + } } /** @@ -295,8 +264,6 @@ void new_info_map_except (int color, maptile * map, object *op, const char *str) { - player *pl; - for_all_players (pl) if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) new_draw_info (color, 0, pl->ob, str); @@ -305,12 +272,9 @@ /** * Writes to everyone on the map except op1 and op2 */ - void new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) { - player *pl; - for_all_players (pl) if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) new_draw_info (color, 0, pl->ob, str); @@ -319,102 +283,15 @@ /** * Writes to everyone on the specified map */ - void new_info_map (int color, maptile * map, const char *str) { - player *pl; - for_all_players (pl) if (pl->ob != NULL && pl->ob->map == map) new_draw_info (color, 0, pl->ob, str); } /** - * This does nothing now. However, in theory, we should probably send - * something to the client and let the client figure out how it might want - * to handle this - */ -void -clear_win_info (object *op) -{ -} - -/** - * Get player's current range attack in obuf. - */ -void -rangetostring (object *pl, char *obuf) -{ - switch (pl->contr->shoottype) - { - case range_none: - strcpy (obuf, "Range: nothing"); - break; - - case range_bow: - { - object *op; - - for (op = pl->inv; op; op = op->below) - if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) - break; - - if (op == NULL) - break; - - sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); - } - break; - - case range_magic: - if (settings.casting_time == TRUE) - { - if (pl->casting_time > -1) - { - if (pl->casting_time == 0) - sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); - else - sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); - } - else - sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); - } - else - sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); - break; - - case range_misc: - sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); - break; - - /* range_scroll is only used for controlling golems. If the - * the player does not have a golem, reset some things. - */ - case range_golem: - if (pl->contr->ranges[range_golem] != NULL) - sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); - else - { - pl->contr->shoottype = range_none; - strcpy (obuf, "Range: nothing"); - } - break; - - case range_skill: - sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); - break; - - case range_builder: - sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); - break; - - default: - strcpy (obuf, "Range: illegal"); - } -} - -/** * Sets player title. */ void @@ -427,6 +304,15 @@ sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); } +// formerly a macro, used only by magic map, so optimised it out +static inline faceidx +GET_MAP_FACE (maptile *m, int x, int y, int layer) +{ + if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) + return op->face; + else + return 0; +} /** * Helper for magic map creation. @@ -445,7 +331,6 @@ int x, y, dx, dy, mflags; sint16 nx, ny; maptile *mp; - facetile *f; for (dx = -1; dx <= 1; dx++) { @@ -467,20 +352,24 @@ if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) { - f = GET_MAP_FACE (mp, nx, ny, 0); + int f = GET_MAP_FACE (mp, nx, ny, 0); if (f == blank_face) - f = GET_MAP_FACE (mp, nx, ny, 1); - if (f == blank_face) - f = GET_MAP_FACE (mp, nx, ny, 2); + { + f = GET_MAP_FACE (mp, nx, ny, 1); + if (f == blank_face) + f = GET_MAP_FACE (mp, nx, ny, 2); + } + + int magicmap = faces [f].magicmap; /* Should probably have P_NO_MAGIC here also, but then shops don't * work. */ if (mflags & P_BLOCKSVIEW) - map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | (f ? f->magicmap : 0); + map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | magicmap; else { - map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); + map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; magic_mapping_mark_recursive (pl, map_mark, x, y); } } @@ -488,7 +377,6 @@ } } - /** * Creates magic map for player. * @@ -504,14 +392,12 @@ * strength is an initial strength*2 rectangular area that we automatically * see in/penetrate through. */ - void magic_mapping_mark (object *pl, char *map_mark, int strength) { int x, y, mflags; sint16 nx, ny; maptile *mp; - facetile *f; for (x = -strength; x < strength; x++) { @@ -520,23 +406,26 @@ mp = pl->map; nx = pl->x + x; ny = pl->y + y; + mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); if (mflags & P_OUT_OF_MAP) continue; - else + + int f = GET_MAP_FACE (mp, nx, ny, 0); + if (f == blank_face) { - f = GET_MAP_FACE (mp, nx, ny, 0); - if (f == blank_face) - f = GET_MAP_FACE (mp, nx, ny, 1); + f = GET_MAP_FACE (mp, nx, ny, 1); if (f == blank_face) f = GET_MAP_FACE (mp, nx, ny, 2); } + int magicmap = faces [f].magicmap; + if (mflags & P_BLOCKSVIEW) - map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | (f ? f->magicmap : 0); + map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_WALL | magicmap; else { - map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | (f ? f->magicmap : 0); + map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] = FACE_FLOOR | magicmap; magic_mapping_mark_recursive (pl, map_mark, x, y); } }