… | |
… | |
2 | |
2 | |
3 | # miscellaneous commands |
3 | # miscellaneous commands |
4 | |
4 | |
5 | sub rename_to($$$) { |
5 | sub rename_to($$$) { |
6 | my ($ob, $from, $to) = @_; |
6 | my ($ob, $from, $to) = @_; |
7 | |
|
|
8 | warn "<$ob|$from|$to>\n";#d# |
|
|
9 | |
7 | |
10 | $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ |
8 | $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ |
11 | or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); |
9 | or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); |
12 | |
10 | |
13 | 127 >= length $to |
11 | 127 >= length $to |
… | |
… | |
36 | $ob->esrv_update_item (cf::UPD_NAME, $item); |
34 | $ob->esrv_update_item (cf::UPD_NAME, $item); |
37 | |
35 | |
38 | return 1; |
36 | return 1; |
39 | } |
37 | } |
40 | |
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 || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" |
|
|
68 | . ($privileged ? " " . $pl->host : "") |
|
|
69 | } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl |
|
|
70 | ) |
|
|
71 | } |
|
|
72 | |
41 | cf::register_command rename => 0, sub { |
73 | cf::register_command who => $cf::TICK, sub { |
42 | my ($ob, $arg) = @_; |
74 | my ($ob, $arg) = @_; |
43 | |
75 | |
44 | warn "<<<$arg>>>\n";#d# |
76 | $ob->reply (undef, (join "\n", who_listing $ob->flag (cf::FLAG_WIZ)), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
|
|
77 | }; |
|
|
78 | |
|
|
79 | cf::register_command rename => $cf::TICK, sub { |
|
|
80 | my ($ob, $arg) = @_; |
45 | |
81 | |
46 | if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]+)> \s*$/x) { |
82 | if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]+)> \s*$/x) { |
47 | # compatibility syntax |
83 | # compatibility syntax |
48 | rename_to $ob, $1, $2; |
84 | rename_to $ob, $1, $2; |
49 | } elsif ($arg =~ / |
85 | } elsif ($arg =~ / |
… | |
… | |
56 | \s*$ |
92 | \s*$ |
57 | /x) { |
93 | /x) { |
58 | # does not unquote $1 or $3 |
94 | # does not unquote $1 or $3 |
59 | rename_to $ob, $2||$1, $4||$3; |
95 | rename_to $ob, $2||$1, $4||$3; |
60 | } else { |
96 | } else { |
61 | $ob->message ('Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
97 | $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
62 | } |
98 | } |
63 | }; |
99 | }; |