… | |
… | |
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*/ |
|
|
229 | static int |
|
|
230 | name_cmp (const chars_names * c1, const chars_names * c2) |
|
|
231 | { |
|
|
232 | return strcasecmp (c1->namebuf, c2->namebuf); |
|
|
233 | } |
|
|
234 | |
|
|
235 | int |
|
|
236 | command_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 */ |
|
|
311 | void |
|
|
312 | display_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 | |
|
|
363 | void |
|
|
364 | get_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 | |
|
|
425 | int |
228 | int |
426 | command_afk (object *op, char *params) |
229 | command_afk (object *op, char *params) |
427 | { |
230 | { |
428 | if QUERY_FLAG |
231 | if QUERY_FLAG |
429 | (op, FLAG_AFK) |
232 | (op, FLAG_AFK) |
… | |
… | |
643 | int |
446 | int |
644 | command_dumpbelow (object *op, char *params) |
447 | command_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 | |
656 | int |
460 | int |
657 | command_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 | |
|
|
682 | int |
|
|
683 | command_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 | |
|
|
708 | int |
|
|
709 | command_dumpallobjects (object *op, char *params) |
|
|
710 | { |
|
|
711 | dump_all_objects (); |
|
|
712 | return 0; |
|
|
713 | } |
|
|
714 | |
|
|
715 | int |
|
|
716 | command_dumpfriendlyobjects (object *op, char *params) |
461 | command_dumpfriendlyobjects (object *op, char *params) |
717 | { |
462 | { |
718 | dump_friendly_objects (); |
463 | dump_friendly_objects (); |
719 | return 0; |
|
|
720 | } |
|
|
721 | |
|
|
722 | int |
|
|
723 | command_dumpallarchetypes (object *op, char *params) |
|
|
724 | { |
|
|
725 | dump_all_archetypes (); |
|
|
726 | return 0; |
464 | return 0; |
727 | } |
465 | } |
728 | |
466 | |
729 | int |
467 | int |
730 | command_dumpmap (object *op, char *params) |
468 | command_dumpmap (object *op, char *params) |
… | |
… | |
844 | int |
582 | int |
845 | command_statistics (object *pl, char *params) |
583 | command_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", |