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