… | |
… | |
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 | use NPC_Dialogue; |
6 | use NPC_Dialogue; |
|
|
7 | use POSIX (); # for strftime only |
7 | |
8 | |
8 | sub clean_timeouts($) { |
9 | sub clean_timeouts($) { |
9 | my ($player) = @_; |
10 | my ($player) = @_; |
10 | my $NOW = time; |
11 | my $NOW = time; |
11 | |
12 | |
12 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
13 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
13 | while (my ($k, $v) = each %$hash) { |
14 | while (my ($k, $v) = each %$hash) { |
14 | if ($v < $NOW) { |
15 | if ($v < $NOW) { |
15 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); |
16 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); |
16 | delete $hash->{$k}; |
17 | delete $hash->{$k}; |
17 | } elsif (!valid_user $k) { |
18 | } elsif (!cf::player::exists $k) { |
18 | $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); |
19 | $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); |
19 | delete $hash->{$k}; |
20 | delete $hash->{$k}; |
20 | } |
21 | } |
21 | } |
22 | } |
22 | } |
23 | } |
… | |
… | |
46 | }; |
47 | }; |
47 | |
48 | |
48 | cf::register_command say => 0, sub { |
49 | cf::register_command say => 0, sub { |
49 | my ($who, $msg) = @_; |
50 | my ($who, $msg) = @_; |
50 | |
51 | |
|
|
52 | utf8::decode $msg; |
|
|
53 | |
51 | if ($msg) { |
54 | if ($msg) { |
52 | my $name = $who->name; |
55 | my $name = $who->name; |
53 | |
56 | |
|
|
57 | utf8::encode $msg; # ->message not yet utf8-ified |
54 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
58 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
55 | 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; |
56 | |
61 | |
57 | # npcs, magic_ears etc. |
62 | # npcs, magic_ears etc. |
58 | # first find all objects and their inventories within a 5x5 square |
63 | # first find all objects and their inventories within a 5x5 square |
59 | # that have something resembling dialogue |
64 | # that have something resembling dialogue |
60 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
65 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
… | |
… | |
68 | ) { |
73 | ) { |
69 | # if some listener teleported us somewhere else, stop right here |
74 | # if some listener teleported us somewhere else, stop right here |
70 | last unless $map->path == $who->map->path; |
75 | last unless $map->path == $who->map->path; |
71 | |
76 | |
72 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
77 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
73 | my $reply = $dialog->tell ($msg); |
78 | my ($reply, @kw) = $dialog->tell ($msg); |
74 | |
79 | |
75 | if (defined $reply) { |
80 | if (defined $reply) { |
76 | if ($npc->type == cf::MAGIC_EAR) { |
81 | if ($npc->type == cf::MAGIC_EAR) { |
77 | if (length $reply) { |
82 | if (length $reply) { |
78 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
83 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
… | |
… | |
84 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
89 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
85 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
90 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
86 | } |
91 | } |
87 | } |
92 | } |
88 | } |
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 | } |
89 | } |
99 | } |
90 | |
100 | |
91 | } else { |
101 | } else { |
92 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
102 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
93 | } |
103 | } |
94 | }; |
104 | }; |
95 | |
105 | |
96 | cf::register_command chat => 0, sub { |
106 | cf::register_command chat => 0, sub { |
97 | my ($who, $msg) = @_; |
107 | my ($who, $msg) = @_; |
|
|
108 | |
|
|
109 | utf8::decode $msg; |
98 | |
110 | |
99 | if ($msg) { |
111 | if ($msg) { |
100 | my $name = $who->name; |
112 | my $name = $who->name; |
101 | my $NOW = time; |
113 | my $NOW = time; |
102 | |
114 | |
|
|
115 | utf8::encode $msg; # ->message not yet utf8-ified |
103 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
116 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
104 | |
117 | |
105 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
118 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
106 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
119 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
107 | |
120 | |
… | |
… | |
110 | } |
123 | } |
111 | }; |
124 | }; |
112 | |
125 | |
113 | cf::register_command shout => 0, sub { |
126 | cf::register_command shout => 0, sub { |
114 | my ($who, $msg) = @_; |
127 | my ($who, $msg) = @_; |
|
|
128 | |
|
|
129 | utf8::decode $msg; |
115 | |
130 | |
116 | if ($msg) { |
131 | if ($msg) { |
117 | my $NOW = time; |
132 | my $NOW = time; |
118 | my $name = $who->name; |
133 | my $name = $who->name; |
119 | |
134 | |
120 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
135 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
121 | |
136 | |
|
|
137 | utf8::encode $msg; # ->message not yet utf8-ified |
122 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
138 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
123 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
139 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
124 | |
140 | |
125 | } else { |
141 | } else { |
126 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
142 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
… | |
… | |
129 | }; |
145 | }; |
130 | |
146 | |
131 | cf::register_command tell => 0, sub { |
147 | cf::register_command tell => 0, sub { |
132 | my ($who, $args) = @_; |
148 | my ($who, $args) = @_; |
133 | my ($target, $msg) = split /\s+/, $args, 2; |
149 | my ($target, $msg) = split /\s+/, $args, 2; |
|
|
150 | |
|
|
151 | utf8::decode $msg; |
134 | |
152 | |
135 | my $name = $who->name; |
153 | my $name = $who->name; |
136 | |
154 | |
137 | if (my $other = cf::player::find $target) { |
155 | if (my $other = cf::player::find $target) { |
138 | |
156 | |
… | |
… | |
140 | if ($target eq $name) { |
158 | if ($target eq $name) { |
141 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
159 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
142 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
160 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
143 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
161 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
144 | } else { |
162 | } else { |
|
|
163 | utf8::encode $msg; # ->message not yet utf8-ified |
145 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
164 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
146 | |
165 | |
147 | $who->message ("You tell $target: $msg"); |
166 | $who->message ("You tell $target: $msg"); |
148 | $other->ob->message ("$name tells you: $msg"); |
167 | $other->ob->message ("$name tells you: $msg"); |
149 | $other->ob->{ext_last_tell} = $name; |
168 | $other->ob->{ext_last_tell} = $name; |
… | |
… | |
159 | |
178 | |
160 | cf::register_command reply => 0, sub { |
179 | cf::register_command reply => 0, sub { |
161 | my ($who, $args) = @_; |
180 | my ($who, $args) = @_; |
162 | my $name = $who->name; |
181 | my $name = $who->name; |
163 | |
182 | |
|
|
183 | utf8::decode $args; |
|
|
184 | |
164 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
185 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
165 | if ($args) { |
186 | if ($args) { |
166 | |
187 | |
167 | $other->ob->{ext_ignore_tell}{$name} >= time |
188 | $other->ob->{ext_ignore_tell}{$name} >= time |
168 | or delete $other->ob->{ext_ignore_tell}{$name}; |
189 | or delete $other->ob->{ext_ignore_tell}{$name}; |
169 | |
190 | |
170 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
191 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
192 | utf8::encode $msg; # ->message not yet utf8-ified |
171 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
193 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
172 | |
194 | |
173 | $who->message ("You tell " . $other->ob->name . ": $args"); |
195 | $who->message ("You tell " . $other->ob->name . ": $args"); |
174 | $other->ob->message ("$name tells you: $args"); |
196 | $other->ob->message ("$name tells you: $args"); |
175 | $who->{ext_last_tell} = $other->ob->name; |
197 | $who->{ext_last_tell} = $other->ob->name; |
… | |
… | |
206 | } elsif ($target && $type) { |
228 | } elsif ($target && $type) { |
207 | |
229 | |
208 | $timeout ne "" or $timeout = 24; |
230 | $timeout ne "" or $timeout = 24; |
209 | my $absolute_timeout = time + $timeout * 3600; |
231 | my $absolute_timeout = time + $timeout * 3600; |
210 | |
232 | |
211 | if (valid_user $target) { |
233 | if (cf::player::exists $target) { |
212 | if ($type eq "tell") { |
234 | if ($type eq "tell") { |
213 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
235 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
214 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
236 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
215 | } elsif ($type eq "shout") { |
237 | } elsif ($type eq "shout") { |
216 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
238 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
… | |
… | |
225 | } else { |
247 | } else { |
226 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
248 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
227 | } |
249 | } |
228 | |
250 | |
229 | } else { |
251 | } else { |
230 | $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" |
252 | $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" |
231 | . "will ignore a player for <timeout> hours.\n" |
253 | . "will ignore a player for <timeout> hours.\n" |
232 | . "Usage: ignore list\n" |
254 | . "Usage: ignore list\n" |
233 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
255 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
234 | } |
256 | } |
235 | }; |
257 | }; |
… | |
… | |
246 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
268 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
247 | } else { |
269 | } else { |
248 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
270 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
249 | } |
271 | } |
250 | } else { |
272 | } else { |
251 | |
273 | if (cf::player::exists $target) { |
252 | if (valid_user $target) { |
|
|
253 | if ($type eq "tell") { |
274 | if ($type eq "tell") { |
254 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
275 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
255 | delete $who->{ext_ignore_tell} {$target}; |
276 | delete $who->{ext_ignore_tell} {$target}; |
256 | } elsif ($type eq "shout") { |
277 | } elsif ($type eq "shout") { |
257 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
278 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
… | |
… | |
264 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
285 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
265 | } |
286 | } |
266 | } else { |
287 | } else { |
267 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
288 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
268 | } |
289 | } |
269 | |
|
|
270 | } |
290 | } |
271 | }; |
291 | }; |
272 | |
292 | |
|
|
293 | cf::register_command seen => 0, sub { |
|
|
294 | my ($who, $args) = @_; |
|
|
295 | |
|
|
296 | if (my ($login) = $args =~ /(\S+)/) { |
|
|
297 | if ($login eq $who->name) { |
|
|
298 | $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
|
|
299 | } elsif (cf::player::find $login) { |
|
|
300 | $who->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
|
|
301 | } elsif (cf::player::exists $login |
|
|
302 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
|
|
303 | my $time = (stat _)[9]; |
|
|
304 | |
|
|
305 | $who->message ("$login was last seen here " |
|
|
306 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
|
|
307 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
|
|
308 | } else { |
|
|
309 | $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
|
|
310 | } |
|
|
311 | } else { |
|
|
312 | $who->message ("Usage: seen <player>", cf::NDI_UNIQUE); |
|
|
313 | } |
|
|
314 | }; |
|
|
315 | |