/usr/share/tiarra/module/User/Vanish.pm is in tiarra 20100212-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | # -----------------------------------------------------------------------------
# $Id: Vanish.pm 11365 2008-05-10 14:58:28Z topia $
# -----------------------------------------------------------------------------
package User::Vanish;
use strict;
use warnings;
use base qw(Module);
use Mask;
use Multicast;
our $DEBUG = 0;
sub message_arrived {
my ($this,$msg,$sender) = @_;
my $result = $msg;
if ($sender->server_p) {
my $method = 'cmd_'.$msg->command;
if ($this->can($method)) {
if ($DEBUG) {
my $original = $msg->serialize;
$result = $this->$method($msg, $sender);
my $filtered = (defined $result ? $result->serialize : '');
if ($original ne $filtered) {
# 内容が書換へられた。
my $debug_msg = "'$original' -> '$filtered'";
eval {
substr($debug_msg, 400) = '...';
};
RunLoop->shared->notify_msg($debug_msg);
}
}
else {
$result = $this->$method($msg, $sender);
}
}
}
elsif ($sender->client_p) {
if ($msg->command eq 'VANISHDEBUG') {
$DEBUG = $msg->param(0);
RunLoop->shared->notify_msg("User::Vanish - debug-mode ".($DEBUG?'enabled':'disabled'));
$result = undef;
}
}
$result;
}
*cmd_NOTICE = \&cmd_PRIVMSG;
sub cmd_PRIVMSG {
my ($this,$msg,$sender) = @_;
# 発行元がVanish対象か?
my $ch_long = $msg->param(0);
my $ch_short = Multicast::detach($ch_long);
if (Multicast::nick_p($ch_short)) {
$ch_long = '#___priv___@'.$sender->network_name;
}
if ($this->target_of_vanish_p($msg->prefix,$ch_long)) {
undef;
}
else {
$msg;
}
}
sub cmd_JOIN {
my ($this,$msg,$sender) = @_;
my @channels; # チャンネルリストを再構成する。
foreach my $channel (split m/,/,$msg->param(0)) {
my ($ch_full,$mode) = ($channel =~ m/^([^\x07]+)(?:\x07(.*))?/);
if (!$this->target_of_vanish_p($msg->prefix,$ch_full)) {
push @channels,$channel;
}
}
if (@channels > 0) {
# 再構成の結果、チャンネルがまだ残ってた。
$msg->param(0,join(',',@channels));
}
else {
$msg = undef;
}
$msg;
}
sub cmd_NJOIN {
my ($this,$msg,$sender) = @_;
my $ch_long = $msg->param(0);
my $ch_short = Multicast::detach($ch_long);
my $ch = $sender->channel($ch_short);
if (defined $ch) {
my @nicks;
foreach my $mode_and_nick (split m/,/,$msg->param(1)) {
my ($mode,$nick) = ($mode_and_nick =~ m/^([@+]*)(.+)$/);
my $person = $ch->names($nick);
if (!defined $person || !$this->target_of_vanish_p) {
push @nicks,$mode_and_nick;
}
}
if (@nicks > 0) {
# 再構成の結果、nickがまだ残ってた。
$msg->param(1,join(',',@nicks));
}
else {
$msg = undef;
}
}
$msg;
}
sub cmd_PART {
my ($this,$msg,$sender) = @_;
if ($this->target_of_vanish_p($msg->prefix,$msg->param(0))) {
undef;
}
else {
$msg;
}
}
sub cmd_INVITE {
my ($this,$msg,$sender) = @_;
if ($this->target_of_vanish_p($msg->prefix,$msg->param(1))) {
undef;
}
else {
$msg;
}
}
*cmd_QUIT = \&cmd_NICK;
sub cmd_NICK {
my ($this,$msg,$sender) = @_;
# 影響を及ぼした全チャンネル名のリストを得る。このリストにはネットワーク名が付いていない。
my $affected = $msg->remark('affected-channels');
# 一つでもVanish対象でないチャンネルとnickの組みがあれば、このNICKは破棄しない。
my $no_vanish;
foreach (@$affected) {
my $ch_long = Multicast::attach($_,$sender->network_name);
if (!$this->target_of_vanish_p($msg->prefix,$ch_long)) {
$no_vanish = 1;
last;
}
}
if ($no_vanish) {
$msg;
}
else {
undef;
}
}
sub cmd_TOPIC {
my ($this,$msg,$sender) = @_;
if ($this->target_of_vanish_p($msg->prefix,$msg->param(0))) {
if ($this->config->drop_topic_by_target) {
$msg->prefix('HIDDEN!HIDDEN@HIDDEN.BY.USER.VANISH');
}
}
$msg;
}
sub cmd_353 {
# RPL_NAMREPLY
my ($this,$msg,$sender) = @_;
my $ch_long = $msg->param(2);
my $ch_short = Multicast::detach($ch_long);
my $ch = $sender->channel($ch_short);
if (defined $ch) {
my @nicks;
foreach my $mode_and_nick (split / /,$msg->param(3)) {
my ($mode,$nick) = ($mode_and_nick =~ m/^([@\+]{0,2})(.+)$/);
my $person = $ch->names($nick);
if (!defined $person || !$this->target_of_vanish_p($person->info,$ch_long)) {
push @nicks,$mode_and_nick;
}
}
$msg->param(3,join(' ',@nicks));
}
$msg;
}
sub cmd_MODE {
my ($this,$msg,$sender) = @_;
# 発行元がVanish対象か?
if ($this->target_of_vanish_p($msg->prefix,$msg->param(0))) {
if ($this->config->drop_mode_by_target) {
# prefix改竄
$msg->prefix('HIDDEN!HIDDEN@HIDDEN.BY.USER.VANISH');
}
}
# +o/-o/+v/-vの対象がVanishの対象か?
my $ch_long = $msg->param(0);
my $ch_short = Multicast::detach($ch_long);
my $ch = $sender->channel($ch_short);
if (defined $ch && (sub{defined$_[0]?$_[0]:1}->($this->config->drop_mode_switch_for_target))) {
my $n_params = @{$msg->params};
my $plus = 0; # 現在評価中のモードが+なのか-なのか。
my $mode_char_pos = 1; # 現在評価中のmode characterの位置。
my $mode_param_offset = 0; # $mode_char_posから幾つの追加パラメタを拾ったか。
my $fetch_param = sub {
$mode_param_offset++;
return $msg->param($mode_char_pos + $mode_param_offset);
};
my @params = ($ch_long); # パラメータを再構築する。
my $add = sub {
my ($char,$option) = @_;
push @params,($plus ? '+' : '-').$char;
if (defined $option) {
push @params,$option;
}
};
for (;$mode_char_pos < $n_params;$mode_char_pos += $mode_param_offset + 1) {
$mode_param_offset = 0; # これは毎回リセットする。
foreach my $c (split //,$msg->param($mode_char_pos)) {
if ($c eq '+') {
$plus = 1;
}
elsif ($c eq '-') {
$plus = 0;
}
elsif (index('bIk',$c) != -1) {
$add->($c,$fetch_param->());
}
elsif (index('Oov',$c) != -1) {
my $target = $fetch_param->();
my $person = $ch->names($target);
if (!defined $person || !$this->target_of_vanish_p($person->info,$ch_long)) {
$add->($c,$target);
}
}
elsif ($c eq 'l') {
if ($plus) {
$add->($c,$fetch_param->()); # 追加パラメタを捨てる
}
else {
$add->($c);
}
}
else {
$add->($c);
}
}
}
# パラメタ再構成の結果、一つも無くなったら、このメッセージは破棄。
if (@params > 1) {
$msg = $this->construct_irc_message(
Prefix => $msg->prefix,
Command => $msg->command,
Params => \@params);
}
else {
$msg = undef;
}
}
$msg;
}
sub cmd_KICK {
my ($this,$msg,$sender) = @_;
if ($this->target_of_vanish_p($msg->prefix,$msg->param(0))) {
if ($this->config->drop_kick_by_target) {
$msg->prefix('HIDDEN!HIDDEN@HIDDEN.BY.USER.VANISH');
}
}
my $kicked_nick = $msg->param(1);
my $ch = $sender->channel(Multicast::detach($msg->param(0)));
if (defined $ch) {
if ($this->config->drop_kick_for_target) {
$msg = undef;
}
}
$msg;
}
sub target_of_vanish_p {
# $userinfo: nick!name@host形式のユーザー情報
# $ch_long : ネットワーク名付きのチャンネル名
# 戻り値: 真偽値
my ($this,$userinfo,$ch_long) = @_;
Mask::match_deep_chan([$this->config->mask('all')],$userinfo,$ch_long);
}
1;
=pod
info: 指定された人物の存在を、様々なメッセージから消去する。
default: off
# 対象となった人物の発行したJOIN、PART、INVITE、QUIT、NICKは消去され、NAMESの返すネームリストからも消える。
# また、対象となった人物のNJOINも消去される。
# Vanish対象が発行したMODEを消去するかどうか。デフォルトで0。
# 消去するとは云え、本当にMODEそのものを消してしまうのではなく、
# そのユーザーの代わりに"HIDDEN!HIDDEN@HIDDEN.BY.USER.VANISH"がMODEを実行した事にする。
drop-mode-by-target: 1
# Vanish対象を対象とするMODE +o/-o/+v/-vを消去するかどうか。デフォルトで1。
drop-mode-switch-for-target: 1
# Vanish対象が発行したKICKを消去するかどうか。デフォルトで0。
# 本当に消すのではなく、"HIDDEN!HIDDEN@HIDDEN.BY.USER.VANISH"がKICKを実行した事にする。
drop-kick-by-target: 1
# Vanish対象を対象とするKICKを消去するかどうか。デフォルトで0。
drop-kick-for-target: 0
# Vanish対象が発行したTOPICを消去するかどうか。デフォルトで0。
# 本当に消すのでは無いが、他の設定と同じ。
drop-topic-by-target: 1
# チャンネルとVanish対象の定義。
# 特定のチャンネルでのみ対象とする、といった事が可能。
# また、privの場合は「#___priv___@ネットワーク名」という文字列をチャンネル名の代わりとしてマッチングを行なう。
# 書式: mask: <チャンネルのマスク> <ユーザーのマスク>
mask: #example@example example!exapmle@example.com
=cut
|