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 | |
|
|
8 | sub valid_user($) { |
|
|
9 | cf::player::find $_[0] |
|
|
10 | or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
|
|
11 | } |
|
|
12 | |
6 | sub clean_timeouts { |
13 | sub clean_timeouts($) { |
7 | my ($player) = @_; |
14 | my ($player) = @_; |
8 | my $NOW = time; |
15 | my $NOW = time; |
9 | |
16 | |
10 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
17 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
11 | delete $hash->{$_} for grep $hash->{$_} < $NOW, keys %$hash; |
18 | while (my ($k, $v) = each %$hash) { |
|
|
19 | if ($v < $NOW) { |
|
|
20 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); |
|
|
21 | delete $hash->{$k}; |
|
|
22 | } elsif (!valid_user $k) { |
|
|
23 | $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); |
|
|
24 | delete $hash->{$k}; |
|
|
25 | } |
|
|
26 | } |
12 | } |
27 | } |
13 | } |
28 | } |
14 | |
29 | |
15 | sub on_logout { |
30 | sub on_logout { |
16 | my ($pl, $host) = @_; |
31 | my ($pl, $host) = @_; |
17 | |
32 | |
18 | clean_timeouts $pl->ob; |
33 | clean_timeouts $pl->ob; |
19 | } |
34 | } |
|
|
35 | |
|
|
36 | cf::register_command listen => 0, sub { |
|
|
37 | my ($who, $msg) = @_; |
|
|
38 | my $player = cf::player::find $who->name; |
|
|
39 | |
|
|
40 | if ($msg ne "") { |
|
|
41 | my $prev_listen = $player->listening; |
|
|
42 | $player->listening ($msg); |
|
|
43 | if ($prev_listen == $player->listening) { |
|
|
44 | $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
|
|
45 | } else { |
|
|
46 | $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
|
|
47 | } |
|
|
48 | } else { |
|
|
49 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
|
|
50 | } |
|
|
51 | }; |
|
|
52 | |
|
|
53 | 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 | }; |
20 | |
101 | |
21 | cf::register_command chat => 0, sub { |
102 | cf::register_command chat => 0, sub { |
22 | my ($who, $msg) = @_; |
103 | my ($who, $msg) = @_; |
23 | |
104 | |
24 | if ($msg) { |
105 | if ($msg) { |
25 | my $name = $who->name; |
106 | my $name = $who->name; |
26 | my $NOW = time; |
107 | my $NOW = time; |
27 | |
108 | |
|
|
109 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
110 | |
28 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
111 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
29 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
112 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
30 | |
113 | |
31 | } else { |
114 | } else { |
32 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
115 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
33 | } |
116 | } |
34 | }; |
117 | }; |
… | |
… | |
38 | |
121 | |
39 | if ($msg) { |
122 | if ($msg) { |
40 | my $NOW = time; |
123 | my $NOW = time; |
41 | my $name = $who->name; |
124 | my $name = $who->name; |
42 | |
125 | |
|
|
126 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
|
|
127 | |
43 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
128 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
44 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
129 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
45 | |
130 | |
46 | } else { |
131 | } else { |
47 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
132 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
48 | } |
133 | } |
49 | |
134 | |
… | |
… | |
53 | my ($who, $args) = @_; |
138 | my ($who, $args) = @_; |
54 | my ($target, $msg) = split /\s+/, $args, 2; |
139 | my ($target, $msg) = split /\s+/, $args, 2; |
55 | |
140 | |
56 | my $name = $who->name; |
141 | my $name = $who->name; |
57 | |
142 | |
58 | if ($msg) { |
|
|
59 | if (my $other = cf::player::find $target) { |
143 | if (my $other = cf::player::find $target) { |
60 | |
144 | |
|
|
145 | if ($msg) { |
|
|
146 | if ($target eq $name) { |
|
|
147 | $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) { |
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 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
|
|
152 | |
62 | $who->message ("You tell $target: $msg"); |
153 | $who->message ("You tell $target: $msg"); |
63 | $other->ob->message ("$name tells you: $msg"); |
154 | $other->ob->message ("$name tells you: $msg"); |
64 | $other->ob->{ext_last_tell} = $name; |
155 | $other->ob->{ext_last_tell} = $name; |
65 | } elsif ($target eq $name) { |
156 | } |
66 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
|
|
67 | } else { |
157 | } 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); |
158 | $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
|
|
159 | } |
|
|
160 | |
|
|
161 | } else { |
|
|
162 | $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
76 | } |
163 | } |
77 | }; |
164 | }; |
78 | |
165 | |
79 | cf::register_command reply => 0, sub { |
166 | cf::register_command reply => 0, sub { |
80 | my ($who, $args) = @_; |
167 | my ($who, $args) = @_; |
81 | my $name = $who->name; |
168 | my $name = $who->name; |
82 | |
169 | |
83 | if ($args) { |
|
|
84 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
170 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
|
|
171 | if ($args) { |
85 | |
172 | |
86 | $other->ob->{ext_ignore_tell}{$name} >= time |
173 | $other->ob->{ext_ignore_tell}{$name} >= time |
87 | or delete $other->ob->{ext_ignore_tell}{$name}; |
174 | or delete $other->ob->{ext_ignore_tell}{$name}; |
88 | |
175 | |
89 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
176 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
177 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
|
|
178 | |
90 | $who->message ("You tell " . $other->ob->name . ": $args"); |
179 | $who->message ("You tell " . $other->ob->name . ": $args"); |
91 | $other->ob->message ("$name tells you: $args"); |
180 | $other->ob->message ("$name tells you: $args"); |
92 | $who->{ext_last_tell} = $other->ob->name; |
181 | $who->{ext_last_tell} = $other->ob->name; |
93 | } else { |
182 | } else { |
94 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
183 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
95 | } |
184 | } |
|
|
185 | } else { |
|
|
186 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
|
|
187 | } |
96 | |
188 | |
97 | } else { |
189 | } else { |
98 | $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
190 | $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 | } |
191 | } |
103 | }; |
192 | }; |
104 | |
193 | |
105 | cf::register_command ignore => 0, sub { |
194 | cf::register_command ignore => 0, sub { |
106 | my ($who, $args) = @_; |
195 | my ($who, $args) = @_; |
… | |
… | |
121 | } |
210 | } |
122 | |
211 | |
123 | } elsif ($target && $type) { |
212 | } elsif ($target && $type) { |
124 | |
213 | |
125 | $timeout ne "" or $timeout = 24; |
214 | $timeout ne "" or $timeout = 24; |
126 | |
|
|
127 | my $absolute_timeout = time + $timeout * 3600; |
215 | my $absolute_timeout = time + $timeout * 3600; |
128 | |
216 | |
129 | if (my $other = cf::player::find $target) { |
217 | if (valid_user $target) { |
130 | if ($type eq "tell") { |
218 | if ($type eq "tell") { |
131 | $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
219 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
132 | $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; |
220 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
133 | } elsif ($type eq "shout") { |
221 | } elsif ($type eq "shout") { |
134 | $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
222 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
135 | $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; |
223 | $who->{ext_ignore_shout}{$target} = $absolute_timeout; |
136 | } elsif ($type eq "all") { |
224 | } elsif ($type eq "all") { |
137 | $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
225 | $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); |
138 | $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; |
226 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
139 | $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; |
227 | $who->{ext_ignore_shout}{$target} = $absolute_timeout; |
140 | } else { |
228 | } else { |
141 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
229 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
142 | } |
230 | } |
143 | } else { |
231 | } else { |
144 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
232 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
145 | } |
233 | } |
146 | |
234 | |
147 | } else { |
235 | } else { |
148 | $who->message ("Usage:", cf::NDI_UNIQUE); |
|
|
149 | $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); |
236 | $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" |
150 | $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); |
237 | . "will ignore a player for <timeout> hours.\n" |
151 | $who->message ("ignore list", cf::NDI_UNIQUE); |
238 | . "Usage: ignore list\n" |
152 | $who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
239 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
153 | } |
240 | } |
154 | }; |
241 | }; |
155 | |
242 | |
156 | cf::register_command unignore => 0, sub { |
243 | cf::register_command unignore => 0, sub { |
157 | my ($who, $args) = @_; |
244 | my ($who, $args) = @_; |
158 | my ($target, $type) = split /\s+/, $args; |
245 | my ($target, $type) = split /\s+/, $args; |
159 | |
246 | |
160 | if ($args eq "") { |
247 | if ($args eq "") { |
161 | if ($who->{ ext_ignore_tell }) { |
248 | if ($who->{ext_ignore_tell}) { |
162 | $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
249 | $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
163 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
250 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
164 | $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
251 | $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
165 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
252 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
166 | } else { |
253 | } else { |
167 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
254 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
168 | } |
255 | } |
169 | } else { |
256 | } else { |
170 | |
257 | |
171 | if (my $other = cf::player::find $target) { |
258 | if (valid_user $target) { |
172 | if ($type eq "tell") { |
259 | if ($type eq "tell") { |
173 | $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); |
260 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
174 | delete $who->{ext_ignore_tell}{$other->ob->name}; |
261 | delete $who->{ext_ignore_tell} {$target}; |
175 | } elsif ($type eq "shout") { |
262 | } elsif ($type eq "shout") { |
176 | $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); |
263 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
177 | delete $who->{ext_ignore_shout}{$other->ob->name}; |
264 | delete $who->{ext_ignore_shout}{$target}; |
178 | } elsif ($type eq "all") { |
265 | } elsif ($type eq "all") { |
179 | $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); |
266 | $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); |
180 | delete $who->{ext_ignore_tell} {$other->ob->name}; |
267 | delete $who->{ext_ignore_tell} {$target}; |
181 | delete $who->{ext_ignore_shout}{$other->ob->name}; |
268 | delete $who->{ext_ignore_shout}{$target}; |
182 | } else { |
269 | } else { |
183 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
270 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
184 | } |
271 | } |
185 | } else { |
272 | } else { |
186 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
273 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |