--- deliantra/server/ext/commands.ext 2007/06/24 01:09:27 1.48 +++ deliantra/server/ext/commands.ext 2007/08/14 12:17:34 1.61 @@ -4,40 +4,6 @@ # miscellaneous commands -sub rename_to($$$) { - my ($ob, $from, $to) = @_; - - $to =~ /^[a-zA-Z0-9.,=#\/%$!^ ]*$/ - or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); - - 127 >= length $to - or return $ob->message ("rename: new name must be <= 127 characters."); - - my $item; - - if (length $from) { - $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 - or return $ob->message ("rename: no from name and no marked item found to rename."); - } - - $item->custom_name (length $to ? $to : undef); - - if (length $to) { - $item->custom_name ($to); - $ob->message ("Your " . $item->base_name . " will now be called $to."); - } else { - $item->custom_name (undef); - $ob->message ("You stop calling your " . $item->base_name . " with weird names."); - } - - $ob->esrv_update_item (cf::UPD_NAME, $item); - - 1 -} - sub who_listing(;$$) { my ($privileged, $select) = @_; @@ -70,7 +36,7 @@ . ($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) + . (sprintf " [rtt %.3fs]", $pl->ns->tcpi_rtt * 1e-6) . ($privileged ? " " . $pl->ns->host : "") } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl ), @@ -83,9 +49,7 @@ $ob->speed_left ($ob->speed_left - 4); - $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who"), $arg), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); - - 1 + $ob->send_msg (log => (join "\n\n", who_listing $ob->may ("extended_who"), $arg), cf::NDI_DK_ORANGE | cf::NDI_REPLY); }; cf::register_command seen => sub { @@ -117,26 +81,24 @@ # 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" - . "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"; + "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"; + $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 ($_) + $reply .= sprintf " %-20s %3d %5d\n", $msg, $ob->slot_info ($_), $ob->slot_used ($_) if $ob->slot_info ($_) or $ob->slot_used ($_); } - $reply .= "You are not allowed to wear armor\n" + $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" + $reply .= "You are not allowed to use weapons\n\n" unless $ob->flag (cf::FLAG_USE_WEAPON); $ob->reply (undef, $reply); - - 1 }; cf::register_command mark => sub { @@ -157,8 +119,6 @@ ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) : "You have no marked object."); } - - 1 }; for my $cmd ("run", "fire") { @@ -171,40 +131,57 @@ $ob->contr->$oncmd (1); $ob->move_player ($arg); - - 1 }; cf::register_command "${cmd}_stop" => sub { my ($ob) = @_; $ob->contr->$oncmd (0); - - 1 }; } cf::register_command mapinfo => sub { my ($ob) = @_; - my $map = $ob->map + my $observe = $ob->contr->observe; + + my $map = $observe->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)) - if $ob->flag (cf::FLAG_WIZ); - $ob->reply (undef, $map->msg); - 1 + 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 + if $ob->flag (cf::FLAG_WIZ); + $ob->send_msg (log => $msg, cf::NDI_REPLY); }; 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)); +}; + +cf::register_command whereabouts => sub { + my ($ob, $arg) = @_; + + my %count; - 1 + for my $pl (cf::player::list) { + ++$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; + + $ob->send_msg (log => $msg, cf::NDI_REPLY); +}; + +cf::register_command hiscore => sub { + my ($ob, $arg) = @_; + + my $url = $cf::CFG->{hiscore_url}; + $ob->send_msg (log => "See $url", cf::NDI_REPLY); }; sub _set_mode($$$@) { @@ -226,24 +203,24 @@ my ($ob, $arg) = @_; _set_mode "applymode", $ob, $arg, unapply => qw(nochoice never always); - - 1 }; cf::register_command petmode => sub { my ($ob, $arg) = @_; _set_mode "petmode", $ob, $arg, petmode => qw(normal sad defend arena); - - 1 }; cf::register_command usekeys => sub { my ($ob, $arg) = @_; _set_mode "usekeys", $ob, $arg, usekeys => qw(inventory keyrings containers); +}; - 1 +cf::register_command hintmode => sub { + my ($ob, $arg) = @_; + + _set_mode "hintmode", $ob, $arg, hintmode => qw(show mark hide); }; cf::register_command afk => sub { @@ -251,8 +228,6 @@ $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"); - - 1 }; cf::register_command sound => sub { @@ -260,8 +235,6 @@ $ob->contr->ns->sound ($ob->contr->ns->sound ? 0 : 1); $ob->reply (undef, $ob->contr->ns->sound ? "The sounds are enabled." : "Silence is golden..."); - - 1 }; cf::register_command brace => sub { @@ -269,8 +242,6 @@ $ob->contr->braced ($ob->contr->braced ? 0 : 1); $ob->reply (undef, $ob->contr->braced ? "You are braced." : "Not braced."); - - 1 }; cf::register_command 'output-rate' => sub { @@ -279,11 +250,10 @@ 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); + # 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); - - 1 }; cf::register_command 'output-count' => sub { @@ -296,8 +266,6 @@ $ob->contr->outputs_count ($arg); $ob->reply (undef, "Output count now set to " . $ob->contr->outputs_count); - - 1 }; cf::register_command 'output-sync' => sub { @@ -310,8 +278,6 @@ $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 }; # XXX: This has a bug. After one sets his wimpy level to 0 and resets it to @@ -328,8 +294,6 @@ if $arg =~ /^\d+$/ and $arg <= 100; $ob->reply (undef, "Incorrect parameters for wimpy: $arg"); - - 1 }; cf::register_command peaceful => sub { @@ -342,10 +306,42 @@ #$ob->contr->peaceful ($ob->contr->peaceful ? 0 : 1); #$ob->reply (undef, $ob->contr->peaceful ? "You will attack other players." : "You will not attack other players."); - - 1 }; +sub rename_to($$$) { + my ($ob, $from, $to) = @_; + + $to =~ /^[a-zA-Z0-9.,=#\/%$!^ ]*$/ + or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); + + 127 >= length $to + or return $ob->message ("rename: new name must be <= 127 characters."); + + my $item; + + if (length $from) { + $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 + or return $ob->message ("rename: no from name and no marked item found to rename."); + } + + $item->custom_name (length $to ? $to : undef); + + if (length $to) { + $item->custom_name ($to); + $ob->message ("Your " . $item->base_name . " will now be called $to."); + } else { + $item->custom_name (undef); + $ob->message ("You stop calling your " . $item->base_name . " with weird names."); + } + + $ob->esrv_update_item (cf::UPD_NAME, $item); + + 1 +} + cf::register_command rename => sub { my ($ob, $arg) = @_; @@ -368,8 +364,6 @@ } else { $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); } - - 1 }; cf::register_command uptime => sub { @@ -378,8 +372,6 @@ my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; $ob->reply (undef, "server started $startup, uptime ${runtime}\d"); - - 1 }; my %IN_MEMORY = ( @@ -416,7 +408,5 @@ $map->visible_name), cf::NDI_BLACK | cf::NDI_UNIQUE); } - - 1 };