| 1 |
root |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
use POSIX (); |
| 4 |
|
|
|
| 5 |
|
|
# miscellaneous commands |
| 6 |
|
|
|
| 7 |
|
|
sub rename_to($$$) { |
| 8 |
|
|
my ($ob, $from, $to) = @_; |
| 9 |
|
|
|
| 10 |
root |
1.12 |
$to =~ /^[a-zA-Z0-9.,=#\/%$!^ ]*$/ |
| 11 |
root |
1.1 |
or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); |
| 12 |
|
|
|
| 13 |
|
|
127 >= length $to |
| 14 |
|
|
or return $ob->message ("rename: new name must be <= 127 characters."); |
| 15 |
|
|
|
| 16 |
|
|
my $item; |
| 17 |
|
|
|
| 18 |
|
|
if (length $from) { |
| 19 |
|
|
$item = $ob->find_best_object_match ($from) |
| 20 |
|
|
or return $ob->message ("rename: could not find a matching item to rename."); |
| 21 |
|
|
} else { |
| 22 |
|
|
$item = $ob->find_marked_object () |
| 23 |
|
|
or return $ob->message ("rename: no from name and no marked item found to rename."); |
| 24 |
|
|
} |
| 25 |
|
|
|
| 26 |
|
|
$item->custom_name (length $to ? $to : undef); |
| 27 |
|
|
|
| 28 |
|
|
if (length $to) { |
| 29 |
|
|
$item->custom_name ($to); |
| 30 |
|
|
$ob->message ("Your " . $item->base_name . " will now be called $to."); |
| 31 |
|
|
} else { |
| 32 |
|
|
$item->custom_name (undef); |
| 33 |
|
|
$ob->message ("You stop calling your " . $item->base_name . " with weird names."); |
| 34 |
|
|
} |
| 35 |
|
|
|
| 36 |
|
|
$ob->esrv_update_item (cf::UPD_NAME, $item); |
| 37 |
|
|
|
| 38 |
|
|
1 |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
|
|
sub ext::schmorp_irc::users; # HACK: TODO: replace by signal |
| 42 |
|
|
|
| 43 |
|
|
sub who_listing(;$) { |
| 44 |
|
|
my ($privileged) = @_; |
| 45 |
|
|
|
| 46 |
|
|
my ($numwiz, $numafk) = (0, 0); |
| 47 |
|
|
my @pl; |
| 48 |
|
|
|
| 49 |
|
|
foreach my $pl (cf::player::list) { |
| 50 |
root |
1.5 |
my $ns = $pl->ns or next; |
| 51 |
root |
1.1 |
my $ob = $pl->ob; |
| 52 |
|
|
|
| 53 |
|
|
next unless $ob->map |
| 54 |
|
|
&& ($privileged || !$pl->hidden); |
| 55 |
|
|
|
| 56 |
|
|
$numwiz++ if $ob->flag (cf::FLAG_WIZ); |
| 57 |
root |
1.5 |
$numafk++ if $ns->afk; |
| 58 |
root |
1.1 |
|
| 59 |
|
|
push @pl, $pl; |
| 60 |
|
|
} |
| 61 |
|
|
|
| 62 |
|
|
( |
| 63 |
|
|
"Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)", |
| 64 |
|
|
( |
| 65 |
|
|
map { |
| 66 |
root |
1.5 |
my ($pl, $ob, $ns) = ($_, $_->ob, $_->ns); |
| 67 |
root |
1.1 |
|
| 68 |
|
|
"* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) |
| 69 |
|
|
. ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") |
| 70 |
root |
1.5 |
. ($ns->afk ? " [AFK]" : "") |
| 71 |
root |
1.1 |
. ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") |
| 72 |
root |
1.4 |
. " [" . $pl->ns->version . "]" |
| 73 |
root |
1.6 |
. " [" . ($pl->peaceful || $privileged ? $ob->map->{path}->visible_name : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" |
| 74 |
root |
1.4 |
. (sprintf " [rtt %.3fs]", $pl->ns->rtt * 1e-6) |
| 75 |
|
|
. ($privileged ? " " . $pl->ns->host : "") |
| 76 |
root |
1.1 |
} sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl |
| 77 |
|
|
), |
| 78 |
|
|
eval { "* IRC: " . join ", ", ext::schmorp_irc::users }, |
| 79 |
|
|
) |
| 80 |
|
|
} |
| 81 |
|
|
|
| 82 |
|
|
cf::register_command who => sub { |
| 83 |
|
|
my ($ob, $arg) = @_; |
| 84 |
|
|
|
| 85 |
|
|
$ob->speed_left ($ob->speed_left - 0.25); |
| 86 |
|
|
|
| 87 |
|
|
$ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
| 88 |
|
|
|
| 89 |
|
|
1 |
| 90 |
|
|
}; |
| 91 |
|
|
|
| 92 |
|
|
cf::register_command rename => sub { |
| 93 |
|
|
my ($ob, $arg) = @_; |
| 94 |
|
|
|
| 95 |
|
|
$ob->speed_left ($ob->speed_left - 0.25); |
| 96 |
|
|
|
| 97 |
|
|
if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]*)> \s*$/x) { |
| 98 |
|
|
# compatibility syntax |
| 99 |
|
|
rename_to $ob, $1, $2; |
| 100 |
|
|
} elsif ($arg =~ / |
| 101 |
|
|
^\s* |
| 102 |
|
|
(?: |
| 103 |
|
|
(?: "((?:[^"]+|\\.)*)" | (\S+) ) |
| 104 |
|
|
\s+)? |
| 105 |
|
|
to \s+ |
| 106 |
|
|
(?: "((?:[^"]+|\\.)*)" | (\S+) ) |
| 107 |
|
|
\s*$ |
| 108 |
|
|
/x) { |
| 109 |
|
|
# does not unquote $1 or $3 |
| 110 |
|
|
rename_to $ob, $2||$1, $4||$3; |
| 111 |
|
|
} else { |
| 112 |
|
|
$ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
| 113 |
|
|
} |
| 114 |
|
|
|
| 115 |
|
|
1 |
| 116 |
|
|
}; |
| 117 |
|
|
|
| 118 |
|
|
cf::register_command uptime => sub { |
| 119 |
|
|
my ($ob, $arg) = @_; |
| 120 |
|
|
|
| 121 |
|
|
my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; |
| 122 |
|
|
my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; |
| 123 |
|
|
$ob->reply (undef, "server started $startup, uptime ${runtime}\d"); |
| 124 |
|
|
|
| 125 |
|
|
1 |
| 126 |
|
|
}; |
| 127 |
|
|
|
| 128 |
root |
1.8 |
my %IN_MEMORY = ( |
| 129 |
|
|
cf::MAP_IN_MEMORY => "I", |
| 130 |
|
|
cf::MAP_SWAPPED => "S", |
| 131 |
|
|
cf::MAP_LOADING => "L", |
| 132 |
|
|
); |
| 133 |
|
|
|
| 134 |
root |
1.7 |
cf::register_command maps => sub { |
| 135 |
|
|
my ($ob, $arg) = @_; |
| 136 |
|
|
|
| 137 |
|
|
no re 'eval'; $arg = qr<$arg>; |
| 138 |
|
|
|
| 139 |
root |
1.9 |
my $format = "%2s %1s %3s %5s %-60.60s\n"; |
| 140 |
root |
1.7 |
|
| 141 |
root |
1.11 |
$ob->reply (undef, sprintf $format, "Pl", "I", "Svd", "Reset", "Name"); |
| 142 |
root |
1.7 |
|
| 143 |
|
|
for (sort keys %cf::MAP) { |
| 144 |
|
|
my $map = $cf::MAP{$_} |
| 145 |
|
|
or next; |
| 146 |
|
|
|
| 147 |
|
|
next unless $map->path =~ $arg; |
| 148 |
|
|
|
| 149 |
root |
1.10 |
my $svd = int $cf::RUNTIME - $map->{last_save}; |
| 150 |
|
|
$svd = "++" if $svd > 99; |
| 151 |
|
|
|
| 152 |
root |
1.11 |
$ob->reply (undef, sprintf $format, |
| 153 |
root |
1.7 |
(scalar $map->players), |
| 154 |
root |
1.8 |
$IN_MEMORY{$map->in_memory} || "?", |
| 155 |
root |
1.10 |
$svd, |
| 156 |
root |
1.7 |
(int $map->reset_at - $cf::RUNTIME), |
| 157 |
root |
1.11 |
$map->{path}->visible_name); |
| 158 |
root |
1.7 |
} |
| 159 |
|
|
|
| 160 |
|
|
1 |
| 161 |
|
|
}; |
| 162 |
|
|
|