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.5 by root, Sat Dec 23 15:49:40 2006 UTC vs.
Revision 1.23 by pippijn, Fri Mar 2 10:54:59 2007 UTC

5# miscellaneous commands 5# miscellaneous commands
6 6
7sub rename_to($$$) { 7sub rename_to($$$) {
8 my ($ob, $from, $to) = @_; 8 my ($ob, $from, $to) = @_;
9 9
10 $to =~ /^[a-zA-Z0-9.,=#\/%$!^]*$/ 10 $to =~ /^[a-zA-Z0-9.,=#\/%$!^ ]*$/
11 or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things."); 11 or return $ob->message ("rename: name must consist only of letters, digits, spaces and a few other things.");
12 12
13 127 >= length $to 13 127 >= length $to
14 or return $ob->message ("rename: new name must be <= 127 characters."); 14 or return $ob->message ("rename: new name must be <= 127 characters.");
15 15
68 "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title) 68 "* " . $ob->name . "/" . $ob->level . " " . (length $pl->own_title ? $pl->own_title : "the " . $pl->title)
69 . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]") 69 . ($pl->peaceful ? " [peaceful]" : " [HOSTILE]")
70 . ($ns->afk ? " [AFK]" : "") 70 . ($ns->afk ? " [AFK]" : "")
71 . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "") 71 . ($ob->flag (cf::FLAG_WIZ) ? " [WIZ]" : "")
72 . " [" . $pl->ns->version . "]" 72 . " [" . $pl->ns->version . "]"
73 . " [" . ($pl->peaceful || $privileged ? $ob->map->path : $ob->map->region ? $ob->map->region->name : "the unknown") . "]" 73 . " [" . ($pl->peaceful || $privileged ? $ob->map->visible_name : $ob->region->name) . "]"
74 . (sprintf " [rtt %.3fs]", $pl->ns->rtt * 1e-6) 74 . (sprintf " [rtt %.3fs]", $pl->ns->rtt * 1e-6)
75 . ($privileged ? " " . $pl->ns->host : "") 75 . ($privileged ? " " . $pl->ns->host : "")
76 } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl 76 } sort { (lc $a->ob->name) cmp (lc $b->ob->name) } @pl
77 ), 77 ),
78 eval { "* IRC: " . join ", ", ext::schmorp_irc::users }, 78 eval { "* IRC: " . join ", ", ext::schmorp_irc::users },
86 86
87 $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE); 87 $ob->reply (undef, (join "\n", who_listing $ob->may ("extended_who")), cf::NDI_UNIQUE | cf::NDI_DK_ORANGE);
88 88
89 1 89 1
90}; 90};
91
92cf::register_command applymode => sub {
93 my ($ob, $arg) = @_;
94 my @types = ("nochoice", "never", "always");
95 my $mapping = {
96 nochoice => 1,
97 never => 2,
98 always => 3,
99 };
100
101 my $oldmode = $ob->contr->unapply;
102 my $oldmode_name = $types[$oldmode];
103
104 return $ob->reply (undef, "applymode is set to $oldmode_name")
105 unless $arg;
106
107 return $ob->reply (undef, "applymode: Unknown options '$arg', valid options are @types")
108 unless $mapping->{$arg};
109
110 $ob->contr->unapply ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0
111 # but $arg would be 0 if a user enters an incorrect value
112 $ob->reply (undef, "applymode" . ($oldmode == $ob->contr->unapply ? "" : " now") . " set to " . $types[$ob->contr->unapply]);
113
114 1
115};
116
117cf::register_command petmode => sub {
118 my ($ob, $arg) = @_;
119 my @types = ("normal", "sad", "defend", "arena");
120 my $mapping = {
121 normal => 1,
122 sad => 2,
123 defend => 3,
124 arena => 4,
125 };
126
127 my $oldtype = $ob->contr->petmode;
128 my $oldtype_name = $types[$oldtype];
129
130 return $ob->reply (undef, "petmode is set to $oldtype_name")
131 unless $arg;
132
133 return $ob->reply (undef, "petmode: Unknown options '$arg', valid options are @types")
134 unless $mapping->{$arg};
135
136 $ob->contr->petmode ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0
137 # but $arg would be 0 if a user enters an incorrect value
138 $ob->reply (undef, "petmode" . ($oldtype == $ob->contr->petmode ? "" : " now") . " set to " . $types[$ob->contr->petmode]);
139
140 1
141};
142
143cf::register_command usekeys => sub {
144 my ($ob, $arg) = @_;
145 my @types = ("inventory", "keyrings", "containers");
146 my $mapping = {
147 inventory => 1,
148 keyrings => 2,
149 containers => 3,
150 };
151
152 my $oldtype = $ob->contr->usekeys;
153 my $oldtype_name = $types[$oldtype];
154
155 return $ob->reply (undef, "usekeys is set to $oldtype_name")
156 unless $arg;
157
158 return $ob->reply (undef, "usekeys: Unknown options '$arg', valid options are @types")
159 unless $mapping->{$arg};
160
161 $ob->contr->usekeys ($mapping->{$arg} - 1); # HACK: because of the $mapping->{$arg} check before, where $arg should not be 0
162 # but $arg would be 0 if a user enters an incorrect value
163 $ob->reply (undef, "usekeys" . ($oldtype == $ob->contr->usekeys ? "" : " now") . " set to " . $types[$ob->contr->usekeys]);
164
165 1
166};
167
168cf::register_command afk => sub {
169 my ($ob, $arg) = @_;
170
171 $ob->contr->ns->afk ($ob->contr->ns->afk ? 0 : 1);
172 $ob->reply (undef, $ob->contr->ns->afk ? "You are now AFK" : "You are no longer AFK");
173
174 1
175};
176
177cf::register_command sound => sub {
178 my ($ob, $arg) = @_;
179
180 $ob->contr->ns->sound ($ob->contr->ns->sound ? 0 : 1);
181 $ob->reply (undef, $ob->contr->ns->sound ? "The sounds are enabled." : "Silence is golden...");
182
183 1
184};
185
186cf::register_command brace => sub {
187 my ($ob, $arg) = @_;
188
189 $ob->contr->braced ($ob->contr->braced ? 0 : 1);
190 $ob->reply (undef, $ob->contr->braced ? "You are braced." : "Not braced.");
191
192 1
193};
194
195# XXX: This has a bug. After one sets his wimpy level to 0 and resets it to
196# some other level (which may also be 0), this does not get echoed,
197# but it does get set.
198cf::register_command wimpy => sub {
199 my ($ob, $arg) = @_;
200
201 my $wimpy = $ob->run_away;
202 return $ob->reply (undef, "Your current wimpy level is $wimpy.")
203 if $arg eq "";
204
205 return $ob->run_away ($arg) && $ob->reply (undef, "Your new wimpy level is $arg.")
206 if $arg =~ /^\d+$/ and $arg <= 100;
207
208 $ob->reply (undef, "Incorrect parameters for wimpy: $arg");
209
210 1
211};
212
213cf::register_command peaceful => sub {
214 my ($ob, $arg) = @_;
215
216 $ob->reply (undef, "You cannot change your peaceful setting with this command."
217 ." Please speak to the priest in the temple of Gorokh"
218 ." if you want to become hostile or in temple of Valriel"
219 ." if you want to become peaceful again.");
220
221 #$ob->contr->peaceful ($ob->contr->peaceful ? 0 : 1);
222 #$ob->reply (undef, $ob->contr->peaceful ? "You will attack other players." : "You will not attack other players.");
223
224 1
225};
226
91 227
92cf::register_command rename => sub { 228cf::register_command rename => sub {
93 my ($ob, $arg) = @_; 229 my ($ob, $arg) = @_;
94 230
95 $ob->speed_left ($ob->speed_left - 0.25); 231 $ob->speed_left ($ob->speed_left - 0.25);
123 $ob->reply (undef, "server started $startup, uptime ${runtime}\d"); 259 $ob->reply (undef, "server started $startup, uptime ${runtime}\d");
124 260
125 1 261 1
126}; 262};
127 263
264my %IN_MEMORY = (
265 cf::MAP_IN_MEMORY => "I",
266 cf::MAP_SWAPPED => "S",
267 cf::MAP_LOADING => "L",
268);
269
270cf::register_command maps => sub {
271 my ($ob, $arg) = @_;
272
273 no re 'eval'; $arg = qr<$arg>;
274
275 my $format = "%2s %1s %3s %5s %.60s\n";
276
277 $ob->reply (undef, (sprintf $format, "Pl", "I", "Svd", "Reset", "Name"), cf::NDI_BLACK | cf::NDI_UNIQUE);
278
279 for (sort keys %cf::MAP) {
280 my $map = $cf::MAP{$_}
281 or next;
282
283 next unless $map->path =~ $arg;
284 next if $map->{deny_list};
285
286 my $svd = int $cf::RUNTIME - $map->{last_save};
287 $svd = "++" if $svd > 99;
288
289 $ob->reply (undef,
290 (sprintf $format,
291 (scalar $map->players),
292 $IN_MEMORY{$map->in_memory} || "?",
293 $svd,
294 (int $map->reset_at - $cf::RUNTIME),
295 $map->visible_name),
296 cf::NDI_BLACK | cf::NDI_UNIQUE);
297 }
298
299 1
300};
301

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines