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