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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines