--- deliantra/server/ext/commands.ext 2007/03/18 03:05:40 1.38 +++ deliantra/server/ext/commands.ext 2007/07/20 14:13:58 1.55 @@ -1,4 +1,4 @@ -#! perl # MANDATORY +#! perl # mandatory depends=irc use POSIX (); @@ -38,10 +38,8 @@ 1 } -sub ext::schmorp_irc::users; # HACK: TODO: replace by signal - -sub who_listing(;$) { - my ($privileged) = @_; +sub who_listing(;$$) { + my ($privileged, $select) = @_; my ($numwiz, $numafk) = (0, 0); my @pl; @@ -61,57 +59,83 @@ ( "Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)", - ( - map { - my ($pl, $ob, $ns) = ($_, $_->ob, $_->ns); - - "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) - . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") - . ($ns->afk ? " [AFK]" : "") - . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") - . " [" . $pl->ns->version . "]" - . " [" . ($pl->peaceful || $privileged ? $ob->map->visible_name : $ob->region->name) . "]" - . (sprintf " [rtt %.3fs]", $pl->ns->rtt * 1e-6) - . ($privileged ? " " . $pl->ns->host : "") - } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl + (grep /$select/, + map { + my ($pl, $ob, $ns) = ($_, $_->ob, $_->ns); + + "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) + . ($pl->gender ? " [f]" : " [m]") + . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") + . ($ns->afk ? " [AFK]" : "") + . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") + . " [" . $pl->ns->version . "]" + . " [" . ($pl->peaceful || $privileged ? $ob->map->visible_name : $ob->region->name) . "]" + . (sprintf " [rtt %.3fs]", $pl->ns->rtt * 1e-6) + . ($privileged ? " " . $pl->ns->host : "") + } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl ), - eval { "* IRC: " . join ", ", ext::schmorp_irc::users }, + eval { "* IRC: " . join ", ", ext::irc::users }, ) } cf::register_command who => sub { my ($ob, $arg) = @_; - $ob->speed_left ($ob->speed_left - 0.25); + $ob->speed_left ($ob->speed_left - 4); - $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); + $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who"), $arg), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); 1 }; +cf::register_command seen => sub { + my ($pl, $args) = @_; + + if (my ($login) = $args =~ /(\S+)/) { + if ($login eq $pl->name) { + $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); + } elsif (cf::player::find_active $login) { + $pl->message ("$login is right here on this server!", cf::NDI_UNIQUE); + } elsif (cf::player::exists $login + and stat cf::player::path $login) { + my $time = (stat _)[9]; + + $pl->message ("$login was last seen here " + . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) + . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); + } else { + $pl->message ("No player named $login is known to me.", cf::NDI_UNIQUE); + } + } else { + $pl->message ("Usage: seen ", cf::NDI_UNIQUE); + } +}; + cf::register_command body => sub { my ($ob) = @_; - my @body_locations = ("in your range slot", "on your arm", "on your body", "on your head", - "around your neck", "in your skill slot", "on your finger", "around your shoulders", - "on your feet", "on your hands", "around your wrists", "around your waist"); - # Too hard to try and make a header that lines everything up, so just # give a description. (comment from C++) - $ob->reply (undef, "The first column is the name of the body location."); - $ob->reply (undef, "The second column is how many of those locations your body has."); - $ob->reply (undef, "The third column is how many slots in that location are available."); - - for (0 .. scalar @body_locations - 1) { - $ob->reply (undef, (sprintf "%-30s %5d %5d", $body_locations[$_], $ob->body_info($_), $ob->body_used($_))) - if $ob->body_info($_) or $ob->body_used($_); + my $reply = + "The first column is the name of the body location.\n\n" + . "The second column is how many of those locations your body has.\n\n" + . "The third column is how many slots in that location are available.\n\n"; + + $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail"; + for (0 .. cf::NUM_BODY_LOCATIONS - 1) { + my $msg = cf::object::slot_nonuse_name $_; + $msg =~ s/^.*? a //; + $reply .= sprintf " %-20s %3d %5d\n", $msg, $ob->slot_info ($_), $ob->slot_used ($_) + if $ob->slot_info ($_) or $ob->slot_used ($_); } - $ob->reply (undef, "You are not allowed to wear armor") + $reply .= "You are not allowed to wear armor\n\n" unless $ob->flag (cf::FLAG_USE_ARMOUR); - $ob->reply (undef, "You are not allowed to use weapons") + $reply .= "You are not allowed to use weapons\n\n" unless $ob->flag (cf::FLAG_USE_WEAPON); + $ob->reply (undef, $reply); + 1 }; @@ -163,11 +187,13 @@ cf::register_command mapinfo => sub { my ($ob) = @_; + $ob = $ob->contr->observe; + my $map = $ob->map or return; $ob->reply (undef, (sprintf "%s (%s) %s", $map->name, $map->path, $ob->region->longname)); $ob->reply (undef, (sprintf "players: %d difficulty: %d size: %d start: %dx%d timeout: %d", - $map->players, $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout)) + (scalar $map->players), $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout)) if $ob->flag (cf::FLAG_WIZ); $ob->reply (undef, $map->msg); @@ -177,7 +203,7 @@ cf::register_command whereami => sub { my ($ob) = @_; - my $reg = $ob->region; + my $reg = $ob->contr->observe->region; $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg)); 1 @@ -222,6 +248,14 @@ 1 }; +cf::register_command hintmode => sub { + my ($ob, $arg) = @_; + + _set_mode "hintmode", $ob, $arg, hintmode => qw(show mark hide); + + 1 +}; + cf::register_command afk => sub { my ($ob, $arg) = @_; @@ -255,7 +289,8 @@ return $ob->reply (undef, sprintf "Output rate is presently %dbps.", $ob->contr->ns->max_rate / $cf::TICK) unless $arg > 0; - $ob->contr->ns->max_rate ($arg * $cf::TICK); + # minimum is 5k/s + $ob->contr->ns->max_rate ((List::Util::max 5000, $arg) * $cf::TICK); $ob->reply (undef, sprintf "Output rate now set to %dbps.", $ob->contr->ns->max_rate / $cf::TICK); 1 @@ -267,6 +302,8 @@ return $ob->reply (undef, "Output count is presently " . $ob->contr->outputs_count) unless $arg > 0; + $arg = 4 if $arg < 4; + $ob->contr->outputs_count ($arg); $ob->reply (undef, "Output count now set to " . $ob->contr->outputs_count); @@ -279,6 +316,8 @@ return $ob->reply (undef, sprintf "Output sync time is presently %.1fs", $ob->contr->outputs_sync * $cf::TICK) unless length $arg; + $arg = 0.5 if $arg < 0.5; + $ob->contr->outputs_sync ($arg / $cf::TICK); $ob->reply (undef, sprintf "Output sync time now set to %.1fs", $ob->contr->outputs_sync * $cf::TICK);