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