1 |
#! perl |
2 |
|
3 |
# implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 |
# adds ignore/unignore functionality |
5 |
|
6 |
sub 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 |
|
11 |
sub 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 |
|
28 |
sub on_logout { |
29 |
my ($pl, $host) = @_; |
30 |
|
31 |
clean_timeouts $pl->ob; |
32 |
} |
33 |
|
34 |
cf::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 |
|
63 |
cf::register_command chat => 0, sub { |
64 |
my ($who, $msg) = @_; |
65 |
|
66 |
if ($msg) { |
67 |
my $name = $who->name; |
68 |
my $NOW = time; |
69 |
|
70 |
cf::LOG cf::llevDebug, sprintf "QBERT [%s] %s\n", $name, $msg; |
71 |
|
72 |
$_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
73 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
74 |
|
75 |
} else { |
76 |
$who->message ("Chat what?", cf::NDI_UNIQUE); |
77 |
} |
78 |
}; |
79 |
|
80 |
cf::register_command shout => 0, sub { |
81 |
my ($who, $msg) = @_; |
82 |
|
83 |
if ($msg) { |
84 |
my $NOW = time; |
85 |
my $name = $who->name; |
86 |
|
87 |
cf::LOG cf::llevDebug, sprintf "QBERT {%s} %s\n", $name, $msg; |
88 |
|
89 |
$_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
90 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
91 |
|
92 |
} else { |
93 |
$who->message ("Shout what?", cf::NDI_UNIQUE); |
94 |
} |
95 |
|
96 |
}; |
97 |
|
98 |
cf::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 |
|
127 |
cf::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 |
|
155 |
cf::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 |
|
204 |
cf::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 |
|