From: morimoto Date: Sun, 21 Mar 2004 11:03:51 +0000 (+0000) Subject: imported http://mrmt.net/src/keitairc/keitairc r1.11 X-Git-Tag: release_1_33~57 X-Git-Url: http://git.osdn.net/view?p=keitairc%2Fkeitairc.git;a=commitdiff_plain;h=10f97886ea59243bbe087496b40a68672251d380 imported mrmt.net/src/keitairc/keitairc r1.11 --- diff --git a/keitairc b/keitairc index 80b9c30..93314ef 100755 --- a/keitairc +++ b/keitairc @@ -1,6 +1,6 @@ #!/usr/bin/perl # keitairc -# $Id: keitairc,v 1.10 2004-03-21 11:03:38 morimoto Exp $ +# $Id: keitairc,v 1.11 2004-03-21 11:03:51 morimoto Exp $ # # Copyright (c) 2003 Jun Morimoto # This program is covered by the GNU General Public License 2 @@ -8,7 +8,7 @@ # Depends: libjcode-pm-perl, libpoe-component-irc-perl, # liburi-perl, libwww-perl, libappconfig-perl -my $rcsid = q$Id: keitairc,v 1.10 2004-03-21 11:03:38 morimoto Exp $; +my $rcsid = q$Id: keitairc,v 1.11 2004-03-21 11:03:51 morimoto Exp $; my ($version) = $rcsid =~ m#,v ([0-9.]+)#; use strict; @@ -55,6 +55,9 @@ my %mtime; # unread lines my %unread; +# chk +my ($send_chk, $update_chk); + # irc component POE::Component::IRC->new('keitairc'); POE::Session->new( @@ -130,22 +133,33 @@ sub on_irc_notice{ sub add_message{ my($channel, $who, $msg) = @_; + my $message = sprintf('%s %s> %s', &now, $who, $msg); + my @tmp = split("\n", $channel_buffer{$channel}); - push @tmp, sprintf('%s %s> %s', &now, $who, $msg); + push @tmp, $message; my @tmp2 = split("\n", $channel_recent{$channel}); - push @tmp2, sprintf('%s %s> %s', &now, $who, $msg); + push @tmp2, $message; if(@tmp > $config->web_lines){ - $channel_buffer{$channel} = join("\n", splice(@tmp, -$config->web_lines)); - $channel_recent{$channel} = join("\n", splice(@tmp2, -$config->web_lines)); + $channel_buffer{$channel} = + join("\n", splice(@tmp, -$config->web_lines)); }else{ $channel_buffer{$channel} = join("\n", @tmp); + } + + if(@tmp2 > $config->web_lines){ + $channel_recent{$channel} = + join("\n", splice(@tmp2, -$config->web_lines)); + }else{ $channel_recent{$channel} = join("\n", @tmp2); } $mtime{$channel} = time; - $unread{$channel}++; + + # unread lines + $unread{$channel} = @tmp2; + if ($unread{$channel} > $config->web_lines) { $unread{$channel} = $config->web_lines; } @@ -188,33 +202,34 @@ sub index_page{ $buf .= &label($accesskey); - if($accesskey < 10){ - $buf .= sprintf('%s', - $accesskey, - $docroot, - uri_escape($channel), - &compact_channel_name($channel)); - }else{ + if($accesskey < 10){ + $buf .= sprintf('%s', + $accesskey, + $docroot, + uri_escape($channel), + &compact_channel_name($channel)); + }else{ $buf .= sprintf('%s', - $docroot, - uri_escape($channel), - &compact_channel_name($channel)); - } + $docroot, + uri_escape($channel), + &compact_channel_name($channel)); + } $accesskey++; if($unread{$channel} > 0){ - $buf .= sprintf(' (%d)', + $buf .= sprintf(' (%d)', $docroot, uri_escape($channel), - $unread{$channel}); + $unread{$channel}); } - $buf .= '
'; } $buf .= qq(); - $buf .= qq( - keitairc $version +++); +# $buf .= qq( - keitairc $version +++); + $buf .= '
'; + $buf .= qq( - Ver.20040226a); $buf; } @@ -267,7 +282,6 @@ sub render{ ################################################################ sub on_web_request{ - local($_); my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0]; # Filter::HTTPD sometimes generates HTTP::Response objects. @@ -313,6 +327,8 @@ sub on_web_request{ &add_message($channel, $config->irc_nick, Jcode->new($message)->euc); + # set flag for "send message" + $send_chk = 1; } } @@ -324,7 +340,7 @@ sub on_web_request{ }else{ $uri =~ s|^/||; - my $update_chk = ($uri =~ /.*.update/); + $update_chk = ($uri =~ /.*.update/); if ($update_chk eq 1) { $uri =~ s/.update//; } @@ -351,7 +367,7 @@ sub on_web_request{ length($channel_buffer{$channel})){ $content .= qq(); $content .= ''; - if ($update_chk eq 1) { + if (($update_chk eq 1)||($send_chk eq 1)) { $content .= &render($channel_recent{$channel}); $content .= sprintf(' ..more(push 5)', "../", uri_escape($channel)); @@ -366,7 +382,13 @@ sub on_web_request{ $content .= "no such channel"; } + # clear check flags + $send_chk = 0; + + # clear unread counter $unread{$channel} = 0; + + # clear recent messages buffer $channel_recent{$channel} = ""; }