--- deliantra/server/ext/commands.ext 2006/12/15 19:29:18 1.1 +++ deliantra/server/ext/commands.ext 2007/03/02 11:13:50 1.25 @@ -7,7 +7,7 @@ sub rename_to($$$) { my ($ob, $from, $to) = @_; - $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ + $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 @@ -47,13 +47,14 @@ my @pl; foreach my $pl (cf::player::list) { + my $ns = $pl->ns or next; my $ob = $pl->ob; next unless $ob->map && ($privileged || !$pl->hidden); $numwiz++ if $ob->flag (cf::FLAG_WIZ); - $numafk++ if $ob->flag (cf::FLAG_AFK); + $numafk++ if $ns->afk; push @pl, $pl; } @@ -62,16 +63,16 @@ "Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)", ( map { - my ($pl, $ob) = ($_, $_->ob); + my ($pl, $ob, $ns) = ($_, $_->ob, $_->ns); "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") - . ($ob->flag (cf::FLAG_AFK) ? " [AFK]" : "") + . ($ns->afk ? " [AFK]" : "") . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") - . " [" . $pl->socket->client . "]" - . " [" . ($pl->peaceful || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" - . (sprintf " [rtt %.3fs/%.3f]", $pl->socket->rtt * 1e-6, $pl->socket->rttvar * 1e-6) - . ($privileged ? " " . $pl->socket->host : "") + . " [" . $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 }, @@ -88,6 +89,174 @@ 1 }; +cf::register_command whereami => sub { + my ($ob) = @_; + + my $reg = $ob->region; + $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg)); + + 1 +}; + +cf::register_command applymode => sub { + my ($ob, $arg) = @_; + my @types = ("nochoice", "never", "always"); + my $mapping = { + nochoice => 1, + never => 2, + always => 3, + }; + + my $oldmode = $ob->contr->unapply; + my $oldmode_name = $types[$oldmode]; + + return $ob->reply (undef, "applymode is set to $oldmode_name") + unless $arg; + + return $ob->reply (undef, "applymode: Unknown options '$arg', valid options are @types") + unless $mapping->{$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]); + + 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]); + + 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]); + + 1 +}; + +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"); + + 1 +}; + +cf::register_command sound => 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..."); + + 1 +}; + +cf::register_command brace => sub { + my ($ob, $arg) = @_; + + $ob->contr->braced ($ob->contr->braced ? 0 : 1); + $ob->reply (undef, $ob->contr->braced ? "You are braced." : "Not braced."); + + 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; + + $ob->contr->outputs_count ($arg); + $ob->reply (undef, "Output count now set to " . $ob->contr->outputs_count); + + 1 +}; + +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; + + $ob->contr->outputs_sync ($arg); + $ob->reply (undef, "Output sync time now set to " . $ob->contr->outputs_sync); + + 1 +}; + +# XXX: This has a bug. After one sets his wimpy level to 0 and resets it to +# some other level (which may also be 0), this does not get echoed, +# but it does get set. +cf::register_command wimpy => sub { + my ($ob, $arg) = @_; + + my $wimpy = $ob->run_away; + return $ob->reply (undef, "Your current wimpy level is $wimpy.") + if $arg eq ""; + + return $ob->run_away ($arg) && $ob->reply (undef, "Your new wimpy level is $arg.") + if $arg =~ /^\d+$/ and $arg <= 100; + + $ob->reply (undef, "Incorrect parameters for wimpy: $arg"); + + 1 +}; + +cf::register_command peaceful => sub { + my ($ob, $arg) = @_; + + $ob->reply (undef, "You cannot change your peaceful setting with this command." + ." Please speak to the priest in the temple of Gorokh" + ." if you want to become hostile or in temple of Valriel" + ." if you want to become peaceful again."); + + #$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 +}; + cf::register_command rename => sub { my ($ob, $arg) = @_; @@ -123,4 +292,42 @@ 1 }; + +my %IN_MEMORY = ( + cf::MAP_IN_MEMORY => "I", + cf::MAP_SWAPPED => "S", + cf::MAP_LOADING => "L", +); + +cf::register_command maps => sub { + my ($ob, $arg) = @_; + + no re 'eval'; $arg = qr<$arg>; + + my $format = "%2s %1s %3s %5s %.60s\n"; + + $ob->reply (undef, (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_BLACK | cf::NDI_UNIQUE); + + for (sort keys %cf::MAP) { + my $map = $cf::MAP{$_} + or next; + + next unless $map->path =~ $arg; + next if $map->{deny_list}; + + 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); + } + + 1 +};