ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/chat.ext
Revision: 1.23
Committed: Fri Jul 21 08:22:02 2006 UTC (17 years, 10 months ago) by root
Branch: MAIN
Changes since 1.22: +22 -2 lines
Log Message:
implemented 'seen' command

File Contents

# User Rev Content
1 pippijn 1.1 #! perl
2 root 1.5
3 pippijn 1.15 # implement a replacement for the built-in say/chat/shout/tell/reply commands
4 root 1.5 # adds ignore/unignore functionality
5    
6 root 1.20 use NPC_Dialogue;
7 root 1.23 use POSIX (); # for strftime only
8 root 1.20
9 root 1.12 sub clean_timeouts($) {
10 root 1.8 my ($player) = @_;
11     my $NOW = time;
12    
13     for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
14 root 1.12 while (my ($k, $v) = each %$hash) {
15     if ($v < $NOW) {
16 root 1.20 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
17 root 1.12 delete $hash->{$k};
18 root 1.22 } elsif (!cf::player::exists $k) {
19 root 1.20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
20 root 1.12 delete $hash->{$k};
21     }
22     }
23 root 1.8 }
24     }
25    
26     sub on_logout {
27     my ($pl, $host) = @_;
28    
29     clean_timeouts $pl->ob;
30     }
31    
32 pippijn 1.15 cf::register_command listen => 0, sub {
33     my ($who, $msg) = @_;
34     my $player = cf::player::find $who->name;
35    
36 pippijn 1.17 if ($msg ne "") {
37 pippijn 1.15 my $prev_listen = $player->listening;
38     $player->listening ($msg);
39     if ($prev_listen == $player->listening) {
40 root 1.20 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
41 pippijn 1.15 } else {
42 root 1.20 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
43 pippijn 1.15 }
44     } else {
45 root 1.20 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
46 pippijn 1.15 }
47     };
48    
49 root 1.21 cf::register_command say => 0, sub {
50 root 1.20 my ($who, $msg) = @_;
51    
52     if ($msg) {
53     my $name = $who->name;
54    
55 root 1.21 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
56     for grep $who->on_same_map_as ($_->ob), cf::player::list;
57 root 1.20
58     # npcs, magic_ears etc.
59     # first find all objects and their inventories within a 5x5 square
60     # that have something resembling dialogue
61     my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
62    
63     for my $npc (
64     grep NPC_Dialogue::has_dialogue $_,
65     map +($_, $_->inv),
66     grep $_,
67     map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
68     0..24
69     ) {
70     # if some listener teleported us somewhere else, stop right here
71     last unless $map->path == $who->map->path;
72    
73     my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
74     my $reply = $dialog->tell ($msg);
75    
76     if (defined $reply) {
77     if ($npc->type == cf::MAGIC_EAR) {
78 root 1.21 if (length $reply) {
79     $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
80     for grep $who->on_same_map_as ($_->ob), cf::player::list;
81     }
82 root 1.20 $npc->use_trigger;
83     } else {
84 root 1.21 if (length $reply) {
85     $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
86     for grep $who->on_same_map_as ($_->ob), cf::player::list;
87     }
88 root 1.20 }
89     }
90     }
91    
92     } else {
93     $who->message ("What do you want to say?", cf::NDI_UNIQUE);
94     }
95     };
96 pippijn 1.15
97 pippijn 1.6 cf::register_command chat => 0, sub {
98 pippijn 1.1 my ($who, $msg) = @_;
99    
100     if ($msg) {
101     my $name = $who->name;
102 root 1.8 my $NOW = time;
103 pippijn 1.1
104 root 1.19 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
105    
106 root 1.4 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
107 pippijn 1.15 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
108 root 1.4
109 pippijn 1.1 } else {
110     $who->message ("Chat what?", cf::NDI_UNIQUE);
111     }
112     };
113    
114 pippijn 1.6 cf::register_command shout => 0, sub {
115 pippijn 1.1 my ($who, $msg) = @_;
116    
117     if ($msg) {
118 root 1.8 my $NOW = time;
119 pippijn 1.1 my $name = $who->name;
120    
121 root 1.19 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
122    
123 root 1.4 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
124 pippijn 1.15 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
125 root 1.4
126 pippijn 1.1 } else {
127     $who->message ("Shout what?", cf::NDI_UNIQUE);
128     }
129    
130     };
131 root 1.5
132     cf::register_command tell => 0, sub {
133     my ($who, $args) = @_;
134     my ($target, $msg) = split /\s+/, $args, 2;
135    
136     my $name = $who->name;
137    
138 pippijn 1.11 if (my $other = cf::player::find $target) {
139 root 1.12
140 pippijn 1.11 if ($msg) {
141 root 1.12 if ($target eq $name) {
142     $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
143     } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
144     $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
145     } else {
146 root 1.19 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
147    
148 pippijn 1.9 $who->message ("You tell $target: $msg");
149     $other->ob->message ("$name tells you: $msg");
150     $other->ob->{ext_last_tell} = $name;
151     }
152 root 1.5 } else {
153 pippijn 1.11 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
154 root 1.5 }
155 root 1.12
156 root 1.5 } else {
157 root 1.12 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
158 root 1.5 }
159     };
160    
161     cf::register_command reply => 0, sub {
162     my ($who, $args) = @_;
163     my $name = $who->name;
164    
165 pippijn 1.11 if (my $other = cf::player::find $who->{ext_last_tell}) {
166     if ($args) {
167 root 1.5
168 pippijn 1.9 $other->ob->{ext_ignore_tell}{$name} >= time
169     or delete $other->ob->{ext_ignore_tell}{$name};
170    
171     if ($other->ob->{ext_ignore_tell}{$name} < time) {
172 root 1.19 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
173    
174 pippijn 1.9 $who->message ("You tell " . $other->ob->name . ": $args");
175     $other->ob->message ("$name tells you: $args");
176     $who->{ext_last_tell} = $other->ob->name;
177     } else {
178     $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
179     }
180 root 1.5 } else {
181 pippijn 1.11 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
182 root 1.5 }
183 pippijn 1.11
184 root 1.5 } else {
185 pippijn 1.11 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
186 root 1.5 }
187     };
188    
189     cf::register_command ignore => 0, sub {
190     my ($who, $args) = @_;
191     my ($target, $type, $timeout) = split /\s+/, $args;
192    
193     if ($args eq "list") {
194 root 1.8 clean_timeouts $who;
195    
196 root 1.5 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
197     + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
198     $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
199     $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
200     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
201     $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
202     $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
203     } else {
204     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
205     }
206    
207     } elsif ($target && $type) {
208    
209     $timeout ne "" or $timeout = 24;
210     my $absolute_timeout = time + $timeout * 3600;
211    
212 root 1.22 if (cf::player::exists $target) {
213 root 1.5 if ($type eq "tell") {
214 root 1.12 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
215     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
216 root 1.5 } elsif ($type eq "shout") {
217 root 1.12 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
218     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
219 root 1.5 } elsif ($type eq "all") {
220 root 1.12 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
221     $who->{ext_ignore_tell}{$target} = $absolute_timeout;
222     $who->{ext_ignore_shout}{$target} = $absolute_timeout;
223 root 1.5 } else {
224     $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
225     }
226     } else {
227 root 1.12 $who->message ("No such player: $target", cf::NDI_UNIQUE);
228 root 1.5 }
229    
230     } else {
231 root 1.23 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
232 root 1.12 . "will ignore a player for <timeout> hours.\n"
233     . "Usage: ignore list\n"
234     . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
235 root 1.5 }
236     };
237    
238     cf::register_command unignore => 0, sub {
239     my ($who, $args) = @_;
240     my ($target, $type) = split /\s+/, $args;
241    
242     if ($args eq "") {
243 root 1.12 if ($who->{ext_ignore_tell}) {
244 root 1.5 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
245     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
246     $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
247     $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
248     } else {
249     $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
250     }
251     } else {
252 root 1.22 if (cf::player::exists $target) {
253 root 1.5 if ($type eq "tell") {
254 root 1.12 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
255     delete $who->{ext_ignore_tell} {$target};
256 root 1.5 } elsif ($type eq "shout") {
257 root 1.12 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
258     delete $who->{ext_ignore_shout}{$target};
259 root 1.5 } elsif ($type eq "all") {
260 root 1.12 $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 root 1.5 } 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 root 1.23 }
270     };
271    
272     cf::register_command seen => 0, sub {
273     my ($who, $args) = @_;
274 root 1.5
275 root 1.23 if (my ($login) = $args =~ /(\S+)/) {
276     if (cf::player::find $login) {
277     $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
278     } elsif (cf::player::exists $login
279     and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
280     my $time = (stat _)[9];
281    
282     $who->message ("$login was last seen here on "
283     . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
284     . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
285     } else {
286     $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
287     }
288     } else {
289     $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
290 root 1.5 }
291     };
292