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) = @_; |
… | |
… | |
31 | $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."); |
32 | } |
34 | } |
33 | |
35 | |
34 | $ob->esrv_update_item (cf::UPD_NAME, $item); |
36 | $ob->esrv_update_item (cf::UPD_NAME, $item); |
35 | |
37 | |
36 | return 1; |
38 | 1 |
37 | } |
39 | } |
38 | |
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->client . "]" |
|
|
72 | . " [" . ($pl->peaceful || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" |
|
|
73 | . ($privileged ? " " . $pl->host : "") |
|
|
74 | } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl |
|
|
75 | ), |
|
|
76 | eval { "* IRC: " . join ", ", ext::schmorp_irc::users }, |
|
|
77 | ) |
|
|
78 | } |
|
|
79 | |
39 | cf::register_command rename => 0, sub { |
80 | cf::register_command who => sub { |
40 | my ($ob, $arg) = @_; |
81 | my ($ob, $arg) = @_; |
41 | |
82 | |
|
|
83 | $ob->speed_left ($ob->speed_left - 0.25); |
|
|
84 | |
|
|
85 | $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
|
|
86 | |
|
|
87 | 1 |
|
|
88 | }; |
|
|
89 | |
|
|
90 | cf::register_command rename => sub { |
|
|
91 | my ($ob, $arg) = @_; |
|
|
92 | |
|
|
93 | $ob->speed_left ($ob->speed_left - 0.25); |
|
|
94 | |
42 | if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]+)> \s*$/x) { |
95 | if ($arg =~ /^\s* (?: <([^>]+)> \s+)? to \s+ <([^>]*)> \s*$/x) { |
43 | # compatibility syntax |
96 | # compatibility syntax |
44 | rename_to $ob, $1, $2; |
97 | rename_to $ob, $1, $2; |
45 | } elsif ($arg =~ / |
98 | } elsif ($arg =~ / |
46 | ^\s* |
99 | ^\s* |
47 | (?: |
100 | (?: |
… | |
… | |
52 | \s*$ |
105 | \s*$ |
53 | /x) { |
106 | /x) { |
54 | # does not unquote $1 or $3 |
107 | # does not unquote $1 or $3 |
55 | rename_to $ob, $2||$1, $4||$3; |
108 | rename_to $ob, $2||$1, $4||$3; |
56 | } else { |
109 | } else { |
57 | $ob->message ('Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
110 | $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
58 | } |
111 | } |
|
|
112 | |
|
|
113 | 1 |
59 | }; |
114 | }; |
|
|
115 | |
|
|
116 | cf::register_command uptime => sub { |
|
|
117 | my ($ob, $arg) = @_; |
|
|
118 | |
|
|
119 | my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; |
|
|
120 | my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; |
|
|
121 | $ob->reply (undef, "server started $startup, uptime ${runtime}\d"); |
|
|
122 | |
|
|
123 | 1 |
|
|
124 | }; |
|
|
125 | |