diff -urN tiarra-20040508/ChangeLog tiarra-20040509/ChangeLog --- tiarra-20040508/ChangeLog 2004-05-08 17:15:56.000000000 +0900 +++ tiarra-20040509/ChangeLog 2004-05-09 13:09:49.000000000 +0900 @@ -1,3 +1,19 @@ +2004-05-09 Topia + + * main/Multicast.pm: + (nick_p): + - 省略可能な nicklen を引数に追加した。 + (channel_p): + - 省略可能な chantypes を引数に追加した。 + + * main/IrcIO/Server.pm: + - isupport を remark からインスタンス変数に変更した。 + (nick_p, channel_p): + - 追加した。 ISUPPORT として NICKLEN, CHANTYPES が指定されていた + 場合にそれを使って検査する。 + (_set_to_next_nick): + - 簡略化した。 + 2004-05-08 Topia * HACKING: @@ -1623,7 +1639,7 @@ * これ以前のログは書いていません。 -# Id: $Id: ChangeLog,v 1.147 2004/05/08 08:11:30 topia Exp $ +# Id: $Id: ChangeLog,v 1.148 2004/05/09 04:08:00 topia Exp $ # Author: $Author: topia $ -# Date: $Date: 2004/05/08 08:11:30 $ -# Revision: $Revision: 1.147 $ +# Date: $Date: 2004/05/09 04:08:00 $ +# Revision: $Revision: 1.148 $ diff -urN tiarra-20040508/main/IrcIO/Server.pm tiarra-20040509/main/IrcIO/Server.pm --- tiarra-20040508/main/IrcIO/Server.pm 2004-05-08 17:15:57.000000000 +0900 +++ tiarra-20040509/main/IrcIO/Server.pm 2004-05-09 13:09:49.000000000 +0900 @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# $Id: Server.pm,v 1.56 2004/05/08 08:11:31 topia Exp $ +# $Id: Server.pm,v 1.57 2004/05/09 04:08:00 topia Exp $ # ----------------------------------------------------------------------------- # IrcIO::ServerはIRCサーバーに接続し、IRCメッセージをやり取りするクラスです。 # このクラスはサーバーからメッセージを受け取ってチャンネル情報や現在のnickなどを保持しますが、 @@ -37,6 +37,7 @@ $obj->{channels} = {}; # 小文字チャンネル名 => ChannelInfo $obj->{people} = {}; # nick => PersonalInfo + $obj->{isupport} = {}; # isupport $obj->connect; } @@ -53,6 +54,22 @@ shift->{server_hostname}; } +sub isupport { + shift->{isupport}; +} + +sub nick_p { + my ($this, $nick) = @_; + + Multicast::nick_p($nick, $this->isupport->{NICKLEN}); +} + +sub channel_p { + my ($this, $name) = @_; + + Multicast::channel_p($name, $this->isupport->{CHANTYPES}); +} + sub channels { # {小文字チャンネル名 => ChannelInfo}のハッシュリファを返す。 # @options(省略可能): @@ -1016,22 +1033,20 @@ my ($this,$msg) = @_; if ($msg->n_params >= 2 && # nick + [params] + 'are supported by this server' $msg->param($msg->n_params - 1) =~ /supported/i) { - my $isupport = $this->remark('isupport'); foreach my $param ((@{$msg->params})[1...($msg->n_params - 2)]) { my ($negate, $key, $value) = $param =~ /^(-)?([[:alnum:]]+)(?:=(.+))?$/; if (!defined $negate) { # empty value $value = '' unless defined $value; - $isupport->{$key} = $value; + $this->{isupport}->{$key} = $value; } elsif (!defined $value) { # negate a previously specified parameter - delete $isupport->{$key}; + delete $this->{isupport}->{$key}; } else { # inconsistency param carp("inconsistency RPL_ISUPPORT param: $param"); } } - $this->remark('isupport', $isupport); } } @@ -1044,15 +1059,7 @@ sub _set_to_next_nick { my ($this,$failed_nick) = @_; # failed_nickの次のnickを試します。nick重複でログインに失敗した時に使います。 - my $nicklen = do { - if (defined $this->remark('isupport') && - defined $this->remark('isupport')->{NICKLEN}) { - $this->remark('isupport')->{NICKLEN}; - } else { - 9; - } - }; - my $next_nick = modify_nick($failed_nick, $nicklen); + my $next_nick = modify_nick($failed_nick, $this->isupport->{NICKLEN}); my $msg_for_user = "Nick $failed_nick was already in use in the ".$this->network_name.". Trying ".$next_nick."..."; $this->send_message( diff -urN tiarra-20040508/main/Multicast.pm tiarra-20040509/main/Multicast.pm --- tiarra-20040508/main/Multicast.pm 2004-05-08 17:15:57.000000000 +0900 +++ tiarra-20040509/main/Multicast.pm 2004-05-09 13:09:49.000000000 +0900 @@ -1,5 +1,5 @@ # ----------------------------------------------------------------------------- -# $Id: Multicast.pm,v 1.25 2004/05/08 08:11:31 topia Exp $ +# $Id: Multicast.pm,v 1.26 2004/05/09 04:08:00 topia Exp $ # ----------------------------------------------------------------------------- # サーバーからクライアントにメッセージが流れるとき、このクラスはフィルタとして # ネットワーク名を付加します。 @@ -639,7 +639,9 @@ sub nick_p { # 文字列がnickとして許される形式であるかどうかを真偽値で返す。 my $str = detach(shift); - return undef unless length($str); + my $nicklen = shift; + return undef unless length($str) && + (!defined $nicklen || (length($str) <= $nicklen)); my $first_char = '[a-zA-Z_\[\]\\\`\^\{\}\|]'; my $remaining_char = '[0-9a-zA-Z_\-\[\]\\\`\^\{\}\|]'; @@ -650,8 +652,9 @@ # 文字列がchannelとして許される形式であるかどうかを真偽値で返す。 my $str = detach(shift); return undef unless length($str); + my $chantypes = shift || '#&+!'; - my $first_char = '[\#\&\+\!]'; + my $first_char = "[\Q$chantypes\E]"; my $suffix_spec = '(?::[a-z*.]+)?'; return $str =~ /^${first_char}.*${suffix_spec}$/ }