1 |
#! perl |
2 |
|
3 |
# miscellaneous commands |
4 |
|
5 |
sub rename_to($$$) { |
6 |
my ($ob, $from, $to) = @_; |
7 |
|
8 |
$to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ |
9 |
or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); |
10 |
|
11 |
127 >= length $to |
12 |
or return $ob->message ("rename: new name must be <= 127 characters."); |
13 |
|
14 |
my $item; |
15 |
|
16 |
if (length $from) { |
17 |
$item = $ob->find_best_object_match ($from) |
18 |
or return $ob->message ("rename: could not find a matching item to rename."); |
19 |
} else { |
20 |
$item = $ob->find_marked_object () |
21 |
or return $ob->message ("rename: no from name and no marked item found to rename."); |
22 |
} |
23 |
|
24 |
$item->custom_name (length $to ? $to : undef); |
25 |
|
26 |
if (length $to) { |
27 |
$item->custom_name ($to); |
28 |
$ob->message ("Your " . $item->base_name . " will now be called $to."); |
29 |
} else { |
30 |
$item->custom_name (undef); |
31 |
$ob->message ("You stop calling your " . $item->base_name . " with weird names."); |
32 |
} |
33 |
|
34 |
$ob->esrv_update_item (cf::UPD_NAME, $item); |
35 |
|
36 |
return 1; |
37 |
} |
38 |
|
39 |
sub who_listing(;$) { |
40 |
my ($privileged) = @_; |
41 |
|
42 |
my ($numwiz, $numafk) = (0, 0); |
43 |
my @pl; |
44 |
|
45 |
foreach my $pl (cf::player::list) { |
46 |
my $ob = $pl->ob; |
47 |
|
48 |
next unless $ob->map |
49 |
&& ($privileged || !$pl->hidden); |
50 |
|
51 |
$numwiz++ if $ob->flag (cf::FLAG_WIZ); |
52 |
$numafk++ if $ob->flag (cf::FLAG_AFK); |
53 |
|
54 |
push @pl, $pl; |
55 |
} |
56 |
|
57 |
( |
58 |
"Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)", |
59 |
map { |
60 |
my ($pl, $ob) = ($_, $_->ob); |
61 |
|
62 |
"* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) |
63 |
. ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") |
64 |
. ($ob->flag (cf::FLAG_AFK) ? " [AFK]" : "") |
65 |
. ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") |
66 |
. " [" . $pl->client . "]" |
67 |
. " [" . ($pl->peaceful ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" |
68 |
. ($privileged ? " " . $pl->host : "") |
69 |
} sort { $a->ob->name cmp $b->ob->name } @pl |
70 |
) |
71 |
} |
72 |
|
73 |
cf::register_command who => $cf::TICK, sub { |
74 |
my ($ob, $arg) = @_; |
75 |
|
76 |
$ob->reply (undef, (join "x\n", who_listing $ob->flag (cf::FLAG_WIZ)), cf::NDI_UNIQUE | cf::NDI_GOLD); |
77 |
}; |
78 |
|
79 |
cf::register_command rename => $cf::TICK, sub { |
80 |
my ($ob, $arg) = @_; |
81 |
|
82 |
if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]+)> \s*$/x) { |
83 |
# compatibility syntax |
84 |
rename_to $ob, $1, $2; |
85 |
} elsif ($arg =~ / |
86 |
^\s* |
87 |
(?: |
88 |
(?: "((?:[^"]+|\\.)*)" | (\S+) ) |
89 |
\s+)? |
90 |
to \s+ |
91 |
(?: "((?:[^"]+|\\.)*)" | (\S+) ) |
92 |
\s*$ |
93 |
/x) { |
94 |
# does not unquote $1 or $3 |
95 |
rename_to $ob, $2||$1, $4||$3; |
96 |
} else { |
97 |
$ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
98 |
} |
99 |
}; |