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.19 by root, Fri Jun 9 04:18:02 2006 UTC vs.
Revision 1.24 by root, Fri Jul 21 08:24:47 2006 UTC

1#! perl 1#! perl
2 2
3# implement a replacement for the built-in say/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
6sub valid_user($) { 6use NPC_Dialogue;
7 cf::player::find $_[0] 7use POSIX (); # for strftime only
8 or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
9}
10 8
11sub clean_timeouts($) { 9sub clean_timeouts($) {
12 my ($player) = @_; 10 my ($player) = @_;
13 my $NOW = time; 11 my $NOW = time;
14 12
15 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 13 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
16 while (my ($k, $v) = each %$hash) { 14 while (my ($k, $v) = each %$hash) {
17 if ($v < $NOW) { 15 if ($v < $NOW) {
18 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); 16 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
19 delete $hash->{$k}; 17 delete $hash->{$k};
20 } elsif (!valid_user $k) { 18 } elsif (!cf::player::exists $k) {
21 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); 19 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
22 delete $hash->{$k}; 20 delete $hash->{$k};
23 } 21 }
24 } 22 }
25 } 23 }
26} 24}
37 35
38 if ($msg ne "") { 36 if ($msg ne "") {
39 my $prev_listen = $player->listening; 37 my $prev_listen = $player->listening;
40 $player->listening ($msg); 38 $player->listening ($msg);
41 if ($prev_listen == $player->listening) { 39 if ($prev_listen == $player->listening) {
42 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); 40 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
43 } else { 41 } else {
44 $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); 42 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
45 } 43 }
46 } else { 44 } else {
47 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); 45 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
48 } 46 }
49}; 47};
50 48
51#cf::register_command say => 0, sub { 49cf::register_command say => 0, sub {
52# my ($who, $msg) = @_; 50 my ($who, $msg) = @_;
53# 51
54# if ($msg) { 52 if ($msg) {
55# my $name = $who->name; 53 my $name = $who->name;
54
56# $_->ob->message ("$name says: $msg", cf::NDI_WHITE) 55 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
57# for grep $who->on_same_map_as ($_->ob), cf::player::list; 56 for grep $who->on_same_map_as ($_->ob), cf::player::list;
57
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 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 $npc->use_trigger;
83 } else {
84 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 }
89 }
90 }
91
58# } else { 92 } else {
59# $who->message ("What do you want to say?", cf::NDI_UNIQUE); 93 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
60# } 94 }
61#}; 95};
62 96
63cf::register_command chat => 0, sub { 97cf::register_command chat => 0, sub {
64 my ($who, $msg) = @_; 98 my ($who, $msg) = @_;
65 99
66 if ($msg) { 100 if ($msg) {
173 } elsif ($target && $type) { 207 } elsif ($target && $type) {
174 208
175 $timeout ne "" or $timeout = 24; 209 $timeout ne "" or $timeout = 24;
176 my $absolute_timeout = time + $timeout * 3600; 210 my $absolute_timeout = time + $timeout * 3600;
177 211
178 if (valid_user $target) { 212 if (cf::player::exists $target) {
179 if ($type eq "tell") { 213 if ($type eq "tell") {
180 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); 214 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
181 $who->{ext_ignore_tell}{$target} = $absolute_timeout; 215 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
182 } elsif ($type eq "shout") { 216 } elsif ($type eq "shout") {
183 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); 217 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
192 } else { 226 } else {
193 $who->message ("No such player: $target", cf::NDI_UNIQUE); 227 $who->message ("No such player: $target", cf::NDI_UNIQUE);
194 } 228 }
195 229
196 } else { 230 } else {
197 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" 231 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
198 . "will ignore a player for <timeout> hours.\n" 232 . "will ignore a player for <timeout> hours.\n"
199 . "Usage: ignore list\n" 233 . "Usage: ignore list\n"
200 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 234 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
201 } 235 }
202}; 236};
213 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 247 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
214 } else { 248 } else {
215 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 249 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
216 } 250 }
217 } else { 251 } else {
218 252 if (cf::player::exists $target) {
219 if (valid_user $target) {
220 if ($type eq "tell") { 253 if ($type eq "tell") {
221 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 254 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
222 delete $who->{ext_ignore_tell} {$target}; 255 delete $who->{ext_ignore_tell} {$target};
223 } elsif ($type eq "shout") { 256 } elsif ($type eq "shout") {
224 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 257 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
231 $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);
232 } 265 }
233 } else { 266 } else {
234 $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);
235 } 268 }
236
237 } 269 }
238}; 270};
239 271
272cf::register_command seen => 0, sub {
273 my ($who, $args) = @_;
274
275 if (my ($login) = $args =~ /(\S+)/) {
276 if ($login eq $who->name) {
277 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);
278 } elsif (cf::player::find $login) {
279 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
280 } elsif (cf::player::exists $login
281 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
282 my $time = (stat _)[9];
283
284 $who->message ("$login was last seen here on "
285 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
286 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
287 } else {
288 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
289 }
290 } else {
291 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
292 }
293};
294

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines