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.8 by root, Sun May 7 09:18:37 2006 UTC vs.
Revision 1.23 by root, Fri Jul 21 08:22:02 2006 UTC

1#! perl 1#! perl
2 2
3# implement a replacement for the built-in 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
6use NPC_Dialogue;
7use POSIX (); # for strftime only
8
6sub clean_timeouts { 9sub clean_timeouts($) {
7 my ($player) = @_; 10 my ($player) = @_;
8 my $NOW = time; 11 my $NOW = time;
9 12
10 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { 13 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
11 delete $hash->{$_} for grep $hash->{$_} < $NOW, keys %$hash; 14 while (my ($k, $v) = each %$hash) {
15 if ($v < $NOW) {
16 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN | cf::NDI_UNIQUE);
17 delete $hash->{$k};
18 } elsif (!cf::player::exists $k) {
19 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN | cf::NDI_UNIQUE);
20 delete $hash->{$k};
21 }
22 }
12 } 23 }
13} 24}
14 25
15sub on_logout { 26sub on_logout {
16 my ($pl, $host) = @_; 27 my ($pl, $host) = @_;
17 28
18 clean_timeouts $pl->ob; 29 clean_timeouts $pl->ob;
19} 30}
31
32cf::register_command listen => 0, sub {
33 my ($who, $msg) = @_;
34 my $player = cf::player::find $who->name;
35
36 if ($msg ne "") {
37 my $prev_listen = $player->listening;
38 $player->listening ($msg);
39 if ($prev_listen == $player->listening) {
40 $who->message ("Your verbose level stayed $prev_listen.", cf::NDI_UNIQUE);
41 } else {
42 $who->message ("Your verbose level is now " . $player->listening . ". (previously: $prev_listen)", cf::NDI_UNIQUE);
43 }
44 } else {
45 $who->message ("Your verbose level is " . $player->listening . ".", cf::NDI_UNIQUE);
46 }
47};
48
49cf::register_command say => 0, sub {
50 my ($who, $msg) = @_;
51
52 if ($msg) {
53 my $name = $who->name;
54
55 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
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
92 } else {
93 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
94 }
95};
20 96
21cf::register_command chat => 0, sub { 97cf::register_command chat => 0, sub {
22 my ($who, $msg) = @_; 98 my ($who, $msg) = @_;
23 99
24 if ($msg) { 100 if ($msg) {
25 my $name = $who->name; 101 my $name = $who->name;
26 my $NOW = time; 102 my $NOW = time;
27 103
104 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
105
28 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 106 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
29 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; 107 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
30 108
31 } else { 109 } else {
32 $who->message ("Chat what?", cf::NDI_UNIQUE); 110 $who->message ("Chat what?", cf::NDI_UNIQUE);
33 } 111 }
34}; 112};
38 116
39 if ($msg) { 117 if ($msg) {
40 my $NOW = time; 118 my $NOW = time;
41 my $name = $who->name; 119 my $name = $who->name;
42 120
121 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
122
43 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 123 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
44 for grep $_->ob->{ext_ignore_shout}{$name} < $NOW, cf::player::list; 124 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
45 125
46 } else { 126 } else {
47 $who->message ("Shout what?", cf::NDI_UNIQUE); 127 $who->message ("Shout what?", cf::NDI_UNIQUE);
48 } 128 }
49 129
55 135
56 my $name = $who->name; 136 my $name = $who->name;
57 137
58 if (my $other = cf::player::find $target) { 138 if (my $other = cf::player::find $target) {
59 139
60 if ($target ne $name and $other->ob->{ext_ignore_tell}{$name} < time) { 140 if ($msg) {
61 $who->message ("You tell $target: $msg");
62 $other->ob->message ("$name tells you: $msg");
63 $other->ob->{ext_last_tell} = $name;
64 } elsif ($target eq $name) { 141 if ($target eq $name) {
65 $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);
143 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
144 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
66 } else { 145 } else {
67 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); 146 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
147
148 $who->message ("You tell $target: $msg");
149 $other->ob->message ("$name tells you: $msg");
150 $other->ob->{ext_last_tell} = $name;
68 } 151 }
69
70 } else { 152 } else {
153 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
154 }
155
156 } else {
71 $who->message ("No such player or ambiguous name. Your message: $msg", cf::NDI_UNIQUE); 157 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
72 } 158 }
73}; 159};
74 160
75cf::register_command reply => 0, sub { 161cf::register_command reply => 0, sub {
76 my ($who, $args) = @_; 162 my ($who, $args) = @_;
77 my $name = $who->name; 163 my $name = $who->name;
78 164
79 if (my $other = cf::player::find $who->{ext_last_tell}) { 165 if (my $other = cf::player::find $who->{ext_last_tell}) {
166 if ($args) {
80 167
81 $other->ob->{ext_ignore_tell}{$name} >= time 168 $other->ob->{ext_ignore_tell}{$name} >= time
82 or delete $other->ob->{ext_ignore_tell}{$name}; 169 or delete $other->ob->{ext_ignore_tell}{$name};
83 170
84 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
85 $who->message ("You tell " . $other->ob->name . ": $args"); 174 $who->message ("You tell " . $other->ob->name . ": $args");
86 $other->ob->message ("$name tells you: $args"); 175 $other->ob->message ("$name tells you: $args");
87 $who->{ext_last_tell} = $other->ob->name; 176 $who->{ext_last_tell} = $other->ob->name;
88 } else { 177 } else {
89 $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);
179 }
180 } else {
181 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
90 } 182 }
91 183
92 } else { 184 } else {
93 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); 185 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
94 } 186 }
113 } 205 }
114 206
115 } elsif ($target && $type) { 207 } elsif ($target && $type) {
116 208
117 $timeout ne "" or $timeout = 24; 209 $timeout ne "" or $timeout = 24;
118
119 my $absolute_timeout = time + $timeout * 3600; 210 my $absolute_timeout = time + $timeout * 3600;
120 211
121 if (my $other = cf::player::find $target) { 212 if (cf::player::exists $target) {
122 if ($type eq "tell") { 213 if ($type eq "tell") {
123 $who->message ("Now ignoring private messages from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 214 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
124 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 215 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
125 } elsif ($type eq "shout") { 216 } elsif ($type eq "shout") {
126 $who->message ("Now ignoring shouts from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 217 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
127 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 218 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
128 } elsif ($type eq "all") { 219 } elsif ($type eq "all") {
129 $who->message ("Now ignoring everything from " . $other->ob->name . " for $timeout hours.", cf::NDI_UNIQUE); 220 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
130 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 221 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
131 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 222 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
132 } else { 223 } else {
133 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); 224 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
134 } 225 }
135 } else { 226 } else {
136 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 227 $who->message ("No such player: $target", cf::NDI_UNIQUE);
137 } 228 }
138 229
139 } else { 230 } else {
140 $who->message ("Usage:", cf::NDI_UNIQUE);
141 $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); 231 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
142 $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); 232 . "will ignore a player for <timeout> hours.\n"
143 $who->message ("ignore list", cf::NDI_UNIQUE); 233 . "Usage: ignore list\n"
144 $who->message ("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);
145 } 235 }
146}; 236};
147 237
148cf::register_command unignore => 0, sub { 238cf::register_command unignore => 0, sub {
149 my ($who, $args) = @_; 239 my ($who, $args) = @_;
150 my ($target, $type) = split /\s+/, $args; 240 my ($target, $type) = split /\s+/, $args;
151 241
152 if ($args eq "") { 242 if ($args eq "") {
153 if ($who->{ ext_ignore_tell }) { 243 if ($who->{ext_ignore_tell}) {
154 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 244 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
155 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); 245 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
156 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 246 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
157 $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);
158 } else { 248 } else {
159 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 249 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
160 } 250 }
161 } else { 251 } else {
162
163 if (my $other = cf::player::find $target) { 252 if (cf::player::exists $target) {
164 if ($type eq "tell") { 253 if ($type eq "tell") {
165 $who->message ("Not ignoring private messages from " . $other->ob->name . " anymore.", cf::NDI_UNIQUE); 254 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
166 delete $who->{ext_ignore_tell}{$other->ob->name}; 255 delete $who->{ext_ignore_tell} {$target};
167 } elsif ($type eq "shout") { 256 } elsif ($type eq "shout") {
168 $who->message ("Not ignoring shouts from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 257 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
169 delete $who->{ext_ignore_shout}{$other->ob->name}; 258 delete $who->{ext_ignore_shout}{$target};
170 } elsif ($type eq "all") { 259 } elsif ($type eq "all") {
171 $who->message ("Not ignoring anything from " . $other->ob->name." anymore . ", cf::NDI_UNIQUE); 260 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
172 delete $who->{ext_ignore_tell} {$other->ob->name}; 261 delete $who->{ext_ignore_tell} {$target};
173 delete $who->{ext_ignore_shout}{$other->ob->name}; 262 delete $who->{ext_ignore_shout}{$target};
174 } else { 263 } else {
175 $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);
176 } 265 }
177 } else { 266 } else {
178 $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);
179 } 268 }
180
181 } 269 }
182}; 270};
183 271
272cf::register_command seen => 0, sub {
273 my ($who, $args) = @_;
274
275 if (my ($login) = $args =~ /(\S+)/) {
276 if (cf::player::find $login) {
277 $who->message ("$login is right here on this server!", cf::NDI_UNIQUE);
278 } elsif (cf::player::exists $login
279 and stat sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($login) x 2) {
280 my $time = (stat _)[9];
281
282 $who->message ("$login was last seen here on "
283 . (POSIX::strftime "%Y-%m-%d %H:%M:%S +0000", gmtime $time)
284 . " which was " . (int +(time - $time) / 3600) . " hours ago.", cf::NDI_UNIQUE);
285 } else {
286 $who->message ("No player named $login is known to me.", cf::NDI_UNIQUE);
287 }
288 } else {
289 $who->message ("Usage: seen <player>", cf::NDI_UNIQUE);
290 }
291};
292

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines