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