--- deliantra/server/ext/commands.ext 2007/03/02 12:16:55 1.29 +++ deliantra/server/ext/commands.ext 2007/05/07 07:47:32 1.44 @@ -1,4 +1,4 @@ -#! perl +#! perl # MANDATORY use POSIX (); @@ -19,7 +19,7 @@ $item = $ob->find_best_object_match ($from) or return $ob->message ("rename: could not find a matching item to rename."); } else { - $item = $ob->find_marked_object () + $item = $ob->find_marked_object or return $ob->message ("rename: no from name and no marked item found to rename."); } @@ -40,8 +40,8 @@ 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,19 +61,19 @@ ( "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->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 }, ) @@ -82,49 +82,68 @@ 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" + . "The second column is how many of those locations your body has.\n" + . "The third column is how many slots in that location are available.\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" 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" unless $ob->flag (cf::FLAG_USE_WEAPON); + $ob->reply (undef, $reply); + 1 }; cf::register_command mark => sub { my ($pl, $arg) = @_; - if (!$arg) { - my $ob = $pl->find_marked_object; - - $pl->reply (undef, $ob - ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) - : "You have no marked object."); - } else { + if (length $arg) { my $ob = $pl->find_best_object_match ($arg); return $pl->reply (undef, "Could not find an object that matches $arg") @@ -132,17 +151,13 @@ $pl->contr->mark ($ob); $pl->reply (undef, (sprintf "Marked item %s", $ob->name, $ob->title)); - } - - 1 -}; - -cf::register_command who => sub { - my ($ob, $arg) = @_; - - $ob->speed_left ($ob->speed_left - 0.25); + } else { + my $ob = $pl->find_marked_object; - $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); + $pl->reply (undef, $ob + ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) + : "You have no marked object."); + } 1 }; @@ -152,15 +167,15 @@ cf::register_command $cmd => sub { my ($ob, $arg) = @_; - return $ob->reply (undef, "Can't $cmd into a non adjacent square.") + $ob->reply (undef, "Can't $cmd into a non adjacent square.") if $arg < 0 or $arg >= 9; $ob->contr->$oncmd (1); - $ob->move ($arg); + $ob->move_player ($arg); 1 }; - + cf::register_command "${cmd}_stop" => sub { my ($ob) = @_; @@ -193,78 +208,41 @@ 1 }; -cf::register_command applymode => sub { - my ($ob, $arg) = @_; - my @types = ("nochoice", "never", "always"); - my $mapping = { - nochoice => 1, - never => 2, - always => 3, - }; +sub _set_mode($$$@) { + my ($name, $ob, $arg, $slot, @choices) = @_; - my $oldmode = $ob->contr->unapply; - my $oldmode_name = $types[$oldmode]; + my $oldmode = $ob->contr->$slot; - return $ob->reply (undef, "applymode is set to $oldmode_name") + return $ob->reply (undef, "$name is set to $choices[$oldmode]") unless $arg; - return $ob->reply (undef, "applymode: Unknown options '$arg', valid options are @types") - unless $mapping->{$arg}; + my ($idx) = grep $choices[$_] eq $arg, 0 .. $#choices + or return $ob->reply (undef, "$name: Unknown options '$arg', valid options are @choices"), 1; + + $ob->contr->$slot ($idx); + $ob->reply (undef, "$name" . ($oldmode == $ob->contr->unapply ? "" : " now") . " set to " . $choices[$ob->contr->$slot]); +} + +cf::register_command applymode => sub { + my ($ob, $arg) = @_; - $ob->contr->unapply ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 - # but $arg would be 0 if a user enters an incorrect value - $ob->reply (undef, "applymode" . ($oldmode == $ob->contr->unapply ? "" : " now") . " set to " . $types[$ob->contr->unapply]); + _set_mode "applymode", $ob, $arg, unapply => qw(nochoice never always); 1 }; cf::register_command petmode => sub { my ($ob, $arg) = @_; - my @types = ("normal", "sad", "defend", "arena"); - my $mapping = { - normal => 1, - sad => 2, - defend => 3, - arena => 4, - }; - - my $oldtype = $ob->contr->petmode; - my $oldtype_name = $types[$oldtype]; - - return $ob->reply (undef, "petmode is set to $oldtype_name") - unless $arg; - return $ob->reply (undef, "petmode: Unknown options '$arg', valid options are @types") - unless $mapping->{$arg}; - - $ob->contr->petmode ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 - # but $arg would be 0 if a user enters an incorrect value - $ob->reply (undef, "petmode" . ($oldtype == $ob->contr->petmode ? "" : " now") . " set to " . $types[$ob->contr->petmode]); + _set_mode "petmode", $ob, $arg, petmode => qw(normal sad defend arena); 1 }; cf::register_command usekeys => sub { my ($ob, $arg) = @_; - my @types = ("inventory", "keyrings", "containers"); - my $mapping = { - inventory => 1, - keyrings => 2, - containers => 3, - }; - my $oldtype = $ob->contr->usekeys; - my $oldtype_name = $types[$oldtype]; - - return $ob->reply (undef, "usekeys is set to $oldtype_name") - unless $arg; - - return $ob->reply (undef, "usekeys: Unknown options '$arg', valid options are @types") - unless $mapping->{$arg}; - - $ob->contr->usekeys ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0 - # but $arg would be 0 if a user enters an incorrect value - $ob->reply (undef, "usekeys" . ($oldtype == $ob->contr->usekeys ? "" : " now") . " set to " . $types[$ob->contr->usekeys]); + _set_mode "usekeys", $ob, $arg, usekeys => qw(inventory keyrings containers); 1 }; @@ -296,12 +274,27 @@ 1 }; +cf::register_command 'output-rate' => sub { + my ($ob, $arg) = @_; + + return $ob->reply (undef, sprintf "Output rate is presently %dbps.", $ob->contr->ns->max_rate / $cf::TICK) + unless $arg > 0; + + # minimum is 2k/s + $ob->contr->ns->max_rate ((List::Util::max 2048, $arg) * $cf::TICK); + $ob->reply (undef, sprintf "Output rate now set to %dbps.", $ob->contr->ns->max_rate / $cf::TICK); + + 1 +}; + cf::register_command 'output-count' => sub { my ($ob, $arg) = @_; 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); @@ -311,11 +304,13 @@ cf::register_command 'output-sync' => sub { my ($ob, $arg) = @_; - return $ob->reply (undef, "Output sync time is presently " . $ob->contr->outputs_sync) - unless $arg > 0; + 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); - $ob->reply (undef, "Output sync time now set to " . $ob->contr->outputs_sync); + $ob->contr->outputs_sync ($arg / $cf::TICK); + $ob->reply (undef, sprintf "Output sync time now set to %.1fs", $ob->contr->outputs_sync * $cf::TICK); 1 };