1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | # implement a replacement for the built-in say/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 | sub valid_user($) { |
6 | use NPC_Dialogue; |
7 | -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
7 | use POSIX (); # for strftime only |
8 | } |
|
|
9 | |
8 | |
10 | sub clean_timeouts($) { |
9 | sub clean_timeouts($) { |
11 | my ($player) = @_; |
10 | my ($player) = @_; |
12 | my $NOW = time; |
11 | my $NOW = time; |
13 | |
12 | |
14 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
13 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
15 | while (my ($k, $v) = each %$hash) { |
14 | while (my ($k, $v) = each %$hash) { |
16 | if ($v < $NOW) { |
15 | if ($v < $NOW) { |
17 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); |
16 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); |
18 | delete $hash->{$k}; |
17 | delete $hash->{$k}; |
19 | } elsif (!valid_user $k) { |
18 | } elsif (!cf::player::exists $k) { |
20 | $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); |
19 | $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); |
21 | delete $hash->{$k}; |
20 | delete $hash->{$k}; |
22 | } |
21 | } |
23 | } |
22 | } |
24 | } |
23 | } |
25 | } |
24 | } |
26 | |
25 | |
27 | sub on_logout { |
26 | sub on_login { |
28 | my ($pl, $host) = @_; |
27 | my ($pl) = @_; |
29 | |
28 | |
30 | clean_timeouts $pl->ob; |
29 | clean_timeouts $pl->ob; |
31 | } |
30 | } |
32 | |
31 | |
33 | cf::register_command listen => 0, sub { |
32 | cf::register_command listen => 0, sub { |
34 | my ($who, $msg) = @_; |
33 | my ($who, $msg) = @_; |
35 | my $player = cf::player::find $who->name; |
34 | my $player = cf::player::find $who->name; |
36 | |
35 | |
37 | if ($msg) { |
36 | if ($msg ne "") { |
38 | my $prev_listen = $player->listening; |
37 | my $prev_listen = $player->listening; |
39 | $player->listening ($msg); |
38 | $player->listening ($msg); |
40 | if ($prev_listen == $player->listening) { |
39 | if ($prev_listen == $player->listening) { |
41 | $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); |
40 | $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
42 | } else { |
41 | } else { |
43 | $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); |
42 | $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
44 | } |
43 | } |
45 | } else { |
44 | } else { |
46 | $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); |
45 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
47 | } |
46 | } |
48 | }; |
47 | }; |
49 | |
48 | |
50 | #cf::register_command say => 0, sub { |
49 | cf::register_command say => 0, sub { |
51 | # my ($who, $msg) = @_; |
50 | my ($who, $msg) = @_; |
52 | # |
51 | |
|
|
52 | utf8::decode $msg; |
|
|
53 | |
53 | # if ($msg) { |
54 | if ($msg) { |
54 | # my $name = $who->name; |
55 | my $name = $who->name; |
|
|
56 | |
|
|
57 | utf8::encode $msg; # ->message not yet utf8-ified |
55 | # $_->ob->message ("$name says: $msg", cf::NDI_WHITE) |
58 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
56 | # for grep $who->on_same_map_as ($_->ob), cf::player::list; |
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 | |
57 | # } else { |
101 | } else { |
58 | # $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
102 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
59 | # } |
103 | } |
60 | #}; |
104 | }; |
61 | |
105 | |
62 | cf::register_command chat => 0, sub { |
106 | cf::register_command chat => 0, sub { |
63 | my ($who, $msg) = @_; |
107 | my ($who, $msg) = @_; |
|
|
108 | |
|
|
109 | utf8::decode $msg; |
64 | |
110 | |
65 | if ($msg) { |
111 | if ($msg) { |
66 | my $name = $who->name; |
112 | my $name = $who->name; |
67 | my $NOW = time; |
113 | my $NOW = time; |
68 | |
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 | |
69 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
119 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
70 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
120 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
71 | |
121 | |
72 | } else { |
122 | } else { |
73 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
123 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
74 | } |
124 | } |
75 | }; |
125 | }; |
76 | |
126 | |
77 | cf::register_command shout => 0, sub { |
127 | cf::register_command shout => 0, sub { |
78 | my ($who, $msg) = @_; |
128 | my ($who, $msg) = @_; |
|
|
129 | |
|
|
130 | utf8::decode $msg; |
79 | |
131 | |
80 | if ($msg) { |
132 | if ($msg) { |
81 | my $NOW = time; |
133 | my $NOW = time; |
82 | my $name = $who->name; |
134 | my $name = $who->name; |
83 | |
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 |
84 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
140 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
85 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
141 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
86 | |
142 | |
87 | } else { |
143 | } else { |
88 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
144 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
… | |
… | |
91 | }; |
147 | }; |
92 | |
148 | |
93 | cf::register_command tell => 0, sub { |
149 | cf::register_command tell => 0, sub { |
94 | my ($who, $args) = @_; |
150 | my ($who, $args) = @_; |
95 | my ($target, $msg) = split /\s+/, $args, 2; |
151 | my ($target, $msg) = split /\s+/, $args, 2; |
|
|
152 | |
|
|
153 | utf8::decode $msg; |
96 | |
154 | |
97 | my $name = $who->name; |
155 | my $name = $who->name; |
98 | |
156 | |
99 | if (my $other = cf::player::find $target) { |
157 | if (my $other = cf::player::find $target) { |
100 | |
158 | |
… | |
… | |
102 | if ($target eq $name) { |
160 | if ($target eq $name) { |
103 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
161 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
104 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
162 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
105 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
163 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
106 | } else { |
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 | |
107 | $who->message ("You tell $target: $msg"); |
168 | $who->message ("You tell $target: $msg"); |
108 | $other->ob->message ("$name tells you: $msg"); |
169 | $other->ob->message ("$name tells you: $msg"); |
109 | $other->ob->{ext_last_tell} = $name; |
170 | $other->ob->{ext_last_tell} = $name; |
110 | } |
171 | } |
111 | } else { |
172 | } else { |
… | |
… | |
119 | |
180 | |
120 | cf::register_command reply => 0, sub { |
181 | cf::register_command reply => 0, sub { |
121 | my ($who, $args) = @_; |
182 | my ($who, $args) = @_; |
122 | my $name = $who->name; |
183 | my $name = $who->name; |
123 | |
184 | |
|
|
185 | utf8::decode $args; |
|
|
186 | |
124 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
187 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
125 | if ($args) { |
188 | if ($args) { |
126 | |
189 | |
127 | $other->ob->{ext_ignore_tell}{$name} >= time |
190 | $other->ob->{ext_ignore_tell}{$name} >= time |
128 | or delete $other->ob->{ext_ignore_tell}{$name}; |
191 | or delete $other->ob->{ext_ignore_tell}{$name}; |
129 | |
192 | |
130 | 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 | |
131 | $who->message ("You tell " . $other->ob->name . ": $args"); |
197 | $who->message ("You tell " . $other->ob->name . ": $args"); |
132 | $other->ob->message ("$name tells you: $args"); |
198 | $other->ob->message ("$name tells you: $args"); |
133 | $who->{ext_last_tell} = $other->ob->name; |
199 | $who->{ext_last_tell} = $other->ob->name; |
134 | } else { |
200 | } else { |
135 | $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); |
… | |
… | |
164 | } elsif ($target && $type) { |
230 | } elsif ($target && $type) { |
165 | |
231 | |
166 | $timeout ne "" or $timeout = 24; |
232 | $timeout ne "" or $timeout = 24; |
167 | my $absolute_timeout = time + $timeout * 3600; |
233 | my $absolute_timeout = time + $timeout * 3600; |
168 | |
234 | |
169 | if (valid_user $target) { |
235 | if (cf::player::exists $target) { |
170 | if ($type eq "tell") { |
236 | if ($type eq "tell") { |
171 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
237 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
172 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
238 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
173 | } elsif ($type eq "shout") { |
239 | } elsif ($type eq "shout") { |
174 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
240 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
… | |
… | |
183 | } else { |
249 | } else { |
184 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
250 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
185 | } |
251 | } |
186 | |
252 | |
187 | } else { |
253 | } else { |
188 | $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" |
254 | $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" |
189 | . "will ignore a player for <timeout> hours.\n" |
255 | . "will ignore a player for <timeout> hours.\n" |
190 | . "Usage: ignore list\n" |
256 | . "Usage: ignore list\n" |
191 | . "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); |
192 | } |
258 | } |
193 | }; |
259 | }; |
… | |
… | |
204 | $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); |
205 | } else { |
271 | } else { |
206 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
272 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
207 | } |
273 | } |
208 | } else { |
274 | } else { |
209 | |
275 | if (cf::player::exists $target) { |
210 | if (valid_user $target) { |
|
|
211 | if ($type eq "tell") { |
276 | if ($type eq "tell") { |
212 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
277 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
213 | delete $who->{ext_ignore_tell} {$target}; |
278 | delete $who->{ext_ignore_tell} {$target}; |
214 | } elsif ($type eq "shout") { |
279 | } elsif ($type eq "shout") { |
215 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
280 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
… | |
… | |
222 | $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); |
223 | } |
288 | } |
224 | } else { |
289 | } else { |
225 | $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); |
226 | } |
291 | } |
227 | |
|
|
228 | } |
292 | } |
229 | }; |
293 | }; |
230 | |
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 | |