… | |
… | |
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_socket * 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 |
… | |
… | |
70 | * subtype type and subtype of text message |
65 | * subtype type and subtype of text message |
71 | * intro Intro message to send with main message if client does not support the message type |
66 | * intro Intro message to send with main message if client does not support the message type |
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 (client_socket * 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 | { |
|
|
111 | esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); |
100 | esrv_print_msg (pl->contr->socket, colr, (char *) tmp); |
112 | return; |
|
|
113 | } |
|
|
114 | } |
101 | } |
115 | |
|
|
116 | |
102 | |
117 | /** |
103 | /** |
118 | * Prints out the contents of specified buffer structures, |
104 | * Prints out the contents of specified buffer structures, |
119 | * and clears the string. |
105 | * and clears the string. |
120 | */ |
106 | */ |
… | |
… | |
217 | { |
203 | { |
218 | |
204 | |
219 | if (flags & NDI_ALL) |
205 | if (flags & NDI_ALL) |
220 | { |
206 | { |
221 | player *tmppl; |
207 | player *tmppl; |
222 | int i; |
|
|
223 | |
208 | |
224 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
209 | for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) |
225 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
210 | new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); |
226 | |
211 | |
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; |
212 | return; |
238 | } |
213 | } |
|
|
214 | |
239 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
215 | if (!pl || (pl->type == PLAYER && pl->contr == NULL)) |
240 | { |
216 | { |
241 | /* Write to the socket? */ |
217 | /* Write to the socket? */ |
242 | print_message (0, NULL, buf); |
218 | print_message (0, NULL, buf); |
243 | return; |
219 | return; |
244 | } |
220 | } |
|
|
221 | |
245 | if (pl->type != PLAYER) |
222 | if (pl->type != PLAYER) |
246 | return; |
223 | return; |
|
|
224 | |
247 | if (pri >= pl->contr->listening) |
225 | if (pri >= pl->contr->listening) |
248 | return; |
226 | return; |
249 | |
227 | |
250 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
228 | if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) |
251 | { |
|
|
252 | /* following prints stuff out, as appropriate */ |
229 | /* following prints stuff out, as appropriate */ |
253 | check_output_buffers (pl, buf); |
230 | check_output_buffers (pl, buf); |
254 | } |
|
|
255 | else |
231 | else |
256 | { |
|
|
257 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
232 | print_message (flags & NDI_COLOR_MASK, pl, buf); |
258 | } |
|
|
259 | } |
233 | } |
260 | |
234 | |
261 | /** |
235 | /** |
262 | * Wrapper for new_draw_info printf-like. |
236 | * Wrapper for new_draw_info printf-like. |
263 | * |
237 | * |
… | |
… | |
291 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
265 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
292 | return; |
266 | return; |
293 | |
267 | |
294 | if (pri >= pl->contr->listening) |
268 | if (pri >= pl->contr->listening) |
295 | return; |
269 | return; |
|
|
270 | |
296 | if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) |
271 | if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) |
297 | { |
272 | { |
298 | char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); |
273 | char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); |
299 | |
274 | |
300 | if (buf == NULL) |
275 | if (buf == NULL) |
301 | LOG (llevError, "info::draw_ext_info -> Out of memory!"); |
276 | LOG (llevError, "info::draw_ext_info -> Out of memory!"); |
… | |
… | |
306 | new_draw_info (flags, pri, pl, buf); |
281 | new_draw_info (flags, pri, pl, buf); |
307 | free (buf); |
282 | free (buf); |
308 | } |
283 | } |
309 | } |
284 | } |
310 | else |
285 | else |
311 | { |
|
|
312 | esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); |
286 | esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); |
313 | } |
|
|
314 | } |
287 | } |
315 | |
288 | |
316 | void |
289 | void |
317 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
290 | draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) |
318 | { |
291 | { |
… | |
… | |
322 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
295 | if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) |
323 | return; |
296 | return; |
324 | |
297 | |
325 | if (pri >= pl->contr->listening) |
298 | if (pri >= pl->contr->listening) |
326 | return; |
299 | return; |
|
|
300 | |
327 | if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) |
301 | if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type)) |
328 | { |
302 | { |
329 | va_list ap; |
303 | va_list ap; |
330 | |
304 | |
331 | LOG (llevDebug, "Non supported extension text type for client.\n"); |
305 | LOG (llevDebug, "Non supported extension text type for client.\n"); |
332 | va_start (ap, new_format); |
306 | va_start (ap, new_format); |
… | |
… | |
341 | |
315 | |
342 | va_start (ap, new_format); |
316 | va_start (ap, new_format); |
343 | vsnprintf (buf, HUGE_BUF, new_format, ap); |
317 | vsnprintf (buf, HUGE_BUF, new_format, ap); |
344 | va_end (ap); |
318 | va_end (ap); |
345 | strip_media_tag (buf); |
319 | strip_media_tag (buf); |
346 | esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); |
320 | esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); |
347 | } |
321 | } |
348 | } |
322 | } |
349 | |
323 | |
350 | /** |
324 | /** |
351 | * Writes to everyone on the map *except* op. This is useful for emotions. |
325 | * Writes to everyone on the map *except* op. This is useful for emotions. |
… | |
… | |
423 | object *op; |
397 | object *op; |
424 | |
398 | |
425 | for (op = pl->inv; op; op = op->below) |
399 | for (op = pl->inv; op; op = op->below) |
426 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
400 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
427 | break; |
401 | break; |
|
|
402 | |
428 | if (op == NULL) |
403 | if (op == NULL) |
429 | break; |
404 | break; |
430 | |
405 | |
431 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
406 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
432 | } |
407 | } |
… | |
… | |
619 | */ |
594 | */ |
620 | |
595 | |
621 | void |
596 | void |
622 | draw_magic_map (object *pl) |
597 | draw_magic_map (object *pl) |
623 | { |
598 | { |
624 | int x, y; |
|
|
625 | char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
599 | char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); |
626 | int xmin, xmax, ymin, ymax; |
600 | int xmin, xmax, ymin, ymax; |
627 | SockList sl; |
|
|
628 | |
601 | |
629 | if (pl->type != PLAYER) |
602 | if (pl->type != PLAYER) |
630 | { |
603 | { |
631 | LOG (llevError, "Non player object called draw_map.\n"); |
604 | LOG (llevError, "Non player object called draw_map.\n"); |
632 | return; |
605 | return; |
… | |
… | |
642 | */ |
615 | */ |
643 | xmin = MAGIC_MAP_SIZE; |
616 | xmin = MAGIC_MAP_SIZE; |
644 | ymin = MAGIC_MAP_SIZE; |
617 | ymin = MAGIC_MAP_SIZE; |
645 | xmax = 0; |
618 | xmax = 0; |
646 | ymax = 0; |
619 | ymax = 0; |
|
|
620 | |
647 | for (x = 0; x < MAGIC_MAP_SIZE; x++) |
621 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
648 | { |
|
|
649 | for (y = 0; y < MAGIC_MAP_SIZE; y++) |
622 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
650 | { |
|
|
651 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
623 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
652 | { |
624 | { |
653 | xmin = x < xmin ? x : xmin; |
625 | xmin = x < xmin ? x : xmin; |
654 | xmax = x > xmax ? x : xmax; |
626 | xmax = x > xmax ? x : xmax; |
655 | ymin = y < ymin ? y : ymin; |
627 | ymin = y < ymin ? y : ymin; |
656 | ymax = y > ymax ? y : ymax; |
628 | ymax = y > ymax ? y : ymax; |
657 | } |
629 | } |
658 | } |
|
|
659 | } |
|
|
660 | |
630 | |
661 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
631 | packet sl; |
662 | snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
632 | sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), |
663 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
633 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
664 | sl.len = strlen ((char *) sl.buf); |
|
|
665 | |
634 | |
666 | for (y = ymin; y <= ymax; y++) |
635 | for (int y = ymin; y <= ymax; y++) |
667 | { |
|
|
668 | for (x = xmin; x <= xmax; x++) |
636 | for (int x = xmin; x <= xmax; x++) |
669 | { |
|
|
670 | sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; |
637 | sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR); |
671 | } /* x loop */ |
|
|
672 | } /* y loop */ |
|
|
673 | |
638 | |
674 | Send_With_Handling (&pl->contr->socket, &sl); |
639 | Send_With_Handling (pl->contr->socket, &sl); |
675 | free (sl.buf); |
640 | |
676 | free (map_mark); |
641 | free (map_mark); |
677 | } |
642 | } |
678 | |
643 | |
679 | |
644 | |
680 | /** |
645 | /** |
… | |
… | |
682 | */ |
647 | */ |
683 | |
648 | |
684 | void |
649 | void |
685 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
650 | Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) |
686 | { |
651 | { |
687 | int i; |
|
|
688 | size_t len; |
652 | size_t len; |
689 | char buf[MAX_BUF]; |
653 | char buf[MAX_BUF]; |
690 | |
654 | |
691 | if (With != NULL) |
655 | if (With != NULL) |
692 | { |
|
|
693 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
656 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); |
694 | } |
|
|
695 | else |
657 | else |
696 | { |
|
|
697 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
658 | snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); |
698 | } |
659 | |
699 | len = strlen (buf); |
660 | len = strlen (buf); |
700 | for (i = 1; i < socket_info.allocated_sockets; i++) |
|
|
701 | { |
|
|
702 | if (init_sockets[i].old_mode == Old_Listen) |
|
|
703 | { |
|
|
704 | cs_write_string (&init_sockets[i], buf, len); |
|
|
705 | } |
|
|
706 | } |
|
|
707 | } |
661 | } |