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.33 by root, Fri Aug 25 15:07:43 2006 UTC

1#! perl 1#! perl
2#CONVERSION: PARTIAL
2 3
3# implement a replacement for the built-in say/chat/shout/tell/reply commands 4# implement a replacement for the built-in say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality 5# adds ignore/unignore functionality
5 6
6sub valid_user($) { 7use NPC_Dialogue;
7 cf::player::find $_[0] 8use POSIX (); # for strftime only
8 or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
9}
10 9
11sub clean_timeouts($) { 10sub clean_timeouts($) {
12 my ($player) = @_; 11 my ($player) = @_;
13 my $NOW = time; 12 my $NOW = time;
14 13
15 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 14 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
16 while (my ($k, $v) = each %$hash) { 15 while (my ($k, $v) = each %$hash) {
17 if ($v < $NOW) { 16 if ($v < $NOW) {
18 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN); 17 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
19 delete $hash->{$k}; 18 delete $hash->{$k};
20 } elsif (!valid_user $k) { 19 } elsif (!cf::player::exists $k) {
21 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN); 20 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
22 delete $hash->{$k}; 21 delete $hash->{$k};
23 } 22 }
24 } 23 }
25 } 24 }
26} 25}
27 26
28sub on_logout { 27cf::attach_to_players
28 prio => -1000,
29 on_login => sub {
29 my ($pl, $host) = @_; 30 my ($pl) = @_;
30 31
31 clean_timeouts $pl->ob; 32 clean_timeouts $pl->ob;
32} 33 },
34;
33 35
34cf::register_command listen => 0, sub { 36cf::register_command listen => 0, sub {
35 my ($who, $msg) = @_; 37 my ($who, $msg) = @_;
36 my $player = cf::player::find $who->name; 38 my $player = cf::player::find $who->name;
37 39
38 if ($msg ne "") { 40 if ($msg ne "") {
39 my $prev_listen = $player->listening; 41 my $prev_listen = $player->listening;
40 $player->listening ($msg); 42 $player->listening ($msg);
41 if ($prev_listen == $player->listening) { 43 if ($prev_listen == $player->listening) {
42 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE); 44 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
43 } else { 45 } else {
44 $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE); 46 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
45 } 47 }
46 } else { 48 } else {
47 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE); 49 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
48 } 50 }
49}; 51};
50 52
51#cf::register_command say => 0, sub { 53cf::register_command say => 0, sub {
52# my ($who, $msg) = @_; 54 my ($who, $msg) = @_;
53# 55
56 utf8::decode $msg;
57
54# if ($msg) { 58 if ($msg) {
55# my $name = $who->name; 59 my $name = $who->name;
60
61 utf8::encode $msg; # ->message not yet utf8-ified
56# $_->ob->message ("$name says: $msg", cf::NDI_WHITE) 62 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
57# for grep $who->on_same_map_as ($_->ob), cf::player::list; 63 for grep $who->on_same_map_as ($_->ob), cf::player::list;
64 utf8::decode $msg;
65
66 # npcs, magic_ears etc.
67 # first find all objects and their inventories within a 5x5 square
68 # that have something resembling dialogue
69 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
70
71 for my $npc (
72 grep NPC_Dialogue::has_dialogue $_,
73 map +($_, $_->inv),
74 grep $_,
75 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
76 0..24
77 ) {
78 # if some listener teleported us somewhere else, stop right here
79 last unless $map->path == $who->map->path;
80
81 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
82 my ($reply, @kw) = $dialog->tell ($msg);
83
84 if (defined $reply) {
85 if ($npc->type == cf::MAGIC_EAR) {
86 if (length $reply) {
87 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
88 for grep $who->on_same_map_as ($_->ob), cf::player::list;
89 }
90 $npc->use_trigger;
91 } else {
92 if (length $reply) {
93 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
94 for grep $who->on_same_map_as ($_->ob), cf::player::list;
95 }
96 }
97 }
98
99 if (@kw) {
100 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE)
101 for grep $who->on_same_map_as ($_->ob), cf::player::list;
102 }
103 }
104
58# } else { 105 } else {
59# $who->message ("What do you want to say?", cf::NDI_UNIQUE); 106 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
60# } 107 }
61#}; 108};
62 109
63cf::register_command chat => 0, sub { 110cf::register_command chat => 0, sub {
64 my ($who, $msg) = @_; 111 my ($who, $msg) = @_;
112
113 utf8::decode $msg;
65 114
66 if ($msg) { 115 if ($msg) {
67 my $name = $who->name; 116 my $name = $who->name;
68 my $NOW = time; 117 my $NOW = time;
69 118
119 utf8::encode $msg; # ->message not yet utf8-ified
120# cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
121 cf::ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg);
122
70 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 123 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
71 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 124 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
72 125
73 } else { 126 } else {
74 $who->message ("Chat what?", cf::NDI_UNIQUE); 127 $who->message ("Chat what?", cf::NDI_UNIQUE);
75 } 128 }
76}; 129};
77 130
78cf::register_command shout => 0, sub { 131cf::register_command shout => 0, sub {
79 my ($who, $msg) = @_; 132 my ($who, $msg) = @_;
133
134 utf8::decode $msg;
80 135
81 if ($msg) { 136 if ($msg) {
82 my $NOW = time; 137 my $NOW = time;
83 my $name = $who->name; 138 my $name = $who->name;
84 139
140# cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
141 cf::ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg);
142
143 utf8::encode $msg; # ->message not yet utf8-ified
85 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 144 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
86 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 145 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
87 146
88 } else { 147 } else {
89 $who->message ("Shout what?", cf::NDI_UNIQUE); 148 $who->message ("Shout what?", cf::NDI_UNIQUE);
92}; 151};
93 152
94cf::register_command tell => 0, sub { 153cf::register_command tell => 0, sub {
95 my ($who, $args) = @_; 154 my ($who, $args) = @_;
96 my ($target, $msg) = split /\s+/, $args, 2; 155 my ($target, $msg) = split /\s+/, $args, 2;
156
157 utf8::decode $msg;
97 158
98 my $name = $who->name; 159 my $name = $who->name;
99 160
100 if (my $other = cf::player::find $target) { 161 if (my $other = cf::player::find $target) {
101 162
103 if ($target eq $name) { 164 if ($target eq $name) {
104 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 165 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
105 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 166 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
106 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 167 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
107 } else { 168 } else {
169 utf8::encode $msg; # ->message not yet utf8-ified
170 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
171
108 $who->message ("You tell $target: $msg"); 172 $who->message ("You tell $target: $msg");
109 $other->ob->message ("$name tells you: $msg"); 173 $other->ob->message ("$name tells you: $msg");
110 $other->ob->{ext_last_tell} = $name; 174 $other->ob->{ext_last_tell} = $name;
111 } 175 }
112 } else { 176 } else {
120 184
121cf::register_command reply => 0, sub { 185cf::register_command reply => 0, sub {
122 my ($who, $args) = @_; 186 my ($who, $args) = @_;
123 my $name = $who->name; 187 my $name = $who->name;
124 188
189 utf8::decode $args;
190
125 if (my $other = cf::player::find $who->{ext_last_tell}) { 191 if (my $other = cf::player::find $who->{ext_last_tell}) {
126 if ($args) { 192 if ($args) {
127 193
128 $other->ob->{ext_ignore_tell}{$name} >= time 194 $other->ob->{ext_ignore_tell}{$name} >= time
129 or delete $other->ob->{ext_ignore_tell}{$name}; 195 or delete $other->ob->{ext_ignore_tell}{$name};
130 196
131 if ($other->ob->{ext_ignore_tell}{$name} < time) { 197 if ($other->ob->{ext_ignore_tell}{$name} < time) {
198 utf8::encode $args; # ->message not yet utf8-ified
199 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
200
132 $who->message ("You tell " . $other->ob->name . ": $args"); 201 $who->message ("You tell " . $other->ob->name . ": $args");
133 $other->ob->message ("$name tells you: $args"); 202 $other->ob->message ("$name tells you: $args");
134 $who->{ext_last_tell} = $other->ob->name; 203 $who->{ext_last_tell} = $other->ob->name;
135 } else { 204 } else {
136 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 205 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
165 } elsif ($target && $type) { 234 } elsif ($target && $type) {
166 235
167 $timeout ne "" or $timeout = 24; 236 $timeout ne "" or $timeout = 24;
168 my $absolute_timeout = time + $timeout * 3600; 237 my $absolute_timeout = time + $timeout * 3600;
169 238
170 if (valid_user $target) { 239 if (cf::player::exists $target) {
171 if ($type eq "tell") { 240 if ($type eq "tell") {
172 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); 241 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
173 $who->{ext_ignore_tell}{$target} = $absolute_timeout; 242 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
174 } elsif ($type eq "shout") { 243 } elsif ($type eq "shout") {
175 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); 244 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
184 } else { 253 } else {
185 $who->message ("No such player: $target", cf::NDI_UNIQUE); 254 $who->message ("No such player: $target", cf::NDI_UNIQUE);
186 } 255 }
187 256
188 } else { 257 } else {
189 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" 258 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
190 . "will ignore a player for <timeout> hours.\n" 259 . "will ignore a player for <timeout> hours.\n"
191 . "Usage: ignore list\n" 260 . "Usage: ignore list\n"
192 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 261 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
193 } 262 }
194}; 263};
205 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 274 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
206 } else { 275 } else {
207 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 276 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
208 } 277 }
209 } else { 278 } else {
210 279 if (cf::player::exists $target) {
211 if (valid_user $target) {
212 if ($type eq "tell") { 280 if ($type eq "tell") {
213 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 281 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
214 delete $who->{ext_ignore_tell} {$target}; 282 delete $who->{ext_ignore_tell} {$target};
215 } elsif ($type eq "shout") { 283 } elsif ($type eq "shout") {
216 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); 284 $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); 291 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
224 } 292 }
225 } else { 293 } else {
226 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 294 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
227 } 295 }
228
229 } 296 }
230}; 297};
231 298
299cf::register_command seen => 0, sub {
300 my ($who, $args) = @_;
301
302 if (my ($login) = $args =~ /(\S+)/) {
303 if ($login eq $who->name) {
304 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);
305 } elsif (cf::player::find $login) {
306 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
307 } elsif (cf::player::exists $login
308 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
309 my $time = (stat _)[9];
310
311 $who->message ("$login was last seen here "
312 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
313 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
314 } else {
315 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
316 }
317 } else {
318 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
319 }
320};
321

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines