File: Rehash.pm

package info (click to toggle)
tiarra 20100212-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,732 kB
  • ctags: 1,712
  • sloc: perl: 32,032; lisp: 193; sh: 109; makefile: 10
file content (131 lines) | stat: -rw-r--r-- 3,858 bytes parent folder | download | duplicates (4)
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
# -----------------------------------------------------------------------------
# $Id: Rehash.pm 11365 2008-05-10 14:58:28Z topia $
# -----------------------------------------------------------------------------
# copyright (C) 2004 Topia <topia@clovery.jp>. all rights reserved.
package Client::Rehash;
use strict;
use warnings;
use base qw(Module);
use Mask;
use Multicast;
use NumericReply;
use Timer;

my $timer_name = __PACKAGE__.'/timer';

sub new {
    my $class = shift;
    my $this = $class->SUPER::new(@_);
}

sub destruct {
    my ($this) = shift;

    # timer があれば解除
    foreach my $client (RunLoop->shared_loop->clients_list) {
	my $timer = $client->remark($timer_name);
	if (defined $timer) {
	    $client->remark($timer_name, undef, 'delete');
	    $timer->uninstall;
	}
    }
}

sub message_arrived {
    my ($this,$msg,$sender) = @_;

    # クライアントからのメッセージか?
    if ($sender->isa('IrcIO::Client')) {
	my $runloop = RunLoop->shared_loop;
	# 指定されたコマンドか?
	if (Mask::match_deep([$this->config->command_nick('all')], $msg->command)) {
	    if (!defined $msg->param(0)) {
	    } elsif ($msg->param(0) eq $runloop->current_nick) {
	    } else {
		$sender->send_message(
		    $this->construct_irc_message(
			Prefix => $msg->param(0).'!'.$sender->username.'@'.
			    $sender->client_host,
			Command => 'NICK',
			Param => $runloop->current_nick,
		       ));

	    }
	    # ここで消す。
	    return undef;
	} elsif (Mask::match_deep([$this->config->command_names('all')], $msg->command)) {
	    my @channels = map {
		my $network_name = $_->network_name;
		map {
		    [$network_name, $_->name];
		} $_->channels_list;
	    } $runloop->networks_list;
	    $sender->remark($timer_name, Timer->new(
	       Interval => (defined $this->config->interval ?
				$this->config->interval : 2),
	       Repeat => 1,
	       Code => sub {
		   my $timer = shift;
		   my $runloop = RunLoop->shared_loop;
		   while (1) {
		       my $entry = shift(@channels);
		       if (defined $entry && $sender->connected) {
			   my ($network_name, $ch_name) = @$entry;
			   my $network = $runloop->network($network_name);
			   my $flush_namreply = sub {
			       my $msg = shift;
			       $msg->param(0, $runloop->current_nick);
			       $sender->send_message($msg);
			   };
			   if (!defined $network) {
			       # network disconnected. ignore
			       next;
			   }
			   my $ch = $network->channel($ch_name);
			   if (!defined $ch) {
			       # parted channel; ignore
			       next;
			   }
			   $sender->do_namreply($ch, $network,
						undef, $flush_namreply);
		       } else {
			   $sender->remark($timer_name, undef, 'delete');
			   $timer->uninstall;
		       }
		       last;
		   }
	       },
	      )->install);

	    # ここで消す。
	    return undef;
	}
    }

    return $msg;
}

1;
=pod
info: 全チャンネル分の names の内部キャッシュをクライアントに送信する。
default: off

# もともとはクライアントの再初期化目的に作ったのですが、 names を送信しても
# 更新されないクライアントが多いので、主に multi-server-mode な Tiarra の
# 下にさらに Tiarra をつないでいる人向けにします。

# names でニックリストを更新してくれるクライアント:
#   Tiarra
# してくれないクライアント: (括弧内は確認したバージョンまたは注釈)
#   LimeChat(1.18)

# nick rehash に使うコマンドを指定します。
# 第二パラメータとして現在クライアントが認識している nick を指定してください。
command-nick: rehash-nick

# names rehash に使うコマンドを指定します。
command-names: rehash-names

# チャンネルとチャンネルの間のウェイトを指定します。
interval: 2
=cut