… | |
… | |
47 | cf::register_command who => sub { |
47 | cf::register_command who => sub { |
48 | my ($ob, $arg) = @_; |
48 | my ($ob, $arg) = @_; |
49 | |
49 | |
50 | $ob->speed_left ($ob->speed_left - 4); |
50 | $ob->speed_left ($ob->speed_left - 4); |
51 | |
51 | |
52 | my $CHANNEL = { |
|
|
53 | id => "who", |
|
|
54 | title => "Players", |
|
|
55 | reply => undef, |
|
|
56 | tooltip => "Shows players who are currently online", |
|
|
57 | }; |
|
|
58 | |
|
|
59 | $ob->send_msg ($CHANNEL => (join "\n\n", who_listing $ob->may ("extended_who"), $arg), cf::NDI_DK_ORANGE | cf::NDI_REPLY | cf::NDI_CLEAR | cf::NDI_DEF); |
52 | $ob->send_msg ("c/who" => (join "\r", who_listing $ob->may ("extended_who"), $arg), cf::NDI_DK_ORANGE | cf::NDI_REPLY | cf::NDI_CLEAR | cf::NDI_DEF); |
60 | }; |
53 | }; |
61 | |
54 | |
62 | cf::register_command seen => sub { |
55 | cf::register_command seen => sub { |
63 | my ($pl, $args) = @_; |
56 | my ($pl, $args) = @_; |
64 | |
57 | |
|
|
58 | cf::async { |
65 | if (my ($login) = $args =~ /(\S+)/) { |
59 | if (my ($login) = $args =~ /(\S+)/) { |
66 | if ($login eq $pl->name) { |
60 | if ($login eq $pl->name) { |
67 | $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_REPLY); |
61 | $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_REPLY); |
68 | } elsif (cf::player::find_active $login) { |
62 | } elsif (cf::player::find_active $login) { |
69 | $pl->message ("$login is right here on this server!", cf::NDI_REPLY); |
63 | $pl->message ("$login is right here on this server!", cf::NDI_REPLY); |
70 | } elsif (cf::player::exists $login |
64 | } elsif (cf::player::exists $login |
71 | and stat cf::player::path $login) { |
65 | and stat cf::player::path $login) { |
72 | my $time = (stat _)[9]; |
66 | my $time = (stat _)[9]; |
73 | |
67 | |
74 | $pl->message ("$login was last seen here " |
68 | $pl->message ("$login was last seen here " |
75 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
69 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
76 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_REPLY); |
70 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_REPLY); |
|
|
71 | } else { |
|
|
72 | $pl->message ("No player named $login is known to me.", cf::NDI_REPLY); |
|
|
73 | } |
77 | } else { |
74 | } else { |
78 | $pl->message ("No player named $login is known to me.", cf::NDI_REPLY); |
75 | $pl->message ("Usage: seen <player>", cf::NDI_REPLY); |
79 | } |
76 | } |
80 | } else { |
|
|
81 | $pl->message ("Usage: seen <player>", cf::NDI_REPLY); |
|
|
82 | } |
77 | }; |
83 | }; |
78 | }; |
84 | |
79 | |
85 | cf::register_command body => sub { |
80 | cf::register_command body => sub { |
86 | my ($ob) = @_; |
81 | my ($ob) = @_; |
87 | |
82 | |
88 | # Too hard to try and make a header that lines everything up, so just |
83 | # Too hard to try and make a header that lines everything up, so just |
89 | # give a description. (comment from C++) |
84 | # give a description. (comment from C++) |
90 | my $reply = |
85 | my $reply = |
91 | "The first column is the name of the body location.\n\n" |
86 | "The first column is the name of the body location.\r" |
92 | . "The second column is how many of those locations your body has.\n\n" |
87 | . "The second column is how many of those locations your body has.\r" |
93 | . "The third column is how many slots in that location are available.\n\n"; |
88 | . "The third column is how many slots in that location are available.\r" |
|
|
89 | . "The last column shows the items currently using the slot\n\n"; |
94 | |
90 | |
|
|
91 | # first process all applied items and hash them into their slots |
|
|
92 | my @slot; |
|
|
93 | |
|
|
94 | for my $item (grep $_->flag (cf::FLAG_APPLIED), $ob->inv) { |
|
|
95 | $item->slot_info ($_) |
|
|
96 | and push @{ $slot[$_] }, $item |
|
|
97 | for 0 .. cf::NUM_BODY_LOCATIONS-1; |
|
|
98 | } |
|
|
99 | |
95 | $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail"; |
100 | $reply .= sprintf " %-20s %3s %5s %s\n", "Location", "You", "Avail", "What"; |
96 | for (0 .. cf::NUM_BODY_LOCATIONS - 1) { |
101 | for (0 .. cf::NUM_BODY_LOCATIONS - 1) { |
97 | my $msg = cf::object::slot_nonuse_name $_; |
102 | my $msg = cf::object::slot_nonuse_name $_; |
98 | $msg =~ s/^.*? a //; |
103 | $msg =~ s/^.*? a //; |
99 | $reply .= sprintf " %-20s %3d %5d\n", $msg, $ob->slot_info ($_), $ob->slot_used ($_) |
104 | $reply .= sprintf " %-20s %3d %5d %s\n", |
|
|
105 | $msg, |
|
|
106 | $ob->slot_info ($_), |
|
|
107 | $ob->slot_used ($_), |
|
|
108 | join ", ", map $_->query_short_name, @{ $slot[$_] } |
100 | if $ob->slot_info ($_) or $ob->slot_used ($_); |
109 | if $ob->slot_info ($_) || $ob->slot_used ($_); |
101 | } |
110 | } |
102 | |
111 | |
103 | $reply .= "You are not allowed to wear armor\n\n" |
112 | $reply .= "You are not allowed to wear armor\r" |
104 | unless $ob->flag (cf::FLAG_USE_ARMOUR); |
113 | unless $ob->flag (cf::FLAG_USE_ARMOUR); |
105 | $reply .= "You are not allowed to use weapons\n\n" |
114 | $reply .= "You are not allowed to use weapons\r" |
106 | unless $ob->flag (cf::FLAG_USE_WEAPON); |
115 | unless $ob->flag (cf::FLAG_USE_WEAPON); |
107 | |
116 | |
108 | my $CHANNEL = { |
|
|
109 | id => "body", |
|
|
110 | title => "Body Parts", |
|
|
111 | reply => undef, |
|
|
112 | tooltip => "Shows which body parts you posess and are available", |
|
|
113 | }; |
|
|
114 | |
|
|
115 | $ob->send_msg ($CHANNEL => $reply, cf::NDI_REPLY); |
117 | $ob->send_msg ("c/body" => $reply, cf::NDI_REPLY); |
116 | }; |
118 | }; |
117 | |
119 | |
118 | cf::register_command mark => sub { |
120 | cf::register_command mark => sub { |
119 | my ($pl, $arg) = @_; |
121 | my ($pl, $arg) = @_; |
120 | |
122 | |
… | |
… | |
152 | |
154 | |
153 | $ob->contr->$oncmd (0); |
155 | $ob->contr->$oncmd (0); |
154 | }; |
156 | }; |
155 | } |
157 | } |
156 | |
158 | |
157 | our $MAPINFO_CHANNEL = { |
|
|
158 | id => "mapinfo", |
|
|
159 | title => "Map Info", |
|
|
160 | reply => undef, |
|
|
161 | tooltip => "Information about the map", |
|
|
162 | }; |
|
|
163 | |
|
|
164 | cf::register_command mapinfo => sub { |
159 | cf::register_command mapinfo => sub { |
165 | my ($ob) = @_; |
160 | my ($ob) = @_; |
166 | |
161 | |
167 | my $observe = $ob->contr->observe; |
162 | my $observe = $ob->contr->observe; |
168 | |
163 | |
169 | my $map = $observe->map |
164 | my $map = $observe->map |
170 | or return; |
165 | or return; |
171 | |
166 | |
172 | my $msg = sprintf "%s (%s) %s", $map->name, $map->path, $observe->region->longname; |
167 | my $msg = sprintf "%s (%s)\r%s", $map->name, $map->path, $observe->region->longname; |
173 | $msg .= sprintf "\n\nplayers: %d difficulty: %d size: %d start: %dx%d timeout: %d", |
168 | $msg .= sprintf "\rplayers: %d difficulty: %d size: %d start: %dx%d timeout: %d", |
174 | (scalar $map->players), $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout |
169 | (scalar $map->players), $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout |
175 | if $ob->flag (cf::FLAG_WIZ); |
170 | if $ob->flag (cf::FLAG_WIZ); |
176 | |
171 | |
177 | $ob->send_msg ($MAPINFO_CHANNEL => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); |
172 | $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); |
178 | }; |
173 | }; |
179 | |
174 | |
180 | cf::register_command whereami => sub { |
175 | cf::register_command whereami => sub { |
181 | my ($ob) = @_; |
176 | my ($ob) = @_; |
182 | |
177 | |
183 | my $reg = $ob->contr->observe->region; |
178 | my $reg = $ob->contr->observe->region; |
184 | $ob->send_msg ($MAPINFO_CHANNEL => (sprintf "You are %s.\n%s", $reg->longname, $reg->msg), cf::NDI_REPLY | cf::NDI_CLEAR); |
179 | $ob->send_msg ("c/who" => (sprintf "You are %s.\n\n%s", $reg->longname, $reg->msg), cf::NDI_REPLY | cf::NDI_CLEAR); |
185 | }; |
180 | }; |
186 | |
181 | |
187 | cf::register_command whereabouts => sub { |
182 | cf::register_command whereabouts => sub { |
188 | my ($ob, $arg) = @_; |
183 | my ($ob, $arg) = @_; |
189 | |
184 | |
… | |
… | |
191 | |
186 | |
192 | for my $pl (cf::player::list) { |
187 | for my $pl (cf::player::list) { |
193 | ++$count{$pl->ob->region->longname}; |
188 | ++$count{$pl->ob->region->longname}; |
194 | } |
189 | } |
195 | |
190 | |
196 | my $msg = "In the world currently there are:\n\n" |
191 | my $msg = "T<In the world currently there are:>\n\n" |
197 | . join "", map "$count{$_} player(s) $_\n\n", sort keys %count; |
192 | . join "", map { sprintf " C<%3d >player(s) %s\r", $count{$_}, $_ } sort keys %count; |
198 | |
193 | |
199 | $ob->send_msg ($MAPINFO_CHANNEL => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); |
194 | $ob->send_msg ("c/who" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); |
200 | }; |
195 | }; |
201 | |
196 | |
202 | cf::register_command hiscore => sub { |
197 | cf::register_command hiscore => sub { |
203 | my ($ob, $arg) = @_; |
198 | my ($ob, $arg) = @_; |
204 | |
199 | |
205 | my $url = $cf::CFG->{hiscore_url}; |
200 | my $url = $cf::CFG{hiscore_url}; |
206 | $ob->send_msg (log => "See $url", cf::NDI_REPLY); |
201 | $ob->send_msg (log => "See $url", cf::NDI_REPLY); |
207 | }; |
202 | }; |
208 | |
203 | |
209 | sub _set_mode($$$@) { |
204 | sub _set_mode($$$@) { |
210 | my ($name, $ob, $arg, $slot, @choices) = @_; |
205 | my ($name, $ob, $arg, $slot, @choices) = @_; |
… | |
… | |
391 | cf::register_command uptime => sub { |
386 | cf::register_command uptime => sub { |
392 | my ($ob, $arg) = @_; |
387 | my ($ob, $arg) = @_; |
393 | |
388 | |
394 | my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; |
389 | my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; |
395 | my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; |
390 | my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; |
396 | $ob->send_msg (log => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY); |
391 | $ob->send_msg ("c/uptime" => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY | cf::NDI_CLEAR); |
397 | }; |
392 | }; |
398 | |
393 | |
399 | my %IN_MEMORY = ( |
394 | my %IN_MEMORY = ( |
400 | cf::MAP_IN_MEMORY => "I", |
395 | cf::MAP_ACTIVE => "I", |
401 | cf::MAP_SWAPPED => "S", |
396 | cf::MAP_SWAPPED => "S", |
402 | cf::MAP_LOADING => "L", |
397 | cf::MAP_LOADING => "L", |
403 | ); |
398 | ); |
404 | |
399 | |
405 | cf::register_command maps => sub { |
400 | cf::register_command maps => sub { |
406 | my ($ob, $arg) = @_; |
401 | my ($ob, $arg) = @_; |
407 | |
402 | |
408 | no re 'eval'; $arg = qr<$arg>; |
403 | no re 'eval'; $arg = qr<$arg>; |
409 | |
404 | |
410 | my $format = "%2s %1s %3s %5s %.60s\n"; |
405 | my $format = " %2s %1s %3s %5s %.60s\n"; |
411 | |
406 | |
412 | $ob->send_msg ($MAPINFO_CHANNEL => (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_REPLY | cf::NDI_CLEAR); |
407 | my $msg = "\n" . sprintf $format, "Pl", "I", "Svd", "Reset", "Name"; |
413 | |
408 | |
414 | for (sort keys %cf::MAP) { |
409 | for (sort keys %cf::MAP) { |
415 | my $map = $cf::MAP{$_} |
410 | my $map = $cf::MAP{$_} |
416 | or next; |
411 | or next; |
417 | |
412 | |
… | |
… | |
419 | next if $map->{deny_list}; |
414 | next if $map->{deny_list}; |
420 | |
415 | |
421 | my $svd = int $cf::RUNTIME - $map->{last_save}; |
416 | my $svd = int $cf::RUNTIME - $map->{last_save}; |
422 | $svd = "++" if $svd > 99; |
417 | $svd = "++" if $svd > 99; |
423 | |
418 | |
424 | $ob->send_msg ($MAPINFO_CHANNEL => |
419 | $msg .= sprintf $format, |
425 | (sprintf $format, |
|
|
426 | (scalar $map->players), |
420 | (scalar $map->players), |
427 | $IN_MEMORY{$map->in_memory} || "?", |
421 | $IN_MEMORY{$map->in_memory} || "?", |
428 | $svd, |
422 | $svd, |
429 | (int $map->reset_at - $cf::RUNTIME), |
423 | (int $map->reset_at - $cf::RUNTIME), |
430 | $map->visible_name) |
424 | $map->visible_name; |
431 | ); |
|
|
432 | } |
425 | } |
433 | }; |
|
|
434 | |
426 | |
|
|
427 | $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); |
|
|
428 | }; |
|
|
429 | |