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. |
… | |
… | |
50 | * replaced with this, just using black as the color. |
45 | * replaced with this, just using black as the color. |
51 | */ |
46 | */ |
52 | static void |
47 | static void |
53 | esrv_print_msg (NewSocket * ns, int color, const char *str) |
48 | esrv_print_msg (NewSocket * ns, int color, const char *str) |
54 | { |
49 | { |
55 | char buf[HUGE_BUF]; |
50 | SockList sl (MAXSOCKBUF); |
56 | |
51 | |
57 | if (ns->status == Ns_Old) |
52 | if (ns->status == Ns_Old) |
58 | { |
53 | sl.printf ("%s\n", str); |
59 | snprintf (buf, HUGE_BUF, "%s\n", str); |
|
|
60 | } |
|
|
61 | else |
54 | else |
62 | { |
|
|
63 | snprintf (buf, HUGE_BUF, "drawinfo %d %s", color, str); |
55 | sl.printf ("drawinfo %d %s", color, str); |
64 | } |
|
|
65 | |
56 | |
66 | /* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ |
57 | ns->send_packet (sl); |
67 | Write_String_To_Socket (ns, buf, strlen (buf)); |
58 | sl.free (); |
68 | } |
59 | } |
69 | |
60 | |
70 | /** |
61 | /** |
71 | * Draws an extended message on the client. |
62 | * Draws an extended message on the client. |
72 | * ns the socket to send message to |
63 | * ns the socket to send message to |
… | |
… | |
77 | * message The main message |
68 | * message The main message |
78 | */ |
69 | */ |
79 | static void |
70 | static void |
80 | esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message) |
71 | esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message) |
81 | { |
72 | { |
82 | char buf[HUGE_BUF]; |
73 | SockList sl (MAXSOCKBUF); |
83 | |
74 | |
84 | snprintf (buf, HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
75 | sl.printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
85 | Write_String_To_Socket (ns, buf, strlen (buf)); |
76 | ns->send_packet (sl); |
86 | |
77 | sl.free (); |
87 | /* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/ |
|
|
88 | |
|
|
89 | } |
78 | } |
90 | |
79 | |
91 | /** |
80 | /** |
92 | * Frontend for esrv_print_msg |
81 | * Frontend for esrv_print_msg |
93 | * \param colr message color |
82 | * \param colr message color |
… | |
… | |
101 | |
90 | |
102 | static void |
91 | static void |
103 | print_message (int colr, const object *pl, const char *tmp) |
92 | print_message (int colr, const object *pl, const char *tmp) |
104 | { |
93 | { |
105 | |
94 | |
106 | if (tmp == (char *) NULL) |
95 | if (!tmp) |
107 | { |
|
|
108 | tmp = "[NULL]"; |
96 | tmp = "[NULL]"; |
109 | } |
|
|
110 | |
97 | |
111 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
98 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
112 | return; |
99 | return; |
113 | |
100 | |
114 | if (pl->type == PLAYER) |
101 | if (pl->type == PLAYER) |
115 | { |
102 | { |
116 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
103 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
117 | return; |
104 | return; |
118 | } |
105 | } |
119 | } |
106 | } |
120 | |
|
|
121 | |
107 | |
122 | /** |
108 | /** |
123 | * Prints out the contents of specified buffer structures, |
109 | * Prints out the contents of specified buffer structures, |
124 | * and clears the string. |
110 | * and clears the string. |
125 | */ |
111 | */ |
… | |
… | |
222 | { |
208 | { |
223 | |
209 | |
224 | if (flags & NDI_ALL) |
210 | if (flags & NDI_ALL) |
225 | { |
211 | { |
226 | player *tmppl; |
212 | player *tmppl; |
227 | int i; |
|
|
228 | |
213 | |
229 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
214 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
230 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
215 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
231 | |
216 | |
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; |
217 | return; |
243 | } |
218 | } |
|
|
219 | |
244 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
220 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
245 | { |
221 | { |
246 | /* Write to the socket? */ |
222 | /* Write to the socket? */ |
247 | print_message (0, NULL, buf); |
223 | print_message (0, NULL, buf); |
248 | return; |
224 | return; |
249 | } |
225 | } |
|
|
226 | |
250 | if (pl->type != PLAYER) |
227 | if (pl->type != PLAYER) |
251 | return; |
228 | return; |
|
|
229 | |
252 | if (pri >= pl->contr->listening) |
230 | if (pri >= pl->contr->listening) |
253 | return; |
231 | return; |
254 | |
232 | |
255 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
233 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
256 | { |
|
|
257 | /* following prints stuff out, as appropriate */ |
234 | /* following prints stuff out, as appropriate */ |
258 | check_output_buffers (pl, buf); |
235 | check_output_buffers (pl, buf); |
259 | } |
|
|
260 | else |
236 | else |
261 | { |
|
|
262 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
237 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
263 | } |
|
|
264 | } |
238 | } |
265 | |
239 | |
266 | /** |
240 | /** |
267 | * Wrapper for new_draw_info printf-like. |
241 | * Wrapper for new_draw_info printf-like. |
268 | * |
242 | * |
… | |
… | |
355 | /** |
329 | /** |
356 | * Writes to everyone on the map *except* op. This is useful for emotions. |
330 | * Writes to everyone on the map *except* op. This is useful for emotions. |
357 | */ |
331 | */ |
358 | |
332 | |
359 | void |
333 | void |
360 | new_info_map_except (int color, mapstruct *map, object *op, const char *str) |
334 | new_info_map_except (int color, maptile * map, object *op, const char *str) |
361 | { |
335 | { |
362 | player *pl; |
336 | player *pl; |
363 | |
337 | |
364 | for (pl = first_player; pl != NULL; pl = pl->next) |
338 | for (pl = first_player; pl != NULL; pl = pl->next) |
365 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
339 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) |
… | |
… | |
371 | /** |
345 | /** |
372 | * Writes to everyone on the map except op1 and op2 |
346 | * Writes to everyone on the map except op1 and op2 |
373 | */ |
347 | */ |
374 | |
348 | |
375 | void |
349 | void |
376 | new_info_map_except2 (int color, mapstruct *map, object *op1, object *op2, const char *str) |
350 | new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str) |
377 | { |
351 | { |
378 | player *pl; |
352 | player *pl; |
379 | |
353 | |
380 | for (pl = first_player; pl != NULL; pl = pl->next) |
354 | for (pl = first_player; pl != NULL; pl = pl->next) |
381 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
355 | if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) |
… | |
… | |
387 | /** |
361 | /** |
388 | * Writes to everyone on the specified map |
362 | * Writes to everyone on the specified map |
389 | */ |
363 | */ |
390 | |
364 | |
391 | void |
365 | void |
392 | new_info_map (int color, mapstruct *map, const char *str) |
366 | new_info_map (int color, maptile * map, const char *str) |
393 | { |
367 | { |
394 | player *pl; |
368 | player *pl; |
395 | |
369 | |
396 | for (pl = first_player; pl != NULL; pl = pl->next) |
370 | for (pl = first_player; pl != NULL; pl = pl->next) |
397 | if (pl->ob != NULL && pl->ob->map == map) |
371 | if (pl->ob != NULL && pl->ob->map == map) |
… | |
… | |
417 | void |
391 | void |
418 | rangetostring (object *pl, char *obuf) |
392 | rangetostring (object *pl, char *obuf) |
419 | { |
393 | { |
420 | switch (pl->contr->shoottype) |
394 | switch (pl->contr->shoottype) |
421 | { |
395 | { |
422 | case range_none: |
396 | case range_none: |
423 | strcpy (obuf, "Range: nothing"); |
397 | strcpy (obuf, "Range: nothing"); |
424 | break; |
398 | break; |
425 | |
399 | |
426 | case range_bow: |
400 | case range_bow: |
|
|
401 | { |
|
|
402 | object *op; |
|
|
403 | |
|
|
404 | for (op = pl->inv; op; op = op->below) |
|
|
405 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
|
|
406 | break; |
|
|
407 | |
|
|
408 | if (op == NULL) |
|
|
409 | break; |
|
|
410 | |
|
|
411 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
|
|
412 | } |
|
|
413 | break; |
|
|
414 | |
|
|
415 | case range_magic: |
|
|
416 | if (settings.casting_time == TRUE) |
427 | { |
417 | { |
428 | object *op; |
418 | if (pl->casting_time > -1) |
429 | |
419 | { |
430 | for (op = pl->inv; op; op = op->below) |
420 | if (pl->casting_time == 0) |
431 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
421 | sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); |
432 | break; |
422 | else |
433 | if (op == NULL) |
423 | sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); |
434 | break; |
424 | } |
435 | |
425 | else |
436 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
426 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
437 | } |
427 | } |
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 |
428 | else |
454 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
429 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
455 | break; |
430 | break; |
456 | |
431 | |
457 | case range_misc: |
432 | case range_misc: |
458 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
433 | sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); |
459 | break; |
434 | break; |
460 | |
435 | |
461 | /* range_scroll is only used for controlling golems. If the |
436 | /* range_scroll is only used for controlling golems. If the |
462 | * the player does not have a golem, reset some things. |
437 | * the player does not have a golem, reset some things. |
463 | */ |
438 | */ |
464 | case range_golem: |
439 | case range_golem: |
465 | if (pl->contr->ranges[range_golem] != NULL) |
440 | if (pl->contr->ranges[range_golem] != NULL) |
466 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
441 | sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); |
467 | else |
442 | else |
468 | { |
443 | { |
469 | pl->contr->shoottype = range_none; |
444 | pl->contr->shoottype = range_none; |
470 | strcpy (obuf, "Range: nothing"); |
445 | strcpy (obuf, "Range: nothing"); |
471 | } |
446 | } |
472 | break; |
447 | break; |
473 | |
448 | |
474 | case range_skill: |
449 | case range_skill: |
475 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
450 | sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); |
476 | break; |
451 | break; |
477 | |
452 | |
478 | case range_builder: |
453 | case range_builder: |
479 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
454 | sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); |
480 | break; |
455 | break; |
481 | |
456 | |
482 | default: |
457 | default: |
483 | strcpy (obuf, "Range: illegal"); |
458 | strcpy (obuf, "Range: illegal"); |
484 | } |
459 | } |
485 | } |
460 | } |
486 | |
461 | |
487 | /** |
462 | /** |
488 | * Sets player title. |
463 | * Sets player title. |
… | |
… | |
512 | static void |
487 | static void |
513 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
488 | magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) |
514 | { |
489 | { |
515 | int x, y, dx, dy, mflags; |
490 | int x, y, dx, dy, mflags; |
516 | sint16 nx, ny; |
491 | sint16 nx, ny; |
517 | mapstruct *mp; |
492 | maptile *mp; |
518 | New_Face *f; |
493 | New_Face *f; |
519 | |
494 | |
520 | for (dx = -1; dx <= 1; dx++) |
495 | for (dx = -1; dx <= 1; dx++) |
521 | { |
496 | { |
522 | for (dy = -1; dy <= 1; dy++) |
497 | for (dy = -1; dy <= 1; dy++) |
… | |
… | |
578 | void |
553 | void |
579 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
554 | magic_mapping_mark (object *pl, char *map_mark, int strength) |
580 | { |
555 | { |
581 | int x, y, mflags; |
556 | int x, y, mflags; |
582 | sint16 nx, ny; |
557 | sint16 nx, ny; |
583 | mapstruct *mp; |
558 | maptile *mp; |
584 | New_Face *f; |
559 | New_Face *f; |
585 | |
560 | |
586 | for (x = -strength; x < strength; x++) |
561 | for (x = -strength; x < strength; x++) |
587 | { |
562 | { |
588 | for (y = -strength; y < strength; y++) |
563 | for (y = -strength; y < strength; y++) |
… | |
… | |
624 | */ |
599 | */ |
625 | |
600 | |
626 | void |
601 | void |
627 | draw_magic_map (object *pl) |
602 | draw_magic_map (object *pl) |
628 | { |
603 | { |
629 | int x, y; |
|
|
630 | char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
604 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
631 | int xmin, xmax, ymin, ymax; |
605 | int xmin, xmax, ymin, ymax; |
632 | SockList sl; |
|
|
633 | |
606 | |
634 | if (pl->type != PLAYER) |
607 | if (pl->type != PLAYER) |
635 | { |
608 | { |
636 | LOG (llevError, "Non player object called draw_map.\n"); |
609 | LOG (llevError, "Non player object called draw_map.\n"); |
637 | return; |
610 | return; |
… | |
… | |
647 | */ |
620 | */ |
648 | xmin = MAGIC_MAP_SIZE; |
621 | xmin = MAGIC_MAP_SIZE; |
649 | ymin = MAGIC_MAP_SIZE; |
622 | ymin = MAGIC_MAP_SIZE; |
650 | xmax = 0; |
623 | xmax = 0; |
651 | ymax = 0; |
624 | ymax = 0; |
|
|
625 | |
652 | for (x = 0; x < MAGIC_MAP_SIZE; x++) |
626 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
653 | { |
|
|
654 | for (y = 0; y < MAGIC_MAP_SIZE; y++) |
627 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
655 | { |
|
|
656 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
628 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
657 | { |
629 | { |
658 | xmin = x < xmin ? x : xmin; |
630 | xmin = x < xmin ? x : xmin; |
659 | xmax = x > xmax ? x : xmax; |
631 | xmax = x > xmax ? x : xmax; |
660 | ymin = y < ymin ? y : ymin; |
632 | ymin = y < ymin ? y : ymin; |
661 | ymax = y > ymax ? y : ymax; |
633 | ymax = y > ymax ? y : ymax; |
662 | } |
634 | } |
663 | } |
|
|
664 | } |
|
|
665 | |
635 | |
666 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
636 | SockList sl (MAXSOCKBUF); |
667 | snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
637 | sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
668 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
638 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
669 | sl.len = strlen ((char *) sl.buf); |
|
|
670 | |
639 | |
671 | for (y = ymin; y <= ymax; y++) |
640 | for (int y = ymin; y <= ymax; y++) |
672 | { |
|
|
673 | for (x = xmin; x <= xmax; x++) |
641 | for (int x = xmin; x <= xmax; x++) |
674 | { |
|
|
675 | sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; |
642 | sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); |
676 | } /* x loop */ |
|
|
677 | } /* y loop */ |
|
|
678 | |
643 | |
679 | Send_With_Handling (&pl->contr->socket, &sl); |
644 | Send_With_Handling (&pl->contr->socket, &sl); |
680 | free (sl.buf); |
645 | |
|
|
646 | sl.free (); |
|
|
647 | |
681 | free (map_mark); |
648 | free (map_mark); |
682 | } |
649 | } |
683 | |
650 | |
684 | |
651 | |
685 | /** |
652 | /** |
… | |
… | |
687 | */ |
654 | */ |
688 | |
655 | |
689 | void |
656 | void |
690 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
657 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
691 | { |
658 | { |
692 | int i; |
|
|
693 | size_t len; |
659 | size_t len; |
694 | char buf[MAX_BUF]; |
660 | char buf[MAX_BUF]; |
695 | |
661 | |
696 | if (With != NULL) |
662 | if (With != NULL) |
697 | { |
|
|
698 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
663 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
699 | } |
|
|
700 | else |
664 | else |
701 | { |
|
|
702 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
665 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
703 | } |
666 | |
704 | len = strlen (buf); |
667 | 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 | } |
668 | } |