… | |
… | |
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. |
… | |
… | |
423 | object *op; |
387 | object *op; |
424 | |
388 | |
425 | for (op = pl->inv; op; op = op->below) |
389 | for (op = pl->inv; op; op = op->below) |
426 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
390 | if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) |
427 | break; |
391 | break; |
|
|
392 | |
428 | if (op == NULL) |
393 | if (op == NULL) |
429 | break; |
394 | break; |
430 | |
395 | |
431 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
396 | sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); |
432 | } |
397 | } |
… | |
… | |
436 | if (settings.casting_time == TRUE) |
401 | if (settings.casting_time == TRUE) |
437 | { |
402 | { |
438 | if (pl->casting_time > -1) |
403 | if (pl->casting_time > -1) |
439 | { |
404 | { |
440 | if (pl->casting_time == 0) |
405 | if (pl->casting_time == 0) |
441 | sprintf (obuf, "Range: Holding spell (%s)", (const char *) pl->spell->name); |
406 | sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name); |
442 | else |
407 | else |
443 | sprintf (obuf, "Range: Casting spell (%s)", (const char *) pl->spell->name); |
408 | sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name); |
444 | } |
409 | } |
445 | else |
410 | else |
446 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
411 | sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); |
447 | } |
412 | } |
448 | else |
413 | else |
… | |
… | |
619 | */ |
584 | */ |
620 | |
585 | |
621 | void |
586 | void |
622 | draw_magic_map (object *pl) |
587 | draw_magic_map (object *pl) |
623 | { |
588 | { |
624 | int x, y; |
|
|
625 | 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); |
626 | int xmin, xmax, ymin, ymax; |
590 | int xmin, xmax, ymin, ymax; |
627 | SockList sl; |
|
|
628 | |
591 | |
629 | if (pl->type != PLAYER) |
592 | if (pl->type != PLAYER) |
630 | { |
593 | { |
631 | LOG (llevError, "Non player object called draw_map.\n"); |
594 | LOG (llevError, "Non player object called draw_map.\n"); |
632 | return; |
595 | return; |
… | |
… | |
642 | */ |
605 | */ |
643 | xmin = MAGIC_MAP_SIZE; |
606 | xmin = MAGIC_MAP_SIZE; |
644 | ymin = MAGIC_MAP_SIZE; |
607 | ymin = MAGIC_MAP_SIZE; |
645 | xmax = 0; |
608 | xmax = 0; |
646 | ymax = 0; |
609 | ymax = 0; |
|
|
610 | |
647 | for (x = 0; x < MAGIC_MAP_SIZE; x++) |
611 | for (int x = 0; x < MAGIC_MAP_SIZE; x++) |
648 | { |
|
|
649 | for (y = 0; y < MAGIC_MAP_SIZE; y++) |
612 | for (int y = 0; y < MAGIC_MAP_SIZE; y++) |
650 | { |
|
|
651 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
613 | if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) |
652 | { |
614 | { |
653 | xmin = x < xmin ? x : xmin; |
615 | xmin = x < xmin ? x : xmin; |
654 | xmax = x > xmax ? x : xmax; |
616 | xmax = x > xmax ? x : xmax; |
655 | ymin = y < ymin ? y : ymin; |
617 | ymin = y < ymin ? y : ymin; |
656 | ymax = y > ymax ? y : ymax; |
618 | ymax = y > ymax ? y : ymax; |
657 | } |
619 | } |
658 | } |
|
|
659 | } |
|
|
660 | |
620 | |
661 | sl.buf = (unsigned char *) malloc (MAXSOCKBUF); |
621 | packet sl; |
662 | 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), |
663 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
623 | MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); |
664 | sl.len = strlen ((char *) sl.buf); |
|
|
665 | |
624 | |
666 | for (y = ymin; y <= ymax; y++) |
625 | for (int y = ymin; y <= ymax; y++) |
667 | { |
|
|
668 | for (x = xmin; x <= xmax; x++) |
626 | for (int x = xmin; x <= xmax; x++) |
669 | { |
|
|
670 | 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); |
671 | } /* x loop */ |
|
|
672 | } /* y loop */ |
|
|
673 | |
628 | |
674 | Send_With_Handling (&pl->contr->socket, &sl); |
629 | pl->contr->socket->send_packet (sl); |
675 | free (sl.buf); |
630 | |
676 | free (map_mark); |
631 | free (map_mark); |
677 | } |
632 | } |
678 | |
633 | |
679 | |
634 | |
680 | /** |
635 | /** |
… | |
… | |
682 | */ |
637 | */ |
683 | |
638 | |
684 | void |
639 | void |
685 | 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) |
686 | { |
641 | { |
687 | int i; |
|
|
688 | size_t len; |
642 | size_t len; |
689 | char buf[MAX_BUF]; |
643 | char buf[MAX_BUF]; |
690 | |
644 | |
691 | if (With != NULL) |
645 | if (With != NULL) |
692 | { |
|
|
693 | 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); |
694 | } |
|
|
695 | else |
647 | else |
696 | { |
|
|
697 | 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); |
698 | } |
649 | |
699 | len = strlen (buf); |
650 | 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 | } |
651 | } |