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

Comparing deliantra/server/server/c_misc.C (file contents):
Revision 1.8 by root, Thu Sep 14 22:34:03 2006 UTC vs.
Revision 1.18 by root, Mon Dec 11 21:32:17 2006 UTC

34 */ 34 */
35 35
36void 36void
37map_info (object *op, char *search) 37map_info (object *op, char *search)
38{ 38{
39 mapstruct *m; 39 maptile *m;
40 char buf[MAX_BUF], map_path[MAX_BUF]; 40 char buf[MAX_BUF], map_path[MAX_BUF];
41 long sec = seconds (); 41 long sec = seconds ();
42 42
43 new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60); 43 new_draw_info_format (NDI_UNIQUE, 0, op, "Current time is: %02ld:%02ld:%02ld.", (sec % 86400) / 3600, (sec % 3600) / 60, sec % 60);
44 new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset"); 44 new_draw_info (NDI_UNIQUE, 0, op, "Path Pl PlM IM TO Dif Reset");
144} 144}
145 145
146void 146void
147current_map_info (object *op) 147current_map_info (object *op)
148{ 148{
149 mapstruct *m = op->map; 149 maptile *m = op->map;
150 150
151 if (!m) 151 if (!m)
152 return; 152 return;
153 153
154 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m)); 154 new_draw_info_format (NDI_UNIQUE, 0, op, "%s (%s) in %s", m->name, m->path, get_name_of_region_for_map (m));
223{ 223{
224 char namebuf[MAX_BUF]; 224 char namebuf[MAX_BUF];
225 int login_order; 225 int login_order;
226} chars_names; 226} chars_names;
227 227
228/*local functon for qsort comparison*/
229static int
230name_cmp (const chars_names * c1, const chars_names * c2)
231{
232 return strcasecmp (c1->namebuf, c2->namebuf);
233}
234
235int
236command_who (object *op, char *params)
237{
238 player *pl;
239 uint16 i;
240 region *reg;
241 char *format;
242 int num_players = 0;
243 int num_wiz = 0;
244 int num_afk = 0;
245 chars_names *chars = NULL;
246
247 /*
248 * The who formats are defined in config to be blank. They should have been
249 * overridden by the settings file, if there are no entries however, it will
250 * have stayed blank. Since this probably isn't what is wanted, we will check if
251 * new formats have been specified, and if not we will use the old defaults.
252 */
253 if (!strcmp (settings.who_format, ""))
254 strcpy (settings.who_format, "%N_%T%t%h%d%n[%m]");
255 if (!strcmp (settings.who_wiz_format, ""))
256 strcpy (settings.who_wiz_format, "%N_%T%t%h%d%nLevel %l [%m](@%i)(%c)");
257 if (op == NULL || QUERY_FLAG (op, FLAG_WIZ))
258 format = settings.who_wiz_format;
259 else
260 format = settings.who_format;
261
262 reg = get_region_from_string (params);
263
264 for (pl = first_player; pl != NULL; pl = pl->next)
265 {
266 if (pl->ob->map == NULL)
267 continue;
268 if (pl->hidden && !QUERY_FLAG (op, FLAG_WIZ))
269 continue;
270
271 if (!region_is_child_of_region (get_region_by_map (pl->ob->map), reg))
272 continue;
273
274 if (pl->state == ST_PLAYING || pl->state == ST_GET_PARTY_PASSWORD)
275 {
276
277 num_players++;
278 chars = (chars_names *) realloc (chars, num_players * sizeof (chars_names));
279 if (chars == NULL)
280 {
281 new_draw_info (NDI_UNIQUE, 0, op, "who failed - out of memory!");
282 return 0;
283 }
284 sprintf (chars[num_players - 1].namebuf, "%s", &pl->ob->name);
285 chars[num_players - 1].login_order = num_players;
286 /*Check for WIZ's & AFK's */
287 if (QUERY_FLAG (pl->ob, FLAG_WIZ))
288 num_wiz++;
289 if (QUERY_FLAG (pl->ob, FLAG_AFK))
290 num_afk++;
291 }
292 }
293 if (first_player != (player *) NULL)
294 {
295 if (reg == NULL)
296 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players (%d) -- WIZ(%d) AFK(%d)", num_players, num_wiz, num_afk);
297 else if (reg->longname == NULL)
298 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players in %s (%d) -- WIZ(%d) AFK(%d)", reg->name, num_players, num_wiz, num_afk);
299 else
300 new_draw_info_format (NDI_UNIQUE, 0, op, "Total Players in %s (%d) -- WIZ(%d) AFK(%d)",
301 reg->longname, num_players, num_wiz, num_afk);
302 }
303 qsort (chars, num_players, sizeof (chars_names), (int (*)(const void *, const void *)) name_cmp);
304 for (i = 0; i < num_players; i++)
305 display_who_entry (op, find_player (chars[i].namebuf), format);
306 free (chars);
307 return 1;
308}
309
310/* Display a line of 'who' to op, about pl, using the formatting specified by format */
311void
312display_who_entry (object *op, player *pl, const char *format)
313{
314 char tmpbuf[MAX_BUF];
315 char outbuf[MAX_BUF];
316 size_t i;
317
318 outbuf[0] = '\0'; /* we strcat to this, so reset it here. */
319 if (pl == NULL)
320 {
321 LOG (llevError, "display_who_entry(): I was passed a null player");
322 return;
323 }
324 for (i = 0; i <= strlen (format); i++)
325 {
326 if (format[i] == '%')
327 {
328 i++;
329 get_who_escape_code_value (tmpbuf, format[i], pl);
330 strcat (outbuf, tmpbuf);
331 }
332 else if (format[i] == '_')
333 strcat (outbuf, " "); /* allow '_' to be used in place of spaces */
334 else
335 {
336 sprintf (tmpbuf, "%c", format[i]);
337 strcat (outbuf, tmpbuf);
338 }
339 }
340 new_draw_info (NDI_UNIQUE, 0, op, outbuf);
341}
342
343/* Returns the value of the escape code used in the who format specifier
344 * the values are:
345 * N Name of character
346 * t title of character
347 * T the optional "the " sequence value (depend if player has own_title or not)
348 * c count
349 * n newline
350 * h [Hostile] if character is hostile, nothing otherwise
351 * d [WIZ] if character is a dm, nothing otherwise
352 * a [AFK] if character is afk, nothing otherwise
353 * l the level of the character
354 * m the map path the character is currently on
355 * M the map name of the map the character is currently on
356 * r the region name (eg scorn, wolfsburg)
357 * R the regional title (eg The Kingdom of Scorn, The Port of Wolfsburg)
358 * i player's ip adress
359 * % a literal %
360 * _ a literal underscore
361 */
362
363void
364get_who_escape_code_value (char *return_val, const char letter, player *pl)
365{
366
367 switch (letter)
368 {
369 case 'N':
370 strcpy (return_val, pl->ob->name);
371 break;
372 case 't':
373 strcpy (return_val, (pl->own_title[0] == '\0' ? pl->title : pl->own_title));
374 break;
375 case 'T':
376 if (pl->own_title[0] == '\0')
377 strcpy (return_val, "the ");
378 else
379 *return_val = '\0';
380 break;
381 case 'c':
382 sprintf (return_val, "%d", pl->ob->count);
383 break;
384 case 'n':
385 strcpy (return_val, "\n");
386 break;
387 case 'h':
388 strcpy (return_val, pl->peaceful ? "" : " [Hostile]");
389 break;
390 case 'l':
391 sprintf (return_val, "%d", pl->ob->level);
392 break;
393 case 'd':
394 strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_WIZ) ? " [WIZ]" : ""));
395 break;
396 case 'a':
397 strcpy (return_val, (QUERY_FLAG (pl->ob, FLAG_AFK) ? " [AFK]" : ""));
398 break;
399 case 'm':
400 strcpy (return_val, pl->ob->map->path);
401 break;
402 case 'M':
403 strcpy (return_val, pl->ob->map->name ? pl->ob->map->name : "Untitled");
404 break;
405 case 'r':
406 strcpy (return_val, get_name_of_region_for_map (pl->ob->map));
407 break;
408 case 'R':
409 strcpy (return_val, get_region_longname (get_region_by_map (pl->ob->map)));
410 break;
411 case 'i':
412 strcpy (return_val, pl->socket.host);
413 break;
414 case '%':
415 strcpy (return_val, "%");
416 break;
417 case '_':
418 strcpy (return_val, "_");
419 break;
420 }
421
422}
423
424
425int 228int
426command_afk (object *op, char *params) 229command_afk (object *op, char *params)
427{ 230{
428 if QUERY_FLAG 231 if QUERY_FLAG
429 (op, FLAG_AFK) 232 (op, FLAG_AFK)
643int 446int
644command_dumpbelow (object *op, char *params) 447command_dumpbelow (object *op, char *params)
645{ 448{
646 if (op && op->below) 449 if (op && op->below)
647 { 450 {
648 dump_object (op->below); 451 char *dump = dump_object (op->below);
649 new_draw_info (NDI_UNIQUE, 0, op, errmsg); 452 new_draw_info (NDI_UNIQUE, 0, op, dump);
453 free (dump);
650 /* Let's push that item on the dm's stack */ 454 /* Let's push that item on the dm's stack */
651 dm_stack_push (op->contr, op->below->count); 455 dm_stack_push (op->contr, op->below->count);
652 } 456 }
653 return 0; 457 return 0;
654} 458}
655 459
656int 460int
657command_wizpass (object *op, char *params)
658{
659 int i;
660
661 if (!op)
662 return 0;
663
664 if (!params)
665 i = (QUERY_FLAG (op, FLAG_WIZPASS)) ? 0 : 1;
666 else
667 i = onoff_value (params);
668
669 if (i)
670 {
671 new_draw_info (NDI_UNIQUE, 0, op, "You will now walk through walls.\n");
672 SET_FLAG (op, FLAG_WIZPASS);
673 }
674 else
675 {
676 new_draw_info (NDI_UNIQUE, 0, op, "You will now be stopped by walls.\n");
677 CLEAR_FLAG (op, FLAG_WIZPASS);
678 }
679 return 0;
680}
681
682int
683command_wizcast (object *op, char *params)
684{
685 int i;
686
687 if (!op)
688 return 0;
689
690 if (!params)
691 i = (QUERY_FLAG (op, FLAG_WIZCAST)) ? 0 : 1;
692 else
693 i = onoff_value (params);
694
695 if (i)
696 {
697 new_draw_info (NDI_UNIQUE, 0, op, "You can now cast spells anywhere.");
698 SET_FLAG (op, FLAG_WIZCAST);
699 }
700 else
701 {
702 new_draw_info (NDI_UNIQUE, 0, op, "You now cannot cast spells in no-magic areas.");
703 CLEAR_FLAG (op, FLAG_WIZCAST);
704 }
705 return 0;
706}
707
708int
709command_dumpallobjects (object *op, char *params)
710{
711 dump_all_objects ();
712 return 0;
713}
714
715int
716command_dumpfriendlyobjects (object *op, char *params) 461command_dumpfriendlyobjects (object *op, char *params)
717{ 462{
718 dump_friendly_objects (); 463 dump_friendly_objects ();
719 return 0;
720}
721
722int
723command_dumpallarchetypes (object *op, char *params)
724{
725 dump_all_archetypes ();
726 return 0; 464 return 0;
727} 465}
728 466
729int 467int
730command_dumpmap (object *op, char *params) 468command_dumpmap (object *op, char *params)
844int 582int
845command_statistics (object *pl, char *params) 583command_statistics (object *pl, char *params)
846{ 584{
847 if (!pl->contr) 585 if (!pl->contr)
848 return 1; 586 return 1;
849#ifndef WIN32
850 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %lld", pl->stats.exp);
851 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %lld", level_exp (pl->level + 1, pl->expmul));
852#else
853 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %I64d", pl->stats.exp); 587 new_draw_info_format (NDI_UNIQUE, 0, pl, " Experience: %" PRId64, pl->stats.exp);
854 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %I64d", level_exp (pl->level + 1, pl->expmul)); 588 new_draw_info_format (NDI_UNIQUE, 0, pl, " Next Level: %" PRId64, level_exp (pl->level + 1, pl->expmul));
855#endif
856 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max"); 589 new_draw_info (NDI_UNIQUE, 0, pl, "\nStat Nat/Real/Max");
857 590
858 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d", 591 new_draw_info_format (NDI_UNIQUE, 0, pl, "Str %2d/ %3d/%3d",
859 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str); 592 pl->contr->orig_stats.Str, pl->stats.Str, 20 + pl->arch->clone.stats.Str);
860 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d", 593 new_draw_info_format (NDI_UNIQUE, 0, pl, "Dex %2d/ %3d/%3d",
930 663
931 664
932int 665int
933command_logs (object *op, char *params) 666command_logs (object *op, char *params)
934{ 667{
935 int i;
936 int first;
937
938 first = 1;
939 for (i = 2; i < socket_info.allocated_sockets; i++)
940 {
941 if (init_sockets[i].old_mode == Old_Listen)
942 {
943 if (first)
944 {
945 new_draw_info (NDI_UNIQUE, 0, op, "Kill-logs are sent to:");
946 first = 0;
947 }
948 new_draw_info_format (NDI_UNIQUE, 0, op, "%s: %s", init_sockets[i].host, init_sockets[i].comment);
949 }
950 }
951 if (first)
952 {
953 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills."); 668 new_draw_info (NDI_UNIQUE, 0, op, "Nobody is currently logging kills.");
954 } 669
955 return 1; 670 return 1;
956} 671}
957 672
958int 673int
959command_applymode (object *op, char *params) 674command_applymode (object *op, char *params)
1685} 1400}
1686 1401
1687int 1402int
1688command_style_map_info (object *op, char *params) 1403command_style_map_info (object *op, char *params)
1689{ 1404{
1690 extern mapstruct *styles; 1405 extern maptile *styles;
1691 mapstruct *mp; 1406 maptile *mp;
1692 int maps_used = 0, mapmem = 0, objects_used = 0, x, y; 1407 int maps_used = 0, mapmem = 0, objects_used = 0, x, y;
1693 object *tmp; 1408 object *tmp;
1694 1409
1695 for (mp = styles; mp != NULL; mp = mp->next) 1410 for (mp = styles; mp != NULL; mp = mp->next)
1696 { 1411 {
1697 maps_used++; 1412 maps_used++;
1698 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (mapstruct); 1413 mapmem += MAP_WIDTH (mp) * MAP_HEIGHT (mp) * (sizeof (object *) + sizeof (MapSpace)) + sizeof (maptile);
1699 for (x = 0; x < MAP_WIDTH (mp); x++) 1414 for (x = 0; x < MAP_WIDTH (mp); x++)
1700 { 1415 {
1701 for (y = 0; y < MAP_HEIGHT (mp); y++) 1416 for (y = 0; y < MAP_HEIGHT (mp); y++)
1702 { 1417 {
1703 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above) 1418 for (tmp = get_map_ob (mp, x, y); tmp != NULL; tmp = tmp->above)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines