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.45 by root, Sun Jun 24 04:09:29 2007 UTC vs.
Revision 1.56 by root, Fri Nov 6 13:07:28 2009 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Multiplayer Online Role Playing Game. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software; you can redistribute it and/or modify it 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * under the terms of the GNU General Public License as published by the Free 9 * the terms of the Affero GNU General Public License as published by the
10 * Software Foundation; either version 2 of the License, or (at your option) 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * any later version. 11 * option) any later version.
12 * 12 *
13 * This program is distributed in the hope that it will be useful, but 13 * This program is distributed in the hope that it will be useful,
14 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * 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 along 18 * You should have received a copy of the Affero GNU General Public License
19 * with Crossfire TRT; if not, write to the Free Software Foundation, Inc. 51 19 * and the GNU General Public License along with this program. If not, see
20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 20 * <http://www.gnu.org/licenses/>.
21 * 21 *
22 * The authors can be reached via e-mail to <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.
140/** 140/**
141 * Sends message to player(s). 141 * Sends message to player(s).
142 * 142 *
143 * flags is various flags - mostly color, plus a few specials. 143 * flags is various flags - mostly color, plus a few specials.
144 * 144 *
145 * pri is priority. It is a little odd - the lower the value, the more 145 * pri is unused.
146 * important it is. Thus, 0 gets sent no matter what. Otherwise, the
147 * value must be less than the listening level that the player has set.
148 * Unfortunately, there is no clear guideline on what each level does what.
149 * 146 *
150 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set 147 * pl can be passed as NULL - in fact, this will be done if NDI_ALL is set
151 * in the flags. 148 * in the flags.
152 * 149 *
153 * If message is black, and not NDI_UNIQUE, gets sent through output buffers. 150 * If message is black, and not NDI_UNIQUE, gets sent through output buffers.
157new_draw_info (int flags, int pri, const object *op, const char *buf) 154new_draw_info (int flags, int pri, const object *op, const char *buf)
158{ 155{
159 if (flags & NDI_ALL) 156 if (flags & NDI_ALL)
160 { 157 {
161 for_all_players (pl) 158 for_all_players (pl)
162 new_draw_info (flags & ~NDI_ALL, pri, pl->ob, buf); 159 new_draw_info (flags & ~NDI_ALL, 0, pl->ob, buf);
163 } 160 }
164 else 161 else
165 { 162 {
166 if (!op || !op->contr || !op->contr->ns) 163 if (!op || !op->contr || !op->contr->ns)
167 return;
168
169 if (pri >= op->contr->listening)
170 return; 164 return;
171 165
172 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK 166 if ((flags & (NDI_COLOR_MASK | NDI_UNIQUE)) != NDI_BLACK
173 || !op->contr->ns->msg_suppressed (buf)) 167 || !op->contr->ns->msg_suppressed (buf))
174 print_message (flags & NDI_COLOR_MASK, op, buf); 168 print_message (flags & NDI_COLOR_MASK, op, buf);
184 * client/server bandwidth (client could keep track of various strings 178 * client/server bandwidth (client could keep track of various strings
185 */ 179 */
186void 180void
187new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...) 181new_draw_info_format (int flags, int pri, const object *pl, const char *format, ...)
188{ 182{
189 char buf[HUGE_BUF];
190
191 va_list ap; 183 va_list ap;
192 va_start (ap, format); 184 va_start (ap, format);
193 vsnprintf (buf, HUGE_BUF, format, ap); 185 new_draw_info (flags, pri, pl, vformat (format, ap));
194 va_end (ap); 186 va_end (ap);
195
196 new_draw_info (flags, pri, pl, buf);
197} 187}
198 188
199void 189void
200draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage) 190draw_ext_info (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *message, const char *oldmessage)
201{ 191{
202
203 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 192 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
204 return;
205
206 if (pri >= pl->contr->listening)
207 return; 193 return;
208 194
209 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) 195 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
210 { 196 {
211 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); 197 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
225} 211}
226 212
227void 213void
228draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) 214draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
229{ 215{
230 char buf[HUGE_BUF]; 216 va_list ap;
217 va_start (ap, new_format);
231 218
232 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 219 if (!pl || !pl->is_player ())
233 return; 220 return;
234 221
235 if (pri >= pl->contr->listening) 222 // TODO: just assume, and rip out?
236 return;
237
238 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type)) 223 if (!CLIENT_SUPPORT_READABLES (pl->contr->ns, type))
239 { 224 {
240 va_list ap;
241
242 LOG (llevDebug, "Non supported extension text type for client.\n"); 225 LOG (llevDebug, "Non supported extension text type for client.\n");
243 va_start (ap, new_format);
244 vsnprintf (buf, HUGE_BUF, old_format, ap);
245 va_end (ap);
246 new_draw_info (flags, pri, pl, buf); 226 new_draw_info (flags, pri, pl, vformat (old_format, ap));
247 return;
248 } 227 }
249 else 228 else
250 { 229 {
251 va_list ap; 230 char *buf = vformat (new_format, ap);
252
253 va_start (ap, new_format);
254 vsnprintf (buf, HUGE_BUF, new_format, ap);
255 va_end (ap);
256 strip_media_tag (buf); 231 strip_media_tag (buf);
257 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf); 232 esrv_print_ext_msg (pl->contr->ns, flags & NDI_COLOR_MASK, type, subtype, buf);
258 } 233 }
234
235 va_end (ap);
259} 236}
260 237
261/** 238/**
262 * Writes to everyone on the map *except* op. This is useful for emotions. 239 * Writes to everyone on the map *except* op. This is useful for emotions.
263 */ 240 */
264
265void 241void
266new_info_map_except (int color, maptile * map, object *op, const char *str) 242new_info_map_except (int color, maptile * map, object *op, const char *str)
267{ 243{
268 for_all_players (pl) 244 for_all_players (pl)
269 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) 245 if (pl->ob->map == map && pl->ob != op)
270 new_draw_info (color, 0, pl->ob, str); 246 new_draw_info (color, 0, pl->ob, str);
271} 247}
272 248
273/** 249/**
274 * Writes to everyone on the map except op1 and op2 250 * Writes to everyone on the map except op1 and op2
275 */ 251 */
276void 252static void
277new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) 253new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
278{ 254{
279 for_all_players (pl) 255 for_all_players (pl)
280 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) 256 if (pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
281 new_draw_info (color, 0, pl->ob, str); 257 new_draw_info (color, 0, pl->ob, str);
282} 258}
283 259
284/** 260/**
285 * Writes to everyone on the specified map 261 * Writes to everyone on the specified map
286 */ 262 */
287void 263void
288new_info_map (int color, maptile * map, const char *str) 264new_info_map (int color, maptile * map, const char *str)
289{ 265{
290 for_all_players (pl) 266 for_all_players (pl)
291 if (pl->ob != NULL && pl->ob->map == map) 267 if (pl->ob->map == map)
292 new_draw_info (color, 0, pl->ob, str); 268 new_draw_info (color, 0, pl->ob, str);
293} 269}
294 270
295/** 271/**
296 * Sets player title. 272 * Sets player title.
305 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title); 281 sprintf (buf, "Player: %s %s", (const char *) pl->name, (const char *) pl->contr->own_title);
306} 282}
307 283
308// formerly a macro, used only by magic map, so optimised it out 284// formerly a macro, used only by magic map, so optimised it out
309static inline faceidx 285static inline faceidx
310GET_MAP_FACE (maptile *m, int x, int y, int layer) 286GET_MAP_FACE (mapspace &ms, int layer)
311{ 287{
312 if (object *op = GET_MAP_FACE_OBJ (m, x, y, layer)) 288 if (object *op = ms.faces_obj [layer])
313 return op->face; 289 return op->face;
314 else 290 else
315 return 0; 291 return 0;
316} 292}
317 293
327 * for various code values. 303 * for various code values.
328 */ 304 */
329static void 305static void
330magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) 306magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py)
331{ 307{
332 int x, y, dx, dy, mflags;
333 sint16 nx, ny;
334 maptile *mp;
335
336 for (dx = -1; dx <= 1; dx++) 308 for (int dx = -1; dx <= 1; dx++)
337 { 309 {
338 for (dy = -1; dy <= 1; dy++) 310 for (int dy = -1; dy <= 1; dy++)
339 { 311 {
340 x = px + dx; 312 int x = px + dx;
341 y = py + dy; 313 int y = py + dy;
342 314
343 if (FABS (x) >= MAGIC_MAP_HALF || FABS (y) >= MAGIC_MAP_HALF) 315 if (abs (x) >= MAGIC_MAP_HALF || abs (y) >= MAGIC_MAP_HALF)
344 continue; 316 continue;
345 317
346 mp = pl->map; 318 mapxy pos (pl);
347 nx = pl->x + x; 319 pos.move (x, y);
348 ny = pl->y + y;
349 320
350 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 321 if (!pos.normalise ())
351 if (mflags & P_OUT_OF_MAP)
352 continue; 322 continue;
323
324 mapspace &ms = pos.ms ();
353 325
354 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0) 326 if (map_mark[MAGIC_MAP_HALF + x + MAGIC_MAP_SIZE * (MAGIC_MAP_HALF + y)] == 0)
355 { 327 {
328 int mflags = ms.flags ();
329
356 int f = GET_MAP_FACE (mp, nx, ny, 0); 330 int f = GET_MAP_FACE (ms, 0);
357 if (f == blank_face) 331 if (f == blank_face)
358 { 332 {
359 f = GET_MAP_FACE (mp, nx, ny, 1); 333 f = GET_MAP_FACE (ms, 1);
360 if (f == blank_face) 334 if (f == blank_face)
361 f = GET_MAP_FACE (mp, nx, ny, 2); 335 f = GET_MAP_FACE (ms, 2);
362 } 336 }
363 337
364 int magicmap = faces [f].magicmap; 338 int magicmap = faces [f].magicmap;
365 339
366 /* Should probably have P_NO_MAGIC here also, but then shops don't 340 /* Should probably have P_NO_MAGIC here also, but then shops don't
379} 353}
380 354
381/** 355/**
382 * Creates magic map for player. 356 * Creates magic map for player.
383 * 357 *
384 * Note: For improved magic mapping display, the space that blocks 358 * Note: For improved magic mapping display, the space that blocks
385 * the view is now marked with value 2. Any dependencies of map_mark 359 * the view is now marked with value 2. Any dependencies of map_mark
386 * being nonzero have been changed to check for 1. Also, since 360 * being nonzero have been changed to check for 1. Also, since
387 * map_mark is a char value, putting 2 in should cause no problems. 361 * map_mark is a char value, putting 2 in should cause no problems.
388 * 362 *
389 * This function examines the map the player is on, and determines what 363 * This function examines the map the player is on, and determines what
390 * is visible. 2 is set for walls or objects that blocks view. 1 364 * is visible. 2 is set for walls or objects that blocks view. 1
391 * is for open spaces. map_mark should already have been initialised 365 * is for open spaces. map_mark should already have been initialised
392 * to zero before this is called. 366 * to zero before this is called.
393 * strength is an initial strength*2 rectangular area that we automatically 367 * strength is an initial strength*2 rectangular area that we automatically
394 * see in/penetrate through. 368 * see in/penetrate through.
395 */ 369 */
396void 370static void
397magic_mapping_mark (object *pl, char *map_mark, int strength) 371magic_mapping_mark (object *pl, char *map_mark, int strength)
398{ 372{
399 int x, y, mflags;
400 sint16 nx, ny;
401 maptile *mp;
402
403 for (x = -strength; x < strength; x++) 373 for (int x = -strength; x < strength; x++)
404 { 374 {
405 for (y = -strength; y < strength; y++) 375 for (int y = -strength; y < strength; y++)
406 { 376 {
407 mp = pl->map; 377 mapxy pos (pl);
408 nx = pl->x + x; 378 pos.move (x, y);
409 ny = pl->y + y;
410 379
411 mflags = get_map_flags (pl->map, &mp, nx, ny, &nx, &ny); 380 if (!pos.normalise ())
412 if (mflags & P_OUT_OF_MAP)
413 continue; 381 continue;
414 382
383 mapspace &ms = pos.ms ();
384
385 int mflags = ms.flags ();
386
415 int f = GET_MAP_FACE (mp, nx, ny, 0); 387 int f = GET_MAP_FACE (ms, 0);
416 if (f == blank_face) 388 if (f == blank_face)
417 { 389 {
418 f = GET_MAP_FACE (mp, nx, ny, 1); 390 f = GET_MAP_FACE (ms, 1);
419 if (f == blank_face) 391 if (f == blank_face)
420 f = GET_MAP_FACE (mp, nx, ny, 2); 392 f = GET_MAP_FACE (ms, 2);
421 } 393 }
422 394
423 int magicmap = faces [f].magicmap; 395 int magicmap = faces [f].magicmap;
424 396
425 if (mflags & P_BLOCKSVIEW) 397 if (mflags & P_BLOCKSVIEW)
487 pl->contr->ns->send_packet (sl); 459 pl->contr->ns->send_packet (sl);
488 460
489 free (map_mark); 461 free (map_mark);
490} 462}
491 463
492/**
493 * Send a kill log record to sockets
494 */
495void
496Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType)
497{
498 size_t len;
499 char buf[MAX_BUF];
500
501 if (With != NULL)
502 snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType);
503 else
504 snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType);
505
506 len = strlen (buf);
507}
508

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines