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 |
$_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
71 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
72 |
|
73 |
} else { |
74 |
$who->message ("Chat what?", cf::NDI_UNIQUE); |
75 |
} |
76 |
}; |
77 |
|
78 |
cf::register_command shout => 0, sub { |
79 |
my ($who, $msg) = @_; |
80 |
|
81 |
if ($msg) { |
82 |
my $NOW = time; |
83 |
my $name = $who->name; |
84 |
|
85 |
$_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
86 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
87 |
|
88 |
} else { |
89 |
$who->message ("Shout what?", cf::NDI_UNIQUE); |
90 |
} |
91 |
|
92 |
}; |
93 |
|
94 |
cf::register_command tell => 0, sub { |
95 |
my ($who, $args) = @_; |
96 |
my ($target, $msg) = split /\s+/, $args, 2; |
97 |
|
98 |
my $name = $who->name; |
99 |
|
100 |
if (my $other = cf::player::find $target) { |
101 |
|
102 |
if ($msg) { |
103 |
if ($target eq $name) { |
104 |
$who->message ("You are talking to yourself, you freak!", cf::NDI_UNIQUE); |
105 |
} elsif ($other->ob->{ext_ignore_tell}{$name} >= time) { |
106 |
$who->message ("$target ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
107 |
} else { |
108 |
$who->message ("You tell $target: $msg"); |
109 |
$other->ob->message ("$name tells you: $msg"); |
110 |
$other->ob->{ext_last_tell} = $name; |
111 |
} |
112 |
} else { |
113 |
$who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
114 |
} |
115 |
|
116 |
} else { |
117 |
$who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
118 |
} |
119 |
}; |
120 |
|
121 |
cf::register_command reply => 0, sub { |
122 |
my ($who, $args) = @_; |
123 |
my $name = $who->name; |
124 |
|
125 |
if (my $other = cf::player::find $who->{ext_last_tell}) { |
126 |
if ($args) { |
127 |
|
128 |
$other->ob->{ext_ignore_tell}{$name} >= time |
129 |
or delete $other->ob->{ext_ignore_tell}{$name}; |
130 |
|
131 |
if ($other->ob->{ext_ignore_tell}{$name} < time) { |
132 |
$who->message ("You tell " . $other->ob->name . ": $args"); |
133 |
$other->ob->message ("$name tells you: $args"); |
134 |
$who->{ext_last_tell} = $other->ob->name; |
135 |
} else { |
136 |
$who->message ($other->ob->name . " ignores what you say. Give up on it.", cf::NDI_UNIQUE); |
137 |
} |
138 |
} else { |
139 |
$who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
140 |
} |
141 |
|
142 |
} else { |
143 |
$who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
144 |
} |
145 |
}; |
146 |
|
147 |
cf::register_command ignore => 0, sub { |
148 |
my ($who, $args) = @_; |
149 |
my ($target, $type, $timeout) = split /\s+/, $args; |
150 |
|
151 |
if ($args eq "list") { |
152 |
clean_timeouts $who; |
153 |
|
154 |
if ((my @ignored_tell = sort keys %{$who->{ext_ignore_tell}}) |
155 |
+ (my @ignored_shout = sort keys %{$who->{ext_ignore_shout}})) { |
156 |
$who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
157 |
$who->message ((join ", ", @ignored_tell), cf::NDI_UNIQUE); |
158 |
$who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
159 |
$who->message ((join ", ", @ignored_shout), cf::NDI_UNIQUE); |
160 |
$who->message ("To stop ignoring one, use unignore.", cf::NDI_UNIQUE); |
161 |
} else { |
162 |
$who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
163 |
} |
164 |
|
165 |
} elsif ($target && $type) { |
166 |
|
167 |
$timeout ne "" or $timeout = 24; |
168 |
my $absolute_timeout = time + $timeout * 3600; |
169 |
|
170 |
if (valid_user $target) { |
171 |
if ($type eq "tell") { |
172 |
$who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
173 |
$who->{ext_ignore_tell}{$target} = $absolute_timeout; |
174 |
} elsif ($type eq "shout") { |
175 |
$who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
176 |
$who->{ext_ignore_shout}{$target} = $absolute_timeout; |
177 |
} elsif ($type eq "all") { |
178 |
$who->message ("Now ignoring everything from $target for $timeout hours.", cf::NDI_UNIQUE); |
179 |
$who->{ext_ignore_tell}{$target} = $absolute_timeout; |
180 |
$who->{ext_ignore_shout}{$target} = $absolute_timeout; |
181 |
} else { |
182 |
$who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
183 |
} |
184 |
} else { |
185 |
$who->message ("No such player: $target", cf::NDI_UNIQUE); |
186 |
} |
187 |
|
188 |
} else { |
189 |
$who->message ("Usage: ignore <player> <tell | shout | all> <timeout>\n" |
190 |
. "will ignore a player for <timeout> hours.\n" |
191 |
. "Usage: ignore list\n" |
192 |
. "will show you a list of players currently ignored.", cf::NDI_UNIQUE); |
193 |
} |
194 |
}; |
195 |
|
196 |
cf::register_command unignore => 0, sub { |
197 |
my ($who, $args) = @_; |
198 |
my ($target, $type) = split /\s+/, $args; |
199 |
|
200 |
if ($args eq "") { |
201 |
if ($who->{ext_ignore_tell}) { |
202 |
$who->message ("Currently ignoring private messages from: ", cf::NDI_UNIQUE); |
203 |
$who->message ((join ", ", sort keys %{ $who->{ext_ignore_tell} }), cf::NDI_UNIQUE); |
204 |
$who->message ("Currently ignoring shouts from: ", cf::NDI_UNIQUE); |
205 |
$who->message ((join ", ", sort keys %{ $who->{ext_ignore_shout} }), cf::NDI_UNIQUE); |
206 |
} else { |
207 |
$who->message ("Not ignoring anyone", cf::NDI_UNIQUE); |
208 |
} |
209 |
} else { |
210 |
|
211 |
if (valid_user $target) { |
212 |
if ($type eq "tell") { |
213 |
$who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
214 |
delete $who->{ext_ignore_tell} {$target}; |
215 |
} elsif ($type eq "shout") { |
216 |
$who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
217 |
delete $who->{ext_ignore_shout}{$target}; |
218 |
} elsif ($type eq "all") { |
219 |
$who->message ("Not ignoring anything from $target anymore.", cf::NDI_UNIQUE); |
220 |
delete $who->{ext_ignore_tell} {$target}; |
221 |
delete $who->{ext_ignore_shout}{$target}; |
222 |
} else { |
223 |
$who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
224 |
} |
225 |
} else { |
226 |
$who->message ("No such player or ambiguous name: $target", cf::NDI_UNIQUE); |
227 |
} |
228 |
|
229 |
} |
230 |
}; |
231 |
|