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 | 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 | } |
… | |
… | |
27 | sub on_logout { |
26 | sub on_logout { |
28 | my ($pl, $host) = @_; |
27 | my ($pl, $host) = @_; |
29 | |
28 | |
30 | clean_timeouts $pl->ob; |
29 | clean_timeouts $pl->ob; |
31 | } |
30 | } |
|
|
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 | if ($msg) { |
|
|
53 | my $name = $who->name; |
|
|
54 | |
|
|
55 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
|
|
56 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
57 | |
|
|
58 | # npcs, magic_ears etc. |
|
|
59 | # first find all objects and their inventories within a 5x5 square |
|
|
60 | # that have something resembling dialogue |
|
|
61 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
|
|
62 | |
|
|
63 | for my $npc ( |
|
|
64 | grep NPC_Dialogue::has_dialogue $_, |
|
|
65 | map +($_, $_->inv), |
|
|
66 | grep $_, |
|
|
67 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
|
|
68 | 0..24 |
|
|
69 | ) { |
|
|
70 | # if some listener teleported us somewhere else, stop right here |
|
|
71 | last unless $map->path == $who->map->path; |
|
|
72 | |
|
|
73 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
|
|
74 | my $reply = $dialog->tell ($msg); |
|
|
75 | |
|
|
76 | if (defined $reply) { |
|
|
77 | if ($npc->type == cf::MAGIC_EAR) { |
|
|
78 | if (length $reply) { |
|
|
79 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
|
|
80 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
81 | } |
|
|
82 | $npc->use_trigger; |
|
|
83 | } else { |
|
|
84 | if (length $reply) { |
|
|
85 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
|
|
86 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
87 | } |
|
|
88 | } |
|
|
89 | } |
|
|
90 | } |
|
|
91 | |
|
|
92 | } else { |
|
|
93 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
|
|
94 | } |
|
|
95 | }; |
32 | |
96 | |
33 | cf::register_command chat => 0, sub { |
97 | cf::register_command chat => 0, sub { |
34 | my ($who, $msg) = @_; |
98 | my ($who, $msg) = @_; |
35 | |
99 | |
36 | if ($msg) { |
100 | if ($msg) { |
37 | my $name = $who->name; |
101 | my $name = $who->name; |
38 | my $NOW = time; |
102 | my $NOW = time; |
39 | |
103 | |
|
|
104 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
105 | |
40 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
106 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
41 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
107 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
42 | |
108 | |
43 | } else { |
109 | } else { |
44 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
110 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
45 | } |
111 | } |
46 | }; |
112 | }; |
… | |
… | |
50 | |
116 | |
51 | if ($msg) { |
117 | if ($msg) { |
52 | my $NOW = time; |
118 | my $NOW = time; |
53 | my $name = $who->name; |
119 | my $name = $who->name; |
54 | |
120 | |
|
|
121 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
|
|
122 | |
55 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
123 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
56 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
124 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
57 | |
125 | |
58 | } else { |
126 | } else { |
59 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
127 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
60 | } |
128 | } |
61 | |
129 | |
… | |
… | |
73 | if ($target eq $name) { |
141 | if ($target eq $name) { |
74 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
142 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
75 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
143 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
76 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
144 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
77 | } else { |
145 | } else { |
|
|
146 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
|
|
147 | |
78 | $who->message ("You tell $target: $msg"); |
148 | $who->message ("You tell $target: $msg"); |
79 | $other->ob->message ("$name tells you: $msg"); |
149 | $other->ob->message ("$name tells you: $msg"); |
80 | $other->ob->{ext_last_tell} = $name; |
150 | $other->ob->{ext_last_tell} = $name; |
81 | } |
151 | } |
82 | } else { |
152 | } else { |
… | |
… | |
97 | |
167 | |
98 | $other->ob->{ext_ignore_tell}{$name} >= time |
168 | $other->ob->{ext_ignore_tell}{$name} >= time |
99 | or delete $other->ob->{ext_ignore_tell}{$name}; |
169 | or delete $other->ob->{ext_ignore_tell}{$name}; |
100 | |
170 | |
101 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
171 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
172 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
|
|
173 | |
102 | $who->message ("You tell " . $other->ob->name . ": $args"); |
174 | $who->message ("You tell " . $other->ob->name . ": $args"); |
103 | $other->ob->message ("$name tells you: $args"); |
175 | $other->ob->message ("$name tells you: $args"); |
104 | $who->{ext_last_tell} = $other->ob->name; |
176 | $who->{ext_last_tell} = $other->ob->name; |
105 | } else { |
177 | } else { |
106 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
178 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
… | |
… | |
135 | } elsif ($target && $type) { |
207 | } elsif ($target && $type) { |
136 | |
208 | |
137 | $timeout ne "" or $timeout = 24; |
209 | $timeout ne "" or $timeout = 24; |
138 | my $absolute_timeout = time + $timeout * 3600; |
210 | my $absolute_timeout = time + $timeout * 3600; |
139 | |
211 | |
140 | if (valid_user $target) { |
212 | if (cf::player::exists $target) { |
141 | if ($type eq "tell") { |
213 | if ($type eq "tell") { |
142 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
214 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
143 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
215 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
144 | } elsif ($type eq "shout") { |
216 | } elsif ($type eq "shout") { |
145 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
217 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
… | |
… | |
154 | } else { |
226 | } else { |
155 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
227 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
156 | } |
228 | } |
157 | |
229 | |
158 | } else { |
230 | } else { |
159 | $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" |
231 | $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n" |
160 | . "will ignore a player for <timeout> hours.\n" |
232 | . "will ignore a player for <timeout> hours.\n" |
161 | . "Usage: ignore list\n" |
233 | . "Usage: ignore list\n" |
162 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
234 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
163 | } |
235 | } |
164 | }; |
236 | }; |
… | |
… | |
175 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
247 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
176 | } else { |
248 | } else { |
177 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
249 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
178 | } |
250 | } |
179 | } else { |
251 | } else { |
180 | |
252 | if (cf::player::exists $target) { |
181 | if (valid_user $target) { |
|
|
182 | if ($type eq "tell") { |
253 | if ($type eq "tell") { |
183 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
254 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
184 | delete $who->{ext_ignore_tell} {$target}; |
255 | delete $who->{ext_ignore_tell} {$target}; |
185 | } elsif ($type eq "shout") { |
256 | } elsif ($type eq "shout") { |
186 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
257 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
… | |
… | |
193 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
264 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
194 | } |
265 | } |
195 | } else { |
266 | } else { |
196 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
267 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
197 | } |
268 | } |
198 | |
|
|
199 | } |
269 | } |
200 | }; |
270 | }; |
201 | |
271 | |
|
|
272 | cf::register_command seen => 0, sub { |
|
|
273 | my ($who, $args) = @_; |
|
|
274 | |
|
|
275 | if (my ($login) = $args =~ /(\S+)/) { |
|
|
276 | if ($login eq $who->name) { |
|
|
277 | $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
|
|
278 | } elsif (cf::player::find $login) { |
|
|
279 | $who->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
|
|
280 | } elsif (cf::player::exists $login |
|
|
281 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
|
|
282 | my $time = (stat _)[9]; |
|
|
283 | |
|
|
284 | $who->message ("$login was last seen here " |
|
|
285 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
|
|
286 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
|
|
287 | } else { |
|
|
288 | $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
|
|
289 | } |
|
|
290 | } else { |
|
|
291 | $who->message ("Usage: seen <player>", cf::NDI_UNIQUE); |
|
|
292 | } |
|
|
293 | }; |
|
|
294 | |