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.4 by root, Sun May 7 08:05:26 2006 UTC vs.
Revision 1.19 by root, Fri Jun 9 04:18:02 2006 UTC

1#! perl 1#! perl
2
3# implement a replacement for the built-in say/chat/shout/tell/reply commands
4# adds ignore/unignore functionality
5
6sub valid_user($) {
7 cf::player::find $_[0]
8 or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2;
9}
10
11sub clean_timeouts($) {
12 my ($player) = @_;
13 my $NOW = time;
14
15 for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) {
16 while (my ($k, $v) = each %$hash) {
17 if ($v < $NOW) {
18 $player->message ("Your ignore on $k has expired.", cf::NDI_GREEN);
19 delete $hash->{$k};
20 } elsif (!valid_user $k) {
21 $player->message ("Your ignore on $k is no longer valid (no such user).", cf::NDI_GREEN);
22 delete $hash->{$k};
23 }
24 }
25 }
26}
27
28sub on_logout {
29 my ($pl, $host) = @_;
30
31 clean_timeouts $pl->ob;
32}
33
34cf::register_command listen => 0, sub {
35 my ($who, $msg) = @_;
36 my $player = cf::player::find $who->name;
37
38 if ($msg ne "") {
39 my $prev_listen = $player->listening;
40 $player->listening ($msg);
41 if ($prev_listen == $player->listening) {
42 $who->message ("Your verbose level stayed ".$prev_listen.".", cf::NDI_UNIQUE);
43 } else {
44 $who->message ("Your verbose level is now ".$player->listening.". (previously: ".$prev_listen.")", cf::NDI_UNIQUE);
45 }
46 } else {
47 $who->message ("Your verbose level is ".$player->listening.".", cf::NDI_UNIQUE);
48 }
49};
50
51#cf::register_command say => 0, sub {
52# my ($who, $msg) = @_;
53#
54# if ($msg) {
55# my $name = $who->name;
56# $_->ob->message ("$name says: $msg", cf::NDI_WHITE)
57# for grep $who->on_same_map_as ($_->ob), cf::player::list;
58# } else {
59# $who->message ("What do you want to say?", cf::NDI_UNIQUE);
60# }
61#};
62
2cf::register_command chat => 0, sub 63cf::register_command chat => 0, sub {
3{
4 my ($who, $msg) = @_; 64 my ($who, $msg) = @_;
5 65
6 if ($msg) { 66 if ($msg) {
7 my $name = $who->name; 67 my $name = $who->name;
68 my $NOW = time;
69
70 cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg;
8 71
9 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE) 72 $_->ob->message ("$name chats: $msg", cf::NDI_BLUE)
10 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 73 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list;
11 74
12 } else { 75 } else {
13 $who->message ("Chat what?", cf::NDI_UNIQUE); 76 $who->message ("Chat what?", cf::NDI_UNIQUE);
14 } 77 }
15}; 78};
16 79
17cf::register_command shout => 0, sub 80cf::register_command shout => 0, sub {
18{
19 my ($who, $msg) = @_; 81 my ($who, $msg) = @_;
20 82
21 if ($msg) { 83 if ($msg) {
84 my $NOW = time;
22 my $name = $who->name; 85 my $name = $who->name;
23 86
87 cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg;
88
24 $_->ob->message ("$name shouts: $msg", cf::NDI_RED) 89 $_->ob->message ("$name shouts: $msg", cf::NDI_RED)
25 for grep !$player->ob->{ext_ignore_shout}, cf::player::list; 90 for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list;
26 91
27 } else { 92 } else {
28 $who->message ("Shout what?", cf::NDI_UNIQUE); 93 $who->message ("Shout what?", cf::NDI_UNIQUE);
29 } 94 }
30 95
31}; 96};
97
98cf::register_command tell => 0, sub {
99 my ($who, $args) = @_;
100 my ($target, $msg) = split /\s+/, $args, 2;
101
102 my $name = $who->name;
103
104 if (my $other = cf::player::find $target) {
105
106 if ($msg) {
107 if ($target eq $name) {
108 $who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE);
109 } elsif ($other->ob->{ext_ignore_tell}{$name} >= time) {
110 $who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE);
111 } else {
112 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $target, $msg;
113
114 $who->message ("You tell $target: $msg");
115 $other->ob->message ("$name tells you: $msg");
116 $other->ob->{ext_last_tell} = $name;
117 }
118 } else {
119 $who->message ("What do you want to tell $target?", cf::NDI_UNIQUE);
120 }
121
122 } else {
123 $who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE);
124 }
125};
126
127cf::register_command reply => 0, sub {
128 my ($who, $args) = @_;
129 my $name = $who->name;
130
131 if (my $other = cf::player::find $who->{ext_last_tell}) {
132 if ($args) {
133
134 $other->ob->{ext_ignore_tell}{$name} >= time
135 or delete $other->ob->{ext_ignore_tell}{$name};
136
137 if ($other->ob->{ext_ignore_tell}{$name} < time) {
138 cf::LOG cf::llevDebug, sprintf "TELL [%s>%s] %s\n", $name, $other->ob->name, $args;
139
140 $who->message ("You tell " . $other->ob->name . ": $args");
141 $other->ob->message ("$name tells you: $args");
142 $who->{ext_last_tell} = $other->ob->name;
143 } else {
144 $who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE);
145 }
146 } else {
147 $who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE);
148 }
149
150 } else {
151 $who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE);
152 }
153};
154
155cf::register_command ignore => 0, sub {
156 my ($who, $args) = @_;
157 my ($target, $type, $timeout) = split /\s+/, $args;
158
159 if ($args eq "list") {
160 clean_timeouts $who;
161
162 if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}})
163 + (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) {
164 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
165 $who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE);
166 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
167 $who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE);
168 $who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE);
169 } else {
170 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
171 }
172
173 } elsif ($target && $type) {
174
175 $timeout ne "" or $timeout = 24;
176 my $absolute_timeout = time + $timeout * 3600;
177
178 if (valid_user $target) {
179 if ($type eq "tell") {
180 $who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE);
181 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
182 } elsif ($type eq "shout") {
183 $who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE);
184 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
185 } elsif ($type eq "all") {
186 $who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE);
187 $who->{ext_ignore_tell}{$target} = $absolute_timeout;
188 $who->{ext_ignore_shout}{$target} = $absolute_timeout;
189 } else {
190 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
191 }
192 } else {
193 $who->message ("No such player: $target", cf::NDI_UNIQUE);
194 }
195
196 } else {
197 $who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n"
198 . "will ignore a player for <timeout> hours.\n"
199 . "Usage: ignore list\n"
200 . "will show you a list of players currently ignored.", cf::NDI_UNIQUE);
201 }
202};
203
204cf::register_command unignore => 0, sub {
205 my ($who, $args) = @_;
206 my ($target, $type) = split /\s+/, $args;
207
208 if ($args eq "") {
209 if ($who->{ext_ignore_tell}) {
210 $who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE);
211 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE);
212 $who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE);
213 $who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE);
214 } else {
215 $who->message ("Not ignoring anyone", cf::NDI_UNIQUE);
216 }
217 } else {
218
219 if (valid_user $target) {
220 if ($type eq "tell") {
221 $who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE);
222 delete $who->{ext_ignore_tell} {$target};
223 } elsif ($type eq "shout") {
224 $who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE);
225 delete $who->{ext_ignore_shout}{$target};
226 } elsif ($type eq "all") {
227 $who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE);
228 delete $who->{ext_ignore_tell} {$target};
229 delete $who->{ext_ignore_shout}{$target};
230 } else {
231 $who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE);
232 }
233 } else {
234 $who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE);
235 }
236
237 }
238};
239

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines