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.76 by root, Mon Apr 12 05:22:37 2010 UTC

32 "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) 32 "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title)
33 . ($pl->gender ? " [f]" : " [m]") 33 . ($pl->gender ? " [f]" : " [m]")
34 . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") 34 . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]")
35 . ($ns->afk ? " [AFK]" : "") 35 . ($ns->afk ? " [AFK]" : "")
36 . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") 36 . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "")
37 . " [" . $pl->ns->version . "]" 37 . " [" . $pl->ns->{who_version} . "]"
38 . " [" . ($pl->peaceful || $privileged ? $ob->map->visible_name : $ob->region->name) . "]" 38 . " [" . ($pl->peaceful || $privileged ? $ob->map->visible_name : $ob->region->name) . "]"
39 . (sprintf " [rtt %.3fs]", $pl->ns->tcpi_rtt * 1e-6) 39 . (sprintf " [rtt %.3fs]", $pl->ns->tcpi_rtt * 1e-6)
40 . ($privileged ? " " . $pl->ns->host : "") 40 . ($privileged ? " " . $pl->ns->host : "")
41 } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl 41 } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl
42 ), 42 ),
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) = @_;
82
83 my $observe = $ob->contr->observe;
87 84
88 # Too hard to try and make a header that lines everything up, so just 85 # Too hard to try and make a header that lines everything up, so just
89 # give a description. (comment from C++) 86 # give a description. (comment from C++)
90 my $reply = 87 my $reply =
91 "The first column is the name of the body location.\n\n" 88 "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" 89 . "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"; 90 . "The third column is how many slots in that location are available.\r"
91 . "The last column shows the items currently using the slot\n\n";
94 92
93 # first process all applied items and hash them into their slots
94 my @slot;
95
96 for my $item (grep $_->flag (cf::FLAG_APPLIED), $observe->inv) {
97 $item->slot_info ($_)
98 and push @{ $slot[$_] }, $item
99 for 0 .. cf::NUM_BODY_LOCATIONS-1;
100 }
101
95 $reply .= sprintf " %-20s %3s %5s\n", "Location", "You", "Avail"; 102 $reply .= sprintf " %-20s %3s %5s %s\n", "Location", "You", "Avail", "What";
96 for (0 .. cf::NUM_BODY_LOCATIONS - 1) { 103 for (0 .. cf::NUM_BODY_LOCATIONS - 1) {
97 my $msg = cf::object::slot_nonuse_name $_; 104 my $msg = cf::object::slot_nonuse_name $_;
98 $msg =~ s/^.*? a //; 105 $msg =~ s/^.*? a //;
99 $reply .= sprintf " %-20s %3d %5d\n", $msg, $ob->slot_info ($_), $ob->slot_used ($_) 106 $reply .= sprintf " %-20s %3d %5d %s\n",
107 $msg,
108 $observe->slot_info ($_),
109 $observe->slot_used ($_),
110 join ", ", map $_->query_short_name, @{ $slot[$_] }
100 if $ob->slot_info ($_) or $ob->slot_used ($_); 111 if $observe->slot_info ($_) || $observe->slot_used ($_);
101 } 112 }
102 113
103 $reply .= "You are not allowed to wear armor\n\n" 114 $reply .= "You are not allowed to wear armor\r"
104 unless $ob->flag (cf::FLAG_USE_ARMOUR); 115 unless $observe->flag (cf::FLAG_USE_ARMOUR);
105 $reply .= "You are not allowed to use weapons\n\n" 116 $reply .= "You are not allowed to use weapons\r"
106 unless $ob->flag (cf::FLAG_USE_WEAPON); 117 unless $observe->flag (cf::FLAG_USE_WEAPON);
107 118
108 my $CHANNEL = { 119 $ob->send_msg ("c/body" => $reply, cf::NDI_REPLY | cf::NDI_CLEAR);
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);
116}; 120};
117 121
118cf::register_command mark => sub { 122#cf::register_command mark => sub {
119 my ($pl, $arg) = @_; 123# my ($pl, $arg) = @_;
120 124#
121 if (length $arg) { 125# if (length $arg) {
122 my $ob = $pl->find_best_object_match ($arg); 126# my $ob = $pl->find_best_object_match ($arg);
123 127#
124 return $pl->reply (undef, "Could not find an object that matches $arg") 128# return $pl->reply (undef, "Could not find an object that matches $arg")
125 unless $ob; 129# unless $ob;
126 130#
127 $pl->contr->mark ($ob); 131# $pl->contr->mark ($ob);
128 $pl->reply (undef, (sprintf "Marked item %s", $ob->name, $ob->title)); 132# $pl->reply (undef, (sprintf "Marked item %s", $ob->name, $ob->title));
129 } else { 133# } else {
130 my $ob = $pl->find_marked_object; 134# my $ob = $pl->find_marked_object;
131 135#
132 $pl->reply (undef, $ob 136# $pl->reply (undef, $ob
133 ? (sprintf "%s %s * is marked.", $ob->name, $ob->title) 137# ? (sprintf "%s %s * is marked.", $ob->name, $ob->title)
134 : "You have no marked object."); 138# : "You have no marked object.");
135 } 139# }
136}; 140#};
137
138for my $cmd ("run", "fire") {
139 my $oncmd = "${cmd}_on";
140 cf::register_command $cmd => sub {
141 my ($ob, $arg) = @_;
142
143 $ob->reply (undef, "Can't $cmd into a non adjacent square.")
144 if $arg < 0 or $arg >= 9;
145
146 $ob->contr->$oncmd (1);
147 $ob->move_player ($arg);
148 };
149
150 cf::register_command "${cmd}_stop" => sub {
151 my ($ob) = @_;
152
153 $ob->contr->$oncmd (0);
154 };
155}
156
157our $MAPINFO_CHANNEL = {
158 id => "mapinfo",
159 title => "Map Info",
160 reply => undef,
161 tooltip => "Information about the map",
162};
163 141
164cf::register_command mapinfo => sub { 142cf::register_command mapinfo => sub {
165 my ($ob) = @_; 143 my ($ob) = @_;
166 144
167 my $observe = $ob->contr->observe; 145 my $observe = $ob->contr->observe;
168 146
169 my $map = $observe->map 147 my $map = $observe->map
170 or return; 148 or return;
171 149
172 my $msg = sprintf "%s (%s) %s", $map->name, $map->path, $observe->region->longname; 150 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", 151 $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 152 (scalar $map->players), $map->difficulty, $map->width, $map->height, $map->enter_x, $map->enter_y, $map->timeout
175 if $ob->flag (cf::FLAG_WIZ); 153 if $ob->flag (cf::FLAG_WIZ);
176 154
177 $ob->send_msg ($MAPINFO_CHANNEL => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); 155 $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
178}; 156};
179 157
180cf::register_command whereami => sub { 158cf::register_command whereami => sub {
181 my ($ob) = @_; 159 my ($ob) = @_;
182 160
183 my $reg = $ob->contr->observe->region; 161 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); 162 $ob->send_msg ("c/who" => (sprintf "You are %s.\n\n%s", $reg->longname, $reg->msg), cf::NDI_REPLY | cf::NDI_CLEAR);
185}; 163};
186 164
187cf::register_command whereabouts => sub { 165cf::register_command whereabouts => sub {
188 my ($ob, $arg) = @_; 166 my ($ob, $arg) = @_;
189 167
191 169
192 for my $pl (cf::player::list) { 170 for my $pl (cf::player::list) {
193 ++$count{$pl->ob->region->longname}; 171 ++$count{$pl->ob->region->longname};
194 } 172 }
195 173
196 my $msg = "In the world currently there are:\n\n" 174 my $msg = "T<In the world currently there are:>\n\n"
197 . join "", map "$count{$_} player(s) $_\n\n", sort keys %count; 175 . join "", map { sprintf " C<%3d >player(s) %s\r", $count{$_}, $_ } sort keys %count;
198 176
199 $ob->send_msg ($MAPINFO_CHANNEL => $msg, cf::NDI_REPLY | cf::NDI_CLEAR); 177 $ob->send_msg ("c/who" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
200}; 178};
201 179
202cf::register_command hiscore => sub { 180cf::register_command hiscore => sub {
203 my ($ob, $arg) = @_; 181 my ($ob, $arg) = @_;
204 182
270 my ($ob, $arg) = @_; 248 my ($ob, $arg) = @_;
271 249
272 return $ob->reply (undef, sprintf "Output rate is presently %dbps.", $ob->contr->ns->max_rate / $cf::TICK) 250 return $ob->reply (undef, sprintf "Output rate is presently %dbps.", $ob->contr->ns->max_rate / $cf::TICK)
273 unless $arg > 0; 251 unless $arg > 0;
274 252
275 # minimum is 5k/s 253 $ob->contr->ns->max_rate ((cf::clamp $arg, $OUTPUT_RATE_MIN, $OUTPUT_RATE_MAX) * $TICK);
276 # maximum is 100k/s, this should be configurable
277 $ob->contr->ns->max_rate ((List::Util::max 5000, List::Util::min 100000, $arg) * $cf::TICK);
278 $ob->reply (undef, sprintf "Output rate now set to %dbps.", $ob->contr->ns->max_rate / $cf::TICK); 254 $ob->reply (undef, sprintf "Output rate now set to %dbps.", $ob->contr->ns->max_rate / $TICK);
279}; 255};
280 256
281cf::register_command 'output-count' => sub { 257cf::register_command 'output-count' => sub {
282 my ($ob, $arg) = @_; 258 my ($ob, $arg) = @_;
283 259
391cf::register_command uptime => sub { 367cf::register_command uptime => sub {
392 my ($ob, $arg) = @_; 368 my ($ob, $arg) = @_;
393 369
394 my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME; 370 my $startup = POSIX::strftime "%Y-%m-%d %H:%M:%S %Z", localtime $cf::UPTIME;
395 my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400; 371 my $runtime = sprintf "%.1f", (time - $cf::UPTIME) / 86400;
396 $ob->send_msg (log => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY); 372 $ob->send_msg ("c/uptime" => "server started $startup, uptime ${runtime}\d", cf::NDI_REPLY | cf::NDI_CLEAR);
397}; 373};
398 374
399my %IN_MEMORY = ( 375my %IN_MEMORY = (
400 cf::MAP_IN_MEMORY => "I", 376 cf::MAP_ACTIVE => "I",
401 cf::MAP_SWAPPED => "S", 377 cf::MAP_SWAPPED => "S",
402 cf::MAP_LOADING => "L", 378 cf::MAP_LOADING => "L",
403); 379);
404 380
405cf::register_command maps => sub { 381cf::register_command maps => sub {
406 my ($ob, $arg) = @_; 382 my ($ob, $arg) = @_;
407 383
408 no re 'eval'; $arg = qr<$arg>; 384 no re 'eval'; $arg = qr<$arg>;
409 385
410 my $format = "%2s %1s %3s %5s %.60s\n"; 386 my $format = " %2s %1s %3s %5s %.60s\n";
411 387
412 $ob->send_msg ($MAPINFO_CHANNEL => (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_REPLY | cf::NDI_CLEAR); 388 my $msg = "\n" . sprintf $format, "Pl", "I", "Svd", "Reset", "Name";
413 389
414 for (sort keys %cf::MAP) { 390 for (sort keys %cf::MAP) {
415 my $map = $cf::MAP{$_} 391 my $map = $cf::MAP{$_}
416 or next; 392 or next;
417 393
419 next if $map->{deny_list}; 395 next if $map->{deny_list};
420 396
421 my $svd = int $cf::RUNTIME - $map->{last_save}; 397 my $svd = int $cf::RUNTIME - $map->{last_save};
422 $svd = "++" if $svd > 99; 398 $svd = "++" if $svd > 99;
423 399
424 $ob->send_msg ($MAPINFO_CHANNEL => 400 $msg .= sprintf $format,
425 (sprintf $format,
426 (scalar $map->players), 401 (scalar $map->players),
427 $IN_MEMORY{$map->in_memory} || "?", 402 $IN_MEMORY{$map->in_memory} || "?",
428 $svd, 403 $svd,
429 (int $map->reset_at - $cf::RUNTIME), 404 (int $map->reset_at - $cf::RUNTIME),
430 $map->visible_name) 405 $map->visible_name;
431 );
432 } 406 }
433};
434 407
408 $ob->send_msg ("c/mapinfo" => $msg, cf::NDI_REPLY | cf::NDI_CLEAR);
409};
410

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines