--- deliantra/server/ext/commands.ext 2007/07/20 14:13:58 1.55 +++ deliantra/server/ext/commands.ext 2008/09/23 00:24:52 1.71 @@ -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,32 +49,32 @@ $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 ("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_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); + 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 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_UNIQUE); + $pl->message ("Usage: seen ", cf::NDI_REPLY); } - } else { - $pl->message ("Usage: seen ", cf::NDI_UNIQUE); - } + }; }; cf::register_command body => sub { @@ -117,8 +83,8 @@ # 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 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.\n\n"; $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail"; @@ -129,14 +95,12 @@ if $ob->slot_info ($_) or $ob->slot_used ($_); } - $reply .= "You are not allowed to wear armor\n\n" + $reply .= "You are not allowed to wear armor\r" unless $ob->flag (cf::FLAG_USE_ARMOUR); - $reply .= "You are not allowed to use weapons\n\n" + $reply .= "You are not allowed to use weapons\r" unless $ob->flag (cf::FLAG_USE_WEAPON); - $ob->reply (undef, $reply); - - 1 + $ob->send_msg ("c/body" => $reply, cf::NDI_REPLY); }; cf::register_command mark => sub { @@ -157,8 +121,6 @@ ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) : "You have no marked object."); } - - 1 }; for my $cmd ("run", "fire") { @@ -171,42 +133,58 @@ $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) = @_; - $ob = $ob->contr->observe; + my $observe = $ob->contr->observe; - my $map = $ob->map + 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", - (scalar $map->players), $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout)) + + my $msg = sprintf "%s (%s)\r%s", $map->name, $map->path, $observe->region->longname; + $msg .= sprintf "\rplayers: %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->reply (undef, $map->msg); - 1 + $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); }; cf::register_command whereami => sub { my ($ob) = @_; my $reg = $ob->contr->observe->region; - $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg)); + $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 { + my ($ob, $arg) = @_; + + my %count; + + for my $pl (cf::player::list) { + ++$count{$pl->ob->region->longname}; + } + + my $msg = "T\n\n" + . join "", map { sprintf " C<%3d >player(s) %s\r", $count{$_}, $_ } sort keys %count; + + $ob->send_msg ("c/who" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); +}; + +cf::register_command hiscore => sub { + my ($ob, $arg) = @_; - 1 + my $url = $cf::CFG{hiscore_url}; + $ob->send_msg (log => "See $url", cf::NDI_REPLY); }; sub _set_mode($$$@) { @@ -228,32 +206,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); - - 1 }; cf::register_command afk => sub { @@ -261,8 +231,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 { @@ -270,8 +238,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 { @@ -279,8 +245,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 { @@ -290,10 +254,9 @@ unless $arg > 0; # minimum is 5k/s - $ob->contr->ns->max_rate ((List::Util::max 5000, $arg) * $cf::TICK); + # 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 { @@ -306,8 +269,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 { @@ -320,8 +281,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 @@ -338,8 +297,6 @@ if $arg =~ /^\d+$/ and $arg <= 100; $ob->reply (undef, "Incorrect parameters for wimpy: $arg"); - - 1 }; cf::register_command peaceful => sub { @@ -352,10 +309,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) = @_; @@ -378,8 +367,6 @@ } else { $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); } - - 1 }; cf::register_command uptime => sub { @@ -387,13 +374,11 @@ 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 + $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_ACTIVE => "I", cf::MAP_SWAPPED => "S", cf::MAP_LOADING => "L", ); @@ -403,9 +388,9 @@ no re 'eval'; $arg = qr<$arg>; - my $format = "%2s %1s %3s %5s %.60s\n"; + my $format = " %2s %1s %3s %5s %.60s\n"; - $ob->reply (undef, (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_BLACK | cf::NDI_UNIQUE); + my $msg = "\n" . sprintf $format, "Pl", "I", "Svd", "Reset", "Name"; for (sort keys %cf::MAP) { my $map = $cf::MAP{$_} @@ -417,16 +402,14 @@ my $svd = int $cf::RUNTIME - $map->{last_save}; $svd = "++" if $svd > 99; - $ob->reply (undef, - (sprintf $format, - (scalar $map->players), - $IN_MEMORY{$map->in_memory} || "?", - $svd, - (int $map->reset_at - $cf::RUNTIME), - $map->visible_name), - cf::NDI_BLACK | cf::NDI_UNIQUE); + $msg .= sprintf $format, + (scalar $map->players), + $IN_MEMORY{$map->in_memory} || "?", + $svd, + (int $map->reset_at - $cf::RUNTIME), + $map->visible_name; } - 1 + $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); };