1# -----------------------------------------------------------------------------
2# $Id: Client.pm 11365 2008-05-10 14:58:28Z topia $
3# -----------------------------------------------------------------------------
4package User::Away::Client;
5use strict;
6use warnings;
7use base qw(Module);
8use RunLoop;
9
10sub client_attached {
11    my ($this,$client) = @_;
12    # クライアントが接続されたという事は、
13    # 少なくとも一つ以上のクライアントが存在するに決まっている。
14    RunLoop->shared->broadcast_to_servers(
15	$this->construct_irc_message(
16	    Command => 'AWAY'));
17}
18
19sub client_detached {
20    my ($this,$client) = @_;
21    # クライアントの数が1(このメソッドから戻った後に0になる)ならAWAYを実行。
22    if (@{RunLoop->shared->clients} == 1 &&
23	defined $this->config->away) {
24
25	RunLoop->shared->broadcast_to_servers(
26	    $this->construct_irc_message(
27		Command => 'AWAY',
28		Param => $this->config->away));
29    }
30}
31
32sub connected_to_server {
33    my ($this,$server,$new_connection) = @_;
34    # クライアントの数が0ならAWAYを実行。
35    if (@{RunLoop->shared->clients} == 0 &&
36	defined $this->config->away) {
37
38	$server->send_message(
39	    $this->construct_irc_message(
40		Command => 'AWAY',
41		Param => $this->config->away));
42    }
43}
44
451;
46
47=pod
48info: クライアントが一つも接続されていない時にAWAYを設定します。
49default: off
50section: important
51
52# どのようなAWAYメッセージを設定するか。省略された場合はAWAYを設定しません。
53-away: 居ない。
54=cut
55