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.18 by root, Tue May 30 04:30:54 2006 UTC vs.
Revision 1.25 by root, Fri Jul 21 08:26:59 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) {
67 my $name = $who->name; 101 my $name = $who->name;
68 my $NOW = time; 102 my $NOW = time;
69 103
104 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
105
70 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 106 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
71 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 107 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
72 108
73 } else { 109 } else {
74 $who->message ("Chat what?", cf::NDI_UNIQUE); 110 $who->message ("Chat what?", cf::NDI_UNIQUE);
79 my ($who, $msg) = @_; 115 my ($who, $msg) = @_;
80 116
81 if ($msg) { 117 if ($msg) {
82 my $NOW = time; 118 my $NOW = time;
83 my $name = $who->name; 119 my $name = $who->name;
120
121 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
84 122
85 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 123 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
86 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 124 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
87 125
88 } else { 126 } else {
103 if ($target eq $name) { 141 if ($target eq $name) {
104 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 142 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
105 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 143 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
106 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 144 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
107 } else { 145 } else {
146 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
147
108 $who->message ("You tell $target: $msg"); 148 $who->message ("You tell $target: $msg");
109 $other->ob->message ("$name tells you: $msg"); 149 $other->ob->message ("$name tells you: $msg");
110 $other->ob->{ext_last_tell} = $name; 150 $other->ob->{ext_last_tell} = $name;
111 } 151 }
112 } else { 152 } else {
127 167
128 $other->ob->{ext_ignore_tell}{$name} >= time 168 $other->ob->{ext_ignore_tell}{$name} >= time
129 or delete $other->ob->{ext_ignore_tell}{$name}; 169 or delete $other->ob->{ext_ignore_tell}{$name};
130 170
131 if ($other->ob->{ext_ignore_tell}{$name} < time) { 171 if ($other->ob->{ext_ignore_tell}{$name} < time) {
172 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
173
132 $who->message ("You tell " . $other->ob->name . ": $args"); 174 $who->message ("You tell " . $other->ob->name . ": $args");
133 $other->ob->message ("$name tells you: $args"); 175 $other->ob->message ("$name tells you: $args");
134 $who->{ext_last_tell} = $other->ob->name; 176 $who->{ext_last_tell} = $other->ob->name;
135 } else { 177 } else {
136 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 178 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
165 } elsif ($target && $type) { 207 } elsif ($target && $type) {
166 208
167 $timeout ne "" or $timeout = 24; 209 $timeout ne "" or $timeout = 24;
168 my $absolute_timeout = time + $timeout * 3600; 210 my $absolute_timeout = time + $timeout * 3600;
169 211
170 if (valid_user $target) { 212 if (cf::player::exists $target) {
171 if ($type eq "tell") { 213 if ($type eq "tell") {
172 $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);
173 $who->{ext_ignore_tell}{$target} = $absolute_timeout; 215 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
174 } elsif ($type eq "shout") { 216 } elsif ($type eq "shout") {
175 $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);
184 } else { 226 } else {
185 $who->message ("No such player: $target", cf::NDI_UNIQUE); 227 $who->message ("No such player: $target", cf::NDI_UNIQUE);
186 } 228 }
187 229
188 } else { 230 } else {
189 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" 231 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
190 . "will ignore a player for <timeout> hours.\n" 232 . "will ignore a player for <timeout> hours.\n"
191 . "Usage: ignore list\n" 233 . "Usage: ignore list\n"
192 . "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);
193 } 235 }
194}; 236};
205 $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);
206 } else { 248 } else {
207 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 249 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
208 } 250 }
209 } else { 251 } else {
210 252 if (cf::player::exists $target) {
211 if (valid_user $target) {
212 if ($type eq "tell") { 253 if ($type eq "tell") {
213 $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);
214 delete $who->{ext_ignore_tell} {$target}; 255 delete $who->{ext_ignore_tell} {$target};
215 } elsif ($type eq "shout") { 256 } elsif ($type eq "shout") {
216 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 257 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
223 $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);
224 } 265 }
225 } else { 266 } else {
226 $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);
227 } 268 }
228
229 } 269 }
230}; 270};
231 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 "
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