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.20 by root, Wed Jul 19 08:52:57 2006 UTC vs.
Revision 1.26 by root, Fri Jul 21 08:33:52 2006 UTC

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
6use NPC_Dialogue; 6use NPC_Dialogue;
7 7use POSIX (); # for strftime only
8sub valid_user($) {
9 cf::player::find $_[0]
10 or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
11}
12 8
13sub clean_timeouts($) { 9sub clean_timeouts($) {
14 my ($player) = @_; 10 my ($player) = @_;
15 my $NOW = time; 11 my $NOW = time;
16 12
17 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 13 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
18 while (my ($k, $v) = each %$hash) { 14 while (my ($k, $v) = each %$hash) {
19 if ($v < $NOW) { 15 if ($v < $NOW) {
20 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE); 16 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
21 delete $hash->{$k}; 17 delete $hash->{$k};
22 } elsif (!valid_user $k) { 18 } elsif (!cf::player::exists $k) {
23 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE); 19 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
24 delete $hash->{$k}; 20 delete $hash->{$k};
25 } 21 }
26 } 22 }
27 } 23 }
48 } else { 44 } else {
49 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE); 45 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
50 } 46 }
51}; 47};
52 48
53cf::register_command xsay => 0, sub { 49cf::register_command say => 0, sub {
54 my ($who, $msg) = @_; 50 my ($who, $msg) = @_;
55 51
56 if ($msg) { 52 if ($msg) {
57 my $name = $who->name; 53 my $name = $who->name;
58 54
59 my @messages = (["$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE]); 55 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
56 for grep $who->on_same_map_as ($_->ob), cf::player::list;
60 57
61 # npcs, magic_ears etc. 58 # npcs, magic_ears etc.
62 # first find all objects and their inventories within a 5x5 square 59 # first find all objects and their inventories within a 5x5 square
63 # that have something resembling dialogue 60 # that have something resembling dialogue
64 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); 61 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
72 ) { 69 ) {
73 # if some listener teleported us somewhere else, stop right here 70 # if some listener teleported us somewhere else, stop right here
74 last unless $map->path == $who->map->path; 71 last unless $map->path == $who->map->path;
75 72
76 my $dialog = new NPC_Dialogue ob => $who, npc => $npc; 73 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
77 my $reply = $dialog->tell ($msg); 74 my ($reply, @kw) = $dialog->tell ($msg);
78 75
79 if (defined $reply) { 76 if (defined $reply) {
80 if ($npc->type == cf::MAGIC_EAR) { 77 if ($npc->type == cf::MAGIC_EAR) {
81 push @messages, [$reply, cf::NDI_BROWN | cf::NDI_UNIQUE] if length $reply; 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; 82 $npc->use_trigger;
83 } else { 83 } else {
84 if (length $reply) {
84 push @messages, [$npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE] 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 }
85 } 88 }
86 } 89 }
87 }
88 90
89 # send replies to all players on this map 91 if (@kw) {
90 for (@messages) { 92 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE)
91 my ($msg, $flags) = @$_;
92
93 $_->ob->message ($msg, $flags)
94 for grep $who->on_same_map_as ($_->ob), cf::player::list; 93 for grep $who->on_same_map_as ($_->ob), cf::player::list;
94 }
95 } 95 }
96 96
97 } else { 97 } else {
98 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 98 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
99 } 99 }
212 } elsif ($target && $type) { 212 } elsif ($target && $type) {
213 213
214 $timeout ne "" or $timeout = 24; 214 $timeout ne "" or $timeout = 24;
215 my $absolute_timeout = time + $timeout * 3600; 215 my $absolute_timeout = time + $timeout * 3600;
216 216
217 if (valid_user $target) { 217 if (cf::player::exists $target) {
218 if ($type eq "tell") { 218 if ($type eq "tell") {
219 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); 219 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
220 $who->{ext_ignore_tell}{$target} = $absolute_timeout; 220 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
221 } elsif ($type eq "shout") { 221 } elsif ($type eq "shout") {
222 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); 222 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
231 } else { 231 } else {
232 $who->message ("No such player: $target", cf::NDI_UNIQUE); 232 $who->message ("No such player: $target", cf::NDI_UNIQUE);
233 } 233 }
234 234
235 } else { 235 } else {
236 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" 236 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
237 . "will ignore a player for <timeout> hours.\n" 237 . "will ignore a player for <timeout> hours.\n"
238 . "Usage: ignore list\n" 238 . "Usage: ignore list\n"
239 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 239 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
240 } 240 }
241}; 241};
252 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 252 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
253 } else { 253 } else {
254 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 254 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
255 } 255 }
256 } else { 256 } else {
257 257 if (cf::player::exists $target) {
258 if (valid_user $target) {
259 if ($type eq "tell") { 258 if ($type eq "tell") {
260 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 259 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
261 delete $who->{ext_ignore_tell} {$target}; 260 delete $who->{ext_ignore_tell} {$target};
262 } elsif ($type eq "shout") { 261 } elsif ($type eq "shout") {
263 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 262 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
270 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 269 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
271 } 270 }
272 } else { 271 } else {
273 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 272 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
274 } 273 }
275
276 } 274 }
277}; 275};
278 276
277cf::register_command seen => 0, sub {
278 my ($who, $args) = @_;
279
280 if (my ($login) = $args =~ /(\S+)/) {
281 if ($login eq $who->name) {
282 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);
283 } elsif (cf::player::find $login) {
284 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
285 } elsif (cf::player::exists $login
286 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
287 my $time = (stat _)[9];
288
289 $who->message ("$login was last seen here "
290 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
291 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
292 } else {
293 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
294 }
295 } else {
296 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
297 }
298};
299

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines