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.29 by elmex, Wed Aug 2 16:59: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
52 utf8::decode $msg;
53
54# if ($msg) { 54 if ($msg) {
55# my $name = $who->name; 55 my $name = $who->name;
56
57 utf8::encode $msg; # ->message not yet utf8-ified
56# $_->ob->message ("$name says: $msg", cf::NDI_WHITE) 58 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
57# for grep $who->on_same_map_as ($_->ob), cf::player::list; 59 for grep $who->on_same_map_as ($_->ob), cf::player::list;
60 utf8::decode $msg;
61
62 # npcs, magic_ears etc.
63 # first find all objects and their inventories within a 5x5 square
64 # that have something resembling dialogue
65 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
66
67 for my $npc (
68 grep NPC_Dialogue::has_dialogue $_,
69 map +($_, $_->inv),
70 grep $_,
71 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
72 0..24
73 ) {
74 # if some listener teleported us somewhere else, stop right here
75 last unless $map->path == $who->map->path;
76
77 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
78 my ($reply, @kw) = $dialog->tell ($msg);
79
80 if (defined $reply) {
81 if ($npc->type == cf::MAGIC_EAR) {
82 if (length $reply) {
83 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
84 for grep $who->on_same_map_as ($_->ob), cf::player::list;
85 }
86 $npc->use_trigger;
87 } else {
88 if (length $reply) {
89 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
90 for grep $who->on_same_map_as ($_->ob), cf::player::list;
91 }
92 }
93 }
94
95 if (@kw) {
96 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE)
97 for grep $who->on_same_map_as ($_->ob), cf::player::list;
98 }
99 }
100
58# } else { 101 } else {
59# $who->message ("What do you want to say?", cf::NDI_UNIQUE); 102 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
60# } 103 }
61#}; 104};
62 105
63cf::register_command chat => 0, sub { 106cf::register_command chat => 0, sub {
64 my ($who, $msg) = @_; 107 my ($who, $msg) = @_;
108
109 utf8::decode $msg;
65 110
66 if ($msg) { 111 if ($msg) {
67 my $name = $who->name; 112 my $name = $who->name;
68 my $NOW = time; 113 my $NOW = time;
69 114
115 utf8::encode $msg; # ->message not yet utf8-ified
116 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
117 cf::ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg);
118
70 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 119 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
71 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 120 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
72 121
73 } else { 122 } else {
74 $who->message ("Chat what?", cf::NDI_UNIQUE); 123 $who->message ("Chat what?", cf::NDI_UNIQUE);
75 } 124 }
76}; 125};
77 126
78cf::register_command shout => 0, sub { 127cf::register_command shout => 0, sub {
79 my ($who, $msg) = @_; 128 my ($who, $msg) = @_;
129
130 utf8::decode $msg;
80 131
81 if ($msg) { 132 if ($msg) {
82 my $NOW = time; 133 my $NOW = time;
83 my $name = $who->name; 134 my $name = $who->name;
84 135
136 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
137 cf::ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg);
138
139 utf8::encode $msg; # ->message not yet utf8-ified
85 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 140 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
86 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 141 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
87 142
88 } else { 143 } else {
89 $who->message ("Shout what?", cf::NDI_UNIQUE); 144 $who->message ("Shout what?", cf::NDI_UNIQUE);
92}; 147};
93 148
94cf::register_command tell => 0, sub { 149cf::register_command tell => 0, sub {
95 my ($who, $args) = @_; 150 my ($who, $args) = @_;
96 my ($target, $msg) = split /\s+/, $args, 2; 151 my ($target, $msg) = split /\s+/, $args, 2;
152
153 utf8::decode $msg;
97 154
98 my $name = $who->name; 155 my $name = $who->name;
99 156
100 if (my $other = cf::player::find $target) { 157 if (my $other = cf::player::find $target) {
101 158
103 if ($target eq $name) { 160 if ($target eq $name) {
104 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 161 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
105 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 162 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
106 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 163 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
107 } else { 164 } else {
165 utf8::encode $msg; # ->message not yet utf8-ified
166 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
167
108 $who->message ("You tell $target: $msg"); 168 $who->message ("You tell $target: $msg");
109 $other->ob->message ("$name tells you: $msg"); 169 $other->ob->message ("$name tells you: $msg");
110 $other->ob->{ext_last_tell} = $name; 170 $other->ob->{ext_last_tell} = $name;
111 } 171 }
112 } else { 172 } else {
120 180
121cf::register_command reply => 0, sub { 181cf::register_command reply => 0, sub {
122 my ($who, $args) = @_; 182 my ($who, $args) = @_;
123 my $name = $who->name; 183 my $name = $who->name;
124 184
185 utf8::decode $args;
186
125 if (my $other = cf::player::find $who->{ext_last_tell}) { 187 if (my $other = cf::player::find $who->{ext_last_tell}) {
126 if ($args) { 188 if ($args) {
127 189
128 $other->ob->{ext_ignore_tell}{$name} >= time 190 $other->ob->{ext_ignore_tell}{$name} >= time
129 or delete $other->ob->{ext_ignore_tell}{$name}; 191 or delete $other->ob->{ext_ignore_tell}{$name};
130 192
131 if ($other->ob->{ext_ignore_tell}{$name} < time) { 193 if ($other->ob->{ext_ignore_tell}{$name} < time) {
194 utf8::encode $args; # ->message not yet utf8-ified
195 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
196
132 $who->message ("You tell " . $other->ob->name . ": $args"); 197 $who->message ("You tell " . $other->ob->name . ": $args");
133 $other->ob->message ("$name tells you: $args"); 198 $other->ob->message ("$name tells you: $args");
134 $who->{ext_last_tell} = $other->ob->name; 199 $who->{ext_last_tell} = $other->ob->name;
135 } else { 200 } else {
136 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 201 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
165 } elsif ($target && $type) { 230 } elsif ($target && $type) {
166 231
167 $timeout ne "" or $timeout = 24; 232 $timeout ne "" or $timeout = 24;
168 my $absolute_timeout = time + $timeout * 3600; 233 my $absolute_timeout = time + $timeout * 3600;
169 234
170 if (valid_user $target) { 235 if (cf::player::exists $target) {
171 if ($type eq "tell") { 236 if ($type eq "tell") {
172 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); 237 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
173 $who->{ext_ignore_tell}{$target} = $absolute_timeout; 238 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
174 } elsif ($type eq "shout") { 239 } elsif ($type eq "shout") {
175 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); 240 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
184 } else { 249 } else {
185 $who->message ("No such player: $target", cf::NDI_UNIQUE); 250 $who->message ("No such player: $target", cf::NDI_UNIQUE);
186 } 251 }
187 252
188 } else { 253 } else {
189 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" 254 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
190 . "will ignore a player for <timeout> hours.\n" 255 . "will ignore a player for <timeout> hours.\n"
191 . "Usage: ignore list\n" 256 . "Usage: ignore list\n"
192 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 257 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
193 } 258 }
194}; 259};
205 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 270 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
206 } else { 271 } else {
207 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 272 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
208 } 273 }
209 } else { 274 } else {
210 275 if (cf::player::exists $target) {
211 if (valid_user $target) {
212 if ($type eq "tell") { 276 if ($type eq "tell") {
213 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 277 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
214 delete $who->{ext_ignore_tell} {$target}; 278 delete $who->{ext_ignore_tell} {$target};
215 } elsif ($type eq "shout") { 279 } elsif ($type eq "shout") {
216 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 280 $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); 287 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
224 } 288 }
225 } else { 289 } else {
226 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 290 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
227 } 291 }
228
229 } 292 }
230}; 293};
231 294
295cf::register_command seen => 0, sub {
296 my ($who, $args) = @_;
297
298 if (my ($login) = $args =~ /(\S+)/) {
299 if ($login eq $who->name) {
300 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);
301 } elsif (cf::player::find $login) {
302 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
303 } elsif (cf::player::exists $login
304 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
305 my $time = (stat _)[9];
306
307 $who->message ("$login was last seen here "
308 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
309 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
310 } else {
311 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
312 }
313 } else {
314 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
315 }
316};
317

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines