--- deliantra/server/ext/commands.ext 2007/10/25 09:01:23 1.64 +++ deliantra/server/ext/commands.ext 2017/01/29 02:47:04 1.84 @@ -34,7 +34,7 @@ . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") . ($ns->afk ? " [AFK]" : "") . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") - . " [" . $pl->ns->version . "]" + . " [" . $pl->ns->{who_version} . "]" . " [" . ($pl->peaceful || $privileged ? $ob->map->visible_name : $ob->region->name) . "]" . (sprintf " [rtt %.3fs]", $pl->ns->tcpi_rtt * 1e-6) . ($privileged ? " " . $pl->ns->host : "") @@ -49,108 +49,126 @@ $ob->speed_left ($ob->speed_left - 4); - $ob->send_msg ("c/who" => (join "\n\n", who_listing $ob->may ("extended_who"), $arg), cf::NDI_DK_ORANGE | cf::NDI_REPLY | cf::NDI_CLEAR | cf::NDI_DEF); + $ob->send_msg ("c/who" => (join "\r", who_listing $ob->may ("extended_who"), $arg), cf::NDI_DK_ORANGE | cf::NDI_REPLY | cf::NDI_CLEAR | cf::NDI_DEF); }; 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_REPLY); - } elsif (cf::player::find_active $login) { - $pl->message ("$login is right here on this server!", cf::NDI_REPLY); - } 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_REPLY); + cf::async { + if (my ($login) = $args =~ /(\S+)/) { + if ($login eq $pl->name) { + $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_REPLY); + } elsif (cf::player::find_active $login) { + $pl->message ("$login is right here on this server!", cf::NDI_REPLY); + } elsif (cf::player::exists $login + and !Coro::AIO::aio_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_REPLY); + } else { + $pl->message ("No player named $login is known to me.", cf::NDI_REPLY); + } } else { - $pl->message ("No player named $login is known to me.", cf::NDI_REPLY); + $pl->message ("Usage: seen ", cf::NDI_REPLY); } - } else { - $pl->message ("Usage: seen ", cf::NDI_REPLY); - } + }; }; cf::register_command body => sub { my ($ob) = @_; + my $observe = $ob->contr->observe; + # Too hard to try and make a header that lines everything up, so just # give a description. (comment from C++) 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"; + "The first column is the name of the body location.\r" + . "The second column is how many of those locations your body has.\r" + . "The third column is how many slots in that location are available.\r" + . "The last column shows the items currently using the slot\n\n"; + + # first process all applied items and hash them into their slots + my @slot; + + for my $item (grep $_->flag (cf::FLAG_APPLIED), $observe->inv) { + $item->slot_info ($_) + and push @{ $slot[$_] }, $item + for 0 .. cf::NUM_BODY_LOCATIONS-1; + } - $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail"; + $reply .= sprintf " %-20s %3s %5s %s\n", "Location", "You", "Avail", "What"; 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 ($_); + $reply .= sprintf " %-20s %3d %5d %s\n", + $msg, + $observe->slot_info ($_), + $observe->slot_used ($_), + join ", ", map $_->query_short_name, @{ $slot[$_] } + if $observe->slot_info ($_) || $observe->slot_used ($_); } - $reply .= "You are not allowed to wear armor\n\n" - unless $ob->flag (cf::FLAG_USE_ARMOUR); - $reply .= "You are not allowed to use weapons\n\n" - unless $ob->flag (cf::FLAG_USE_WEAPON); + $reply .= "You are not allowed to wear armor\r" + unless $observe->flag (cf::FLAG_USE_ARMOUR); + $reply .= "You are not allowed to use weapons\r" + unless $observe->flag (cf::FLAG_USE_WEAPON); + + $ob->send_msg ("c/body" => $reply, cf::NDI_REPLY | cf::NDI_CLEAR); +}; + +#cf::register_command mark => sub { +# my ($pl, $arg) = @_; +# +# if (length $arg) { +# my $ob = $pl->find_best_object_match ($arg); +# +# return $pl->reply (undef, "Could not find an object that matches $arg") +# unless $ob; +# +# $pl->contr->mark ($ob); +# $pl->reply (undef, (sprintf "Marked item %s", $ob->name, $ob->title)); +# } else { +# my $ob = $pl->mark; +# +# $pl->reply (undef, $ob +# ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) +# : "You have no marked object."); +# } +#}; - $ob->send_msg ("c/body" => $reply, cf::NDI_REPLY); -}; +cf::register_command mapinfo => sub { + my ($ob) = @_; -cf::register_command mark => sub { - my ($pl, $arg) = @_; + my $observe = $ob->contr->observe; - if (length $arg) { - my $ob = $pl->find_best_object_match ($arg); + my $map = $observe->map + or return; - return $pl->reply (undef, "Could not find an object that matches $arg") - unless $ob; + my $msg = ''; - $pl->contr->mark ($ob); - $pl->reply (undef, (sprintf "Marked item %s", $ob->name, $ob->title)); + if ($map->name ne '') { + $msg .= sprintf "%s [%s] ", $map->name, $map->visible_name } else { - my $ob = $pl->find_marked_object; - - $pl->reply (undef, $ob - ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) - : "You have no marked object."); + $msg .= sprintf "%s ", $map->visible_name } -}; - -for my $cmd ("run", "fire") { - my $oncmd = "${cmd}_on"; - cf::register_command $cmd => sub { - my ($ob, $arg) = @_; - - $ob->reply (undef, "Can't $cmd into a non adjacent square.") - if $arg < 0 or $arg >= 9; - - $ob->contr->$oncmd (1); - $ob->move_player ($arg); - }; - - cf::register_command "${cmd}_stop" => sub { - my ($ob) = @_; - - $ob->contr->$oncmd (0); - }; -} -cf::register_command mapinfo => sub { - my ($ob) = @_; - - my $observe = $ob->contr->observe; + if ($map->visible_name ne $map->path) { + $msg .= sprintf "(%s) ", $map->path; + } - my $map = $observe->map - or return; + $msg .= sprintf "\r%s", $observe->region->longname; - my $msg = sprintf "%s (%s) %s", $map->name, $map->path, $observe->region->longname; - $msg .= sprintf "\n\nplayers: %d difficulty: %d size: %d start: %dx%d timeout: %d", - (scalar $map->players), $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout + $msg .= sprintf "\rplayers: %d difficulty: %d" + . "\rsize: %dx%d start: %dx%d position: (%d|%d) timeout: %d", + (scalar $map->players), + $map->difficulty, + $map->width, $map->height, + $map->enter_x, $map->enter_y, + $ob->x, $ob->y, + $map->timeout if $ob->flag (cf::FLAG_WIZ); $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); @@ -160,7 +178,7 @@ my ($ob) = @_; my $reg = $ob->contr->observe->region; - $ob->send_msg ("c/mapinfo" => (sprintf "You are %s.\n%s", $reg->longname, $reg->msg), cf::NDI_REPLY | cf::NDI_CLEAR); + $ob->send_msg ("c/who" => (sprintf "You are %s.\n\n%s", $reg->longname, $reg->msg), cf::NDI_REPLY | cf::NDI_CLEAR); }; cf::register_command whereabouts => sub { @@ -172,10 +190,10 @@ ++$count{$pl->ob->region->longname}; } - my $msg = "In the world currently there are:\n\n" - . join "", map "$count{$_} player(s) $_\n\n", sort keys %count; + my $msg = "T\n\n" + . join "", map { sprintf " C<%3d >player(s) %s\r", $count{$_}, $_ } sort keys %count; - $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); + $ob->send_msg ("c/who" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); }; cf::register_command hiscore => sub { @@ -227,34 +245,39 @@ cf::register_command afk => sub { my ($ob, $arg) = @_; - $ob->contr->ns->afk ($ob->contr->ns->afk ? 0 : 1); - $ob->reply (undef, $ob->contr->ns->afk ? "You are now AFK" : "You are no longer AFK"); + $ob->contr->ns->afk (!(length $arg ? !$arg : $ob->contr->ns->afk)); + $ob->reply (undef, $ob->contr->ns->afk ? "You are now AFK." : "You are no longer AFK."); }; -cf::register_command sound => sub { +cf::register_command bumpmsg => sub { my ($ob, $arg) = @_; - $ob->contr->ns->sound ($ob->contr->ns->sound ? 0 : 1); - $ob->reply (undef, $ob->contr->ns->sound ? "The sounds are enabled." : "Silence is golden..."); + $ob->contr->ns->bumpmsg (!(length $arg ? !$arg : $ob->contr->ns->bumpmsg)); + $ob->reply (undef, $ob->contr->ns->bumpmsg ? "Bumping into walls sounds more painful now." : "Bumping into walls will now be silent."); }; cf::register_command brace => sub { my ($ob, $arg) = @_; - $ob->contr->braced ($ob->contr->braced ? 0 : 1); + $ob->contr->braced (!(length $arg ? !$arg : $ob->contr->braced)); $ob->reply (undef, $ob->contr->braced ? "You are braced." : "Not braced."); }; +cf::register_command sound => sub { + my ($ob, $arg) = @_; + + $ob->contr->ns->sound (!(length $arg ? !$arg : $ob->contr->ns->sound)); + $ob->reply (undef, $ob->contr->ns->sound ? "The sounds are enabled." : "Silence is golden..."); +}; + 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 5k/s - # maximum is 100k/s, this should be configurable - $ob->contr->ns->max_rate ((List::Util::max 5000, List::Util::min 100000, $arg) * $cf::TICK); - $ob->reply (undef, sprintf "Output rate now set to %dbps.", $ob->contr->ns->max_rate / $cf::TICK); + $ob->contr->ns->max_rate ((cf::clamp $arg, $OUTPUT_RATE_MIN, $OUTPUT_RATE_MAX) * $TICK); + $ob->reply (undef, sprintf "Output rate now set to %dbps.", $ob->contr->ns->max_rate / $TICK); }; cf::register_command 'output-count' => sub { @@ -324,7 +347,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->mark or return $ob->message ("rename: no from name and no marked item found to rename."); } @@ -372,13 +395,13 @@ my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; - $ob->send_msg ("c/uptime" => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY); + $ob->send_msg ("c/uptime" => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY | cf::NDI_CLEAR); }; -my %IN_MEMORY = ( - cf::MAP_IN_MEMORY => "I", - cf::MAP_SWAPPED => "S", - cf::MAP_LOADING => "L", +my %MAP_STATE = ( + cf::MAP_ACTIVE => "A", + cf::MAP_INACTIVE => "I", + cf::MAP_SWAPPED => "S", ); cf::register_command maps => sub { @@ -386,9 +409,9 @@ no re 'eval'; $arg = qr<$arg>; - my $format = "%2s %1s %3s %5s %.60s\n"; + my $format = " %2s %1s %3s %5s %.60s\n"; - $ob->send_msg ("c/mapinfo" => (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_REPLY | cf::NDI_CLEAR); + my $msg = "\n" . sprintf $format, "Pl", "S", "Svd", "Reset", "Name"; for (sort keys %cf::MAP) { my $map = $cf::MAP{$_} @@ -400,14 +423,14 @@ my $svd = int $cf::RUNTIME - $map->{last_save}; $svd = "++" if $svd > 99; - $ob->send_msg ("c/mapinfo" => - (sprintf $format, - (scalar $map->players), - $IN_MEMORY{$map->in_memory} || "?", - $svd, - (int $map->reset_at - $cf::RUNTIME), - $map->visible_name) - ); + $msg .= sprintf $format, + (scalar $map->players), + $MAP_STATE{$map->state} || "?", + $svd, + (int $map->reset_at - $cf::RUNTIME), + $map->visible_name; } + + $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); };