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.6 by root, Thu Sep 14 22:34:05 2006 UTC vs.
Revision 1.14 by root, Thu Dec 14 01:12:35 2006 UTC

1
1/* 2/*
2 CrossFire, A Multiplayer game for X-windows 3 CrossFire, A Multiplayer game for X-windows
3 4
4 Copyright (C) 2002 Mark Wedel & Crossfire Development Team 5 Copyright (C) 2002 Mark Wedel & Crossfire Development Team
5 Copyright (C) 1992 Frank Tore Johansen 6 Copyright (C) 1992 Frank Tore Johansen
44 * replaced with this, just using black as the color. 45 * replaced with this, just using black as the color.
45 */ 46 */
46static void 47static void
47esrv_print_msg (NewSocket * ns, int color, const char *str) 48esrv_print_msg (NewSocket * ns, int color, const char *str)
48{ 49{
49 char buf[HUGE_BUF]; 50 SockList sl (MAXSOCKBUF);
50 51
51 if (ns->status == Ns_Old) 52 if (ns->status == Ns_Old)
52 { 53 sl.printf ("%s\n", str);
53 snprintf (buf, HUGE_BUF, "%s\n", str);
54 }
55 else 54 else
56 {
57 snprintf (buf, HUGE_BUF, "drawinfo %d %s", color, str); 55 sl.printf ("drawinfo %d %s", color, str);
58 }
59 56
60/* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/ 57 ns->send_packet (sl);
61 Write_String_To_Socket (ns, buf, strlen (buf)); 58 sl.free ();
62} 59}
63 60
64/** 61/**
65 * Draws an extended message on the client. 62 * Draws an extended message on the client.
66 * ns the socket to send message to 63 * ns the socket to send message to
71 * message The main message 68 * message The main message
72 */ 69 */
73static void 70static void
74esrv_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)
75{ 72{
76 char buf[HUGE_BUF]; 73 SockList sl (MAXSOCKBUF);
77 74
78 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);
79 Write_String_To_Socket (ns, buf, strlen (buf)); 76 ns->send_packet (sl);
80 77 sl.free ();
81/* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/
82
83} 78}
84 79
85/** 80/**
86 * Frontend for esrv_print_msg 81 * Frontend for esrv_print_msg
87 * \param colr message color 82 * \param colr message color
95 90
96static void 91static void
97print_message (int colr, const object *pl, const char *tmp) 92print_message (int colr, const object *pl, const char *tmp)
98{ 93{
99 94
100 if (tmp == (char *) NULL) 95 if (!tmp)
101 {
102 tmp = "[NULL]"; 96 tmp = "[NULL]";
103 }
104 97
105 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 98 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
106 return; 99 return;
107 100
108 if (pl->type == PLAYER) 101 if (pl->type == PLAYER)
109 { 102 {
110 esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); 103 esrv_print_msg (&pl->contr->socket, colr, (char *) tmp);
111 return; 104 return;
112 } 105 }
113} 106}
114
115 107
116/** 108/**
117 * Prints out the contents of specified buffer structures, 109 * Prints out the contents of specified buffer structures,
118 * and clears the string. 110 * and clears the string.
119 */ 111 */
216{ 208{
217 209
218 if (flags & NDI_ALL) 210 if (flags & NDI_ALL)
219 { 211 {
220 player *tmppl; 212 player *tmppl;
221 int i;
222 213
223 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) 214 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next)
224 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); 215 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf);
225 216
226 for (i = 1; i < socket_info.allocated_sockets; i++)
227 {
228 if (init_sockets[i].status == Ns_Old && init_sockets[i].old_mode != Old_Listen && pri < 10)
229 {
230 cs_write_string (&init_sockets[i], buf, strlen (buf));
231 /* Most messages don't have a newline, so add one */
232 cs_write_string (&init_sockets[i], "\n", 1);
233 }
234 }
235
236 return; 217 return;
237 } 218 }
219
238 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 220 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
239 { 221 {
240 /* Write to the socket? */ 222 /* Write to the socket? */
241 print_message (0, NULL, buf); 223 print_message (0, NULL, buf);
242 return; 224 return;
243 } 225 }
226
244 if (pl->type != PLAYER) 227 if (pl->type != PLAYER)
245 return; 228 return;
229
246 if (pri >= pl->contr->listening) 230 if (pri >= pl->contr->listening)
247 return; 231 return;
248 232
249 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) 233 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE))
250 {
251 /* following prints stuff out, as appropriate */ 234 /* following prints stuff out, as appropriate */
252 check_output_buffers (pl, buf); 235 check_output_buffers (pl, buf);
253 }
254 else 236 else
255 {
256 print_message (flags & NDI_COLOR_MASK, pl, buf); 237 print_message (flags & NDI_COLOR_MASK, pl, buf);
257 }
258} 238}
259 239
260/** 240/**
261 * Wrapper for new_draw_info printf-like. 241 * Wrapper for new_draw_info printf-like.
262 * 242 *
349/** 329/**
350 * Writes to everyone on the map *except* op. This is useful for emotions. 330 * Writes to everyone on the map *except* op. This is useful for emotions.
351 */ 331 */
352 332
353void 333void
354new_info_map_except (int color, mapstruct *map, object *op, const char *str) 334new_info_map_except (int color, maptile * map, object *op, const char *str)
355{ 335{
356 player *pl; 336 player *pl;
357 337
358 for (pl = first_player; pl != NULL; pl = pl->next) 338 for (pl = first_player; pl != NULL; pl = pl->next)
359 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) 339 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op)
365/** 345/**
366 * Writes to everyone on the map except op1 and op2 346 * Writes to everyone on the map except op1 and op2
367 */ 347 */
368 348
369void 349void
370new_info_map_except2 (int color, mapstruct *map, object *op1, object *op2, const char *str) 350new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
371{ 351{
372 player *pl; 352 player *pl;
373 353
374 for (pl = first_player; pl != NULL; pl = pl->next) 354 for (pl = first_player; pl != NULL; pl = pl->next)
375 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) 355 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
381/** 361/**
382 * Writes to everyone on the specified map 362 * Writes to everyone on the specified map
383 */ 363 */
384 364
385void 365void
386new_info_map (int color, mapstruct *map, const char *str) 366new_info_map (int color, maptile * map, const char *str)
387{ 367{
388 player *pl; 368 player *pl;
389 369
390 for (pl = first_player; pl != NULL; pl = pl->next) 370 for (pl = first_player; pl != NULL; pl = pl->next)
391 if (pl->ob != NULL && pl->ob->map == map) 371 if (pl->ob != NULL && pl->ob->map == map)
411void 391void
412rangetostring (object *pl, char *obuf) 392rangetostring (object *pl, char *obuf)
413{ 393{
414 switch (pl->contr->shoottype) 394 switch (pl->contr->shoottype)
415 { 395 {
416 case range_none: 396 case range_none:
417 strcpy (obuf, "Range: nothing"); 397 strcpy (obuf, "Range: nothing");
418 break; 398 break;
419 399
420 case range_bow: 400 case range_bow:
401 {
402 object *op;
403
404 for (op = pl->inv; op; op = op->below)
405 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED))
406 break;
407
408 if (op == NULL)
409 break;
410
411 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing");
412 }
413 break;
414
415 case range_magic:
416 if (settings.casting_time == TRUE)
421 { 417 {
422 object *op; 418 if (pl->casting_time > -1)
423 419 {
424 for (op = pl->inv; op; op = op->below) 420 if (pl->casting_time == 0)
425 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) 421 sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name);
426 break; 422 else
427 if (op == NULL) 423 sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name);
428 break; 424 }
429 425 else
430 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); 426 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name);
431 } 427 }
432 break;
433
434 case range_magic:
435 if (settings.casting_time == TRUE)
436 {
437 if (pl->casting_time > -1)
438 {
439 if (pl->casting_time == 0)
440 sprintf (obuf, "Range: Holding spell (%s)", (const char *) pl->spell->name);
441 else
442 sprintf (obuf, "Range: Casting spell (%s)", (const char *) pl->spell->name);
443 }
444 else
445 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name);
446 }
447 else 428 else
448 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); 429 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name);
449 break; 430 break;
450 431
451 case range_misc: 432 case range_misc:
452 sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); 433 sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none");
453 break; 434 break;
454 435
455 /* range_scroll is only used for controlling golems. If the 436 /* range_scroll is only used for controlling golems. If the
456 * the player does not have a golem, reset some things. 437 * the player does not have a golem, reset some things.
457 */ 438 */
458 case range_golem: 439 case range_golem:
459 if (pl->contr->ranges[range_golem] != NULL) 440 if (pl->contr->ranges[range_golem] != NULL)
460 sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); 441 sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name);
461 else 442 else
462 { 443 {
463 pl->contr->shoottype = range_none; 444 pl->contr->shoottype = range_none;
464 strcpy (obuf, "Range: nothing"); 445 strcpy (obuf, "Range: nothing");
465 } 446 }
466 break; 447 break;
467 448
468 case range_skill: 449 case range_skill:
469 sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); 450 sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none");
470 break; 451 break;
471 452
472 case range_builder: 453 case range_builder:
473 sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); 454 sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0));
474 break; 455 break;
475 456
476 default: 457 default:
477 strcpy (obuf, "Range: illegal"); 458 strcpy (obuf, "Range: illegal");
478 } 459 }
479} 460}
480 461
481/** 462/**
482 * Sets player title. 463 * Sets player title.
506static void 487static void
507magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py) 488magic_mapping_mark_recursive (object *pl, char *map_mark, int px, int py)
508{ 489{
509 int x, y, dx, dy, mflags; 490 int x, y, dx, dy, mflags;
510 sint16 nx, ny; 491 sint16 nx, ny;
511 mapstruct *mp; 492 maptile *mp;
512 New_Face *f; 493 New_Face *f;
513 494
514 for (dx = -1; dx <= 1; dx++) 495 for (dx = -1; dx <= 1; dx++)
515 { 496 {
516 for (dy = -1; dy <= 1; dy++) 497 for (dy = -1; dy <= 1; dy++)
572void 553void
573magic_mapping_mark (object *pl, char *map_mark, int strength) 554magic_mapping_mark (object *pl, char *map_mark, int strength)
574{ 555{
575 int x, y, mflags; 556 int x, y, mflags;
576 sint16 nx, ny; 557 sint16 nx, ny;
577 mapstruct *mp; 558 maptile *mp;
578 New_Face *f; 559 New_Face *f;
579 560
580 for (x = -strength; x < strength; x++) 561 for (x = -strength; x < strength; x++)
581 { 562 {
582 for (y = -strength; y < strength; y++) 563 for (y = -strength; y < strength; y++)
618 */ 599 */
619 600
620void 601void
621draw_magic_map (object *pl) 602draw_magic_map (object *pl)
622{ 603{
623 int x, y;
624 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);
625 int xmin, xmax, ymin, ymax; 605 int xmin, xmax, ymin, ymax;
626 SockList sl;
627 606
628 if (pl->type != PLAYER) 607 if (pl->type != PLAYER)
629 { 608 {
630 LOG (llevError, "Non player object called draw_map.\n"); 609 LOG (llevError, "Non player object called draw_map.\n");
631 return; 610 return;
641 */ 620 */
642 xmin = MAGIC_MAP_SIZE; 621 xmin = MAGIC_MAP_SIZE;
643 ymin = MAGIC_MAP_SIZE; 622 ymin = MAGIC_MAP_SIZE;
644 xmax = 0; 623 xmax = 0;
645 ymax = 0; 624 ymax = 0;
625
646 for (x = 0; x < MAGIC_MAP_SIZE; x++) 626 for (int x = 0; x < MAGIC_MAP_SIZE; x++)
647 {
648 for (y = 0; y < MAGIC_MAP_SIZE; y++) 627 for (int y = 0; y < MAGIC_MAP_SIZE; y++)
649 {
650 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) 628 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR)
651 { 629 {
652 xmin = x < xmin ? x : xmin; 630 xmin = x < xmin ? x : xmin;
653 xmax = x > xmax ? x : xmax; 631 xmax = x > xmax ? x : xmax;
654 ymin = y < ymin ? y : ymin; 632 ymin = y < ymin ? y : ymin;
655 ymax = y > ymax ? y : ymax; 633 ymax = y > ymax ? y : ymax;
656 } 634 }
657 }
658 }
659 635
660 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 636 SockList sl (MAXSOCKBUF);
661 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),
662 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); 638 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin);
663 sl.len = strlen ((char *) sl.buf);
664 639
665 for (y = ymin; y <= ymax; y++) 640 for (int y = ymin; y <= ymax; y++)
666 {
667 for (x = xmin; x <= xmax; x++) 641 for (int x = xmin; x <= xmax; x++)
668 {
669 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);
670 } /* x loop */
671 } /* y loop */
672 643
673 Send_With_Handling (&pl->contr->socket, &sl); 644 Send_With_Handling (&pl->contr->socket, &sl);
674 free (sl.buf); 645
646 sl.free ();
647
675 free (map_mark); 648 free (map_mark);
676} 649}
677 650
678 651
679/** 652/**
681 */ 654 */
682 655
683void 656void
684Log_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)
685{ 658{
686 int i;
687 size_t len; 659 size_t len;
688 char buf[MAX_BUF]; 660 char buf[MAX_BUF];
689 661
690 if (With != NULL) 662 if (With != NULL)
691 {
692 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);
693 }
694 else 664 else
695 {
696 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);
697 } 666
698 len = strlen (buf); 667 len = strlen (buf);
699 for (i = 1; i < socket_info.allocated_sockets; i++)
700 {
701 if (init_sockets[i].old_mode == Old_Listen)
702 {
703 cs_write_string (&init_sockets[i], buf, len);
704 }
705 }
706} 668}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines