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.20 by root, Fri Dec 15 19:59:20 2006 UTC

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 */
47static void 47static void
48esrv_print_msg (NewSocket * ns, int color, const char *str) 48esrv_print_msg (client * ns, int color, const char *str)
49{ 49{
50 char buf[HUGE_BUF]; 50 packet sl;
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); 51 sl.printf ("drawinfo %d %s", color, str);
59 } 52 ns->send_packet (sl);
60
61/* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/
62 Write_String_To_Socket (ns, buf, strlen (buf));
63} 53}
64 54
65/** 55/**
66 * Draws an extended message on the client. 56 * Draws an extended message on the client.
67 * ns the socket to send message to 57 * ns the socket to send message to
70 * subtype type and subtype of text message 60 * subtype type and subtype of text message
71 * intro Intro message to send with main message if client does not support the message type 61 * intro Intro message to send with main message if client does not support the message type
72 * message The main message 62 * message The main message
73 */ 63 */
74static void 64static void
75esrv_print_ext_msg (NewSocket * ns, int color, uint8 type, uint8 subtype, const char *message) 65esrv_print_ext_msg (client * ns, int color, uint8 type, uint8 subtype, const char *message)
76{ 66{
77 char buf[HUGE_BUF]; 67 packet sl;
78 68
79 snprintf (buf, HUGE_BUF, "drawextinfo %d %hhu %hhu %s", color, type, subtype, message); 69 sl.printf ("drawextinfo %d %hhu %hhu %s", color, type, subtype, message);
80 Write_String_To_Socket (ns, buf, strlen (buf)); 70 ns->send_packet (sl);
81
82/* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/
83
84} 71}
85 72
86/** 73/**
87 * Frontend for esrv_print_msg 74 * Frontend for esrv_print_msg
88 * \param colr message color 75 * \param colr message color
96 83
97static void 84static void
98print_message (int colr, const object *pl, const char *tmp) 85print_message (int colr, const object *pl, const char *tmp)
99{ 86{
100 87
101 if (tmp == (char *) NULL) 88 if (!tmp)
102 {
103 tmp = "[NULL]"; 89 tmp = "[NULL]";
104 }
105 90
106 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 91 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
107 return; 92 return;
108 93
109 if (pl->type == PLAYER) 94 if (pl->type == PLAYER)
110 {
111 esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); 95 esrv_print_msg (pl->contr->socket, colr, (char *) tmp);
112 return;
113 }
114} 96}
115
116 97
117/** 98/**
118 * Prints out the contents of specified buffer structures, 99 * Prints out the contents of specified buffer structures,
119 * and clears the string. 100 * and clears the string.
120 */ 101 */
217{ 198{
218 199
219 if (flags & NDI_ALL) 200 if (flags & NDI_ALL)
220 { 201 {
221 player *tmppl; 202 player *tmppl;
222 int i;
223 203
224 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) 204 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next)
225 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); 205 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf);
226 206
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; 207 return;
238 } 208 }
209
239 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 210 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
240 { 211 {
241 /* Write to the socket? */ 212 /* Write to the socket? */
242 print_message (0, NULL, buf); 213 print_message (0, NULL, buf);
243 return; 214 return;
244 } 215 }
216
245 if (pl->type != PLAYER) 217 if (pl->type != PLAYER)
246 return; 218 return;
219
247 if (pri >= pl->contr->listening) 220 if (pri >= pl->contr->listening)
248 return; 221 return;
249 222
250 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) 223 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE))
251 {
252 /* following prints stuff out, as appropriate */ 224 /* following prints stuff out, as appropriate */
253 check_output_buffers (pl, buf); 225 check_output_buffers (pl, buf);
254 }
255 else 226 else
256 {
257 print_message (flags & NDI_COLOR_MASK, pl, buf); 227 print_message (flags & NDI_COLOR_MASK, pl, buf);
258 }
259} 228}
260 229
261/** 230/**
262 * Wrapper for new_draw_info printf-like. 231 * Wrapper for new_draw_info printf-like.
263 * 232 *
291 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 260 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
292 return; 261 return;
293 262
294 if (pri >= pl->contr->listening) 263 if (pri >= pl->contr->listening)
295 return; 264 return;
265
296 if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) 266 if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type))
297 { 267 {
298 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); 268 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
299 269
300 if (buf == NULL) 270 if (buf == NULL)
301 LOG (llevError, "info::draw_ext_info -> Out of memory!"); 271 LOG (llevError, "info::draw_ext_info -> Out of memory!");
306 new_draw_info (flags, pri, pl, buf); 276 new_draw_info (flags, pri, pl, buf);
307 free (buf); 277 free (buf);
308 } 278 }
309 } 279 }
310 else 280 else
311 {
312 esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message); 281 esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, message);
313 }
314} 282}
315 283
316void 284void
317draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...) 285draw_ext_info_format (int flags, int pri, const object *pl, uint8 type, uint8 subtype, const char *old_format, char *new_format, ...)
318{ 286{
322 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 290 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
323 return; 291 return;
324 292
325 if (pri >= pl->contr->listening) 293 if (pri >= pl->contr->listening)
326 return; 294 return;
295
327 if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) 296 if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type))
328 { 297 {
329 va_list ap; 298 va_list ap;
330 299
331 LOG (llevDebug, "Non supported extension text type for client.\n"); 300 LOG (llevDebug, "Non supported extension text type for client.\n");
332 va_start (ap, new_format); 301 va_start (ap, new_format);
341 310
342 va_start (ap, new_format); 311 va_start (ap, new_format);
343 vsnprintf (buf, HUGE_BUF, new_format, ap); 312 vsnprintf (buf, HUGE_BUF, new_format, ap);
344 va_end (ap); 313 va_end (ap);
345 strip_media_tag (buf); 314 strip_media_tag (buf);
346 esrv_print_ext_msg (&pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf); 315 esrv_print_ext_msg (pl->contr->socket, flags & NDI_COLOR_MASK, type, subtype, buf);
347 } 316 }
348} 317}
349 318
350/** 319/**
351 * Writes to everyone on the map *except* op. This is useful for emotions. 320 * Writes to everyone on the map *except* op. This is useful for emotions.
423 object *op; 392 object *op;
424 393
425 for (op = pl->inv; op; op = op->below) 394 for (op = pl->inv; op; op = op->below)
426 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) 395 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED))
427 break; 396 break;
397
428 if (op == NULL) 398 if (op == NULL)
429 break; 399 break;
430 400
431 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); 401 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing");
432 } 402 }
436 if (settings.casting_time == TRUE) 406 if (settings.casting_time == TRUE)
437 { 407 {
438 if (pl->casting_time > -1) 408 if (pl->casting_time > -1)
439 { 409 {
440 if (pl->casting_time == 0) 410 if (pl->casting_time == 0)
441 sprintf (obuf, "Range: Holding spell (%s)", (const char *) pl->spell->name); 411 sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name);
442 else 412 else
443 sprintf (obuf, "Range: Casting spell (%s)", (const char *) pl->spell->name); 413 sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name);
444 } 414 }
445 else 415 else
446 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); 416 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name);
447 } 417 }
448 else 418 else
619 */ 589 */
620 590
621void 591void
622draw_magic_map (object *pl) 592draw_magic_map (object *pl)
623{ 593{
624 int x, y;
625 char *map_mark = (char *) calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1); 594 char *map_mark = (char *)calloc (MAGIC_MAP_SIZE * MAGIC_MAP_SIZE, 1);
626 int xmin, xmax, ymin, ymax; 595 int xmin, xmax, ymin, ymax;
627 SockList sl;
628 596
629 if (pl->type != PLAYER) 597 if (pl->type != PLAYER)
630 { 598 {
631 LOG (llevError, "Non player object called draw_map.\n"); 599 LOG (llevError, "Non player object called draw_map.\n");
632 return; 600 return;
642 */ 610 */
643 xmin = MAGIC_MAP_SIZE; 611 xmin = MAGIC_MAP_SIZE;
644 ymin = MAGIC_MAP_SIZE; 612 ymin = MAGIC_MAP_SIZE;
645 xmax = 0; 613 xmax = 0;
646 ymax = 0; 614 ymax = 0;
615
647 for (x = 0; x < MAGIC_MAP_SIZE; x++) 616 for (int x = 0; x < MAGIC_MAP_SIZE; x++)
648 {
649 for (y = 0; y < MAGIC_MAP_SIZE; y++) 617 for (int y = 0; y < MAGIC_MAP_SIZE; y++)
650 {
651 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) 618 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR)
652 { 619 {
653 xmin = x < xmin ? x : xmin; 620 xmin = x < xmin ? x : xmin;
654 xmax = x > xmax ? x : xmax; 621 xmax = x > xmax ? x : xmax;
655 ymin = y < ymin ? y : ymin; 622 ymin = y < ymin ? y : ymin;
656 ymax = y > ymax ? y : ymax; 623 ymax = y > ymax ? y : ymax;
657 } 624 }
658 }
659 }
660 625
661 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 626 packet sl;
662 snprintf ((char *) sl.buf, MAXSOCKBUF, "magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1), 627 sl.printf ("magicmap %d %d %d %d ", (xmax - xmin + 1), (ymax - ymin + 1),
663 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); 628 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin);
664 sl.len = strlen ((char *) sl.buf);
665 629
666 for (y = ymin; y <= ymax; y++) 630 for (int y = ymin; y <= ymax; y++)
667 {
668 for (x = xmin; x <= xmax; x++) 631 for (int x = xmin; x <= xmax; x++)
669 {
670 sl.buf[sl.len++] = map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR; 632 sl << uint8 (map_mark[x + MAGIC_MAP_SIZE * y] & ~FACE_FLOOR);
671 } /* x loop */
672 } /* y loop */
673 633
674 Send_With_Handling (&pl->contr->socket, &sl); 634 pl->contr->socket->send_packet (sl);
675 free (sl.buf); 635
676 free (map_mark); 636 free (map_mark);
677} 637}
678 638
679 639
680/** 640/**
682 */ 642 */
683 643
684void 644void
685Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType) 645Log_Kill (const char *Who, const char *What, int WhatType, const char *With, int WithType)
686{ 646{
687 int i;
688 size_t len; 647 size_t len;
689 char buf[MAX_BUF]; 648 char buf[MAX_BUF];
690 649
691 if (With != NULL) 650 if (With != NULL)
692 {
693 snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType); 651 snprintf (buf, MAX_BUF, "%s\t%s\t%d\t%s\t%d\n", Who, What, WhatType, With, WithType);
694 }
695 else 652 else
696 {
697 snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType); 653 snprintf (buf, MAX_BUF, "%s\t%s\t%d\n", Who, What, WhatType);
698 } 654
699 len = strlen (buf); 655 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} 656}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines