1 |
pippijn |
1.1 |
#! perl |
2 |
root |
1.5 |
|
3 |
pippijn |
1.15 |
# implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 |
root |
1.5 |
# adds ignore/unignore functionality |
5 |
|
|
|
6 |
root |
1.20 |
use NPC_Dialogue; |
7 |
root |
1.23 |
use POSIX (); # for strftime only |
8 |
root |
1.20 |
|
9 |
root |
1.12 |
sub clean_timeouts($) { |
10 |
root |
1.8 |
my ($player) = @_; |
11 |
|
|
my $NOW = time; |
12 |
|
|
|
13 |
|
|
for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
14 |
root |
1.12 |
while (my ($k, $v) = each %$hash) { |
15 |
|
|
if ($v < $NOW) { |
16 |
root |
1.20 |
$player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); |
17 |
root |
1.12 |
delete $hash->{$k}; |
18 |
root |
1.22 |
} elsif (!cf::player::exists $k) { |
19 |
root |
1.20 |
$player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); |
20 |
root |
1.12 |
delete $hash->{$k}; |
21 |
|
|
} |
22 |
|
|
} |
23 |
root |
1.8 |
} |
24 |
|
|
} |
25 |
|
|
|
26 |
|
|
sub on_logout { |
27 |
|
|
my ($pl, $host) = @_; |
28 |
|
|
|
29 |
|
|
clean_timeouts $pl->ob; |
30 |
|
|
} |
31 |
|
|
|
32 |
pippijn |
1.15 |
cf::register_command listen => 0, sub { |
33 |
|
|
my ($who, $msg) = @_; |
34 |
|
|
my $player = cf::player::find $who->name; |
35 |
|
|
|
36 |
pippijn |
1.17 |
if ($msg ne "") { |
37 |
pippijn |
1.15 |
my $prev_listen = $player->listening; |
38 |
|
|
$player->listening ($msg); |
39 |
|
|
if ($prev_listen == $player->listening) { |
40 |
root |
1.20 |
$who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
41 |
pippijn |
1.15 |
} else { |
42 |
root |
1.20 |
$who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
43 |
pippijn |
1.15 |
} |
44 |
|
|
} else { |
45 |
root |
1.20 |
$who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
46 |
pippijn |
1.15 |
} |
47 |
|
|
}; |
48 |
|
|
|
49 |
root |
1.21 |
cf::register_command say => 0, sub { |
50 |
root |
1.20 |
my ($who, $msg) = @_; |
51 |
|
|
|
52 |
root |
1.27 |
utf8::decode $msg; |
53 |
|
|
|
54 |
root |
1.20 |
if ($msg) { |
55 |
|
|
my $name = $who->name; |
56 |
|
|
|
57 |
root |
1.27 |
utf8::encode $msg; # ->message not yet utf8-ified |
58 |
root |
1.21 |
$_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
59 |
|
|
for grep $who->on_same_map_as ($_->ob), cf::player::list; |
60 |
root |
1.27 |
utf8::decode $msg; |
61 |
root |
1.20 |
|
62 |
|
|
# npcs, magic_ears etc. |
63 |
|
|
# first find all objects and their inventories within a 5x5 square |
64 |
|
|
# that have something resembling dialogue |
65 |
|
|
my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
66 |
|
|
|
67 |
|
|
for my $npc ( |
68 |
|
|
grep NPC_Dialogue::has_dialogue $_, |
69 |
|
|
map +($_, $_->inv), |
70 |
|
|
grep $_, |
71 |
|
|
map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
72 |
|
|
0..24 |
73 |
|
|
) { |
74 |
|
|
# if some listener teleported us somewhere else, stop right here |
75 |
|
|
last unless $map->path == $who->map->path; |
76 |
|
|
|
77 |
|
|
my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
78 |
root |
1.26 |
my ($reply, @kw) = $dialog->tell ($msg); |
79 |
root |
1.20 |
|
80 |
|
|
if (defined $reply) { |
81 |
|
|
if ($npc->type == cf::MAGIC_EAR) { |
82 |
root |
1.21 |
if (length $reply) { |
83 |
|
|
$_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
84 |
|
|
for grep $who->on_same_map_as ($_->ob), cf::player::list; |
85 |
|
|
} |
86 |
root |
1.20 |
$npc->use_trigger; |
87 |
|
|
} else { |
88 |
root |
1.21 |
if (length $reply) { |
89 |
|
|
$_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
90 |
|
|
for grep $who->on_same_map_as ($_->ob), cf::player::list; |
91 |
|
|
} |
92 |
root |
1.20 |
} |
93 |
|
|
} |
94 |
root |
1.26 |
|
95 |
|
|
if (@kw) { |
96 |
|
|
$_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) |
97 |
|
|
for grep $who->on_same_map_as ($_->ob), cf::player::list; |
98 |
|
|
} |
99 |
root |
1.20 |
} |
100 |
|
|
|
101 |
|
|
} else { |
102 |
|
|
$who->message ("What do you want to say?", cf::NDI_UNIQUE); |
103 |
|
|
} |
104 |
|
|
}; |
105 |
pippijn |
1.15 |
|
106 |
pippijn |
1.6 |
cf::register_command chat => 0, sub { |
107 |
pippijn |
1.1 |
my ($who, $msg) = @_; |
108 |
|
|
|
109 |
root |
1.27 |
utf8::decode $msg; |
110 |
|
|
|
111 |
pippijn |
1.1 |
if ($msg) { |
112 |
|
|
my $name = $who->name; |
113 |
root |
1.8 |
my $NOW = time; |
114 |
pippijn |
1.1 |
|
115 |
root |
1.27 |
utf8::encode $msg; # ->message not yet utf8-ified |
116 |
root |
1.19 |
cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
117 |
elmex |
1.29 |
cf::ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
118 |
root |
1.19 |
|
119 |
root |
1.4 |
$_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
120 |
pippijn |
1.15 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
121 |
root |
1.4 |
|
122 |
pippijn |
1.1 |
} else { |
123 |
|
|
$who->message ("Chat what?", cf::NDI_UNIQUE); |
124 |
|
|
} |
125 |
|
|
}; |
126 |
|
|
|
127 |
pippijn |
1.6 |
cf::register_command shout => 0, sub { |
128 |
pippijn |
1.1 |
my ($who, $msg) = @_; |
129 |
|
|
|
130 |
root |
1.27 |
utf8::decode $msg; |
131 |
|
|
|
132 |
pippijn |
1.1 |
if ($msg) { |
133 |
root |
1.8 |
my $NOW = time; |
134 |
pippijn |
1.1 |
my $name = $who->name; |
135 |
|
|
|
136 |
root |
1.19 |
cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
137 |
elmex |
1.29 |
cf::ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg); |
138 |
root |
1.19 |
|
139 |
root |
1.27 |
utf8::encode $msg; # ->message not yet utf8-ified |
140 |
root |
1.4 |
$_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
141 |
pippijn |
1.15 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
142 |
root |
1.4 |
|
143 |
pippijn |
1.1 |
} else { |
144 |
|
|
$who->message ("Shout what?", cf::NDI_UNIQUE); |
145 |
|
|
} |
146 |
|
|
|
147 |
|
|
}; |
148 |
root |
1.5 |
|
149 |
|
|
cf::register_command tell => 0, sub { |
150 |
|
|
my ($who, $args) = @_; |
151 |
|
|
my ($target, $msg) = split /\s+/, $args, 2; |
152 |
|
|
|
153 |
root |
1.27 |
utf8::decode $msg; |
154 |
|
|
|
155 |
root |
1.5 |
my $name = $who->name; |
156 |
|
|
|
157 |
pippijn |
1.11 |
if (my $other = cf::player::find $target) { |
158 |
root |
1.12 |
|
159 |
pippijn |
1.11 |
if ($msg) { |
160 |
root |
1.12 |
if ($target eq $name) { |
161 |
|
|
$who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
162 |
|
|
} elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
163 |
|
|
$who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
164 |
|
|
} else { |
165 |
root |
1.27 |
utf8::encode $msg; # ->message not yet utf8-ified |
166 |
root |
1.19 |
cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
167 |
|
|
|
168 |
pippijn |
1.9 |
$who->message ("You tell $target: $msg"); |
169 |
|
|
$other->ob->message ("$name tells you: $msg"); |
170 |
|
|
$other->ob->{ext_last_tell} = $name; |
171 |
|
|
} |
172 |
root |
1.5 |
} else { |
173 |
pippijn |
1.11 |
$who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
174 |
root |
1.5 |
} |
175 |
root |
1.12 |
|
176 |
root |
1.5 |
} else { |
177 |
root |
1.12 |
$who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
178 |
root |
1.5 |
} |
179 |
|
|
}; |
180 |
|
|
|
181 |
|
|
cf::register_command reply => 0, sub { |
182 |
|
|
my ($who, $args) = @_; |
183 |
|
|
my $name = $who->name; |
184 |
|
|
|
185 |
root |
1.27 |
utf8::decode $args; |
186 |
|
|
|
187 |
pippijn |
1.11 |
if (my $other = cf::player::find $who->{ext_last_tell}) { |
188 |
|
|
if ($args) { |
189 |
root |
1.5 |
|
190 |
pippijn |
1.9 |
$other->ob->{ext_ignore_tell}{$name} >= time |
191 |
|
|
or delete $other->ob->{ext_ignore_tell}{$name}; |
192 |
|
|
|
193 |
|
|
if ($other->ob->{ext_ignore_tell}{$name} < time) { |
194 |
root |
1.28 |
utf8::encode $args; # ->message not yet utf8-ified |
195 |
root |
1.19 |
cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
196 |
|
|
|
197 |
pippijn |
1.9 |
$who->message ("You tell " . $other->ob->name . ": $args"); |
198 |
|
|
$other->ob->message ("$name tells you: $args"); |
199 |
|
|
$who->{ext_last_tell} = $other->ob->name; |
200 |
|
|
} else { |
201 |
|
|
$who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
202 |
|
|
} |
203 |
root |
1.5 |
} else { |
204 |
pippijn |
1.11 |
$who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
205 |
root |
1.5 |
} |
206 |
pippijn |
1.11 |
|
207 |
root |
1.5 |
} else { |
208 |
pippijn |
1.11 |
$who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
209 |
root |
1.5 |
} |
210 |
|
|
}; |
211 |
|
|
|
212 |
|
|
cf::register_command ignore => 0, sub { |
213 |
|
|
my ($who, $args) = @_; |
214 |
|
|
my ($target, $type, $timeout) = split /\s+/, $args; |
215 |
|
|
|
216 |
|
|
if ($args eq "list") { |
217 |
root |
1.8 |
clean_timeouts $who; |
218 |
|
|
|
219 |
root |
1.5 |
if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) |
220 |
|
|
+ (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { |
221 |
|
|
$who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
222 |
|
|
$who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); |
223 |
|
|
$who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
224 |
|
|
$who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); |
225 |
|
|
$who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); |
226 |
|
|
} else { |
227 |
|
|
$who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
228 |
|
|
} |
229 |
|
|
|
230 |
|
|
} elsif ($target && $type) { |
231 |
|
|
|
232 |
|
|
$timeout ne "" or $timeout = 24; |
233 |
|
|
my $absolute_timeout = time + $timeout * 3600; |
234 |
|
|
|
235 |
root |
1.22 |
if (cf::player::exists $target) { |
236 |
root |
1.5 |
if ($type eq "tell") { |
237 |
root |
1.12 |
$who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
238 |
|
|
$who->{ext_ignore_tell}{$target} = $absolute_timeout; |
239 |
root |
1.5 |
} elsif ($type eq "shout") { |
240 |
root |
1.12 |
$who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
241 |
|
|
$who->{ext_ignore_shout}{$target} = $absolute_timeout; |
242 |
root |
1.5 |
} elsif ($type eq "all") { |
243 |
root |
1.12 |
$who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); |
244 |
|
|
$who->{ext_ignore_tell}{$target} = $absolute_timeout; |
245 |
|
|
$who->{ext_ignore_shout}{$target} = $absolute_timeout; |
246 |
root |
1.5 |
} else { |
247 |
|
|
$who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
248 |
|
|
} |
249 |
|
|
} else { |
250 |
root |
1.12 |
$who->message ("No such player: $target", cf::NDI_UNIQUE); |
251 |
root |
1.5 |
} |
252 |
|
|
|
253 |
|
|
} else { |
254 |
root |
1.23 |
$who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" |
255 |
root |
1.12 |
. "will ignore a player for <timeout> hours.\n" |
256 |
|
|
. "Usage: ignore list\n" |
257 |
|
|
. "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
258 |
root |
1.5 |
} |
259 |
|
|
}; |
260 |
|
|
|
261 |
|
|
cf::register_command unignore => 0, sub { |
262 |
|
|
my ($who, $args) = @_; |
263 |
|
|
my ($target, $type) = split /\s+/, $args; |
264 |
|
|
|
265 |
|
|
if ($args eq "") { |
266 |
root |
1.12 |
if ($who->{ext_ignore_tell}) { |
267 |
root |
1.5 |
$who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
268 |
|
|
$who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
269 |
|
|
$who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
270 |
|
|
$who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
271 |
|
|
} else { |
272 |
|
|
$who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
273 |
|
|
} |
274 |
|
|
} else { |
275 |
root |
1.22 |
if (cf::player::exists $target) { |
276 |
root |
1.5 |
if ($type eq "tell") { |
277 |
root |
1.12 |
$who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
278 |
|
|
delete $who->{ext_ignore_tell} {$target}; |
279 |
root |
1.5 |
} elsif ($type eq "shout") { |
280 |
root |
1.12 |
$who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
281 |
|
|
delete $who->{ext_ignore_shout}{$target}; |
282 |
root |
1.5 |
} elsif ($type eq "all") { |
283 |
root |
1.12 |
$who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); |
284 |
|
|
delete $who->{ext_ignore_tell} {$target}; |
285 |
|
|
delete $who->{ext_ignore_shout}{$target}; |
286 |
root |
1.5 |
} else { |
287 |
|
|
$who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
288 |
|
|
} |
289 |
|
|
} else { |
290 |
|
|
$who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
291 |
|
|
} |
292 |
root |
1.23 |
} |
293 |
|
|
}; |
294 |
|
|
|
295 |
|
|
cf::register_command seen => 0, sub { |
296 |
|
|
my ($who, $args) = @_; |
297 |
root |
1.5 |
|
298 |
root |
1.23 |
if (my ($login) = $args =~ /(\S+)/) { |
299 |
root |
1.24 |
if ($login eq $who->name) { |
300 |
|
|
$who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
301 |
|
|
} elsif (cf::player::find $login) { |
302 |
root |
1.23 |
$who->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
303 |
|
|
} elsif (cf::player::exists $login |
304 |
|
|
and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
305 |
|
|
my $time = (stat _)[9]; |
306 |
|
|
|
307 |
root |
1.25 |
$who->message ("$login was last seen here " |
308 |
root |
1.23 |
. (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
309 |
|
|
. " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
310 |
|
|
} else { |
311 |
|
|
$who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
312 |
|
|
} |
313 |
|
|
} else { |
314 |
|
|
$who->message ("Usage: seen <player>", cf::NDI_UNIQUE); |
315 |
root |
1.5 |
} |
316 |
|
|
}; |
317 |
|
|
|