1 | #! perl |
1 | #! perl |
|
|
2 | |
|
|
3 | use POSIX (); |
2 | |
4 | |
3 | # miscellaneous commands |
5 | # miscellaneous commands |
4 | |
6 | |
5 | sub rename_to($$$) { |
7 | sub rename_to($$$) { |
6 | my ($ob, $from, $to) = @_; |
8 | my ($ob, $from, $to) = @_; |
7 | |
|
|
8 | warn "<$ob|$from|$to>\n";#d# |
|
|
9 | |
9 | |
10 | $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ |
10 | $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ |
11 | or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); |
11 | or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); |
12 | |
12 | |
13 | 127 >= length $to |
13 | 127 >= length $to |
… | |
… | |
33 | $ob->message ("You stop calling your " . $item->base_name . " with weird names."); |
33 | $ob->message ("You stop calling your " . $item->base_name . " with weird names."); |
34 | } |
34 | } |
35 | |
35 | |
36 | $ob->esrv_update_item (cf::UPD_NAME, $item); |
36 | $ob->esrv_update_item (cf::UPD_NAME, $item); |
37 | |
37 | |
38 | return 1; |
38 | 1 |
39 | } |
39 | } |
40 | |
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 | my $ob = $pl->ob; |
|
|
51 | |
|
|
52 | next unless $ob->map |
|
|
53 | && ($privileged || !$pl->hidden); |
|
|
54 | |
|
|
55 | $numwiz++ if $ob->flag (cf::FLAG_WIZ); |
|
|
56 | $numafk++ if $ob->flag (cf::FLAG_AFK); |
|
|
57 | |
|
|
58 | push @pl, $pl; |
|
|
59 | } |
|
|
60 | |
|
|
61 | ( |
|
|
62 | "Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)", |
|
|
63 | ( |
|
|
64 | map { |
|
|
65 | my ($pl, $ob) = ($_, $_->ob); |
|
|
66 | |
|
|
67 | "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) |
|
|
68 | . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") |
|
|
69 | . ($ob->flag (cf::FLAG_AFK) ? " [AFK]" : "") |
|
|
70 | . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") |
|
|
71 | . " [" . $pl->socket->client . "]" |
|
|
72 | . " [" . ($pl->peaceful || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" |
|
|
73 | . (sprintf " [rtt %.3fs/%.3f]", $pl->socket->rtt * 1e-6, $pl->socket->rttvar * 1e-6) |
|
|
74 | . ($privileged ? " " . $pl->socket->host : "") |
|
|
75 | } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl |
|
|
76 | ), |
|
|
77 | eval { "* IRC: " . join ", ", ext::schmorp_irc::users }, |
|
|
78 | ) |
|
|
79 | } |
|
|
80 | |
41 | cf::register_command rename => 0, sub { |
81 | cf::register_command who => sub { |
42 | my ($ob, $arg) = @_; |
82 | my ($ob, $arg) = @_; |
43 | |
83 | |
44 | warn "<<<$arg>>>\n";#d# |
84 | $ob->speed_left ($ob->speed_left - 0.25); |
45 | |
85 | |
|
|
86 | $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
|
|
87 | |
|
|
88 | 1 |
|
|
89 | }; |
|
|
90 | |
|
|
91 | cf::register_command rename => sub { |
|
|
92 | my ($ob, $arg) = @_; |
|
|
93 | |
|
|
94 | $ob->speed_left ($ob->speed_left - 0.25); |
|
|
95 | |
46 | if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]+)> \s*$/x) { |
96 | if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]*)> \s*$/x) { |
47 | # compatibility syntax |
97 | # compatibility syntax |
48 | rename_to $ob, $1, $2; |
98 | rename_to $ob, $1, $2; |
49 | } elsif ($arg =~ / |
99 | } elsif ($arg =~ / |
50 | ^\s* |
100 | ^\s* |
51 | (?: |
101 | (?: |
… | |
… | |
56 | \s*$ |
106 | \s*$ |
57 | /x) { |
107 | /x) { |
58 | # does not unquote $1 or $3 |
108 | # does not unquote $1 or $3 |
59 | rename_to $ob, $2||$1, $4||$3; |
109 | rename_to $ob, $2||$1, $4||$3; |
60 | } else { |
110 | } else { |
61 | $ob->message ('Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
111 | $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
62 | } |
112 | } |
|
|
113 | |
|
|
114 | 1 |
63 | }; |
115 | }; |
|
|
116 | |
|
|
117 | cf::register_command uptime => sub { |
|
|
118 | my ($ob, $arg) = @_; |
|
|
119 | |
|
|
120 | my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; |
|
|
121 | my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; |
|
|
122 | $ob->reply (undef, "server started $startup, uptime ${runtime}\d"); |
|
|
123 | |
|
|
124 | 1 |
|
|
125 | }; |
|
|
126 | |