… | |
… | |
45 | * replaced with this, just using black as the color. |
45 | * replaced with this, just using black as the color. |
46 | */ |
46 | */ |
47 | static void |
47 | static void |
48 | esrv_print_msg (NewSocket * ns, int color, const char *str) |
48 | esrv_print_msg (NewSocket * ns, int color, const char *str) |
49 | { |
49 | { |
50 | char buf[HUGE_BUF]; |
50 | packet sl; |
51 | |
51 | |
52 | if (ns->status == Ns_Old) |
52 | if (ns->status == Ns_Old) |
53 | { |
53 | sl.printf ("%s\n", str); |
54 | snprintf (buf, HUGE_BUF, "%s\n", str); |
|
|
55 | } |
|
|
56 | else |
54 | else |
57 | { |
|
|
58 | snprintf (buf, HUGE_BUF, "drawinfo %d %s", color, str); |
55 | sl.printf ("drawinfo %d %s", color, str); |
59 | } |
|
|
60 | |
56 | |
61 | /* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ |
57 | ns->send_packet (sl); |
62 | Write_String_To_Socket (ns, buf, strlen (buf)); |
|
|
63 | } |
58 | } |
64 | |
59 | |
65 | /** |
60 | /** |
66 | * Draws an extended message on the client. |
61 | * Draws an extended message on the client. |
67 | * ns the socket to send message to |
62 | * ns the socket to send message to |
… | |
… | |
72 | * message The main message |
67 | * message The main message |
73 | */ |
68 | */ |
74 | static void |
69 | static void |
75 | 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) |
76 | { |
71 | { |
77 | char buf[HUGE_BUF]; |
72 | packet sl; |
78 | |
73 | |
79 | 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); |
80 | Write_String_To_Socket (ns, buf, strlen (buf)); |
75 | ns->send_packet (sl); |
81 | |
|
|
82 | /* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/ |
|
|
83 | |
|
|
84 | } |
76 | } |
85 | |
77 | |
86 | /** |
78 | /** |
87 | * Frontend for esrv_print_msg |
79 | * Frontend for esrv_print_msg |
88 | * \param colr message color |
80 | * \param colr message color |
… | |
… | |
96 | |
88 | |
97 | static void |
89 | static void |
98 | print_message (int colr, const object *pl, const char *tmp) |
90 | print_message (int colr, const object *pl, const char *tmp) |
99 | { |
91 | { |
100 | |
92 | |
101 | if (tmp == (char *) NULL) |
93 | if (!tmp) |
102 | { |
|
|
103 | tmp = "[NULL]"; |
94 | tmp = "[NULL]"; |
104 | } |
|
|
105 | |
95 | |
106 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
96 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
107 | return; |
97 | return; |
108 | |
98 | |
109 | if (pl->type == PLAYER) |
99 | if (pl->type == PLAYER) |
110 | { |
100 | { |
111 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
101 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
112 | return; |
102 | return; |
113 | } |
103 | } |
114 | } |
104 | } |
115 | |
|
|
116 | |
105 | |
117 | /** |
106 | /** |
118 | * Prints out the contents of specified buffer structures, |
107 | * Prints out the contents of specified buffer structures, |
119 | * and clears the string. |
108 | * and clears the string. |
120 | */ |
109 | */ |
… | |
… | |
217 | { |
206 | { |
218 | |
207 | |
219 | if (flags & NDI_ALL) |
208 | if (flags & NDI_ALL) |
220 | { |
209 | { |
221 | player *tmppl; |
210 | player *tmppl; |
222 | int i; |
|
|
223 | |
211 | |
224 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
212 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
225 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
213 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
226 | |
214 | |
227 | for (i = 1; i < socket_info.allocated_sockets; i++) |
|
|
228 | { |
|
|
229 | if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri < 10) |
|
|
230 | { |
|
|
231 | cs_write_string (&init_sockets[i], buf, strlen (buf)); |
|
|
232 | /* Most messages don't have a newline, so add one */ |
|
|
233 | cs_write_string (&init_sockets[i], "\n", 1); |
|
|
234 | } |
|
|
235 | } |
|
|
236 | |
|
|
237 | return; |
215 | return; |
238 | } |
216 | } |
|
|
217 | |
239 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
218 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
240 | { |
219 | { |
241 | /* Write to the socket? */ |
220 | /* Write to the socket? */ |
242 | print_message (0, NULL, buf); |
221 | print_message (0, NULL, buf); |
243 | return; |
222 | return; |
244 | } |
223 | } |
|
|
224 | |
245 | if (pl->type != PLAYER) |
225 | if (pl->type != PLAYER) |
246 | return; |
226 | return; |
|
|
227 | |
247 | if (pri >= pl->contr->listening) |
228 | if (pri >= pl->contr->listening) |
248 | return; |
229 | return; |
249 | |
230 | |
250 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
231 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
251 | { |
|
|
252 | /* following prints stuff out, as appropriate */ |
232 | /* following prints stuff out, as appropriate */ |
253 | check_output_buffers (pl, buf); |
233 | check_output_buffers (pl, buf); |
254 | } |
|
|
255 | else |
234 | else |
256 | { |
|
|
257 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
235 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
258 | } |
|
|
259 | } |
236 | } |
260 | |
237 | |
261 | /** |
238 | /** |
262 | * Wrapper for new_draw_info printf-like. |
239 | * Wrapper for new_draw_info printf-like. |
263 | * |
240 | * |
… | |
… | |
620 | */ |
597 | */ |
621 | |
598 | |
622 | void |
599 | void |
623 | draw_magic_map (object *pl) |
600 | draw_magic_map (object *pl) |
624 | { |
601 | { |
625 | int x, y; |
|
|
626 | 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); |
627 | int xmin, xmax, ymin, ymax; |
603 | int xmin, xmax, ymin, ymax; |
628 | SockList sl; |
|
|
629 | |
604 | |
630 | if (pl->type != PLAYER) |
605 | if (pl->type != PLAYER) |
631 | { |
606 | { |
632 | LOG (llevError, "Non player object called draw_map.\n"); |
607 | LOG (llevError, "Non player object called draw_map.\n"); |
633 | return; |
608 | return; |
… | |
… | |
643 | */ |
618 | */ |
644 | xmin = MAGIC_MAP_SIZE; |
619 | xmin = MAGIC_MAP_SIZE; |
645 | ymin = MAGIC_MAP_SIZE; |
620 | ymin = MAGIC_MAP_SIZE; |
646 | xmax = 0; |
621 | xmax = 0; |
647 | ymax = 0; |
622 | ymax = 0; |
|
|
623 | |
648 | for (x = 0; x < MAGIC_MAP_SIZE; x++) |
624 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
649 | { |
|
|
650 | for (y = 0; y < MAGIC_MAP_SIZE; y++) |
625 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
651 | { |
|
|
652 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
626 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
653 | { |
627 | { |
654 | xmin = x < xmin ? x : xmin; |
628 | xmin = x < xmin ? x : xmin; |
655 | xmax = x > xmax ? x : xmax; |
629 | xmax = x > xmax ? x : xmax; |
656 | ymin = y < ymin ? y : ymin; |
630 | ymin = y < ymin ? y : ymin; |
657 | ymax = y > ymax ? y : ymax; |
631 | ymax = y > ymax ? y : ymax; |
658 | } |
632 | } |
659 | } |
|
|
660 | } |
|
|
661 | |
633 | |
662 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
634 | packet sl; |
663 | 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), |
664 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
636 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
665 | sl.len = strlen ((char *) sl.buf); |
|
|
666 | |
637 | |
667 | for (y = ymin; y <= ymax; y++) |
638 | for (int y = ymin; y <= ymax; y++) |
668 | { |
|
|
669 | for (x = xmin; x <= xmax; x++) |
639 | for (int x = xmin; x <= xmax; x++) |
670 | { |
|
|
671 | 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); |
672 | } /* x loop */ |
|
|
673 | } /* y loop */ |
|
|
674 | |
641 | |
675 | Send_With_Handling (&pl->contr->socket, &sl); |
642 | Send_With_Handling (&pl->contr->socket, &sl); |
676 | free (sl.buf); |
643 | |
|
|
644 | |
677 | free (map_mark); |
645 | free (map_mark); |
678 | } |
646 | } |
679 | |
647 | |
680 | |
648 | |
681 | /** |
649 | /** |
… | |
… | |
683 | */ |
651 | */ |
684 | |
652 | |
685 | void |
653 | void |
686 | 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) |
687 | { |
655 | { |
688 | int i; |
|
|
689 | size_t len; |
656 | size_t len; |
690 | char buf[MAX_BUF]; |
657 | char buf[MAX_BUF]; |
691 | |
658 | |
692 | if (With != NULL) |
659 | if (With != NULL) |
693 | { |
|
|
694 | 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); |
695 | } |
|
|
696 | else |
661 | else |
697 | { |
|
|
698 | 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); |
699 | } |
663 | |
700 | len = strlen (buf); |
664 | len = strlen (buf); |
701 | for (i = 1; i < socket_info.allocated_sockets; i++) |
|
|
702 | { |
|
|
703 | if (init_sockets[i].old_mode == Old_Listen) |
|
|
704 | { |
|
|
705 | cs_write_string (&init_sockets[i], buf, len); |
|
|
706 | } |
|
|
707 | } |
|
|
708 | } |
665 | } |