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.15 by pippijn, Mon May 8 05:01:50 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 -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; 7use POSIX (); # for strftime only
8}
9 8
10sub clean_timeouts($) { 9sub clean_timeouts($) {
11 my ($player) = @_; 10 my ($player) = @_;
12 my $NOW = time; 11 my $NOW = time;
13 12
14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 13 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
15 while (my ($k, $v) = each %$hash) { 14 while (my ($k, $v) = each %$hash) {
16 if ($v < $NOW) { 15 if ($v < $NOW) {
17 $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);
18 delete $hash->{$k}; 17 delete $hash->{$k};
19 } elsif (!valid_user $k) { 18 } elsif (!cf::player::exists $k) {
20 $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);
21 delete $hash->{$k}; 20 delete $hash->{$k};
22 } 21 }
23 } 22 }
24 } 23 }
25} 24}
32 31
33cf::register_command listen => 0, sub { 32cf::register_command listen => 0, sub {
34 my ($who, $msg) = @_; 33 my ($who, $msg) = @_;
35 my $player = cf::player::find $who->name; 34 my $player = cf::player::find $who->name;
36 35
37 if ($msg) { 36 if ($msg ne "") {
38 my $prev_listen = $player->listening; 37 my $prev_listen = $player->listening;
39 $player->listening ($msg); 38 $player->listening ($msg);
40 if ($prev_listen == $player->listening) { 39 if ($prev_listen == $player->listening) {
41 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); 40 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
42 } else { 41 } else {
43 $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);
44 } 43 }
45 } else { 44 } else {
46 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); 45 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
47 } 46 }
48}; 47};
49 48
50cf::register_command say => 0, sub { 49cf::register_command say => 0, sub {
51 my ($who, $msg) = @_; 50 my ($who, $msg) = @_;
52 51
53 if ($msg) { 52 if ($msg) {
54 my $name = $who->name; 53 my $name = $who->name;
54
55 $_->ob->message ("$name says: $msg", cf::NDI_WHITE) 55 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
56 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
57 } else { 92 } else {
58 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 93 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
59 } 94 }
60}; 95};
61 96
64 99
65 if ($msg) { 100 if ($msg) {
66 my $name = $who->name; 101 my $name = $who->name;
67 my $NOW = time; 102 my $NOW = time;
68 103
104 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
105
69 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 106 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
70 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;
71 108
72 } else { 109 } else {
73 $who->message ("Chat what?", cf::NDI_UNIQUE); 110 $who->message ("Chat what?", cf::NDI_UNIQUE);
78 my ($who, $msg) = @_; 115 my ($who, $msg) = @_;
79 116
80 if ($msg) { 117 if ($msg) {
81 my $NOW = time; 118 my $NOW = time;
82 my $name = $who->name; 119 my $name = $who->name;
120
121 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
83 122
84 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 123 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
85 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;
86 125
87 } else { 126 } else {
102 if ($target eq $name) { 141 if ($target eq $name) {
103 $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);
104 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 143 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
105 $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);
106 } else { 145 } else {
146 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
147
107 $who->message ("You tell $target: $msg"); 148 $who->message ("You tell $target: $msg");
108 $other->ob->message ("$name tells you: $msg"); 149 $other->ob->message ("$name tells you: $msg");
109 $other->ob->{ext_last_tell} = $name; 150 $other->ob->{ext_last_tell} = $name;
110 } 151 }
111 } else { 152 } else {
126 167
127 $other->ob->{ext_ignore_tell}{$name} >= time 168 $other->ob->{ext_ignore_tell}{$name} >= time
128 or delete $other->ob->{ext_ignore_tell}{$name}; 169 or delete $other->ob->{ext_ignore_tell}{$name};
129 170
130 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
131 $who->message ("You tell " . $other->ob->name . ": $args"); 174 $who->message ("You tell " . $other->ob->name . ": $args");
132 $other->ob->message ("$name tells you: $args"); 175 $other->ob->message ("$name tells you: $args");
133 $who->{ext_last_tell} = $other->ob->name; 176 $who->{ext_last_tell} = $other->ob->name;
134 } else { 177 } else {
135 $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);
164 } elsif ($target && $type) { 207 } elsif ($target && $type) {
165 208
166 $timeout ne "" or $timeout = 24; 209 $timeout ne "" or $timeout = 24;
167 my $absolute_timeout = time + $timeout * 3600; 210 my $absolute_timeout = time + $timeout * 3600;
168 211
169 if (valid_user $target) { 212 if (cf::player::exists $target) {
170 if ($type eq "tell") { 213 if ($type eq "tell") {
171 $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);
172 $who->{ext_ignore_tell}{$target} = $absolute_timeout; 215 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
173 } elsif ($type eq "shout") { 216 } elsif ($type eq "shout") {
174 $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);
183 } else { 226 } else {
184 $who->message ("No such player: $target", cf::NDI_UNIQUE); 227 $who->message ("No such player: $target", cf::NDI_UNIQUE);
185 } 228 }
186 229
187 } else { 230 } else {
188 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" 231 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
189 . "will ignore a player for <timeout> hours.\n" 232 . "will ignore a player for <timeout> hours.\n"
190 . "Usage: ignore list\n" 233 . "Usage: ignore list\n"
191 . "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);
192 } 235 }
193}; 236};
204 $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);
205 } else { 248 } else {
206 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 249 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
207 } 250 }
208 } else { 251 } else {
209 252 if (cf::player::exists $target) {
210 if (valid_user $target) {
211 if ($type eq "tell") { 253 if ($type eq "tell") {
212 $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);
213 delete $who->{ext_ignore_tell} {$target}; 255 delete $who->{ext_ignore_tell} {$target};
214 } elsif ($type eq "shout") { 256 } elsif ($type eq "shout") {
215 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 257 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
222 $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);
223 } 265 }
224 } else { 266 } else {
225 $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);
226 } 268 }
227
228 } 269 }
229}; 270};
230 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