1 | #! perl |
1 | #! perl |
|
|
2 | #CONVERSION: PARTIAL |
2 | |
3 | |
3 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 | # implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 | # adds ignore/unignore functionality |
5 | # adds ignore/unignore functionality |
5 | |
6 | |
6 | use NPC_Dialogue; |
7 | use NPC_Dialogue; |
… | |
… | |
21 | } |
22 | } |
22 | } |
23 | } |
23 | } |
24 | } |
24 | } |
25 | } |
25 | |
26 | |
26 | sub on_login { |
27 | cf::attach_to_players |
|
|
28 | prio => -1000, |
|
|
29 | on_login => sub { |
27 | my ($pl, $host) = @_; |
30 | my ($pl) = @_; |
28 | |
31 | |
29 | clean_timeouts $pl->ob; |
32 | clean_timeouts $pl->ob; |
30 | } |
33 | }, |
|
|
34 | ; |
31 | |
35 | |
32 | cf::register_command listen => 0, sub { |
36 | cf::register_command listen => sub { |
33 | my ($who, $msg) = @_; |
37 | my ($who, $msg) = @_; |
34 | my $player = cf::player::find $who->name; |
38 | my $player = cf::player::find $who->name; |
35 | |
39 | |
36 | if ($msg ne "") { |
40 | if ($msg ne "") { |
37 | my $prev_listen = $player->listening; |
41 | my $prev_listen = $player->listening; |
… | |
… | |
44 | } else { |
48 | } else { |
45 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
49 | $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); |
46 | } |
50 | } |
47 | }; |
51 | }; |
48 | |
52 | |
49 | cf::register_command say => 0, sub { |
53 | cf::register_command say => sub { |
50 | my ($who, $msg) = @_; |
54 | my ($who, $msg) = @_; |
51 | |
55 | |
52 | utf8::decode $msg; |
56 | utf8::decode $msg; |
|
|
57 | |
|
|
58 | return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
53 | |
59 | |
54 | if ($msg) { |
60 | if ($msg) { |
55 | my $name = $who->name; |
61 | my $name = $who->name; |
56 | |
62 | |
57 | utf8::encode $msg; # ->message not yet utf8-ified |
63 | utf8::encode $msg; # ->message not yet utf8-ified |
58 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
64 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
59 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
65 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
60 | utf8::decode $msg; |
66 | utf8::decode $msg; |
61 | |
67 | |
62 | # npcs, magic_ears etc. |
68 | # npcs, magic_ears etc. |
63 | # first find all objects and their inventories within a 5x5 square |
69 | # first find all objects and theirt-level inventories |
64 | # that have something resembling dialogue |
70 | # within a 5x5 square # that have something resembling |
|
|
71 | # dialogue or support on_say. |
65 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
72 | my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); |
66 | |
73 | |
67 | for my $npc ( |
74 | for my $npc ( |
68 | grep NPC_Dialogue::has_dialogue $_, |
75 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
69 | map +($_, $_->inv), |
76 | map +($_, $_->inv), |
70 | grep $_, |
77 | grep $_, |
71 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
78 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
72 | 0..24 |
79 | 0..24 |
73 | ) { |
80 | ) { |
… | |
… | |
101 | } else { |
108 | } else { |
102 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
109 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
103 | } |
110 | } |
104 | }; |
111 | }; |
105 | |
112 | |
106 | cf::register_command chat => 0, sub { |
113 | cf::register_command chat => sub { |
107 | my ($who, $msg) = @_; |
114 | my ($who, $msg) = @_; |
108 | |
115 | |
109 | utf8::decode $msg; |
116 | utf8::decode $msg; |
|
|
117 | |
|
|
118 | return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); |
110 | |
119 | |
111 | if ($msg) { |
120 | if ($msg) { |
112 | my $name = $who->name; |
121 | my $name = $who->name; |
113 | my $NOW = time; |
122 | my $NOW = time; |
114 | |
123 | |
115 | utf8::encode $msg; # ->message not yet utf8-ified |
124 | utf8::encode $msg; # ->message not yet utf8-ified |
116 | # cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
125 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
117 | cf::ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
126 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
118 | |
127 | |
119 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
128 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
120 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
129 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
121 | |
130 | |
122 | } else { |
131 | } else { |
123 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
132 | $who->message ("Chat what?", cf::NDI_UNIQUE); |
124 | } |
133 | } |
125 | }; |
134 | }; |
126 | |
135 | |
127 | cf::register_command shout => 0, sub { |
136 | cf::register_command shout => sub { |
128 | my ($who, $msg) = @_; |
137 | my ($who, $msg) = @_; |
129 | |
138 | |
130 | utf8::decode $msg; |
139 | utf8::decode $msg; |
|
|
140 | |
|
|
141 | return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
131 | |
142 | |
132 | if ($msg) { |
143 | if ($msg) { |
133 | my $NOW = time; |
144 | my $NOW = time; |
134 | my $name = $who->name; |
145 | my $name = $who->name; |
135 | |
146 | |
136 | # cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
147 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
137 | cf::ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg); |
148 | ext::schmorp_irc::do_notice (sprintf "\007\0034{%s} %s\n", $name, $msg); |
138 | |
149 | |
139 | utf8::encode $msg; # ->message not yet utf8-ified |
150 | utf8::encode $msg; # ->message not yet utf8-ified |
140 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
151 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
141 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
152 | for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
142 | |
153 | |
… | |
… | |
144 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
155 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
145 | } |
156 | } |
146 | |
157 | |
147 | }; |
158 | }; |
148 | |
159 | |
149 | cf::register_command tell => 0, sub { |
160 | cf::register_command tell => sub { |
150 | my ($who, $args) = @_; |
161 | my ($who, $args) = @_; |
151 | my ($target, $msg) = split /\s+/, $args, 2; |
162 | my ($target, $msg) = split /\s+/, $args, 2; |
152 | |
163 | |
153 | utf8::decode $msg; |
164 | utf8::decode $msg; |
154 | |
165 | |
|
|
166 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
|
|
167 | |
155 | my $name = $who->name; |
168 | my $name = $who->name; |
156 | |
169 | |
|
|
170 | if ($target =~ /irc\//) { |
|
|
171 | my (undef, $nick) = split /\//, $target, 2; |
|
|
172 | $who->message ("You tell $target: $args"); |
|
|
173 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $msg); |
157 | if (my $other = cf::player::find $target) { |
174 | } elsif (my $other = cf::player::find $target) { |
158 | |
175 | |
159 | if ($msg) { |
176 | if ($msg) { |
160 | if ($target eq $name) { |
177 | if ($target eq $name) { |
161 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
178 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
162 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
179 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
… | |
… | |
176 | } else { |
193 | } else { |
177 | $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
194 | $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
178 | } |
195 | } |
179 | }; |
196 | }; |
180 | |
197 | |
181 | cf::register_command reply => 0, sub { |
198 | cf::register_command reply => sub { |
182 | my ($who, $args) = @_; |
199 | my ($who, $args) = @_; |
183 | my $name = $who->name; |
200 | my $name = $who->name; |
184 | |
201 | |
185 | utf8::decode $args; |
202 | utf8::decode $args; |
186 | |
203 | |
|
|
204 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); |
|
|
205 | |
|
|
206 | if ($who->{ext_last_tell} =~ /irc\//) { |
|
|
207 | my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2; |
|
|
208 | $who->message ("You tell " . $who->{ext_last_tell} . ": $args"); |
|
|
209 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
187 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
210 | } elsif (my $other = cf::player::find $who->{ext_last_tell}) { |
|
|
211 | |
188 | if ($args) { |
212 | if ($args) { |
189 | |
|
|
190 | $other->ob->{ext_ignore_tell}{$name} >= time |
213 | $other->ob->{ext_ignore_tell}{$name} >= time |
191 | or delete $other->ob->{ext_ignore_tell}{$name}; |
214 | or delete $other->ob->{ext_ignore_tell}{$name}; |
192 | |
215 | |
193 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
216 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
194 | utf8::encode $args; # ->message not yet utf8-ified |
217 | utf8::encode $args; # ->message not yet utf8-ified |
… | |
… | |
203 | } else { |
226 | } else { |
204 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
227 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
205 | } |
228 | } |
206 | |
229 | |
207 | } else { |
230 | } else { |
208 | $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
231 | $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE); |
209 | } |
232 | } |
210 | }; |
233 | }; |
211 | |
234 | |
212 | cf::register_command ignore => 0, sub { |
235 | cf::register_command ignore => sub { |
213 | my ($who, $args) = @_; |
236 | my ($who, $args) = @_; |
214 | my ($target, $type, $timeout) = split /\s+/, $args; |
237 | my ($target, $type, $timeout) = split /\s+/, $args; |
215 | |
238 | |
216 | if ($args eq "list") { |
239 | if ($args eq "list") { |
217 | clean_timeouts $who; |
240 | clean_timeouts $who; |
… | |
… | |
256 | . "Usage: ignore list\n" |
279 | . "Usage: ignore list\n" |
257 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
280 | . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
258 | } |
281 | } |
259 | }; |
282 | }; |
260 | |
283 | |
261 | cf::register_command unignore => 0, sub { |
284 | cf::register_command unignore => sub { |
262 | my ($who, $args) = @_; |
285 | my ($who, $args) = @_; |
263 | my ($target, $type) = split /\s+/, $args; |
286 | my ($target, $type) = split /\s+/, $args; |
264 | |
287 | |
265 | if ($args eq "") { |
288 | if ($args eq "") { |
266 | if ($who->{ext_ignore_tell}) { |
289 | if ($who->{ext_ignore_tell}) { |
… | |
… | |
290 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
313 | $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
291 | } |
314 | } |
292 | } |
315 | } |
293 | }; |
316 | }; |
294 | |
317 | |
295 | cf::register_command seen => 0, sub { |
318 | cf::register_command seen => sub { |
296 | my ($who, $args) = @_; |
319 | my ($who, $args) = @_; |
297 | |
320 | |
298 | if (my ($login) = $args =~ /(\S+)/) { |
321 | if (my ($login) = $args =~ /(\S+)/) { |
299 | if ($login eq $who->name) { |
322 | if ($login eq $who->name) { |
300 | $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |
323 | $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE); |