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