--- deliantra/server/ext/commands.ext 2007/07/28 00:15:03 1.57 +++ deliantra/server/ext/commands.ext 2007/10/07 15:52:05 1.63 @@ -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) = @_; @@ -83,9 +49,14 @@ $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); + my $CHANNEL = { + id => "who", + title => "Players", + reply => undef, + tooltip => "Shows players who are currently online", + }; - 1 + $ob->send_msg ($CHANNEL => (join "\n\n", 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 { @@ -93,21 +64,21 @@ if (my ($login) = $args =~ /(\S+)/) { if ($login eq $pl->name) { - $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); + $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_UNIQUE); + $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_UNIQUE); + . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_REPLY); } else { - $pl->message ("No player named $login is known to me.", cf::NDI_UNIQUE); + $pl->message ("No player named $login is known to me.", cf::NDI_REPLY); } } else { - $pl->message ("Usage: seen ", cf::NDI_UNIQUE); + $pl->message ("Usage: seen ", cf::NDI_REPLY); } }; @@ -134,9 +105,14 @@ $reply .= "You are not allowed to use weapons\n\n" unless $ob->flag (cf::FLAG_USE_WEAPON); - $ob->reply (undef, $reply); + my $CHANNEL = { + id => "body", + title => "Body Parts", + reply => undef, + tooltip => "Shows which body parts you posess and are available", + }; - 1 + $ob->send_msg ($CHANNEL => $reply, cf::NDI_REPLY); }; cf::register_command mark => sub { @@ -157,8 +133,6 @@ ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) : "You have no marked object."); } - - 1 }; for my $cmd ("run", "fire") { @@ -171,19 +145,22 @@ $ob->contr->$oncmd (1); $ob->move_player ($arg); - - 1 }; cf::register_command "${cmd}_stop" => sub { my ($ob) = @_; $ob->contr->$oncmd (0); - - 1 }; } +our $MAPINFO_CHANNEL = { + id => "mapinfo", + title => "Map Info", + reply => undef, + tooltip => "Information about the map", +}; + cf::register_command mapinfo => sub { my ($ob) = @_; @@ -191,22 +168,42 @@ my $map = $observe->map or return; - $ob->reply (undef, (sprintf "%s (%s) %s", $map->name, $map->path, $observe->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) %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->reply (undef, $map->msg); - 1 + $ob->send_msg ($MAPINFO_CHANNEL => $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 ($MAPINFO_CHANNEL => (sprintf "You are %s.\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 = "In the world currently there are:\n\n" + . join "", map "$count{$_} player(s) $_\n\n", sort keys %count; + + $ob->send_msg ($MAPINFO_CHANNEL => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); +}; - 1 +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($$$@) { @@ -228,32 +225,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 +250,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 +257,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 +264,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 { @@ -293,8 +276,6 @@ # 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 { @@ -307,8 +288,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 { @@ -321,8 +300,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 @@ -339,8 +316,6 @@ if $arg =~ /^\d+$/ and $arg <= 100; $ob->reply (undef, "Incorrect parameters for wimpy: $arg"); - - 1 }; cf::register_command peaceful => sub { @@ -353,10 +328,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) = @_; @@ -379,8 +386,6 @@ } else { $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); } - - 1 }; cf::register_command uptime => sub { @@ -388,9 +393,7 @@ 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 (log => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY); }; my %IN_MEMORY = ( @@ -406,7 +409,7 @@ my $format = "%2s %1s %3s %5s %.60s\n"; - $ob->reply (undef, (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_BLACK | cf::NDI_UNIQUE); + $ob->send_msg ($MAPINFO_CHANNEL => (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_REPLY | cf::NDI_CLEAR); for (sort keys %cf::MAP) { my $map = $cf::MAP{$_} @@ -418,16 +421,14 @@ my $svd = int $cf::RUNTIME - $map->{last_save}; $svd = "++" if $svd > 99; - $ob->reply (undef, + $ob->send_msg ($MAPINFO_CHANNEL => (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); + $map->visible_name) + ); } - - 1 };