… | |
… | |
96 | |
96 | |
97 | static void |
97 | static void |
98 | print_message (int colr, const object *pl, const char *tmp) |
98 | print_message (int colr, const object *pl, const char *tmp) |
99 | { |
99 | { |
100 | |
100 | |
101 | if (tmp == (char *) NULL) |
101 | if (!tmp) |
102 | { |
|
|
103 | tmp = "[NULL]"; |
102 | tmp = "[NULL]"; |
104 | } |
|
|
105 | |
103 | |
106 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
104 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
107 | return; |
105 | return; |
108 | |
106 | |
109 | if (pl->type == PLAYER) |
107 | if (pl->type == PLAYER) |
110 | { |
108 | { |
111 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
109 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
112 | return; |
110 | return; |
113 | } |
111 | } |
114 | } |
112 | } |
115 | |
|
|
116 | |
113 | |
117 | /** |
114 | /** |
118 | * Prints out the contents of specified buffer structures, |
115 | * Prints out the contents of specified buffer structures, |
119 | * and clears the string. |
116 | * and clears the string. |
120 | */ |
117 | */ |
… | |
… | |
217 | { |
214 | { |
218 | |
215 | |
219 | if (flags & NDI_ALL) |
216 | if (flags & NDI_ALL) |
220 | { |
217 | { |
221 | player *tmppl; |
218 | player *tmppl; |
222 | int i; |
|
|
223 | |
219 | |
224 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
220 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
225 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
221 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
226 | |
222 | |
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; |
223 | return; |
238 | } |
224 | } |
|
|
225 | |
239 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
226 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
240 | { |
227 | { |
241 | /* Write to the socket? */ |
228 | /* Write to the socket? */ |
242 | print_message (0, NULL, buf); |
229 | print_message (0, NULL, buf); |
243 | return; |
230 | return; |
244 | } |
231 | } |
|
|
232 | |
245 | if (pl->type != PLAYER) |
233 | if (pl->type != PLAYER) |
246 | return; |
234 | return; |
|
|
235 | |
247 | if (pri >= pl->contr->listening) |
236 | if (pri >= pl->contr->listening) |
248 | return; |
237 | return; |
249 | |
238 | |
250 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
239 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
251 | { |
|
|
252 | /* following prints stuff out, as appropriate */ |
240 | /* following prints stuff out, as appropriate */ |
253 | check_output_buffers (pl, buf); |
241 | check_output_buffers (pl, buf); |
254 | } |
|
|
255 | else |
242 | else |
256 | { |
|
|
257 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
243 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
258 | } |
|
|
259 | } |
244 | } |
260 | |
245 | |
261 | /** |
246 | /** |
262 | * Wrapper for new_draw_info printf-like. |
247 | * Wrapper for new_draw_info printf-like. |
263 | * |
248 | * |
… | |
… | |
620 | */ |
605 | */ |
621 | |
606 | |
622 | void |
607 | void |
623 | draw_magic_map (object *pl) |
608 | draw_magic_map (object *pl) |
624 | { |
609 | { |
625 | int x, y; |
|
|
626 | char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
610 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
627 | int xmin, xmax, ymin, ymax; |
611 | int xmin, xmax, ymin, ymax; |
628 | SockList sl; |
|
|
629 | |
612 | |
630 | if (pl->type != PLAYER) |
613 | if (pl->type != PLAYER) |
631 | { |
614 | { |
632 | LOG (llevError, "Non player object called draw_map.\n"); |
615 | LOG (llevError, "Non player object called draw_map.\n"); |
633 | return; |
616 | return; |
… | |
… | |
643 | */ |
626 | */ |
644 | xmin = MAGIC_MAP_SIZE; |
627 | xmin = MAGIC_MAP_SIZE; |
645 | ymin = MAGIC_MAP_SIZE; |
628 | ymin = MAGIC_MAP_SIZE; |
646 | xmax = 0; |
629 | xmax = 0; |
647 | ymax = 0; |
630 | ymax = 0; |
|
|
631 | |
648 | for (x = 0; x < MAGIC_MAP_SIZE; x++) |
632 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
649 | { |
|
|
650 | for (y = 0; y < MAGIC_MAP_SIZE; y++) |
633 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
651 | { |
|
|
652 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
634 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
653 | { |
635 | { |
654 | xmin = x < xmin ? x : xmin; |
636 | xmin = x < xmin ? x : xmin; |
655 | xmax = x > xmax ? x : xmax; |
637 | xmax = x > xmax ? x : xmax; |
656 | ymin = y < ymin ? y : ymin; |
638 | ymin = y < ymin ? y : ymin; |
657 | ymax = y > ymax ? y : ymax; |
639 | ymax = y > ymax ? y : ymax; |
658 | } |
640 | } |
659 | } |
|
|
660 | } |
|
|
661 | |
641 | |
662 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
642 | SockList sl (MAXSOCKBUF); |
663 | snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
643 | sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
664 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
644 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
665 | sl.len = strlen ((char *) sl.buf); |
|
|
666 | |
645 | |
667 | for (y = ymin; y <= ymax; y++) |
646 | for (int y = ymin; y <= ymax; y++) |
668 | { |
|
|
669 | for (x = xmin; x <= xmax; x++) |
647 | for (int x = xmin; x <= xmax; x++) |
670 | { |
|
|
671 | sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; |
648 | sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); |
672 | } /* x loop */ |
|
|
673 | } /* y loop */ |
|
|
674 | |
649 | |
675 | Send_With_Handling (&pl->contr->socket, &sl); |
650 | Send_With_Handling (&pl->contr->socket, &sl); |
676 | free (sl.buf); |
651 | |
|
|
652 | sl.free (); |
|
|
653 | |
677 | free (map_mark); |
654 | free (map_mark); |
678 | } |
655 | } |
679 | |
656 | |
680 | |
657 | |
681 | /** |
658 | /** |
… | |
… | |
683 | */ |
660 | */ |
684 | |
661 | |
685 | void |
662 | void |
686 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
663 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
687 | { |
664 | { |
688 | int i; |
|
|
689 | size_t len; |
665 | size_t len; |
690 | char buf[MAX_BUF]; |
666 | char buf[MAX_BUF]; |
691 | |
667 | |
692 | if (With != NULL) |
668 | if (With != NULL) |
693 | { |
|
|
694 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
669 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
695 | } |
|
|
696 | else |
670 | else |
697 | { |
|
|
698 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
671 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
699 | } |
672 | |
700 | len = strlen (buf); |
673 | 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 | } |
674 | } |