--- deliantra/server/socket/info.C 2006/12/14 20:39:54 1.19 +++ deliantra/server/socket/info.C 2007/03/11 02:12:45 1.35 @@ -1,26 +1,26 @@ - /* - CrossFire, A Multiplayer game for X-windows - - Copyright (C) 2002 Mark Wedel & Crossfire Development Team - 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 authors can be reached via e-mail at -*/ + * CrossFire, A Multiplayer game for X-windows + * + * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team + * Copyright (C) 2002 Mark Wedel & Crossfire Development Team + * 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 authors can be reached via e-mail at + */ /** * \file @@ -45,11 +45,9 @@ * replaced with this, just using black as the color. */ static void -esrv_print_msg (client_socket * ns, int color, const char *str) +esrv_print_msg (client *ns, int color, const char *str) { - packet sl; - sl.printf ("drawinfo %d %s", color, str); - ns->send_packet (sl); + ns->send_packet_printf ("drawinfo %d %s", color, str); } /** @@ -62,12 +60,9 @@ * message The main message */ static void -esrv_print_ext_msg (client_socket * ns, int color, uint8 type, uint8 subtype, const char *message) +esrv_print_ext_msg (client *ns, int color, uint8 type, uint8 subtype, const char *message) { - packet sl; - - sl.printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); - ns->send_packet (sl); + ns->send_packet_printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); } /** @@ -80,11 +75,9 @@ * * Else sends message to player via esrv_print_msg */ - static void print_message (int colr, const object *pl, const char *tmp) { - if (!tmp) tmp = "[NULL]"; @@ -92,14 +85,13 @@ return; if (pl->type == PLAYER) - esrv_print_msg (pl->contr->socket, 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) { @@ -133,7 +125,6 @@ * 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) { @@ -174,8 +165,6 @@ } } - - /** * Sends message to player(s). * @@ -196,32 +185,21 @@ void new_draw_info (int flags, int pri, const object *pl, const char *buf) { - if (flags & NDI_ALL) { - player *tmppl; - - for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) - new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); + for_all_players (pl) + new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); return; } - if (!pl || (pl->type == PLAYER && pl->contr == NULL)) - { - /* Write to the socket? */ - print_message (0, NULL, buf); - return; - } - - if (pl->type != PLAYER) + if (!pl || pl->type != PLAYER || !pl->contr || !pl->contr->ns) return; if (pri >= pl->contr->listening) return; if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) - /* following prints stuff out, as appropriate */ check_output_buffers (pl, buf); else print_message (flags & NDI_COLOR_MASK, pl, buf); @@ -235,24 +213,19 @@ * it here. It may also have advantages in the future for reduction of * client/server bandwidth (client could keep track of various strings */ - void new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) { char buf[HUGE_BUF]; va_list ap; - va_start (ap, format); - vsnprintf (buf, HUGE_BUF, format, ap); - va_end (ap); new_draw_info (flags, pri, pl, buf); } - void draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) { @@ -263,7 +236,7 @@ if (pri >= pl->contr->listening) return; - if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) + if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) { char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); @@ -278,13 +251,12 @@ } } else - esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); + esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message); } void draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) { - char buf[HUGE_BUF]; if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) @@ -293,7 +265,7 @@ if (pri >= pl->contr->listening) return; - if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) + if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) { va_list ap; @@ -312,7 +284,7 @@ vsnprintf (buf, HUGE_BUF, new_format, ap); va_end (ap); strip_media_tag (buf); - esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); + esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf); } } @@ -323,13 +295,9 @@ void new_info_map_except (int color, maptile * map, object *op, const char *str) { - player *pl; - - for (pl = first_player; pl != NULL; pl = pl->next) + for_all_players (pl) if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) - { - new_draw_info (color, 0, pl->ob, str); - } + new_draw_info (color, 0, pl->ob, str); } /** @@ -339,13 +307,9 @@ void new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) { - player *pl; - - for (pl = first_player; pl != NULL; pl = pl->next) + 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); - } + new_draw_info (color, 0, pl->ob, str); } /** @@ -355,16 +319,11 @@ void new_info_map (int color, maptile * map, const char *str) { - player *pl; - - for (pl = first_player; pl != NULL; pl = pl->next) + for_all_players (pl) if (pl->ob != NULL && pl->ob->map == map) - { - new_draw_info (color, 0, pl->ob, str); - } + 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 @@ -462,7 +421,6 @@ sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); } - /** * Helper for magic map creation. * @@ -480,7 +438,6 @@ int x, y, dx, dy, mflags; sint16 nx, ny; maptile *mp; - New_Face *f; for (dx = -1; dx <= 1; dx++) { @@ -502,20 +459,24 @@ if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) { - f = GET_MAP_FACE (mp, nx, ny, 0); - if (f == blank_face) - f = GET_MAP_FACE (mp, nx, ny, 1); + int f = GET_MAP_FACE (mp, nx, ny, 0); 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); } } @@ -523,7 +484,6 @@ } } - /** * Creates magic map for player. * @@ -534,19 +494,17 @@ * * This function examines the map the player is on, and determines what * is visible. 2 is set for walls or objects that blocks view. 1 - * is for open spaces. map_mark should already have been initialized + * is for open spaces. map_mark should already have been initialised * to zero before this is called. * 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; - New_Face *f; for (x = -strength; x < strength; x++) { @@ -555,30 +513,32 @@ 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); } } } } - /** * Creates and sends magic map to player. * @@ -587,7 +547,6 @@ * * Mark Wedel */ - void draw_magic_map (object *pl) { @@ -615,7 +574,7 @@ for (int x = 0; x < MAGIC_MAP_SIZE; x++) for (int y = 0; y < MAGIC_MAP_SIZE; y++) - if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) + if (map_mark[x + pl->map->width * y] | FACE_FLOOR) { xmin = x < xmin ? x : xmin; xmax = x > xmax ? x : xmax; @@ -631,16 +590,14 @@ for (int x = xmin; x <= xmax; x++) sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); - pl->contr->socket->send_packet (sl); + pl->contr->ns->send_packet (sl); free (map_mark); } - /** * Send a kill log record to sockets */ - void Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) { @@ -654,3 +611,4 @@ len = strlen (buf); } +