ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/info.C
(Generate patch)

Comparing deliantra/server/socket/info.C (file contents):
Revision 1.41 by root, Thu May 3 10:39:46 2007 UTC vs.
Revision 1.59 by root, Fri Mar 26 00:59:22 2010 UTC

1/* 1/*
2 * CrossFire, A Multiplayer game for X-windows 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002 Mark Wedel & Crossfire Development Team
6 * Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (©) 1992 Frank Tore Johansen
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * it under the terms of the GNU General Public License as published by 9 * the terms of the Affero GNU General Public License as published by the
10 * the Free Software Foundation; either version 2 of the License, or 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * (at your option) any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 16 * GNU General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU General Public License 18 * You should have received a copy of the Affero GNU General Public License
19 * along with this program; if not, write to the Free Software 19 * and the GNU General Public License along with this program. If not, see
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 23 */
24 24
25/** 25/**
26 * \file 26 * \file
27 * Basic client output functions. 27 * Basic client output functions.
36#include <sproto.h> 36#include <sproto.h>
37#include <stdarg.h> 37#include <stdarg.h>
38#include <spells.h> 38#include <spells.h>
39#include <skills.h> 39#include <skills.h>
40 40
41#include <cstring>
42
41/** 43/**
42 * Draws a normal message on the client. It is pretty 44 * Draws a normal message on the client. It is pretty
43 * much the same thing as the draw_info above, but takes a color 45 * much the same thing as the draw_info above, but takes a color
44 * parameter. the esrv_drawinfo functions should probably be 46 * parameter. the esrv_drawinfo functions should probably be
45 * replaced with this, just using black as the color. 47 * replaced with this, just using black as the color.
46 */ 48 */
47static void 49static void
48esrv_print_msg (client *ns, int color, const char *str) 50esrv_print_msg (client *ns, int color, const char *str)
49{ 51{
50 ns->send_packet_printf ("drawinfo %d %s", color, str); 52 ns->send_msg (color, "info", str);
51}
52
53/**
54 * Draws an extended message on the client.
55 * ns the socket to send message to
56 * color color informations (used mainly if client does not support message type)
57 * type,
58 * subtype type and subtype of text message
59 * intro Intro message to send with main message if client does not support the message type
60 * message The main message
61 */
62static void
63esrv_print_ext_msg (client *ns, int color, uint8 type, uint8 subtype, const char *message)
64{
65 ns->send_packet_printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message);
66} 53}
67 54
68/** 55/**
69 * Frontend for esrv_print_msg 56 * Frontend for esrv_print_msg
70 * \param colr message color 57 * \param colr message color
83 70
84 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 71 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
85 return; 72 return;
86 73
87 if (pl->type == PLAYER) 74 if (pl->type == PLAYER)
88 esrv_print_msg (pl->contr->ns, colr, (char *) tmp); 75 esrv_print_msg (pl->contr->ns, colr, (char *)tmp);
89} 76}
90 77
91bool 78bool
92client::msg_suppressed (const char *msg) 79client::msg_suppressed (const char *msg)
93{ 80{
138/** 125/**
139 * Sends message to player(s). 126 * Sends message to player(s).
140 * 127 *
141 * flags is various flags - mostly color, plus a few specials. 128 * flags is various flags - mostly color, plus a few specials.
142 * 129 *
143 * pri is priority. It is a little odd - the lower the value, the more 130 * pri is unused.
144 * important it is. Thus, 0 gets sent no matter what. Otherwise, the
145 * value must be less than the listening level that the player has set.
146 * Unfortunately, there is no clear guideline on what each level does what.
147 * 131 *
148 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set 132 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set
149 * in the flags. 133 * in the flags.
150 * 134 *
151 * If message is black, and not NDI_UNIQUE, gets sent through output buffers. 135 * If message is black, and not NDI_UNIQUE, gets sent through output buffers.
153 */ 137 */
154void 138void
155new_draw_info (int flags, int pri, const object *op, const char *buf) 139new_draw_info (int flags, int pri, const object *op, const char *buf)
156{ 140{
157 if (flags & NDI_ALL) 141 if (flags & NDI_ALL)
142 {
158 for_all_players (pl) 143 for_all_players (pl)
159 new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); 144 new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf);
145 }
160 else 146 else
161 { 147 {
162 if (!op || !op->contr || !op->contr->ns) 148 if (!op || !op->contr || !op->contr->ns)
163 return;
164
165 if (pri >= op->contr->listening)
166 return; 149 return;
167 150
168 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK 151 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK
169 || !op->contr->ns->msg_suppressed (buf)) 152 || !op->contr->ns->msg_suppressed (buf))
170 print_message (flags & NDI_COLOR_MASK, op, buf); 153 print_message (flags & NDI_COLOR_MASK, op, buf);
180 * client/server bandwidth (client could keep track of various strings 163 * client/server bandwidth (client could keep track of various strings
181 */ 164 */
182void 165void
183new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) 166new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...)
184{ 167{
185 char buf[HUGE_BUF];
186
187 va_list ap; 168 va_list ap;
188 va_start (ap, format); 169 va_start (ap, format);
189 vsnprintf (buf, HUGE_BUF, format, ap); 170 new_draw_info (flags, pri, pl, vformat (format, ap));
190 va_end (ap); 171 va_end (ap);
191
192 new_draw_info (flags, pri, pl, buf);
193}
194
195void
196draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
197{
198
199 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
200 return;
201
202 if (pri >= pl->contr->listening)
203 return;
204
205 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
206 {
207 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
208
209 if (buf == NULL)
210 LOG (llevError, "info::draw_ext_info -> Out of memory!");
211 else
212 {
213 strcpy (buf, oldmessage == NULL ? message : oldmessage);
214 strip_media_tag (buf);
215 new_draw_info (flags, pri, pl, buf);
216 free (buf);
217 }
218 }
219 else
220 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, message);
221}
222
223void
224draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
225{
226 char buf[HUGE_BUF];
227
228 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
229 return;
230
231 if (pri >= pl->contr->listening)
232 return;
233
234 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
235 {
236 va_list ap;
237
238 LOG (llevDebug, "Non supported extension text type for client.\n");
239 va_start (ap, new_format);
240 vsnprintf (buf, HUGE_BUF, old_format, ap);
241 va_end (ap);
242 new_draw_info (flags, pri, pl, buf);
243 return;
244 }
245 else
246 {
247 va_list ap;
248
249 va_start (ap, new_format);
250 vsnprintf (buf, HUGE_BUF, new_format, ap);
251 va_end (ap);
252 strip_media_tag (buf);
253 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
254 }
255} 172}
256 173
257/** 174/**
258 * Writes to everyone on the map *except* op. This is useful for emotions. 175 * Writes to everyone on the map *except* op. This is useful for emotions.
259 */ 176 */
260
261void 177void
262new_info_map_except (int color, maptile * map, object *op, const char *str) 178new_info_map_except (int color, maptile * map, object *op, const char *str)
263{ 179{
264 for_all_players (pl) 180 for_all_players (pl)
265 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) 181 if (pl->ob->map == map && pl->ob != op)
266 new_draw_info (color, 0, pl->ob, str); 182 new_draw_info (color, 0, pl->ob, str);
267} 183}
268 184
269/** 185/**
270 * Writes to everyone on the map except op1 and op2 186 * Writes to everyone on the specified map
271 */ 187 */
272
273void 188void
274new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) 189new_info_map (int color, maptile * map, const char *str)
275{ 190{
276 for_all_players (pl) 191 for_all_players (pl)
277 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) 192 if (pl->ob->map == map)
278 new_draw_info (color, 0, pl->ob, str); 193 new_draw_info (color, 0, pl->ob, str);
279}
280
281/**
282 * Writes to everyone on the specified map
283 */
284
285void
286new_info_map (int color, maptile * map, const char *str)
287{
288 for_all_players (pl)
289 if (pl->ob != NULL && pl->ob->map == map)
290 new_draw_info (color, 0, pl->ob, str);
291}
292
293/**
294 * This does nothing now. However, in theory, we should probably send
295 * something to the client and let the client figure out how it might want
296 * to handle this
297 */
298void
299clear_win_info (object *op)
300{
301} 194}
302 195
303/** 196/**
304 * Sets player title. 197 * Sets player title.
305 */ 198 */
313 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); 206 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title);
314} 207}
315 208
316// formerly a macro, used only by magic map, so optimised it out 209// formerly a macro, used only by magic map, so optimised it out
317static inline faceidx 210static inline faceidx
318GET_MAP_FACE (maptile *m, int x, int y, int layer) 211GET_MAP_FACE (mapspace &ms, int layer)
319{ 212{
320 if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) 213 if (object *op = ms.faces_obj [layer])
321 return op->face; 214 return op->face;
322 else 215 else
323 return 0; 216 return 0;
324} 217}
325 218
335 * for various code values. 228 * for various code values.
336 */ 229 */
337static void 230static void
338magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) 231magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py)
339{ 232{
340 int x, y, dx, dy, mflags;
341 sint16 nx, ny;
342 maptile *mp;
343
344 for (dx = -1; dx <= 1; dx++) 233 for (int dx = -1; dx <= 1; dx++)
345 { 234 {
346 for (dy = -1; dy <= 1; dy++) 235 for (int dy = -1; dy <= 1; dy++)
347 { 236 {
348 x = px + dx; 237 int x = px + dx;
349 y = py + dy; 238 int y = py + dy;
350 239
351 if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) 240 if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF)
352 continue; 241 continue;
353 242
354 mp = pl->map; 243 mapxy pos (pl);
355 nx = pl->x + x; 244 pos.move (x, y);
356 ny = pl->y + y;
357 245
358 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 246 if (!pos.normalise ())
359 if (mflags & P_OUT_OF_MAP)
360 continue; 247 continue;
248
249 mapspace &ms = pos.ms ();
361 250
362 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) 251 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0)
363 { 252 {
253 int mflags = ms.flags ();
254
364 int f = GET_MAP_FACE (mp, nx, ny, 0); 255 int f = GET_MAP_FACE (ms, 0);
365 if (f == blank_face) 256 if (f == blank_face)
366 { 257 {
367 f = GET_MAP_FACE (mp, nx, ny, 1); 258 f = GET_MAP_FACE (ms, 1);
368 if (f == blank_face) 259 if (f == blank_face)
369 f = GET_MAP_FACE (mp, nx, ny, 2); 260 f = GET_MAP_FACE (ms, 2);
370 } 261 }
371 262
372 int magicmap = faces [f].magicmap; 263 int magicmap = faces [f].magicmap;
373 264
374 /* Should probably have P_NO_MAGIC here also, but then shops don't 265 /* Should probably have P_NO_MAGIC here also, but then shops don't
387} 278}
388 279
389/** 280/**
390 * Creates magic map for player. 281 * Creates magic map for player.
391 * 282 *
392 * Note: For improved magic mapping display, the space that blocks 283 * Note: For improved magic mapping display, the space that blocks
393 * the view is now marked with value 2. Any dependencies of map_mark 284 * the view is now marked with value 2. Any dependencies of map_mark
394 * being nonzero have been changed to check for 1. Also, since 285 * being nonzero have been changed to check for 1. Also, since
395 * map_mark is a char value, putting 2 in should cause no problems. 286 * map_mark is a char value, putting 2 in should cause no problems.
396 * 287 *
397 * This function examines the map the player is on, and determines what 288 * This function examines the map the player is on, and determines what
398 * is visible. 2 is set for walls or objects that blocks view. 1 289 * is visible. 2 is set for walls or objects that blocks view. 1
399 * is for open spaces. map_mark should already have been initialised 290 * is for open spaces. map_mark should already have been initialised
400 * to zero before this is called. 291 * to zero before this is called.
401 * strength is an initial strength*2 rectangular area that we automatically 292 * strength is an initial strength*2 rectangular area that we automatically
402 * see in/penetrate through. 293 * see in/penetrate through.
403 */ 294 */
404void 295static void
405magic_mapping_mark (object *pl, char *map_mark, int strength) 296magic_mapping_mark (object *pl, char *map_mark, int strength)
406{ 297{
407 int x, y, mflags;
408 sint16 nx, ny;
409 maptile *mp;
410
411 for (x = -strength; x < strength; x++) 298 for (int x = -strength; x < strength; x++)
412 { 299 {
413 for (y = -strength; y < strength; y++) 300 for (int y = -strength; y < strength; y++)
414 { 301 {
415 mp = pl->map; 302 mapxy pos (pl);
416 nx = pl->x + x; 303 pos.move (x, y);
417 ny = pl->y + y;
418 304
419 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 305 if (!pos.normalise ())
420 if (mflags & P_OUT_OF_MAP)
421 continue; 306 continue;
422 307
308 mapspace &ms = pos.ms ();
309
310 int mflags = ms.flags ();
311
423 int f = GET_MAP_FACE (mp, nx, ny, 0); 312 int f = GET_MAP_FACE (ms, 0);
424 if (f == blank_face) 313 if (f == blank_face)
425 { 314 {
426 f = GET_MAP_FACE (mp, nx, ny, 1); 315 f = GET_MAP_FACE (ms, 1);
427 if (f == blank_face) 316 if (f == blank_face)
428 f = GET_MAP_FACE (mp, nx, ny, 2); 317 f = GET_MAP_FACE (ms, 2);
429 } 318 }
430 319
431 int magicmap = faces [f].magicmap; 320 int magicmap = faces [f].magicmap;
432 321
433 if (mflags & P_BLOCKSVIEW) 322 if (mflags & P_BLOCKSVIEW)
495 pl->contr->ns->send_packet (sl); 384 pl->contr->ns->send_packet (sl);
496 385
497 free (map_mark); 386 free (map_mark);
498} 387}
499 388
500/**
501 * Send a kill log record to sockets
502 */
503void
504Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType)
505{
506 size_t len;
507 char buf[MAX_BUF];
508
509 if (With != NULL)
510 snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType);
511 else
512 snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType);
513
514 len = strlen (buf);
515}
516

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines