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_logout { |
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 => 0, 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 | |
… | |
… | |
47 | }; |
51 | }; |
48 | |
52 | |
49 | cf::register_command say => 0, sub { |
53 | cf::register_command say => 0, sub { |
50 | my ($who, $msg) = @_; |
54 | my ($who, $msg) = @_; |
51 | |
55 | |
|
|
56 | utf8::decode $msg; |
|
|
57 | |
|
|
58 | return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg); |
|
|
59 | |
52 | if ($msg) { |
60 | if ($msg) { |
53 | my $name = $who->name; |
61 | my $name = $who->name; |
54 | |
62 | |
|
|
63 | utf8::encode $msg; # ->message not yet utf8-ified |
55 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
64 | $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) |
56 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
65 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
66 | utf8::decode $msg; |
57 | |
67 | |
58 | # npcs, magic_ears etc. |
68 | # npcs, magic_ears etc. |
59 | # first find all objects and their inventories within a 5x5 square |
69 | # first find all objects and theirt-level inventories |
60 | # that have something resembling dialogue |
70 | # within a 5x5 square # that have something resembling |
|
|
71 | # dialogue or support on_say. |
61 | 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); |
62 | |
73 | |
63 | for my $npc ( |
74 | for my $npc ( |
64 | grep NPC_Dialogue::has_dialogue $_, |
75 | grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_, |
65 | map +($_, $_->inv), |
76 | map +($_, $_->inv), |
66 | grep $_, |
77 | grep $_, |
67 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
78 | map $map->at ($x + $_ % 5, $y + (int $_ / 5)), |
68 | 0..24 |
79 | 0..24 |
69 | ) { |
80 | ) { |
70 | # if some listener teleported us somewhere else, stop right here |
81 | # if some listener teleported us somewhere else, stop right here |
71 | last unless $map->path == $who->map->path; |
82 | last unless $map->path == $who->map->path; |
72 | |
83 | |
73 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
84 | my $dialog = new NPC_Dialogue ob => $who, npc => $npc; |
74 | my $reply = $dialog->tell ($msg); |
85 | my ($reply, @kw) = $dialog->tell ($msg); |
75 | |
86 | |
76 | if (defined $reply) { |
87 | if (defined $reply) { |
77 | if ($npc->type == cf::MAGIC_EAR) { |
88 | if ($npc->type == cf::MAGIC_EAR) { |
78 | if (length $reply) { |
89 | if (length $reply) { |
79 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
90 | $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) |
… | |
… | |
85 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
96 | $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) |
86 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
97 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
87 | } |
98 | } |
88 | } |
99 | } |
89 | } |
100 | } |
|
|
101 | |
|
|
102 | if (@kw) { |
|
|
103 | $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE) |
|
|
104 | for grep $who->on_same_map_as ($_->ob), cf::player::list; |
|
|
105 | } |
90 | } |
106 | } |
91 | |
107 | |
92 | } else { |
108 | } else { |
93 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
109 | $who->message ("What do you want to say?", cf::NDI_UNIQUE); |
94 | } |
110 | } |
95 | }; |
111 | }; |
96 | |
112 | |
97 | cf::register_command chat => 0, sub { |
113 | cf::register_command chat => 0, sub { |
98 | my ($who, $msg) = @_; |
114 | my ($who, $msg) = @_; |
|
|
115 | |
|
|
116 | utf8::decode $msg; |
|
|
117 | |
|
|
118 | return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg); |
99 | |
119 | |
100 | if ($msg) { |
120 | if ($msg) { |
101 | my $name = $who->name; |
121 | my $name = $who->name; |
102 | my $NOW = time; |
122 | my $NOW = time; |
103 | |
123 | |
|
|
124 | utf8::encode $msg; # ->message not yet utf8-ified |
104 | cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
125 | # cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
|
|
126 | ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg); |
105 | |
127 | |
106 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
128 | $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
107 | 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; |
108 | |
130 | |
109 | } else { |
131 | } else { |
… | |
… | |
111 | } |
133 | } |
112 | }; |
134 | }; |
113 | |
135 | |
114 | cf::register_command shout => 0, sub { |
136 | cf::register_command shout => 0, sub { |
115 | my ($who, $msg) = @_; |
137 | my ($who, $msg) = @_; |
|
|
138 | |
|
|
139 | utf8::decode $msg; |
|
|
140 | |
|
|
141 | return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg); |
116 | |
142 | |
117 | if ($msg) { |
143 | if ($msg) { |
118 | my $NOW = time; |
144 | my $NOW = time; |
119 | my $name = $who->name; |
145 | my $name = $who->name; |
120 | |
146 | |
121 | cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
147 | # cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
|
|
148 | ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg); |
122 | |
149 | |
|
|
150 | utf8::encode $msg; # ->message not yet utf8-ified |
123 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
151 | $_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
124 | 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; |
125 | |
153 | |
126 | } else { |
154 | } else { |
127 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
155 | $who->message ("Shout what?", cf::NDI_UNIQUE); |
… | |
… | |
131 | |
159 | |
132 | cf::register_command tell => 0, sub { |
160 | cf::register_command tell => 0, sub { |
133 | my ($who, $args) = @_; |
161 | my ($who, $args) = @_; |
134 | my ($target, $msg) = split /\s+/, $args, 2; |
162 | my ($target, $msg) = split /\s+/, $args, 2; |
135 | |
163 | |
|
|
164 | utf8::decode $msg; |
|
|
165 | |
|
|
166 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg); |
|
|
167 | |
136 | my $name = $who->name; |
168 | my $name = $who->name; |
137 | |
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); |
|
|
174 | } |
|
|
175 | |
138 | if (my $other = cf::player::find $target) { |
176 | elsif (my $other = cf::player::find $target) { |
139 | |
177 | |
140 | if ($msg) { |
178 | if ($msg) { |
141 | if ($target eq $name) { |
179 | if ($target eq $name) { |
142 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
180 | $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
143 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
181 | } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
144 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
182 | $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
145 | } else { |
183 | } else { |
|
|
184 | utf8::encode $msg; # ->message not yet utf8-ified |
146 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
185 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; |
147 | |
186 | |
148 | $who->message ("You tell $target: $msg"); |
187 | $who->message ("You tell $target: $msg"); |
149 | $other->ob->message ("$name tells you: $msg"); |
188 | $other->ob->message ("$name tells you: $msg"); |
150 | $other->ob->{ext_last_tell} = $name; |
189 | $other->ob->{ext_last_tell} = $name; |
… | |
… | |
160 | |
199 | |
161 | cf::register_command reply => 0, sub { |
200 | cf::register_command reply => 0, sub { |
162 | my ($who, $args) = @_; |
201 | my ($who, $args) = @_; |
163 | my $name = $who->name; |
202 | my $name = $who->name; |
164 | |
203 | |
|
|
204 | utf8::decode $args; |
|
|
205 | |
|
|
206 | return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args); |
|
|
207 | |
|
|
208 | if ($who->{ext_last_tell} =~ /irc\//) { |
|
|
209 | my (undef, $nick) = split /\//, $who->{ext_last_tell}, 2; |
|
|
210 | $who->message ("You tell " . $who->{ext_last_tell} . ": $args"); |
|
|
211 | ext::schmorp_irc::do_notice (sprintf "(%s) %s: %s\n", $name, $nick, $args); |
|
|
212 | } |
|
|
213 | |
165 | if (my $other = cf::player::find $who->{ext_last_tell}) { |
214 | elsif (my $other = cf::player::find $who->{ext_last_tell}) { |
|
|
215 | |
166 | if ($args) { |
216 | if ($args) { |
167 | |
|
|
168 | $other->ob->{ext_ignore_tell}{$name} >= time |
217 | $other->ob->{ext_ignore_tell}{$name} >= time |
169 | or delete $other->ob->{ext_ignore_tell}{$name}; |
218 | or delete $other->ob->{ext_ignore_tell}{$name}; |
170 | |
219 | |
171 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
220 | if ($other->ob->{ext_ignore_tell}{$name} < time) { |
|
|
221 | utf8::encode $args; # ->message not yet utf8-ified |
172 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
222 | cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; |
173 | |
223 | |
174 | $who->message ("You tell " . $other->ob->name . ": $args"); |
224 | $who->message ("You tell " . $other->ob->name . ": $args"); |
175 | $other->ob->message ("$name tells you: $args"); |
225 | $other->ob->message ("$name tells you: $args"); |
176 | $who->{ext_last_tell} = $other->ob->name; |
226 | $who->{ext_last_tell} = $other->ob->name; |
… | |
… | |
180 | } else { |
230 | } else { |
181 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
231 | $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
182 | } |
232 | } |
183 | |
233 | |
184 | } else { |
234 | } else { |
185 | $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
235 | $who->message ("Can't reply, player left. Your message: $args".$who->{ext_last_tell}, cf::NDI_UNIQUE); |
186 | } |
236 | } |
187 | }; |
237 | }; |
188 | |
238 | |
189 | cf::register_command ignore => 0, sub { |
239 | cf::register_command ignore => 0, sub { |
190 | my ($who, $args) = @_; |
240 | my ($who, $args) = @_; |
… | |
… | |
279 | $who->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
329 | $who->message ("$login is right here on this server!", cf::NDI_UNIQUE); |
280 | } elsif (cf::player::exists $login |
330 | } elsif (cf::player::exists $login |
281 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
331 | and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) { |
282 | my $time = (stat _)[9]; |
332 | my $time = (stat _)[9]; |
283 | |
333 | |
284 | $who->message ("$login was last seen here on " |
334 | $who->message ("$login was last seen here " |
285 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
335 | . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time) |
286 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
336 | . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE); |
287 | } else { |
337 | } else { |
288 | $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
338 | $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE); |
289 | } |
339 | } |