ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
(Generate patch)

Comparing deliantra/maps/perl/chat.ext (file contents):
Revision 1.4 by root, Sun May 7 08:05:26 2006 UTC vs.
Revision 1.21 by root, Wed Jul 19 22:20:07 2006 UTC

1#! perl 1#! perl
2
3# implement a replacement for the built-in say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality
5
6use NPC_Dialogue;
7
8sub clean_timeouts($) {
9 my ($player) = @_;
10 my $NOW = time;
11
12 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
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 (!valid_user $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 }
22 }
23}
24
25sub on_logout {
26 my ($pl, $host) = @_;
27
28 clean_timeouts $pl->ob;
29}
30
31cf::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
2cf::register_command chat => 0, sub 48cf::register_command say => 0, sub {
3{
4 my ($who, $msg) = @_; 49 my ($who, $msg) = @_;
5 50
6 if ($msg) { 51 if ($msg) {
7 my $name = $who->name; 52 my $name = $who->name;
8 53
9 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 54 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
10 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 55 for grep $who->on_same_map_as ($_->ob), cf::player::list;
11 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
12 } else { 91 } else {
13 $who->message ("Chat what?", cf::NDI_UNIQUE); 92 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
14 } 93 }
15}; 94};
16 95
17cf::register_command shout => 0, sub 96cf::register_command chat => 0, sub {
18{
19 my ($who, $msg) = @_; 97 my ($who, $msg) = @_;
20 98
21 if ($msg) { 99 if ($msg) {
22 my $name = $who->name; 100 my $name = $who->name;
101 my $NOW = time;
102
103 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
104
105 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
106 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
107
108 } else {
109 $who->message ("Chat what?", cf::NDI_UNIQUE);
110 }
111};
112
113cf::register_command shout => 0, sub {
114 my ($who, $msg) = @_;
115
116 if ($msg) {
117 my $NOW = time;
118 my $name = $who->name;
119
120 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
23 121
24 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 122 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
25 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 123 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
26 124
27 } else { 125 } else {
28 $who->message ("Shout what?", cf::NDI_UNIQUE); 126 $who->message ("Shout what?", cf::NDI_UNIQUE);
29 } 127 }
30 128
31}; 129};
130
131cf::register_command tell => 0, sub {
132 my ($who, $args) = @_;
133 my ($target, $msg) = split /\s+/, $args, 2;
134
135 my $name = $who->name;
136
137 if (my $other = cf::player::find $target) {
138
139 if ($msg) {
140 if ($target eq $name) {
141 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
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
147 $who->message ("You tell $target: $msg");
148 $other->ob->message ("$name tells you: $msg");
149 $other->ob->{ext_last_tell} = $name;
150 }
151 } else {
152 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
153 }
154
155 } else {
156 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
157 }
158};
159
160cf::register_command reply => 0, sub {
161 my ($who, $args) = @_;
162 my $name = $who->name;
163
164 if (my $other = cf::player::find $who->{ext_last_tell}) {
165 if ($args) {
166
167 $other->ob->{ext_ignore_tell}{$name} >= time
168 or delete $other->ob->{ext_ignore_tell}{$name};
169
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
173 $who->message ("You tell " . $other->ob->name . ": $args");
174 $other->ob->message ("$name tells you: $args");
175 $who->{ext_last_tell} = $other->ob->name;
176 } else {
177 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
178 }
179 } else {
180 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
181 }
182
183 } else {
184 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
185 }
186};
187
188cf::register_command ignore => 0, sub {
189 my ($who, $args) = @_;
190 my ($target, $type, $timeout) = split /\s+/, $args;
191
192 if ($args eq "list") {
193 clean_timeouts $who;
194
195 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
196 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
197 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
198 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
199 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
200 $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
201 $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
202 } else {
203 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
204 }
205
206 } elsif ($target && $type) {
207
208 $timeout ne "" or $timeout = 24;
209 my $absolute_timeout = time + $timeout * 3600;
210
211 if (valid_user $target) {
212 if ($type eq "tell") {
213 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
214 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
215 } elsif ($type eq "shout") {
216 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
217 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
218 } elsif ($type eq "all") {
219 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
220 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
221 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
222 } else {
223 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
224 }
225 } else {
226 $who->message ("No such player: $target", cf::NDI_UNIQUE);
227 }
228
229 } else {
230 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
231 . "will ignore a player for <timeout> hours.\n"
232 . "Usage: ignore list\n"
233 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
234 }
235};
236
237cf::register_command unignore => 0, sub {
238 my ($who, $args) = @_;
239 my ($target, $type) = split /\s+/, $args;
240
241 if ($args eq "") {
242 if ($who->{ext_ignore_tell}) {
243 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
244 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
245 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
246 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
247 } else {
248 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
249 }
250 } else {
251
252 if (valid_user $target) {
253 if ($type eq "tell") {
254 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
255 delete $who->{ext_ignore_tell} {$target};
256 } elsif ($type eq "shout") {
257 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
258 delete $who->{ext_ignore_shout}{$target};
259 } elsif ($type eq "all") {
260 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
261 delete $who->{ext_ignore_tell} {$target};
262 delete $who->{ext_ignore_shout}{$target};
263 } else {
264 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
265 }
266 } else {
267 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
268 }
269
270 }
271};
272

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines