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.58 by root, Fri Aug 10 05:25:16 2007 UTC vs.
Revision 1.72 by root, Sun Jan 11 06:08:40 2009 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 $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who"), $arg), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); 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);
53}; 53};
54 54
55cf::register_command seen => sub { 55cf::register_command seen => sub {
56 my ($pl, $args) = @_; 56 my ($pl, $args) = @_;
57 57
58 cf::async {
58 if (my ($login) = $args =~ /(\S+)/) { 59 if (my ($login) = $args =~ /(\S+)/) {
59 if ($login eq $pl->name) { 60 if ($login eq $pl->name) {
60 $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); 61 $pl->message ("Very funny, $login. Ha. Ha.", cf::NDI_REPLY);
61 } elsif (cf::player::find_active $login) { 62 } elsif (cf::player::find_active $login) {
62 $pl->message ("$login is right here on this server!", cf::NDI_UNIQUE); 63 $pl->message ("$login is right here on this server!", cf::NDI_REPLY);
63 } elsif (cf::player::exists $login 64 } elsif (cf::player::exists $login
64 and stat cf::player::path $login) { 65 and stat cf::player::path $login) {
65 my $time = (stat _)[9]; 66 my $time = (stat _)[9];
66 67
67 $pl->message ("$login was last seen here " 68 $pl->message ("$login was last seen here "
68 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) 69 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
69 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); 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 }
70 } else { 74 } else {
71 $pl->message ("No player named $login is known to me.", cf::NDI_UNIQUE); 75 $pl->message ("Usage: seen <player>", cf::NDI_REPLY);
72 } 76 }
73 } else {
74 $pl->message ("Usage: seen <player>", cf::NDI_UNIQUE);
75 } 77 };
76}; 78};
77 79
78cf::register_command body => sub { 80cf::register_command body => sub {
79 my ($ob) = @_; 81 my ($ob) = @_;
80 82
81 # 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
82 # give a description. (comment from C++) 84 # give a description. (comment from C++)
83 my $reply = 85 my $reply =
84 "The first column is the name of the body location.\n\n" 86 "The first column is the name of the body location.\r"
85 . "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"
86 . "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";
87 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
88 $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail"; 100 $reply .= sprintf " %-20s %3s %5s %s\n", "Location", "You", "Avail", "What";
89 for (0 .. cf::NUM_BODY_LOCATIONS - 1) { 101 for (0 .. cf::NUM_BODY_LOCATIONS - 1) {
90 my $msg = cf::object::slot_nonuse_name $_; 102 my $msg = cf::object::slot_nonuse_name $_;
91 $msg =~ s/^.*? a //; 103 $msg =~ s/^.*? a //;
92 $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[$_] }
93 if $ob->slot_info ($_) or $ob->slot_used ($_); 109 if $ob->slot_info ($_) || $ob->slot_used ($_);
94 } 110 }
95 111
96 $reply .= "You are not allowed to wear armor\n\n" 112 $reply .= "You are not allowed to wear armor\r"
97 unless $ob->flag (cf::FLAG_USE_ARMOUR); 113 unless $ob->flag (cf::FLAG_USE_ARMOUR);
98 $reply .= "You are not allowed to use weapons\n\n" 114 $reply .= "You are not allowed to use weapons\r"
99 unless $ob->flag (cf::FLAG_USE_WEAPON); 115 unless $ob->flag (cf::FLAG_USE_WEAPON);
100 116
101 $ob->reply (undef, $reply); 117 $ob->send_msg ("c/body" => $reply, cf::NDI_REPLY);
102}; 118};
103 119
104cf::register_command mark => sub { 120cf::register_command mark => sub {
105 my ($pl, $arg) = @_; 121 my ($pl, $arg) = @_;
106 122
145 161
146 my $observe = $ob->contr->observe; 162 my $observe = $ob->contr->observe;
147 163
148 my $map = $observe->map 164 my $map = $observe->map
149 or return; 165 or return;
166
150 $ob->reply (undef, (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;
151 $ob->reply (undef, (sprintf "players: %d difficulty: %d size: %d start: %dx%d timeout: %d", 168 $msg .= sprintf "\rplayers: %d difficulty: %d size: %d start: %dx%d timeout: %d",
152 (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
153 if $ob->flag (cf::FLAG_WIZ); 170 if $ob->flag (cf::FLAG_WIZ);
154 $ob->reply (undef, $map->msg); 171
172 $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
155}; 173};
156 174
157cf::register_command whereami => sub { 175cf::register_command whereami => sub {
158 my ($ob) = @_; 176 my ($ob) = @_;
159 177
160 my $reg = $ob->contr->observe->region; 178 my $reg = $ob->contr->observe->region;
161 $ob->reply (undef, (sprintf "You are %s.\n%s", $reg->longname, $reg->msg)); 179 $ob->send_msg ("c/who" => (sprintf "You are %s.\n\n%s", $reg->longname, $reg->msg), cf::NDI_REPLY | cf::NDI_CLEAR);
162}; 180};
163 181
164cf::register_command whereabouts => sub { 182cf::register_command whereabouts => sub {
165 my ($ob, $arg) = @_; 183 my ($ob, $arg) = @_;
166 184
168 186
169 for my $pl (cf::player::list) { 187 for my $pl (cf::player::list) {
170 ++$count{$pl->ob->region->longname}; 188 ++$count{$pl->ob->region->longname};
171 } 189 }
172 190
173 my $msg = "In the world currently there are:\n\n" 191 my $msg = "T<In the world currently there are:>\n\n"
174 . join "", map "$count{$_} player(s) in $_\n\n", sort keys %count; 192 . join "", map { sprintf " C<%3d >player(s) %s\r", $count{$_}, $_ } sort keys %count;
175 193
176 $ob->contr->ns->send_msg (log => $msg, cf::NDI_REPLY); 194 $ob->send_msg ("c/who" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
177}; 195};
178 196
179cf::register_command hiscore => sub { 197cf::register_command hiscore => sub {
180 my ($ob, $arg) = @_; 198 my ($ob, $arg) = @_;
181 199
182 my $url = $cf::CFG->{hiscore_url}; 200 my $url = $cf::CFG{hiscore_url};
183 $ob->contr->ns->send_msg (log => "See $url", cf::NDI_REPLY); 201 $ob->send_msg (log => "See $url", cf::NDI_REPLY);
184}; 202};
185 203
186sub _set_mode($$$@) { 204sub _set_mode($$$@) {
187 my ($name, $ob, $arg, $slot, @choices) = @_; 205 my ($name, $ob, $arg, $slot, @choices) = @_;
188 206
368cf::register_command uptime => sub { 386cf::register_command uptime => sub {
369 my ($ob, $arg) = @_; 387 my ($ob, $arg) = @_;
370 388
371 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;
372 my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; 390 my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400;
373 $ob->reply (undef, "server started $startup, uptime ${runtime}\d"); 391 $ob->send_msg ("c/uptime" => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY | cf::NDI_CLEAR);
374}; 392};
375 393
376my %IN_MEMORY = ( 394my %IN_MEMORY = (
377 cf::MAP_IN_MEMORY => "I", 395 cf::MAP_ACTIVE => "I",
378 cf::MAP_SWAPPED => "S", 396 cf::MAP_SWAPPED => "S",
379 cf::MAP_LOADING => "L", 397 cf::MAP_LOADING => "L",
380); 398);
381 399
382cf::register_command maps => sub { 400cf::register_command maps => sub {
383 my ($ob, $arg) = @_; 401 my ($ob, $arg) = @_;
384 402
385 no re 'eval'; $arg = qr<$arg>; 403 no re 'eval'; $arg = qr<$arg>;
386 404
387 my $format = "%2s %1s %3s %5s %.60s\n"; 405 my $format = " %2s %1s %3s %5s %.60s\n";
388 406
389 $ob->reply (undef, (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_BLACK | cf::NDI_UNIQUE); 407 my $msg = "\n" . sprintf $format, "Pl", "I", "Svd", "Reset", "Name";
390 408
391 for (sort keys %cf::MAP) { 409 for (sort keys %cf::MAP) {
392 my $map = $cf::MAP{$_} 410 my $map = $cf::MAP{$_}
393 or next; 411 or next;
394 412
396 next if $map->{deny_list}; 414 next if $map->{deny_list};
397 415
398 my $svd = int $cf::RUNTIME - $map->{last_save}; 416 my $svd = int $cf::RUNTIME - $map->{last_save};
399 $svd = "++" if $svd > 99; 417 $svd = "++" if $svd > 99;
400 418
401 $ob->reply (undef, 419 $msg .= sprintf $format,
402 (sprintf $format,
403 (scalar $map->players), 420 (scalar $map->players),
404 $IN_MEMORY{$map->in_memory} || "?", 421 $IN_MEMORY{$map->in_memory} || "?",
405 $svd, 422 $svd,
406 (int $map->reset_at - $cf::RUNTIME), 423 (int $map->reset_at - $cf::RUNTIME),
407 $map->visible_name), 424 $map->visible_name;
408 cf::NDI_BLACK | cf::NDI_UNIQUE);
409 } 425 }
410};
411 426
427 $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
428};
429

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines