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