1 |
pippijn |
1.1 |
#! perl |
2 |
root |
1.5 |
|
3 |
pippijn |
1.15 |
# implement a replacement for the built-in say/chat/shout/tell/reply commands |
4 |
root |
1.5 |
# adds ignore/unignore functionality |
5 |
|
|
|
6 |
root |
1.12 |
sub valid_user($) { |
7 |
root |
1.18 |
cf::player::find $_[0] |
8 |
|
|
or -f sprintf "%s/%s/%s/%s.pl", cf::localdir, cf::playerdir, ($_[0]) x 2; |
9 |
root |
1.12 |
} |
10 |
|
|
|
11 |
|
|
sub clean_timeouts($) { |
12 |
root |
1.8 |
my ($player) = @_; |
13 |
|
|
my $NOW = time; |
14 |
|
|
|
15 |
|
|
for my $hash (@$player{qw(ext_ignore_shout ext_ignore_tell)}) { |
16 |
root |
1.12 |
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 |
root |
1.8 |
} |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
sub on_logout { |
29 |
|
|
my ($pl, $host) = @_; |
30 |
|
|
|
31 |
|
|
clean_timeouts $pl->ob; |
32 |
|
|
} |
33 |
|
|
|
34 |
pippijn |
1.15 |
cf::register_command listen => 0, sub { |
35 |
|
|
my ($who, $msg) = @_; |
36 |
|
|
my $player = cf::player::find $who->name; |
37 |
|
|
|
38 |
pippijn |
1.17 |
if ($msg ne "") { |
39 |
pippijn |
1.15 |
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 |
pippijn |
1.16 |
#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 |
pippijn |
1.15 |
|
63 |
pippijn |
1.6 |
cf::register_command chat => 0, sub { |
64 |
pippijn |
1.1 |
my ($who, $msg) = @_; |
65 |
|
|
|
66 |
|
|
if ($msg) { |
67 |
|
|
my $name = $who->name; |
68 |
root |
1.8 |
my $NOW = time; |
69 |
pippijn |
1.1 |
|
70 |
root |
1.4 |
$_->ob->message ("$name chats: $msg", cf::NDI_BLUE) |
71 |
pippijn |
1.15 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 10 } cf::player::list; |
72 |
root |
1.4 |
|
73 |
pippijn |
1.1 |
} else { |
74 |
|
|
$who->message ("Chat what?", cf::NDI_UNIQUE); |
75 |
|
|
} |
76 |
|
|
}; |
77 |
|
|
|
78 |
pippijn |
1.6 |
cf::register_command shout => 0, sub { |
79 |
pippijn |
1.1 |
my ($who, $msg) = @_; |
80 |
|
|
|
81 |
|
|
if ($msg) { |
82 |
root |
1.8 |
my $NOW = time; |
83 |
pippijn |
1.1 |
my $name = $who->name; |
84 |
|
|
|
85 |
root |
1.4 |
$_->ob->message ("$name shouts: $msg", cf::NDI_RED) |
86 |
pippijn |
1.15 |
for grep { $_->ob->{ext_ignore_shout}{$name} < $NOW && $_->listening >= 2 } cf::player::list; |
87 |
root |
1.4 |
|
88 |
pippijn |
1.1 |
} else { |
89 |
|
|
$who->message ("Shout what?", cf::NDI_UNIQUE); |
90 |
|
|
} |
91 |
|
|
|
92 |
|
|
}; |
93 |
root |
1.5 |
|
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 |
pippijn |
1.11 |
if (my $other = cf::player::find $target) { |
101 |
root |
1.12 |
|
102 |
pippijn |
1.11 |
if ($msg) { |
103 |
root |
1.12 |
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 |
pippijn |
1.9 |
$who->message ("You tell $target: $msg"); |
109 |
|
|
$other->ob->message ("$name tells you: $msg"); |
110 |
|
|
$other->ob->{ext_last_tell} = $name; |
111 |
|
|
} |
112 |
root |
1.5 |
} else { |
113 |
pippijn |
1.11 |
$who->message ("What do you want to tell $target?", cf::NDI_UNIQUE); |
114 |
root |
1.5 |
} |
115 |
root |
1.12 |
|
116 |
root |
1.5 |
} else { |
117 |
root |
1.12 |
$who->message ("No such player. Your message: $msg", cf::NDI_UNIQUE); |
118 |
root |
1.5 |
} |
119 |
|
|
}; |
120 |
|
|
|
121 |
|
|
cf::register_command reply => 0, sub { |
122 |
|
|
my ($who, $args) = @_; |
123 |
|
|
my $name = $who->name; |
124 |
|
|
|
125 |
pippijn |
1.11 |
if (my $other = cf::player::find $who->{ext_last_tell}) { |
126 |
|
|
if ($args) { |
127 |
root |
1.5 |
|
128 |
pippijn |
1.9 |
$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 |
root |
1.5 |
} else { |
139 |
pippijn |
1.11 |
$who->message ("What do you want to tell ".$other->ob->name."?", cf::NDI_UNIQUE); |
140 |
root |
1.5 |
} |
141 |
pippijn |
1.11 |
|
142 |
root |
1.5 |
} else { |
143 |
pippijn |
1.11 |
$who->message ("Can't reply, player left. Your message: $args", cf::NDI_UNIQUE); |
144 |
root |
1.5 |
} |
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 |
root |
1.8 |
clean_timeouts $who; |
153 |
|
|
|
154 |
root |
1.5 |
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 |
root |
1.12 |
if (valid_user $target) { |
171 |
root |
1.5 |
if ($type eq "tell") { |
172 |
root |
1.12 |
$who->message ("Now ignoring private messages from $target for $timeout hours.", cf::NDI_UNIQUE); |
173 |
|
|
$who->{ext_ignore_tell}{$target} = $absolute_timeout; |
174 |
root |
1.5 |
} elsif ($type eq "shout") { |
175 |
root |
1.12 |
$who->message ("Now ignoring shouts from $target for $timeout hours.", cf::NDI_UNIQUE); |
176 |
|
|
$who->{ext_ignore_shout}{$target} = $absolute_timeout; |
177 |
root |
1.5 |
} elsif ($type eq "all") { |
178 |
root |
1.12 |
$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 |
root |
1.5 |
} else { |
182 |
|
|
$who->message ("You need to specify tell, shout or all.", cf::NDI_UNIQUE); |
183 |
|
|
} |
184 |
|
|
} else { |
185 |
root |
1.12 |
$who->message ("No such player: $target", cf::NDI_UNIQUE); |
186 |
root |
1.5 |
} |
187 |
|
|
|
188 |
|
|
} else { |
189 |
root |
1.12 |
$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 |
root |
1.5 |
} |
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 |
root |
1.12 |
if ($who->{ext_ignore_tell}) { |
202 |
root |
1.5 |
$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 |
root |
1.12 |
if (valid_user $target) { |
212 |
root |
1.5 |
if ($type eq "tell") { |
213 |
root |
1.12 |
$who->message ("Not ignoring private messages from $target anymore.", cf::NDI_UNIQUE); |
214 |
|
|
delete $who->{ext_ignore_tell} {$target}; |
215 |
root |
1.5 |
} elsif ($type eq "shout") { |
216 |
root |
1.12 |
$who->message ("Not ignoring shouts from $target anymore.", cf::NDI_UNIQUE); |
217 |
|
|
delete $who->{ext_ignore_shout}{$target}; |
218 |
root |
1.5 |
} elsif ($type eq "all") { |
219 |
root |
1.12 |
$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 |
root |
1.5 |
} 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 |
|
|
|