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 | } |
|
|
40 | |
|
|
41 | sub ext::schmorp_irc::users; # HACK: TODO: replace by signal |
38 | |
42 | |
39 | sub who_listing(;$) { |
43 | sub who_listing(;$) { |
40 | my ($privileged) = @_; |
44 | my ($privileged) = @_; |
41 | |
45 | |
42 | my ($numwiz, $numafk) = (0, 0); |
46 | my ($numwiz, $numafk) = (0, 0); |
… | |
… | |
54 | push @pl, $pl; |
58 | push @pl, $pl; |
55 | } |
59 | } |
56 | |
60 | |
57 | ( |
61 | ( |
58 | "Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)", |
62 | "Total Players in The World. (" . (scalar @pl) . ") -- WIZ($numwiz) AFK($numafk) BOT(0)", |
|
|
63 | ( |
59 | map { |
64 | map { |
60 | my ($pl, $ob) = ($_, $_->ob); |
65 | my ($pl, $ob) = ($_, $_->ob); |
61 | |
66 | |
62 | "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) |
67 | "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) |
63 | . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") |
68 | . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") |
64 | . ($ob->flag (cf::FLAG_AFK) ? " [AFK]" : "") |
69 | . ($ob->flag (cf::FLAG_AFK) ? " [AFK]" : "") |
65 | . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") |
70 | . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") |
66 | . " [" . $pl->client . "]" |
71 | . " [" . $pl->client . "]" |
67 | . " [" . ($pl->peaceful || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" |
72 | . " [" . ($pl->peaceful || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" |
68 | . ($privileged ? " " . $pl->host : "") |
73 | . ($privileged ? " " . $pl->host : "") |
69 | } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl |
74 | } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl |
|
|
75 | ), |
|
|
76 | eval { "* IRC: " . join ", ", ext::schmorp_irc::users }, |
70 | ) |
77 | ) |
71 | } |
78 | } |
72 | |
79 | |
73 | cf::register_command who => $cf::TICK, sub { |
80 | cf::register_command who => $cf::TICK, sub { |
74 | my ($ob, $arg) = @_; |
81 | my ($ob, $arg) = @_; |
75 | |
82 | |
76 | $ob->reply (undef, (join "\n", who_listing $ob->flag (cf::FLAG_WIZ)), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
83 | $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); |
|
|
84 | |
|
|
85 | 1 |
77 | }; |
86 | }; |
78 | |
87 | |
79 | cf::register_command rename => $cf::TICK, sub { |
88 | cf::register_command rename => $cf::TICK, sub { |
80 | my ($ob, $arg) = @_; |
89 | my ($ob, $arg) = @_; |
81 | |
90 | |
… | |
… | |
94 | # does not unquote $1 or $3 |
103 | # does not unquote $1 or $3 |
95 | rename_to $ob, $2||$1, $4||$3; |
104 | rename_to $ob, $2||$1, $4||$3; |
96 | } else { |
105 | } else { |
97 | $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
106 | $ob->reply (undef, 'Syntax error. Rename usage: rename ["oldname"] to "newname"'); |
98 | } |
107 | } |
|
|
108 | |
|
|
109 | 1 |
99 | }; |
110 | }; |
|
|
111 | |
|
|
112 | cf::register_command uptime => 0, sub { |
|
|
113 | my ($ob, $arg) = @_; |
|
|
114 | |
|
|
115 | my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; |
|
|
116 | my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; |
|
|
117 | $ob->reply (undef, "server started $startup, uptime ${runtime}\d"); |
|
|
118 | |
|
|
119 | 1 |
|
|
120 | }; |
|
|
121 | |