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.7 by root, Sat Sep 16 22:24:13 2006 UTC vs.
Revision 1.20 by root, Fri Dec 15 19:59:20 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
42 * 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
43 * parameter. the esrv_drawinfo functions should probably be 44 * parameter. the esrv_drawinfo functions should probably be
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 (client * ns, int color, const char *str)
48{ 49{
49 char buf[HUGE_BUF]; 50 packet sl;
50
51 if (ns->status == Ns_Old)
52 {
53 snprintf (buf, HUGE_BUF, "%s\n", str);
54 }
55 else
56 {
57 snprintf (buf, HUGE_BUF, "drawinfo %d %s", color, str); 51 sl.printf ("drawinfo %d %s", color, str);
58 } 52 ns->send_packet (sl);
59
60/* LOG(llevDebug,"sending %s to socket, len=%d\n", buf, strlen(buf));*/
61 Write_String_To_Socket (ns, buf, strlen (buf));
62} 53}
63 54
64/** 55/**
65 * Draws an extended message on the client. 56 * Draws an extended message on the client.
66 * ns the socket to send message to 57 * ns the socket to send message to
69 * subtype type and subtype of text message 60 * subtype type and subtype of text message
70 * 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
71 * message The main message 62 * message The main message
72 */ 63 */
73static void 64static void
74esrv_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)
75{ 66{
76 char buf[HUGE_BUF]; 67 packet sl;
77 68
78 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);
79 Write_String_To_Socket (ns, buf, strlen (buf)); 70 ns->send_packet (sl);
80
81/* LOG(llevDebug,"sending %s to socket, len=%d", buf, strlen(buf));*/
82
83} 71}
84 72
85/** 73/**
86 * Frontend for esrv_print_msg 74 * Frontend for esrv_print_msg
87 * \param colr message color 75 * \param colr message color
95 83
96static void 84static void
97print_message (int colr, const object *pl, const char *tmp) 85print_message (int colr, const object *pl, const char *tmp)
98{ 86{
99 87
100 if (tmp == (char *) NULL) 88 if (!tmp)
101 {
102 tmp = "[NULL]"; 89 tmp = "[NULL]";
103 }
104 90
105 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 91 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
106 return; 92 return;
107 93
108 if (pl->type == PLAYER) 94 if (pl->type == PLAYER)
109 {
110 esrv_print_msg (&pl->contr->socket, colr, (char *) tmp); 95 esrv_print_msg (pl->contr->socket, colr, (char *) tmp);
111 return;
112 }
113} 96}
114
115 97
116/** 98/**
117 * Prints out the contents of specified buffer structures, 99 * Prints out the contents of specified buffer structures,
118 * and clears the string. 100 * and clears the string.
119 */ 101 */
216{ 198{
217 199
218 if (flags & NDI_ALL) 200 if (flags & NDI_ALL)
219 { 201 {
220 player *tmppl; 202 player *tmppl;
221 int i;
222 203
223 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next) 204 for (tmppl = first_player; tmppl != NULL; tmppl = tmppl->next)
224 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf); 205 new_draw_info ((flags & ~NDI_ALL), pri, tmppl->ob, buf);
225 206
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; 207 return;
237 } 208 }
209
238 if (!pl || (pl->type == PLAYER && pl->contr == NULL)) 210 if (!pl || (pl->type == PLAYER && pl->contr == NULL))
239 { 211 {
240 /* Write to the socket? */ 212 /* Write to the socket? */
241 print_message (0, NULL, buf); 213 print_message (0, NULL, buf);
242 return; 214 return;
243 } 215 }
216
244 if (pl->type != PLAYER) 217 if (pl->type != PLAYER)
245 return; 218 return;
219
246 if (pri >= pl->contr->listening) 220 if (pri >= pl->contr->listening)
247 return; 221 return;
248 222
249 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE)) 223 if ((flags & NDI_COLOR_MASK) == NDI_BLACK && !(flags & NDI_UNIQUE))
250 {
251 /* following prints stuff out, as appropriate */ 224 /* following prints stuff out, as appropriate */
252 check_output_buffers (pl, buf); 225 check_output_buffers (pl, buf);
253 }
254 else 226 else
255 {
256 print_message (flags & NDI_COLOR_MASK, pl, buf); 227 print_message (flags & NDI_COLOR_MASK, pl, buf);
257 }
258} 228}
259 229
260/** 230/**
261 * Wrapper for new_draw_info printf-like. 231 * Wrapper for new_draw_info printf-like.
262 * 232 *
290 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 260 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
291 return; 261 return;
292 262
293 if (pri >= pl->contr->listening) 263 if (pri >= pl->contr->listening)
294 return; 264 return;
265
295 if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) 266 if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type))
296 { 267 {
297 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1); 268 char *buf = (char *) malloc (strlen (oldmessage == NULL ? message : oldmessage) + 1);
298 269
299 if (buf == NULL) 270 if (buf == NULL)
300 LOG (llevError, "info::draw_ext_info -> Out of memory!"); 271 LOG (llevError, "info::draw_ext_info -> Out of memory!");
305 new_draw_info (flags, pri, pl, buf); 276 new_draw_info (flags, pri, pl, buf);
306 free (buf); 277 free (buf);
307 } 278 }
308 } 279 }
309 else 280 else
310 {
311 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);
312 }
313} 282}
314 283
315void 284void
316draw_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, ...)
317{ 286{
321 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL)) 290 if (!pl || (pl->type != PLAYER) || (pl->contr == NULL))
322 return; 291 return;
323 292
324 if (pri >= pl->contr->listening) 293 if (pri >= pl->contr->listening)
325 return; 294 return;
295
326 if (!CLIENT_SUPPORT_READABLES (&pl->contr->socket, type)) 296 if (!CLIENT_SUPPORT_READABLES (pl->contr->socket, type))
327 { 297 {
328 va_list ap; 298 va_list ap;
329 299
330 LOG (llevDebug, "Non supported extension text type for client.\n"); 300 LOG (llevDebug, "Non supported extension text type for client.\n");
331 va_start (ap, new_format); 301 va_start (ap, new_format);
340 310
341 va_start (ap, new_format); 311 va_start (ap, new_format);
342 vsnprintf (buf, HUGE_BUF, new_format, ap); 312 vsnprintf (buf, HUGE_BUF, new_format, ap);
343 va_end (ap); 313 va_end (ap);
344 strip_media_tag (buf); 314 strip_media_tag (buf);
345 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);
346 } 316 }
347} 317}
348 318
349/** 319/**
350 * 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.
351 */ 321 */
352 322
353void 323void
354new_info_map_except (int color, maptile *map, object *op, const char *str) 324new_info_map_except (int color, maptile * map, object *op, const char *str)
355{ 325{
356 player *pl; 326 player *pl;
357 327
358 for (pl = first_player; pl != NULL; pl = pl->next) 328 for (pl = first_player; pl != NULL; pl = pl->next)
359 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op) 329 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op)
365/** 335/**
366 * Writes to everyone on the map except op1 and op2 336 * Writes to everyone on the map except op1 and op2
367 */ 337 */
368 338
369void 339void
370new_info_map_except2 (int color, maptile *map, object *op1, object *op2, const char *str) 340new_info_map_except2 (int color, maptile * map, object *op1, object *op2, const char *str)
371{ 341{
372 player *pl; 342 player *pl;
373 343
374 for (pl = first_player; pl != NULL; pl = pl->next) 344 for (pl = first_player; pl != NULL; pl = pl->next)
375 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2) 345 if (pl->ob != NULL && pl->ob->map == map && pl->ob != op1 && pl->ob != op2)
381/** 351/**
382 * Writes to everyone on the specified map 352 * Writes to everyone on the specified map
383 */ 353 */
384 354
385void 355void
386new_info_map (int color, maptile *map, const char *str) 356new_info_map (int color, maptile * map, const char *str)
387{ 357{
388 player *pl; 358 player *pl;
389 359
390 for (pl = first_player; pl != NULL; pl = pl->next) 360 for (pl = first_player; pl != NULL; pl = pl->next)
391 if (pl->ob != NULL && pl->ob->map == map) 361 if (pl->ob != NULL && pl->ob->map == map)
411void 381void
412rangetostring (object *pl, char *obuf) 382rangetostring (object *pl, char *obuf)
413{ 383{
414 switch (pl->contr->shoottype) 384 switch (pl->contr->shoottype)
415 { 385 {
416 case range_none: 386 case range_none:
417 strcpy (obuf, "Range: nothing"); 387 strcpy (obuf, "Range: nothing");
418 break; 388 break;
419 389
420 case range_bow: 390 case range_bow:
391 {
392 object *op;
393
394 for (op = pl->inv; op; op = op->below)
395 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED))
396 break;
397
398 if (op == NULL)
399 break;
400
401 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing");
402 }
403 break;
404
405 case range_magic:
406 if (settings.casting_time == TRUE)
421 { 407 {
422 object *op; 408 if (pl->casting_time > -1)
423 409 {
424 for (op = pl->inv; op; op = op->below) 410 if (pl->casting_time == 0)
425 if (op->type == BOW && QUERY_FLAG (op, FLAG_APPLIED)) 411 sprintf (obuf, "Range: Holding spell (%s)", &pl->spell->name);
426 break; 412 else
427 if (op == NULL) 413 sprintf (obuf, "Range: Casting spell (%s)", &pl->spell->name);
428 break; 414 }
429 415 else
430 sprintf (obuf, "Range: %s (%s)", query_base_name (op, 0), op->race ? (const char *) op->race : "nothing"); 416 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name);
431 } 417 }
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 418 else
448 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name); 419 sprintf (obuf, "Range: spell (%s)", &pl->contr->ranges[range_magic]->name);
449 break; 420 break;
450 421
451 case range_misc: 422 case range_misc:
452 sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none"); 423 sprintf (obuf, "Range: %s", pl->contr->ranges[range_misc] ? query_base_name (pl->contr->ranges[range_misc], 0) : "none");
453 break; 424 break;
454 425
455 /* range_scroll is only used for controlling golems. If the 426 /* range_scroll is only used for controlling golems. If the
456 * the player does not have a golem, reset some things. 427 * the player does not have a golem, reset some things.
457 */ 428 */
458 case range_golem: 429 case range_golem:
459 if (pl->contr->ranges[range_golem] != NULL) 430 if (pl->contr->ranges[range_golem] != NULL)
460 sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name); 431 sprintf (obuf, "Range: golem (%s)", &pl->contr->ranges[range_golem]->name);
461 else 432 else
462 { 433 {
463 pl->contr->shoottype = range_none; 434 pl->contr->shoottype = range_none;
464 strcpy (obuf, "Range: nothing"); 435 strcpy (obuf, "Range: nothing");
465 } 436 }
466 break; 437 break;
467 438
468 case range_skill: 439 case range_skill:
469 sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none"); 440 sprintf (obuf, "Skill: %s", pl->chosen_skill != NULL ? (const char *) pl->chosen_skill->name : "none");
470 break; 441 break;
471 442
472 case range_builder: 443 case range_builder:
473 sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0)); 444 sprintf (obuf, "Builder: %s", query_base_name (pl->contr->ranges[range_builder], 0));
474 break; 445 break;
475 446
476 default: 447 default:
477 strcpy (obuf, "Range: illegal"); 448 strcpy (obuf, "Range: illegal");
478 } 449 }
479} 450}
480 451
481/** 452/**
482 * Sets player title. 453 * Sets player title.
618 */ 589 */
619 590
620void 591void
621draw_magic_map (object *pl) 592draw_magic_map (object *pl)
622{ 593{
623 int x, y;
624 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);
625 int xmin, xmax, ymin, ymax; 595 int xmin, xmax, ymin, ymax;
626 SockList sl;
627 596
628 if (pl->type != PLAYER) 597 if (pl->type != PLAYER)
629 { 598 {
630 LOG (llevError, "Non player object called draw_map.\n"); 599 LOG (llevError, "Non player object called draw_map.\n");
631 return; 600 return;
641 */ 610 */
642 xmin = MAGIC_MAP_SIZE; 611 xmin = MAGIC_MAP_SIZE;
643 ymin = MAGIC_MAP_SIZE; 612 ymin = MAGIC_MAP_SIZE;
644 xmax = 0; 613 xmax = 0;
645 ymax = 0; 614 ymax = 0;
615
646 for (x = 0; x < MAGIC_MAP_SIZE; x++) 616 for (int x = 0; x < MAGIC_MAP_SIZE; x++)
647 {
648 for (y = 0; y < MAGIC_MAP_SIZE; y++) 617 for (int y = 0; y < MAGIC_MAP_SIZE; y++)
649 {
650 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR) 618 if (map_mark[x + MAP_WIDTH (pl->map) * y] | FACE_FLOOR)
651 { 619 {
652 xmin = x < xmin ? x : xmin; 620 xmin = x < xmin ? x : xmin;
653 xmax = x > xmax ? x : xmax; 621 xmax = x > xmax ? x : xmax;
654 ymin = y < ymin ? y : ymin; 622 ymin = y < ymin ? y : ymin;
655 ymax = y > ymax ? y : ymax; 623 ymax = y > ymax ? y : ymax;
656 } 624 }
657 }
658 }
659 625
660 sl.buf = (unsigned char *) malloc (MAXSOCKBUF); 626 packet sl;
661 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),
662 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin); 628 MAGIC_MAP_HALF - xmin, MAGIC_MAP_HALF - ymin);
663 sl.len = strlen ((char *) sl.buf);
664 629
665 for (y = ymin; y <= ymax; y++) 630 for (int y = ymin; y <= ymax; y++)
666 {
667 for (x = xmin; x <= xmax; x++) 631 for (int x = xmin; x <= xmax; x++)
668 {
669 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);
670 } /* x loop */
671 } /* y loop */
672 633
673 Send_With_Handling (&pl->contr->socket, &sl); 634 pl->contr->socket->send_packet (sl);
674 free (sl.buf); 635
675 free (map_mark); 636 free (map_mark);
676} 637}
677 638
678 639
679/** 640/**
681 */ 642 */
682 643
683void 644void
684Log_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)
685{ 646{
686 int i;
687 size_t len; 647 size_t len;
688 char buf[MAX_BUF]; 648 char buf[MAX_BUF];
689 649
690 if (With != NULL) 650 if (With != NULL)
691 {
692 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);
693 }
694 else 652 else
695 {
696 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);
697 } 654
698 len = strlen (buf); 655 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} 656}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines