… | |
… | |
43 | * much the same thing as the draw_info above, but takes a color |
43 | * much the same thing as the draw_info above, but takes a color |
44 | * parameter. the esrv_drawinfo functions should probably be |
44 | * parameter. the esrv_drawinfo functions should probably be |
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 (client * ns, int color, const char *str) |
49 | { |
49 | { |
50 | char buf[HUGE_BUF]; |
50 | ns->send_packet_printf ("drawinfo %d %s", color, str); |
51 | |
|
|
52 | if (ns->status == Ns_Old) |
|
|
53 | { |
|
|
54 | snprintf (buf, HUGE_BUF, "%s\n", str); |
|
|
55 | } |
|
|
56 | else |
|
|
57 | { |
|
|
58 | snprintf (buf, HUGE_BUF, "drawinfo %d %s", color, str); |
|
|
59 | } |
|
|
60 | |
|
|
61 | /* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ |
|
|
62 | Write_String_To_Socket (ns, buf, strlen (buf)); |
|
|
63 | } |
51 | } |
64 | |
52 | |
65 | /** |
53 | /** |
66 | * Draws an extended message on the client. |
54 | * Draws an extended message on the client. |
67 | * ns the socket to send message to |
55 | * ns the socket to send message to |
… | |
… | |
70 | * subtype type and subtype of text message |
58 | * subtype type and subtype of text message |
71 | * intro Intro message to send with main message if client does not support the message type |
59 | * intro Intro message to send with main message if client does not support the message type |
72 | * message The main message |
60 | * message The main message |
73 | */ |
61 | */ |
74 | static void |
62 | static void |
75 | esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message) |
63 | esrv_print_ext_msg (client * ns, int color, uint8 type, uint8 subtype, const char *message) |
76 | { |
64 | { |
77 | char buf[HUGE_BUF]; |
|
|
78 | |
|
|
79 | snprintf (buf, HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
65 | ns->send_packet_printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message); |
80 | Write_String_To_Socket (ns, buf, strlen (buf)); |
|
|
81 | |
|
|
82 | /* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/ |
|
|
83 | |
|
|
84 | } |
66 | } |
85 | |
67 | |
86 | /** |
68 | /** |
87 | * Frontend for esrv_print_msg |
69 | * Frontend for esrv_print_msg |
88 | * \param colr message color |
70 | * \param colr message color |
… | |
… | |
96 | |
78 | |
97 | static void |
79 | static void |
98 | print_message (int colr, const object *pl, const char *tmp) |
80 | print_message (int colr, const object *pl, const char *tmp) |
99 | { |
81 | { |
100 | |
82 | |
101 | if (tmp == (char *) NULL) |
83 | if (!tmp) |
102 | { |
|
|
103 | tmp = "[NULL]"; |
84 | tmp = "[NULL]"; |
104 | } |
|
|
105 | |
85 | |
106 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
86 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
107 | return; |
87 | return; |
108 | |
88 | |
109 | if (pl->type == PLAYER) |
89 | if (pl->type == PLAYER) |
110 | { |
|
|
111 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
90 | esrv_print_msg (pl->contr->socket, colr, (char *) tmp); |
112 | return; |
|
|
113 | } |
|
|
114 | } |
91 | } |
115 | |
|
|
116 | |
92 | |
117 | /** |
93 | /** |
118 | * Prints out the contents of specified buffer structures, |
94 | * Prints out the contents of specified buffer structures, |
119 | * and clears the string. |
95 | * and clears the string. |
120 | */ |
96 | */ |
… | |
… | |
217 | { |
193 | { |
218 | |
194 | |
219 | if (flags & NDI_ALL) |
195 | if (flags & NDI_ALL) |
220 | { |
196 | { |
221 | player *tmppl; |
197 | player *tmppl; |
222 | int i; |
|
|
223 | |
198 | |
224 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
199 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
225 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
200 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
226 | |
201 | |
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; |
202 | return; |
238 | } |
203 | } |
|
|
204 | |
239 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
205 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
240 | { |
206 | { |
241 | /* Write to the socket? */ |
207 | /* Write to the socket? */ |
242 | print_message (0, NULL, buf); |
208 | print_message (0, NULL, buf); |
243 | return; |
209 | return; |
244 | } |
210 | } |
|
|
211 | |
245 | if (pl->type != PLAYER) |
212 | if (pl->type != PLAYER) |
246 | return; |
213 | return; |
|
|
214 | |
247 | if (pri >= pl->contr->listening) |
215 | if (pri >= pl->contr->listening) |
248 | return; |
216 | return; |
249 | |
217 | |
250 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
218 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
251 | { |
|
|
252 | /* following prints stuff out, as appropriate */ |
219 | /* following prints stuff out, as appropriate */ |
253 | check_output_buffers (pl, buf); |
220 | check_output_buffers (pl, buf); |
254 | } |
|
|
255 | else |
221 | else |
256 | { |
|
|
257 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
222 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
258 | } |
|
|
259 | } |
223 | } |
260 | |
224 | |
261 | /** |
225 | /** |
262 | * Wrapper for new_draw_info printf-like. |
226 | * Wrapper for new_draw_info printf-like. |
263 | * |
227 | * |
… | |
… | |
291 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
255 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
292 | return; |
256 | return; |
293 | |
257 | |
294 | if (pri >= pl->contr->listening) |
258 | if (pri >= pl->contr->listening) |
295 | return; |
259 | return; |
|
|
260 | |
296 | if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) |
261 | if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) |
297 | { |
262 | { |
298 | char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); |
263 | char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); |
299 | |
264 | |
300 | if (buf == NULL) |
265 | if (buf == NULL) |
301 | LOG (llevError, "info::draw_ext_info -> Out of memory!"); |
266 | LOG (llevError, "info::draw_ext_info -> Out of memory!"); |
… | |
… | |
306 | new_draw_info (flags, pri, pl, buf); |
271 | new_draw_info (flags, pri, pl, buf); |
307 | free (buf); |
272 | free (buf); |
308 | } |
273 | } |
309 | } |
274 | } |
310 | else |
275 | else |
311 | { |
|
|
312 | esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); |
276 | esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); |
313 | } |
|
|
314 | } |
277 | } |
315 | |
278 | |
316 | void |
279 | void |
317 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
280 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
318 | { |
281 | { |
… | |
… | |
322 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
285 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
323 | return; |
286 | return; |
324 | |
287 | |
325 | if (pri >= pl->contr->listening) |
288 | if (pri >= pl->contr->listening) |
326 | return; |
289 | return; |
|
|
290 | |
327 | if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) |
291 | if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) |
328 | { |
292 | { |
329 | va_list ap; |
293 | va_list ap; |
330 | |
294 | |
331 | LOG (llevDebug, "Non supported extension text type for client.\n"); |
295 | LOG (llevDebug, "Non supported extension text type for client.\n"); |
332 | va_start (ap, new_format); |
296 | va_start (ap, new_format); |
… | |
… | |
341 | |
305 | |
342 | va_start (ap, new_format); |
306 | va_start (ap, new_format); |
343 | vsnprintf (buf, HUGE_BUF, new_format, ap); |
307 | vsnprintf (buf, HUGE_BUF, new_format, ap); |
344 | va_end (ap); |
308 | va_end (ap); |
345 | strip_media_tag (buf); |
309 | strip_media_tag (buf); |
346 | esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); |
310 | esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); |
347 | } |
311 | } |
348 | } |
312 | } |
349 | |
313 | |
350 | /** |
314 | /** |
351 | * Writes to everyone on the map *except* op. This is useful for emotions. |
315 | * Writes to everyone on the map *except* op. This is useful for emotions. |
… | |
… | |
620 | */ |
584 | */ |
621 | |
585 | |
622 | void |
586 | void |
623 | draw_magic_map (object *pl) |
587 | draw_magic_map (object *pl) |
624 | { |
588 | { |
625 | int x, y; |
|
|
626 | char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
589 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
627 | int xmin, xmax, ymin, ymax; |
590 | int xmin, xmax, ymin, ymax; |
628 | SockList sl; |
|
|
629 | |
591 | |
630 | if (pl->type != PLAYER) |
592 | if (pl->type != PLAYER) |
631 | { |
593 | { |
632 | LOG (llevError, "Non player object called draw_map.\n"); |
594 | LOG (llevError, "Non player object called draw_map.\n"); |
633 | return; |
595 | return; |
… | |
… | |
643 | */ |
605 | */ |
644 | xmin = MAGIC_MAP_SIZE; |
606 | xmin = MAGIC_MAP_SIZE; |
645 | ymin = MAGIC_MAP_SIZE; |
607 | ymin = MAGIC_MAP_SIZE; |
646 | xmax = 0; |
608 | xmax = 0; |
647 | ymax = 0; |
609 | ymax = 0; |
|
|
610 | |
648 | for (x = 0; x < MAGIC_MAP_SIZE; x++) |
611 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
649 | { |
|
|
650 | for (y = 0; y < MAGIC_MAP_SIZE; y++) |
612 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
651 | { |
|
|
652 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
613 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
653 | { |
614 | { |
654 | xmin = x < xmin ? x : xmin; |
615 | xmin = x < xmin ? x : xmin; |
655 | xmax = x > xmax ? x : xmax; |
616 | xmax = x > xmax ? x : xmax; |
656 | ymin = y < ymin ? y : ymin; |
617 | ymin = y < ymin ? y : ymin; |
657 | ymax = y > ymax ? y : ymax; |
618 | ymax = y > ymax ? y : ymax; |
658 | } |
619 | } |
659 | } |
|
|
660 | } |
|
|
661 | |
620 | |
662 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
621 | packet sl; |
663 | snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
622 | sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
664 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
623 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
665 | sl.len = strlen ((char *) sl.buf); |
|
|
666 | |
624 | |
667 | for (y = ymin; y <= ymax; y++) |
625 | for (int y = ymin; y <= ymax; y++) |
668 | { |
|
|
669 | for (x = xmin; x <= xmax; x++) |
626 | for (int x = xmin; x <= xmax; x++) |
670 | { |
|
|
671 | sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; |
627 | sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); |
672 | } /* x loop */ |
|
|
673 | } /* y loop */ |
|
|
674 | |
628 | |
675 | Send_With_Handling (&pl->contr->socket, &sl); |
629 | pl->contr->socket->send_packet (sl); |
676 | free (sl.buf); |
630 | |
677 | free (map_mark); |
631 | free (map_mark); |
678 | } |
632 | } |
679 | |
633 | |
680 | |
634 | |
681 | /** |
635 | /** |
… | |
… | |
683 | */ |
637 | */ |
684 | |
638 | |
685 | void |
639 | void |
686 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
640 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
687 | { |
641 | { |
688 | int i; |
|
|
689 | size_t len; |
642 | size_t len; |
690 | char buf[MAX_BUF]; |
643 | char buf[MAX_BUF]; |
691 | |
644 | |
692 | if (With != NULL) |
645 | if (With != NULL) |
693 | { |
|
|
694 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
646 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
695 | } |
|
|
696 | else |
647 | else |
697 | { |
|
|
698 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
648 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
699 | } |
649 | |
700 | len = strlen (buf); |
650 | 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 | } |
651 | } |