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