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 | |
6 | sub clean_timeouts { |
8 | sub clean_timeouts($) { |
7 | my ($player) = @_; |
9 | my ($player) = @_; |
8 | my $NOW = time; |
10 | my $NOW = time; |
9 | |
11 | |
10 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
12 | for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
11 | delete $hash->{$_} for grep $hash->{$_} < $NOW, keys %$hash; |
13 | while (my ($k, $v) = each %$hash) { |
|
|
14 | if ($v < $NOW) { |
|
|
15 | $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); |
|
|
16 | delete $hash->{$k}; |
|
|
17 | } 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 | delete $hash->{$k}; |
|
|
20 | } |
|
|
21 | } |
12 | } |
22 | } |
13 | } |
23 | } |
14 | |
24 | |
15 | sub on_logout { |
25 | sub on_logout { |
16 | my ($pl, $host) = @_; |
26 | my ($pl, $host) = @_; |
17 | |
27 | |
18 | clean_timeouts $pl->ob; |
28 | clean_timeouts $pl->ob; |
19 | } |
29 | } |
|
|
30 | |
|
|
31 | cf::register_command listen => 0, sub { |
|
|
32 | my ($who, $msg) = @_; |
|
|
33 | my $player = cf::player::find $who->name; |
|
|
34 | |
|
|
35 | if ($msg ne "") { |
|
|
36 | my $prev_listen = $player->listening; |
|
|
37 | $player->listening ($msg); |
|
|
38 | if ($prev_listen == $player->listening) { |
|
|
39 | $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE); |
|
|
40 | } else { |
|
|
41 | $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE); |
|
|
42 | } |
|
|
43 | } else { |
|
|
44 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
|
|
45 | } |
|
|
46 | }; |
|
|
47 | |
|
|
48 | cf::register_command say => 0, sub { |
|
|
49 | my ($who, $msg) = @_; |
|
|
50 | |
|
|
51 | if ($msg) { |
|
|
52 | my $name = $who->name; |
|
|
53 | |
|
|
54 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
|
|
55 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
56 | |
|
|
57 | # npcs, magic_ears etc. |
|
|
58 | # first find all objects and their inventories within a 5x5 square |
|
|
59 | # that have something resembling dialogue |
|
|
60 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
|
|
61 | |
|
|
62 | for my $npc ( |
|
|
63 | grep NPC_Dialogue::has_dialogue $_, |
|
|
64 | map +($_, $_->inv), |
|
|
65 | grep $_, |
|
|
66 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
|
|
67 | 0..24 |
|
|
68 | ) { |
|
|
69 | # if some listener teleported us somewhere else, stop right here |
|
|
70 | last unless $map->path == $who->map->path; |
|
|
71 | |
|
|
72 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
|
|
73 | my $reply = $dialog->tell ($msg); |
|
|
74 | |
|
|
75 | if (defined $reply) { |
|
|
76 | if ($npc->type == cf::MAGIC_EAR) { |
|
|
77 | if (length $reply) { |
|
|
78 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
|
|
79 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
80 | } |
|
|
81 | $npc->use_trigger; |
|
|
82 | } else { |
|
|
83 | if (length $reply) { |
|
|
84 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
|
|
85 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
86 | } |
|
|
87 | } |
|
|
88 | } |
|
|
89 | } |
|
|
90 | |
|
|
91 | } else { |
|
|
92 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
|
|
93 | } |
|
|
94 | }; |
20 | |
95 | |
21 | cf::register_command chat => 0, sub { |
96 | cf::register_command chat => 0, sub { |
22 | my ($who, $msg) = @_; |
97 | my ($who, $msg) = @_; |
23 | |
98 | |
24 | if ($msg) { |
99 | if ($msg) { |
25 | my $name = $who->name; |
100 | my $name = $who->name; |
26 | my $NOW = time; |
101 | my $NOW = time; |
27 | |
102 | |
|
|
103 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
104 | |
28 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
105 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
29 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
106 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
30 | |
107 | |
31 | } else { |
108 | } else { |
32 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
109 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
33 | } |
110 | } |
34 | }; |
111 | }; |
… | |
… | |
38 | |
115 | |
39 | if ($msg) { |
116 | if ($msg) { |
40 | my $NOW = time; |
117 | my $NOW = time; |
41 | my $name = $who->name; |
118 | my $name = $who->name; |
42 | |
119 | |
|
|
120 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
|
|
121 | |
43 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
122 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
44 | for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; |
123 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
45 | |
124 | |
46 | } else { |
125 | } else { |
47 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
126 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
48 | } |
127 | } |
49 | |
128 | |
… | |
… | |
54 | my ($target, $msg) = split /\s+/, $args, 2; |
133 | my ($target, $msg) = split /\s+/, $args, 2; |
55 | |
134 | |
56 | my $name = $who->name; |
135 | my $name = $who->name; |
57 | |
136 | |
58 | if (my $other = cf::player::find $target) { |
137 | if (my $other = cf::player::find $target) { |
|
|
138 | |
59 | if ($msg) { |
139 | if ($msg) { |
60 | |
140 | if ($target eq $name) { |
|
|
141 | $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) { |
142 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
|
|
143 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
|
|
144 | } else { |
|
|
145 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
|
|
146 | |
62 | $who->message ("You tell $target: $msg"); |
147 | $who->message ("You tell $target: $msg"); |
63 | $other->ob->message ("$name tells you: $msg"); |
148 | $other->ob->message ("$name tells you: $msg"); |
64 | $other->ob->{ext_last_tell} = $name; |
149 | $other->ob->{ext_last_tell} = $name; |
65 | } elsif ($target eq $name) { |
|
|
66 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
|
|
67 | } else { |
|
|
68 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
|
|
69 | } |
150 | } |
70 | |
|
|
71 | } else { |
151 | } else { |
72 | $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
152 | $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
73 | } |
153 | } |
|
|
154 | |
74 | } else { |
155 | } else { |
75 | $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); |
156 | $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
76 | } |
157 | } |
77 | }; |
158 | }; |
78 | |
159 | |
79 | cf::register_command reply => 0, sub { |
160 | cf::register_command reply => 0, sub { |
80 | my ($who, $args) = @_; |
161 | my ($who, $args) = @_; |
… | |
… | |
85 | |
166 | |
86 | $other->ob->{ext_ignore_tell}{$name} >= time |
167 | $other->ob->{ext_ignore_tell}{$name} >= time |
87 | or delete $other->ob->{ext_ignore_tell}{$name}; |
168 | or delete $other->ob->{ext_ignore_tell}{$name}; |
88 | |
169 | |
89 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
170 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
171 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
|
|
172 | |
90 | $who->message ("You tell " . $other->ob->name . ": $args"); |
173 | $who->message ("You tell " . $other->ob->name . ": $args"); |
91 | $other->ob->message ("$name tells you: $args"); |
174 | $other->ob->message ("$name tells you: $args"); |
92 | $who->{ext_last_tell} = $other->ob->name; |
175 | $who->{ext_last_tell} = $other->ob->name; |
93 | } else { |
176 | } else { |
94 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
177 | $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
… | |
… | |
121 | } |
204 | } |
122 | |
205 | |
123 | } elsif ($target && $type) { |
206 | } elsif ($target && $type) { |
124 | |
207 | |
125 | $timeout ne "" or $timeout = 24; |
208 | $timeout ne "" or $timeout = 24; |
126 | |
|
|
127 | my $absolute_timeout = time + $timeout * 3600; |
209 | my $absolute_timeout = time + $timeout * 3600; |
128 | |
210 | |
129 | if (my $other = cf::player::find $target) { |
211 | if (cf::player::exists $target) { |
130 | if ($type eq "tell") { |
212 | if ($type eq "tell") { |
131 | $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
213 | $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
132 | $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; |
214 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
133 | } elsif ($type eq "shout") { |
215 | } elsif ($type eq "shout") { |
134 | $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
216 | $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
135 | $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; |
217 | $who->{ext_ignore_shout}{$target} = $absolute_timeout; |
136 | } elsif ($type eq "all") { |
218 | } elsif ($type eq "all") { |
137 | $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); |
219 | $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); |
138 | $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; |
220 | $who->{ext_ignore_tell}{$target} = $absolute_timeout; |
139 | $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; |
221 | $who->{ext_ignore_shout}{$target} = $absolute_timeout; |
140 | } else { |
222 | } else { |
141 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
223 | $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
142 | } |
224 | } |
143 | } else { |
225 | } else { |
144 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
226 | $who->message ("No such player: $target", cf::NDI_UNIQUE); |
145 | } |
227 | } |
146 | |
228 | |
147 | } else { |
229 | } else { |
148 | $who->message ("Usage:", cf::NDI_UNIQUE); |
|
|
149 | $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); |
230 | $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" |
150 | $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); |
231 | . "will ignore a player for <timeout> hours.\n" |
151 | $who->message ("ignore list", cf::NDI_UNIQUE); |
232 | . "Usage: ignore list\n" |
152 | $who->message ("will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
233 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
153 | } |
234 | } |
154 | }; |
235 | }; |
155 | |
236 | |
156 | cf::register_command unignore => 0, sub { |
237 | cf::register_command unignore => 0, sub { |
157 | my ($who, $args) = @_; |
238 | my ($who, $args) = @_; |
158 | my ($target, $type) = split /\s+/, $args; |
239 | my ($target, $type) = split /\s+/, $args; |
159 | |
240 | |
160 | if ($args eq "") { |
241 | if ($args eq "") { |
161 | if ($who->{ ext_ignore_tell }) { |
242 | if ($who->{ext_ignore_tell}) { |
162 | $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
243 | $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
163 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
244 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
164 | $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
245 | $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
165 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
246 | $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
166 | } else { |
247 | } else { |
167 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
248 | $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
168 | } |
249 | } |
169 | } else { |
250 | } else { |
170 | |
251 | |
171 | if (my $other = cf::player::find $target) { |
252 | if (cf::player::exists $target) { |
172 | if ($type eq "tell") { |
253 | if ($type eq "tell") { |
173 | $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); |
254 | $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
174 | delete $who->{ext_ignore_tell}{$other->ob->name}; |
255 | delete $who->{ext_ignore_tell} {$target}; |
175 | } elsif ($type eq "shout") { |
256 | } elsif ($type eq "shout") { |
176 | $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); |
257 | $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
177 | delete $who->{ext_ignore_shout}{$other->ob->name}; |
258 | delete $who->{ext_ignore_shout}{$target}; |
178 | } elsif ($type eq "all") { |
259 | } elsif ($type eq "all") { |
179 | $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); |
260 | $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); |
180 | delete $who->{ext_ignore_tell} {$other->ob->name}; |
261 | delete $who->{ext_ignore_tell} {$target}; |
181 | delete $who->{ext_ignore_shout}{$other->ob->name}; |
262 | delete $who->{ext_ignore_shout}{$target}; |
182 | } else { |
263 | } else { |
183 | $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); |
184 | } |
265 | } |
185 | } else { |
266 | } else { |
186 | $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); |