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.5 by root, Sun May 7 08:10:23 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 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
9sub clean_timeouts($) {
10 my ($player) = @_;
11 my $NOW = time;
12
13 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
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 }
23 }
24}
25
26sub on_logout {
27 my ($pl, $host) = @_;
28
29 clean_timeouts $pl->ob;
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
6cf::register_command chat => 0, sub 49cf::register_command say => 0, sub {
7{
8 my ($who, $msg) = @_; 50 my ($who, $msg) = @_;
9 51
10 if ($msg) { 52 if ($msg) {
11 my $name = $who->name; 53 my $name = $who->name;
12 54
13 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 55 $_->ob->message ("$name says: $msg", cf::NDI_GREY | cf::NDI_UNIQUE)
14 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 56 for grep $who->on_same_map_as ($_->ob), cf::player::list;
15 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
16 } else { 92 } else {
17 $who->message ("Chat what?", cf::NDI_UNIQUE); 93 $who->message ("What do you want to say?", cf::NDI_UNIQUE);
18 } 94 }
19}; 95};
20 96
21cf::register_command shout => 0, sub 97cf::register_command chat => 0, sub {
22{
23 my ($who, $msg) = @_; 98 my ($who, $msg) = @_;
24 99
25 if ($msg) { 100 if ($msg) {
26 my $name = $who->name; 101 my $name = $who->name;
102 my $NOW = time;
103
104 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
105
106 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
107 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
108
109 } else {
110 $who->message ("Chat what?", cf::NDI_UNIQUE);
111 }
112};
113
114cf::register_command shout => 0, sub {
115 my ($who, $msg) = @_;
116
117 if ($msg) {
118 my $NOW = time;
119 my $name = $who->name;
120
121 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
27 122
28 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 123 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
29 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 124 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
30 125
31 } else { 126 } else {
32 $who->message ("Shout what?", cf::NDI_UNIQUE); 127 $who->message ("Shout what?", cf::NDI_UNIQUE);
33 } 128 }
34 129
40 135
41 my $name = $who->name; 136 my $name = $who->name;
42 137
43 if (my $other = cf::player::find $target) { 138 if (my $other = cf::player::find $target) {
44 139
45 $other->ob->{ext_ignore_tell}{$name} >= time 140 if ($msg) {
46 or delete $other->ob->{ext_ignore_tell}{$name};
47
48 if ($target ne $name and !$other->ob->{ext_ignore_tell}{$name}) {
49 $who->message ("You tell $target: $msg");
50 $other->ob->message ("$name tells you: $msg");
51 $other->ob->{ext_last_tell} = $name;
52 } elsif ($target eq $name) { 141 if ($target eq $name) {
53 $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);
54 } else { 145 } else {
55 $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;
56 } 151 }
57
58 } else { 152 } else {
153 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
154 }
155
156 } else {
59 $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);
60 } 158 }
61}; 159};
62 160
63cf::register_command reply => 0, sub { 161cf::register_command reply => 0, sub {
64 my ($who, $args) = @_; 162 my ($who, $args) = @_;
65 my $name = $who->name; 163 my $name = $who->name;
66 164
67 if (my $other = cf::player::find $who->{ext_last_tell}) { 165 if (my $other = cf::player::find $who->{ext_last_tell}) {
166 if ($args) {
68 167
69 $other->ob->{ext_ignore_tell}{$name} >= time 168 $other->ob->{ext_ignore_tell}{$name} >= time
70 or delete $other->ob->{ext_ignore_tell}{$name}; 169 or delete $other->ob->{ext_ignore_tell}{$name};
71 170
72 if (!$other->ob->{ext_ignore_tell}{$name}) { 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
73 $who->message ("You tell " . $other->ob->name . ": $args"); 174 $who->message ("You tell " . $other->ob->name . ": $args");
74 $other->ob->message ("$name tells you: $args"); 175 $other->ob->message ("$name tells you: $args");
75 $who->{ext_last_tell} = $other->ob->name; 176 $who->{ext_last_tell} = $other->ob->name;
76 } else { 177 } else {
77 $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);
78 } 182 }
79 183
80 } else { 184 } else {
81 $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);
82 } 186 }
85cf::register_command ignore => 0, sub { 189cf::register_command ignore => 0, sub {
86 my ($who, $args) = @_; 190 my ($who, $args) = @_;
87 my ($target, $type, $timeout) = split /\s+/, $args; 191 my ($target, $type, $timeout) = split /\s+/, $args;
88 192
89 if ($args eq "list") { 193 if ($args eq "list") {
194 clean_timeouts $who;
195
90 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) 196 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
91 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { 197 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
92 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 198 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
93 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); 199 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
94 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 200 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
99 } 205 }
100 206
101 } elsif ($target && $type) { 207 } elsif ($target && $type) {
102 208
103 $timeout ne "" or $timeout = 24; 209 $timeout ne "" or $timeout = 24;
104
105 my $absolute_timeout = time + $timeout * 3600; 210 my $absolute_timeout = time + $timeout * 3600;
106 211
107 if (my $other = cf::player::find $target) { 212 if (cf::player::exists $target) {
108 if ($type eq "tell") { 213 if ($type eq "tell") {
109 $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);
110 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 215 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
111 } elsif ($type eq "shout") { 216 } elsif ($type eq "shout") {
112 $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);
113 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 218 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
114 } elsif ($type eq "all") { 219 } elsif ($type eq "all") {
115 $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);
116 $who->{ext_ignore_tell}{$other->ob->name} = $absolute_timeout; 221 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
117 $who->{ext_ignore_shout}{$other->ob->name} = $absolute_timeout; 222 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
118 } else { 223 } else {
119 $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);
120 } 225 }
121 } else { 226 } else {
122 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); 227 $who->message ("No such player: $target", cf::NDI_UNIQUE);
123 } 228 }
124 229
125 } else { 230 } else {
126 $who->message ("Usage:", cf::NDI_UNIQUE);
127 $who->message ("ignore <player> <tell | shout | all> <timeout>", cf::NDI_UNIQUE); 231 $who->message ("Usage: ignore <player> <tell|shout|all> <timeout>\n"
128 $who->message ("will ignore a player for <timeout> hours.", cf::NDI_UNIQUE); 232 . "will ignore a player for <timeout> hours.\n"
129 $who->message ("ignore list", cf::NDI_UNIQUE); 233 . "Usage: ignore list\n"
130 $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);
131 } 235 }
132}; 236};
133 237
134cf::register_command unignore => 0, sub { 238cf::register_command unignore => 0, sub {
135 my ($who, $args) = @_; 239 my ($who, $args) = @_;
136 my ($target, $type) = split /\s+/, $args; 240 my ($target, $type) = split /\s+/, $args;
137 241
138 if ($args eq "") { 242 if ($args eq "") {
139 if ($who->{ ext_ignore_tell }) { 243 if ($who->{ext_ignore_tell}) {
140 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); 244 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
141 $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);
142 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); 246 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
143 $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);
144 } else { 248 } else {
145 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE); 249 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
146 } 250 }
147 } else { 251 } else {
148
149 if (my $other = cf::player::find $target) { 252 if (cf::player::exists $target) {
150 if ($type eq "tell") { 253 if ($type eq "tell") {
151 $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);
152 delete $who->{ext_ignore_tell}{$other->ob->name}; 255 delete $who->{ext_ignore_tell} {$target};
153 } elsif ($type eq "shout") { 256 } elsif ($type eq "shout") {
154 $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);
155 delete $who->{ext_ignore_shout}{$other->ob->name}; 258 delete $who->{ext_ignore_shout}{$target};
156 } elsif ($type eq "all") { 259 } elsif ($type eq "all") {
157 $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);
158 delete $who->{ext_ignore_tell} {$other->ob->name}; 261 delete $who->{ext_ignore_tell} {$target};
159 delete $who->{ext_ignore_shout}{$other->ob->name}; 262 delete $who->{ext_ignore_shout}{$target};
160 } else { 263 } else {
161 $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);
162 } 265 }
163 } else { 266 } else {
164 $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);
165 } 268 }
166
167 } 269 }
168}; 270};
169 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