ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/socket/info.C
(Generate patch)

Comparing deliantra/server/socket/info.C (file contents):
Revision 1.8 by root, Tue Sep 19 09:38:32 2006 UTC vs.
Revision 1.14 by root, Thu Dec 14 01:12:35 2006 UTC

45 * replaced with this, just using black as the color. 45 * replaced with this, just using black as the color.
46 */ 46 */
47static void 47static void
48esrv_print_msg (NewSocket * ns, int color, const char *str) 48esrv_print_msg (NewSocket * ns, int color, const char *str)
49{ 49{
50 char buf[HUGE_BUF]; 50 SockList sl (MAXSOCKBUF);
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)); 58 sl.free ();
63} 59}
64 60
65/** 61/**
66 * Draws an extended message on the client. 62 * Draws an extended message on the client.
67 * ns the socket to send message to 63 * ns the socket to send message to
72 * message The main message 68 * message The main message
73 */ 69 */
74static void 70static void
75esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message) 71esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message)
76{ 72{
77 char buf[HUGE_BUF]; 73 SockList sl (MAXSOCKBUF);
78 74
79 snprintf (buf, HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); 75 sl.printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message);
80 Write_String_To_Socket (ns, buf, strlen (buf)); 76 ns->send_packet (sl);
81 77 sl.free ();
82/* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/
83
84} 78}
85 79
86/** 80/**
87 * Frontend for esrv_print_msg 81 * Frontend for esrv_print_msg
88 * \param colr message color 82 * \param colr message color
96 90
97static void 91static void
98print_message (int colr, const object *pl, const char *tmp) 92print_message (int colr, const object *pl, const char *tmp)
99{ 93{
100 94
101 if (tmp == (char *) NULL) 95 if (!tmp)
102 {
103 tmp = "[NULL]"; 96 tmp = "[NULL]";
104 }
105 97
106 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 98 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
107 return; 99 return;
108 100
109 if (pl->type == PLAYER) 101 if (pl->type == PLAYER)
110 { 102 {
111 esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); 103 esrv_print_msg (&pl->contr->socket, colr, (char *) tmp);
112 return; 104 return;
113 } 105 }
114} 106}
115
116 107
117/** 108/**
118 * Prints out the contents of specified buffer structures, 109 * Prints out the contents of specified buffer structures,
119 * and clears the string. 110 * and clears the string.
120 */ 111 */
217{ 208{
218 209
219 if (flags & NDI_ALL) 210 if (flags & NDI_ALL)
220 { 211 {
221 player *tmppl; 212 player *tmppl;
222 int i;
223 213
224 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) 214 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next)
225 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); 215 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf);
226 216
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; 217 return;
238 } 218 }
219
239 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 220 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
240 { 221 {
241 /* Write to the socket? */ 222 /* Write to the socket? */
242 print_message (0, NULL, buf); 223 print_message (0, NULL, buf);
243 return; 224 return;
244 } 225 }
226
245 if (pl->type != PLAYER) 227 if (pl->type != PLAYER)
246 return; 228 return;
229
247 if (pri >= pl->contr->listening) 230 if (pri >= pl->contr->listening)
248 return; 231 return;
249 232
250 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) 233 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE))
251 {
252 /* following prints stuff out, as appropriate */ 234 /* following prints stuff out, as appropriate */
253 check_output_buffers (pl, buf); 235 check_output_buffers (pl, buf);
254 }
255 else 236 else
256 {
257 print_message (flags & NDI_COLOR_MASK, pl, buf); 237 print_message (flags & NDI_COLOR_MASK, pl, buf);
258 }
259} 238}
260 239
261/** 240/**
262 * Wrapper for new_draw_info printf-like. 241 * Wrapper for new_draw_info printf-like.
263 * 242 *
423 object *op; 402 object *op;
424 403
425 for (op = pl->inv; op; op = op->below) 404 for (op = pl->inv; op; op = op->below)
426 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) 405 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED))
427 break; 406 break;
407
428 if (op == NULL) 408 if (op == NULL)
429 break; 409 break;
430 410
431 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); 411 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing");
432 } 412 }
436 if (settings.casting_time == TRUE) 416 if (settings.casting_time == TRUE)
437 { 417 {
438 if (pl->casting_time > -1) 418 if (pl->casting_time > -1)
439 { 419 {
440 if (pl->casting_time == 0) 420 if (pl->casting_time == 0)
441 sprintf (obuf, "Range: Holding spell (%s)", (const char *) pl->spell->name); 421 sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name);
442 else 422 else
443 sprintf (obuf, "Range: Casting spell (%s)", (const char *) pl->spell->name); 423 sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name);
444 } 424 }
445 else 425 else
446 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); 426 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name);
447 } 427 }
448 else 428 else
619 */ 599 */
620 600
621void 601void
622draw_magic_map (object *pl) 602draw_magic_map (object *pl)
623{ 603{
624 int x, y;
625 char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); 604 char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1);
626 int xmin, xmax, ymin, ymax; 605 int xmin, xmax, ymin, ymax;
627 SockList sl;
628 606
629 if (pl->type != PLAYER) 607 if (pl->type != PLAYER)
630 { 608 {
631 LOG (llevError, "Non player object called draw_map.\n"); 609 LOG (llevError, "Non player object called draw_map.\n");
632 return; 610 return;
642 */ 620 */
643 xmin = MAGIC_MAP_SIZE; 621 xmin = MAGIC_MAP_SIZE;
644 ymin = MAGIC_MAP_SIZE; 622 ymin = MAGIC_MAP_SIZE;
645 xmax = 0; 623 xmax = 0;
646 ymax = 0; 624 ymax = 0;
625
647 for (x = 0; x < MAGIC_MAP_SIZE; x++) 626 for (int x = 0; x < MAGIC_MAP_SIZE; x++)
648 {
649 for (y = 0; y < MAGIC_MAP_SIZE; y++) 627 for (int y = 0; y < MAGIC_MAP_SIZE; y++)
650 {
651 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) 628 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR)
652 { 629 {
653 xmin = x < xmin ? x : xmin; 630 xmin = x < xmin ? x : xmin;
654 xmax = x > xmax ? x : xmax; 631 xmax = x > xmax ? x : xmax;
655 ymin = y < ymin ? y : ymin; 632 ymin = y < ymin ? y : ymin;
656 ymax = y > ymax ? y : ymax; 633 ymax = y > ymax ? y : ymax;
657 } 634 }
658 }
659 }
660 635
661 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 636 SockList sl (MAXSOCKBUF);
662 snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), 637 sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1),
663 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); 638 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin);
664 sl.len = strlen ((char *) sl.buf);
665 639
666 for (y = ymin; y <= ymax; y++) 640 for (int y = ymin; y <= ymax; y++)
667 {
668 for (x = xmin; x <= xmax; x++) 641 for (int x = xmin; x <= xmax; x++)
669 {
670 sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; 642 sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR);
671 } /* x loop */
672 } /* y loop */
673 643
674 Send_With_Handling (&pl->contr->socket, &sl); 644 Send_With_Handling (&pl->contr->socket, &sl);
675 free (sl.buf); 645
646 sl.free ();
647
676 free (map_mark); 648 free (map_mark);
677} 649}
678 650
679 651
680/** 652/**
682 */ 654 */
683 655
684void 656void
685Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) 657Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType)
686{ 658{
687 int i;
688 size_t len; 659 size_t len;
689 char buf[MAX_BUF]; 660 char buf[MAX_BUF];
690 661
691 if (With != NULL) 662 if (With != NULL)
692 {
693 snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); 663 snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType);
694 }
695 else 664 else
696 {
697 snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); 665 snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType);
698 } 666
699 len = strlen (buf); 667 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} 668}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines