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.22 by root, Fri Jul 21 00:25:29 2006 UTC vs.
Revision 1.36 by root, Wed Aug 30 08:34:20 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
6use NPC_Dialogue; 7use NPC_Dialogue;
8use POSIX (); # for strftime only
7 9
8sub clean_timeouts($) { 10sub clean_timeouts($) {
9 my ($player) = @_; 11 my ($player) = @_;
10 my $NOW = time; 12 my $NOW = time;
11 13
20 } 22 }
21 } 23 }
22 } 24 }
23} 25}
24 26
25sub on_logout { 27cf::attach_to_players
28 prio => -1000,
29 on_login => sub {
26 my ($pl, $host) = @_; 30 my ($pl) = @_;
27 31
28 clean_timeouts $pl->ob; 32 clean_timeouts $pl->ob;
29} 33 },
34;
30 35
31cf::register_command listen => 0, sub { 36cf::register_command listen => 0, sub {
32 my ($who, $msg) = @_; 37 my ($who, $msg) = @_;
33 my $player = cf::player::find $who->name; 38 my $player = cf::player::find $who->name;
34 39
46}; 51};
47 52
48cf::register_command say => 0, sub { 53cf::register_command say => 0, sub {
49 my ($who, $msg) = @_; 54 my ($who, $msg) = @_;
50 55
56 utf8::decode $msg;
57
58 return if $who->contr->invoke (cf::EVENT_PLAYER_SAY, $msg);
59
51 if ($msg) { 60 if ($msg) {
52 my $name = $who->name; 61 my $name = $who->name;
53 62
63 utf8::encode $msg; # ->message not yet utf8-ified
54 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE) 64 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
55 for grep $who->on_same_map_as ($_->ob), cf::player::list; 65 for grep $who->on_same_map_as ($_->ob), cf::player::list;
66 utf8::decode $msg;
56 67
57 # npcs, magic_ears etc. 68 # npcs, magic_ears etc.
58 # first find all objects and their inventories within a 5x5 square 69 # first find all objects and theirt-level inventories
59 # that have something resembling dialogue 70 # within a 5x5 square # that have something resembling
71 # dialogue or support on_say.
60 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2); 72 my ($map, $x, $y) = ($who->map, $who->x - 2, $who->y - 2);
61 73
62 for my $npc ( 74 for my $npc (
63 grep NPC_Dialogue::has_dialogue $_, 75 grep +($_->invoke (cf::EVENT_OBJECT_SAY, $who->contr, $msg) && return) || NPC_Dialogue::has_dialogue $_,
64 map +($_, $_->inv), 76 map +($_, $_->inv),
65 grep $_, 77 grep $_,
66 map $map->at ($x + $_ % 5, $y + (int $_ / 5)), 78 map $map->at ($x + $_ % 5, $y + (int $_ / 5)),
67 0..24 79 0..24
68 ) { 80 ) {
69 # if some listener teleported us somewhere else, stop right here 81 # if some listener teleported us somewhere else, stop right here
70 last unless $map->path == $who->map->path; 82 last unless $map->path == $who->map->path;
71 83
72 my $dialog = new NPC_Dialogue ob => $who, npc => $npc; 84 my $dialog = new NPC_Dialogue ob => $who, npc => $npc;
73 my $reply = $dialog->tell ($msg); 85 my ($reply, @kw) = $dialog->tell ($msg);
74 86
75 if (defined $reply) { 87 if (defined $reply) {
76 if ($npc->type == cf::MAGIC_EAR) { 88 if ($npc->type == cf::MAGIC_EAR) {
77 if (length $reply) { 89 if (length $reply) {
78 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE) 90 $_->ob->message ($reply, cf::NDI_BROWN | cf::NDI_UNIQUE)
84 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE) 96 $_->ob->message ($npc->name . " says: $reply", cf::NDI_BROWN | cf::NDI_UNIQUE)
85 for grep $who->on_same_map_as ($_->ob), cf::player::list; 97 for grep $who->on_same_map_as ($_->ob), cf::player::list;
86 } 98 }
87 } 99 }
88 } 100 }
101
102 if (@kw) {
103 $_->ob->message ("[further topics: " . (join ", ", @kw) . "]", cf::NDI_BROWN | cf::NDI_UNIQUE)
104 for grep $who->on_same_map_as ($_->ob), cf::player::list;
105 }
89 } 106 }
90 107
91 } else { 108 } else {
92 $who->message ("What do you want to say?", cf::NDI_UNIQUE); 109 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
93 } 110 }
94}; 111};
95 112
96cf::register_command chat => 0, sub { 113cf::register_command chat => 0, sub {
97 my ($who, $msg) = @_; 114 my ($who, $msg) = @_;
115
116 utf8::decode $msg;
117
118 return if $who->contr->invoke (cf::EVENT_PLAYER_CHAT, $msg);
98 119
99 if ($msg) { 120 if ($msg) {
100 my $name = $who->name; 121 my $name = $who->name;
101 my $NOW = time; 122 my $NOW = time;
102 123
124 utf8::encode $msg; # ->message not yet utf8-ified
103 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; 125# cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
126 ext::schmorp_irc::do_notice (sprintf "[%s] %s", $name, $msg);
104 127
105 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 128 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
106 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; 129 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
107 130
108 } else { 131 } else {
110 } 133 }
111}; 134};
112 135
113cf::register_command shout => 0, sub { 136cf::register_command shout => 0, sub {
114 my ($who, $msg) = @_; 137 my ($who, $msg) = @_;
138
139 utf8::decode $msg;
140
141 return if $who->contr->invoke (cf::EVENT_PLAYER_SHOUT, $msg);
115 142
116 if ($msg) { 143 if ($msg) {
117 my $NOW = time; 144 my $NOW = time;
118 my $name = $who->name; 145 my $name = $who->name;
119 146
120 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; 147# cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
148 ext::schmorp_irc::do_notice (sprintf "{%s} %s\n", $name, $msg);
121 149
150 utf8::encode $msg; # ->message not yet utf8-ified
122 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 151 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
123 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; 152 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
124 153
125 } else { 154 } else {
126 $who->message ("Shout what?", cf::NDI_UNIQUE); 155 $who->message ("Shout what?", cf::NDI_UNIQUE);
129}; 158};
130 159
131cf::register_command tell => 0, sub { 160cf::register_command tell => 0, sub {
132 my ($who, $args) = @_; 161 my ($who, $args) = @_;
133 my ($target, $msg) = split /\s+/, $args, 2; 162 my ($target, $msg) = split /\s+/, $args, 2;
163
164 utf8::decode $msg;
165
166 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $target, $msg);
134 167
135 my $name = $who->name; 168 my $name = $who->name;
136 169
137 if (my $other = cf::player::find $target) { 170 if (my $other = cf::player::find $target) {
138 171
140 if ($target eq $name) { 173 if ($target eq $name) {
141 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); 174 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
142 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { 175 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
143 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); 176 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
144 } else { 177 } else {
178 utf8::encode $msg; # ->message not yet utf8-ified
145 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg; 179 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
146 180
147 $who->message ("You tell $target: $msg"); 181 $who->message ("You tell $target: $msg");
148 $other->ob->message ("$name tells you: $msg"); 182 $other->ob->message ("$name tells you: $msg");
149 $other->ob->{ext_last_tell} = $name; 183 $other->ob->{ext_last_tell} = $name;
159 193
160cf::register_command reply => 0, sub { 194cf::register_command reply => 0, sub {
161 my ($who, $args) = @_; 195 my ($who, $args) = @_;
162 my $name = $who->name; 196 my $name = $who->name;
163 197
198 utf8::decode $args;
199
200 return if $who->contr->invoke (cf::EVENT_PLAYER_TELL, $who->{ext_last_tell}, $args);
201
164 if (my $other = cf::player::find $who->{ext_last_tell}) { 202 if (my $other = cf::player::find $who->{ext_last_tell}) {
203
165 if ($args) { 204 if ($args) {
166
167 $other->ob->{ext_ignore_tell}{$name} >= time 205 $other->ob->{ext_ignore_tell}{$name} >= time
168 or delete $other->ob->{ext_ignore_tell}{$name}; 206 or delete $other->ob->{ext_ignore_tell}{$name};
169 207
170 if ($other->ob->{ext_ignore_tell}{$name} < time) { 208 if ($other->ob->{ext_ignore_tell}{$name} < time) {
209 utf8::encode $args; # ->message not yet utf8-ified
171 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args; 210 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
172 211
173 $who->message ("You tell " . $other->ob->name . ": $args"); 212 $who->message ("You tell " . $other->ob->name . ": $args");
174 $other->ob->message ("$name tells you: $args"); 213 $other->ob->message ("$name tells you: $args");
175 $who->{ext_last_tell} = $other->ob->name; 214 $who->{ext_last_tell} = $other->ob->name;
225 } else { 264 } else {
226 $who->message ("No such player: $target", cf::NDI_UNIQUE); 265 $who->message ("No such player: $target", cf::NDI_UNIQUE);
227 } 266 }
228 267
229 } else { 268 } else {
230 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" 269 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
231 . "will ignore a player for <timeout> hours.\n" 270 . "will ignore a player for <timeout> hours.\n"
232 . "Usage: ignore list\n" 271 . "Usage: ignore list\n"
233 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE); 272 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
234 } 273 }
235}; 274};
246 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); 285 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
247 } else { 286 } else {
248 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 287 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
249 } 288 }
250 } else { 289 } else {
251
252 if (cf::player::exists $target) { 290 if (cf::player::exists $target) {
253 if ($type eq "tell") { 291 if ($type eq "tell") {
254 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); 292 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
255 delete $who->{ext_ignore_tell} {$target}; 293 delete $who->{ext_ignore_tell} {$target};
256 } elsif ($type eq "shout") { 294 } elsif ($type eq "shout") {
264 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 302 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
265 } 303 }
266 } else { 304 } else {
267 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 305 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
268 } 306 }
269
270 } 307 }
271}; 308};
272 309
310cf::register_command seen => 0, sub {
311 my ($who, $args) = @_;
312
313 if (my ($login) = $args =~ /(\S+)/) {
314 if ($login eq $who->name) {
315 $who->message ("Very funny, $login. Ha. Ha.", cf::NDI_UNIQUE);
316 } elsif (cf::player::find $login) {
317 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
318 } elsif (cf::player::exists $login
319 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
320 my $time = (stat _)[9];
321
322 $who->message ("$login was last seen here "
323 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
324 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
325 } else {
326 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
327 }
328 } else {
329 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
330 }
331};
332

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines