ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/commands.ext
(Generate patch)

Comparing deliantra/server/ext/commands.ext (file contents):
Revision 1.63 by root, Sun Oct 7 15:52:05 2007 UTC vs.
Revision 1.71 by root, Tue Sep 23 00:24:52 2008 UTC

47cf::register_command who => sub { 47cf::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
62cf::register_command seen => sub { 55cf::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
85cf::register_command body => sub { 80cf::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.\n\n";
94 89
95 $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail"; 90 $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail";
96 for (0 .. cf::NUM_BODY_LOCATIONS - 1) { 91 for (0 .. cf::NUM_BODY_LOCATIONS - 1) {
97 my $msg = cf::object::slot_nonuse_name $_; 92 my $msg = cf::object::slot_nonuse_name $_;
98 $msg =~ s/^.*? a //; 93 $msg =~ s/^.*? a //;
99 $reply .= sprintf " %-20s %3d %5d\n", $msg, $ob->slot_info ($_), $ob->slot_used ($_) 94 $reply .= sprintf " %-20s %3d %5d\n", $msg, $ob->slot_info ($_), $ob->slot_used ($_)
100 if $ob->slot_info ($_) or $ob->slot_used ($_); 95 if $ob->slot_info ($_) or $ob->slot_used ($_);
101 } 96 }
102 97
103 $reply .= "You are not allowed to wear armor\n\n" 98 $reply .= "You are not allowed to wear armor\r"
104 unless $ob->flag (cf::FLAG_USE_ARMOUR); 99 unless $ob->flag (cf::FLAG_USE_ARMOUR);
105 $reply .= "You are not allowed to use weapons\n\n" 100 $reply .= "You are not allowed to use weapons\r"
106 unless $ob->flag (cf::FLAG_USE_WEAPON); 101 unless $ob->flag (cf::FLAG_USE_WEAPON);
107 102
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); 103 $ob->send_msg ("c/body" => $reply, cf::NDI_REPLY);
116}; 104};
117 105
118cf::register_command mark => sub { 106cf::register_command mark => sub {
119 my ($pl, $arg) = @_; 107 my ($pl, $arg) = @_;
120 108
152 140
153 $ob->contr->$oncmd (0); 141 $ob->contr->$oncmd (0);
154 }; 142 };
155} 143}
156 144
157our $MAPINFO_CHANNEL = {
158 id => "mapinfo",
159 title => "Map Info",
160 reply => undef,
161 tooltip => "Information about the map",
162};
163
164cf::register_command mapinfo => sub { 145cf::register_command mapinfo => sub {
165 my ($ob) = @_; 146 my ($ob) = @_;
166 147
167 my $observe = $ob->contr->observe; 148 my $observe = $ob->contr->observe;
168 149
169 my $map = $observe->map 150 my $map = $observe->map
170 or return; 151 or return;
171 152
172 my $msg = sprintf "%s (%s) %s", $map->name, $map->path, $observe->region->longname; 153 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", 154 $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 155 (scalar $map->players), $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout
175 if $ob->flag (cf::FLAG_WIZ); 156 if $ob->flag (cf::FLAG_WIZ);
176 157
177 $ob->send_msg ($MAPINFO_CHANNEL => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); 158 $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
178}; 159};
179 160
180cf::register_command whereami => sub { 161cf::register_command whereami => sub {
181 my ($ob) = @_; 162 my ($ob) = @_;
182 163
183 my $reg = $ob->contr->observe->region; 164 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); 165 $ob->send_msg ("c/who" => (sprintf "You are %s.\n\n%s", $reg->longname, $reg->msg), cf::NDI_REPLY | cf::NDI_CLEAR);
185}; 166};
186 167
187cf::register_command whereabouts => sub { 168cf::register_command whereabouts => sub {
188 my ($ob, $arg) = @_; 169 my ($ob, $arg) = @_;
189 170
191 172
192 for my $pl (cf::player::list) { 173 for my $pl (cf::player::list) {
193 ++$count{$pl->ob->region->longname}; 174 ++$count{$pl->ob->region->longname};
194 } 175 }
195 176
196 my $msg = "In the world currently there are:\n\n" 177 my $msg = "T<In the world currently there are:>\n\n"
197 . join "", map "$count{$_} player(s) $_\n\n", sort keys %count; 178 . join "", map { sprintf " C<%3d >player(s) %s\r", $count{$_}, $_ } sort keys %count;
198 179
199 $ob->send_msg ($MAPINFO_CHANNEL => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); 180 $ob->send_msg ("c/who" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
200}; 181};
201 182
202cf::register_command hiscore => sub { 183cf::register_command hiscore => sub {
203 my ($ob, $arg) = @_; 184 my ($ob, $arg) = @_;
204 185
391cf::register_command uptime => sub { 372cf::register_command uptime => sub {
392 my ($ob, $arg) = @_; 373 my ($ob, $arg) = @_;
393 374
394 my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; 375 my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME;
395 my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; 376 my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400;
396 $ob->send_msg (log => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY); 377 $ob->send_msg ("c/uptime" => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY | cf::NDI_CLEAR);
397}; 378};
398 379
399my %IN_MEMORY = ( 380my %IN_MEMORY = (
400 cf::MAP_IN_MEMORY => "I", 381 cf::MAP_ACTIVE => "I",
401 cf::MAP_SWAPPED => "S", 382 cf::MAP_SWAPPED => "S",
402 cf::MAP_LOADING => "L", 383 cf::MAP_LOADING => "L",
403); 384);
404 385
405cf::register_command maps => sub { 386cf::register_command maps => sub {
406 my ($ob, $arg) = @_; 387 my ($ob, $arg) = @_;
407 388
408 no re 'eval'; $arg = qr<$arg>; 389 no re 'eval'; $arg = qr<$arg>;
409 390
410 my $format = "%2s %1s %3s %5s %.60s\n"; 391 my $format = " %2s %1s %3s %5s %.60s\n";
411 392
412 $ob->send_msg ($MAPINFO_CHANNEL => (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_REPLY | cf::NDI_CLEAR); 393 my $msg = "\n" . sprintf $format, "Pl", "I", "Svd", "Reset", "Name";
413 394
414 for (sort keys %cf::MAP) { 395 for (sort keys %cf::MAP) {
415 my $map = $cf::MAP{$_} 396 my $map = $cf::MAP{$_}
416 or next; 397 or next;
417 398
419 next if $map->{deny_list}; 400 next if $map->{deny_list};
420 401
421 my $svd = int $cf::RUNTIME - $map->{last_save}; 402 my $svd = int $cf::RUNTIME - $map->{last_save};
422 $svd = "++" if $svd > 99; 403 $svd = "++" if $svd > 99;
423 404
424 $ob->send_msg ($MAPINFO_CHANNEL => 405 $msg .= sprintf $format,
425 (sprintf $format,
426 (scalar $map->players), 406 (scalar $map->players),
427 $IN_MEMORY{$map->in_memory} || "?", 407 $IN_MEMORY{$map->in_memory} || "?",
428 $svd, 408 $svd,
429 (int $map->reset_at - $cf::RUNTIME), 409 (int $map->reset_at - $cf::RUNTIME),
430 $map->visible_name) 410 $map->visible_name;
431 );
432 } 411 }
433};
434 412
413 $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
414};
415

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines