1 | |
|
|
2 | /* |
|
|
3 | * static char *rcsid_sock_info_c = |
|
|
4 | * "$Id: info.C,v 1.5 2006/09/10 13:43:33 root Exp $"; |
|
|
5 | */ |
|
|
6 | |
1 | |
7 | /* |
2 | /* |
8 | CrossFire, A Multiplayer game for X-windows |
3 | CrossFire, A Multiplayer game for X-windows |
9 | |
4 | |
10 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
… | |
… | |
22 | |
17 | |
23 | You should have received a copy of the GNU General Public License |
18 | You should have received a copy of the GNU General Public License |
24 | along with this program; if not, write to the Free Software |
19 | along with this program; if not, write to the Free Software |
25 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
26 | |
21 | |
27 | The authors can be reached via e-mail at crossfire-devel@real-time.com |
22 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
28 | */ |
23 | */ |
29 | |
24 | |
30 | /** |
25 | /** |
31 | * \file |
26 | * \file |
32 | * Basic client output functions. |
27 | * Basic client output functions. |
… | |
… | |
101 | |
96 | |
102 | static void |
97 | static void |
103 | print_message (int colr, const object *pl, const char *tmp) |
98 | print_message (int colr, const object *pl, const char *tmp) |
104 | { |
99 | { |
105 | |
100 | |
106 | if (tmp == (char *) NULL) |
101 | if (!tmp) |
107 | { |
|
|
108 | tmp = "[NULL]"; |
102 | tmp = "[NULL]"; |
109 | } |
|
|
110 | |
103 | |
111 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
104 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
112 | return; |
105 | return; |
113 | |
106 | |
114 | if (pl->type == PLAYER) |
107 | if (pl->type == PLAYER) |
115 | { |
108 | { |
116 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
109 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
117 | return; |
110 | return; |
118 | } |
111 | } |
119 | } |
112 | } |
120 | |
|
|
121 | |
113 | |
122 | /** |
114 | /** |
123 | * Prints out the contents of specified buffer structures, |
115 | * Prints out the contents of specified buffer structures, |
124 | * and clears the string. |
116 | * and clears the string. |
125 | */ |
117 | */ |
… | |
… | |
222 | { |
214 | { |
223 | |
215 | |
224 | if (flags & NDI_ALL) |
216 | if (flags & NDI_ALL) |
225 | { |
217 | { |
226 | player *tmppl; |
218 | player *tmppl; |
227 | int i; |
|
|
228 | |
219 | |
229 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
220 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
230 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
221 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
231 | |
222 | |
232 | for (i = 1; i < socket_info.allocated_sockets; i++) |
|
|
233 | { |
|
|
234 | if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri < 10) |
|
|
235 | { |
|
|
236 | cs_write_string (&init_sockets[i], buf, strlen (buf)); |
|
|
237 | /* Most messages don't have a newline, so add one */ |
|
|
238 | cs_write_string (&init_sockets[i], "\n", 1); |
|
|
239 | } |
|
|
240 | } |
|
|
241 | |
|
|
242 | return; |
223 | return; |
243 | } |
224 | } |
|
|
225 | |
244 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
226 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
245 | { |
227 | { |
246 | /* Write to the socket? */ |
228 | /* Write to the socket? */ |
247 | print_message (0, NULL, buf); |
229 | print_message (0, NULL, buf); |
248 | return; |
230 | return; |
249 | } |
231 | } |
|
|
232 | |
250 | if (pl->type != PLAYER) |
233 | if (pl->type != PLAYER) |
251 | return; |
234 | return; |
|
|
235 | |
252 | if (pri >= pl->contr->listening) |
236 | if (pri >= pl->contr->listening) |
253 | return; |
237 | return; |
254 | |
238 | |
255 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
239 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
256 | { |
|
|
257 | /* following prints stuff out, as appropriate */ |
240 | /* following prints stuff out, as appropriate */ |
258 | check_output_buffers (pl, buf); |
241 | check_output_buffers (pl, buf); |
259 | } |
|
|
260 | else |
242 | else |
261 | { |
|
|
262 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
243 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
263 | } |
|
|
264 | } |
244 | } |
265 | |
245 | |
266 | /** |
246 | /** |
267 | * Wrapper for new_draw_info printf-like. |
247 | * Wrapper for new_draw_info printf-like. |
268 | * |
248 | * |
… | |
… | |
355 | /** |
335 | /** |
356 | * Writes to everyone on the map *except* op. This is useful for emotions. |
336 | * Writes to everyone on the map *except* op. This is useful for emotions. |
357 | */ |
337 | */ |
358 | |
338 | |
359 | void |
339 | void |
360 | new_info_map_except (int color, mapstruct *map, object *op, const char *str) |
340 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
361 | { |
341 | { |
362 | player *pl; |
342 | player *pl; |
363 | |
343 | |
364 | for (pl = first_player; pl != NULL; pl = pl->next) |
344 | for (pl = first_player; pl != NULL; pl = pl->next) |
365 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
345 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
… | |
… | |
371 | /** |
351 | /** |
372 | * Writes to everyone on the map except op1 and op2 |
352 | * Writes to everyone on the map except op1 and op2 |
373 | */ |
353 | */ |
374 | |
354 | |
375 | void |
355 | void |
376 | new_info_map_except2 (int color, mapstruct *map, object *op1, object *op2, const char *str) |
356 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
377 | { |
357 | { |
378 | player *pl; |
358 | player *pl; |
379 | |
359 | |
380 | for (pl = first_player; pl != NULL; pl = pl->next) |
360 | for (pl = first_player; pl != NULL; pl = pl->next) |
381 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
361 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
… | |
… | |
387 | /** |
367 | /** |
388 | * Writes to everyone on the specified map |
368 | * Writes to everyone on the specified map |
389 | */ |
369 | */ |
390 | |
370 | |
391 | void |
371 | void |
392 | new_info_map (int color, mapstruct *map, const char *str) |
372 | new_info_map (int color, maptile * map, const char *str) |
393 | { |
373 | { |
394 | player *pl; |
374 | player *pl; |
395 | |
375 | |
396 | for (pl = first_player; pl != NULL; pl = pl->next) |
376 | for (pl = first_player; pl != NULL; pl = pl->next) |
397 | if (pl->ob != NULL && pl->ob->map == map) |
377 | if (pl->ob != NULL && pl->ob->map == map) |
… | |
… | |
417 | void |
397 | void |
418 | rangetostring (object *pl, char *obuf) |
398 | rangetostring (object *pl, char *obuf) |
419 | { |
399 | { |
420 | switch (pl->contr->shoottype) |
400 | switch (pl->contr->shoottype) |
421 | { |
401 | { |
422 | case range_none: |
402 | case range_none: |
423 | strcpy (obuf, "Range: nothing"); |
403 | strcpy (obuf, "Range: nothing"); |
424 | break; |
404 | break; |
425 | |
405 | |
426 | case range_bow: |
406 | case range_bow: |
|
|
407 | { |
|
|
408 | object *op; |
|
|
409 | |
|
|
410 | for (op = pl->inv; op; op = op->below) |
|
|
411 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
412 | break; |
|
|
413 | |
|
|
414 | if (op == NULL) |
|
|
415 | break; |
|
|
416 | |
|
|
417 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
|
|
418 | } |
|
|
419 | break; |
|
|
420 | |
|
|
421 | case range_magic: |
|
|
422 | if (settings.casting_time == TRUE) |
427 | { |
423 | { |
428 | object *op; |
424 | if (pl->casting_time > -1) |
429 | |
425 | { |
430 | for (op = pl->inv; op; op = op->below) |
426 | if (pl->casting_time == 0) |
431 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
427 | sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); |
432 | break; |
428 | else |
433 | if (op == NULL) |
429 | sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); |
434 | break; |
430 | } |
435 | |
431 | else |
436 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
432 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
437 | } |
433 | } |
438 | break; |
|
|
439 | |
|
|
440 | case range_magic: |
|
|
441 | if (settings.casting_time == TRUE) |
|
|
442 | { |
|
|
443 | if (pl->casting_time > -1) |
|
|
444 | { |
|
|
445 | if (pl->casting_time == 0) |
|
|
446 | sprintf (obuf, "Range: Holding spell (%s)", (const char *) pl->spell->name); |
|
|
447 | else |
|
|
448 | sprintf (obuf, "Range: Casting spell (%s)", (const char *) pl->spell->name); |
|
|
449 | } |
|
|
450 | else |
|
|
451 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
|
|
452 | } |
|
|
453 | else |
434 | else |
454 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
435 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
455 | break; |
436 | break; |
456 | |
437 | |
457 | case range_misc: |
438 | case range_misc: |
458 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
439 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
459 | break; |
440 | break; |
460 | |
441 | |
461 | /* range_scroll is only used for controlling golems. If the |
442 | /* range_scroll is only used for controlling golems. If the |
462 | * the player does not have a golem, reset some things. |
443 | * the player does not have a golem, reset some things. |
463 | */ |
444 | */ |
464 | case range_golem: |
445 | case range_golem: |
465 | if (pl->contr->ranges[range_golem] != NULL) |
446 | if (pl->contr->ranges[range_golem] != NULL) |
466 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
447 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
467 | else |
448 | else |
468 | { |
449 | { |
469 | pl->contr->shoottype = range_none; |
450 | pl->contr->shoottype = range_none; |
470 | strcpy (obuf, "Range: nothing"); |
451 | strcpy (obuf, "Range: nothing"); |
471 | } |
452 | } |
472 | break; |
453 | break; |
473 | |
454 | |
474 | case range_skill: |
455 | case range_skill: |
475 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
456 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
476 | break; |
457 | break; |
477 | |
458 | |
478 | case range_builder: |
459 | case range_builder: |
479 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
460 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
480 | break; |
461 | break; |
481 | |
462 | |
482 | default: |
463 | default: |
483 | strcpy (obuf, "Range: illegal"); |
464 | strcpy (obuf, "Range: illegal"); |
484 | } |
465 | } |
485 | } |
466 | } |
486 | |
467 | |
487 | /** |
468 | /** |
488 | * Sets player title. |
469 | * Sets player title. |
… | |
… | |
512 | static void |
493 | static void |
513 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
494 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
514 | { |
495 | { |
515 | int x, y, dx, dy, mflags; |
496 | int x, y, dx, dy, mflags; |
516 | sint16 nx, ny; |
497 | sint16 nx, ny; |
517 | mapstruct *mp; |
498 | maptile *mp; |
518 | New_Face *f; |
499 | New_Face *f; |
519 | |
500 | |
520 | for (dx = -1; dx <= 1; dx++) |
501 | for (dx = -1; dx <= 1; dx++) |
521 | { |
502 | { |
522 | for (dy = -1; dy <= 1; dy++) |
503 | for (dy = -1; dy <= 1; dy++) |
… | |
… | |
578 | void |
559 | void |
579 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
560 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
580 | { |
561 | { |
581 | int x, y, mflags; |
562 | int x, y, mflags; |
582 | sint16 nx, ny; |
563 | sint16 nx, ny; |
583 | mapstruct *mp; |
564 | maptile *mp; |
584 | New_Face *f; |
565 | New_Face *f; |
585 | |
566 | |
586 | for (x = -strength; x < strength; x++) |
567 | for (x = -strength; x < strength; x++) |
587 | { |
568 | { |
588 | for (y = -strength; y < strength; y++) |
569 | for (y = -strength; y < strength; y++) |
… | |
… | |
687 | */ |
668 | */ |
688 | |
669 | |
689 | void |
670 | void |
690 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
671 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
691 | { |
672 | { |
692 | int i; |
|
|
693 | size_t len; |
673 | size_t len; |
694 | char buf[MAX_BUF]; |
674 | char buf[MAX_BUF]; |
695 | |
675 | |
696 | if (With != NULL) |
676 | if (With != NULL) |
697 | { |
|
|
698 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
677 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
699 | } |
|
|
700 | else |
678 | else |
701 | { |
|
|
702 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
679 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
703 | } |
680 | |
704 | len = strlen (buf); |
681 | len = strlen (buf); |
705 | for (i = 1; i < socket_info.allocated_sockets; i++) |
|
|
706 | { |
|
|
707 | if (init_sockets[i].old_mode == Old_Listen) |
|
|
708 | { |
|
|
709 | cs_write_string (&init_sockets[i], buf, len); |
|
|
710 | } |
|
|
711 | } |
|
|
712 | } |
682 | } |