#! /usr/local/bin/perl # #ゆいちゃっとMini(チャット仕様)β版 #過去ログ保存のためコマンド修正版 require './jcodeLE.pl'; $| = 1; &init; &decode; &jikan; &write if ($chat); &sanka; &html; &ended; exit; sub init{ #初期設定など $sanka_file = './sanka_log'; #参加記録ファイル $chat_file = './chat_log'; #チャットログ(ファイル名はなるべく変更しておくこと。) $cgidir = 'http://www.big.or.jp/~vampire/Mini2';#最後の/をつけない..こと。 $method = 'GET';#やっぱり、GETよねぇ〜 #退室後のページは、他のHPにも変えられます。 $endpage= "$cgidir/chat.cgi?window=50"; $title = 'ゆいちゃっとMini(チャット仕様)'; $body=''; $max = 50;#ログの最大行数(過去ログを残すためには200〜500がよいかも。) $host = $ENV{'REMOTE_HOST'};if($host=~/bmc/){$host="ppp753.master.ad.jp";} ####荒らし対策用アクセス制限を使用するなら、#を消す。 #$kill_file = './killfile';#アクセス制限用 #open(DB,"$kill_file") || die "Cannot Open Log File $kill_file: $!"; # @lines2 = ; close(DB); #foreach $line (@lines2) { # next if(length($line)<4); chop $line; # if( $host=~/$line/ ){ print "Status: 404\n\n"; exit; } #} ####アクセス制限ここまで }#init END sub ended{ #unlinkとexitを行うためだけのもの。 # unlink($lock_file);#ロックファイルを使用するなら、#を消す。 exit; }#ended END sub html { $link = "./chat.cgi?window=$window&reload=$reload&mode=$mode&name=$name"; print "Content-type: text/html\n\n"; print "$title\n"; print "\n" if($reload); &hide; print <<"_HTML_"; $body
$title _HTML_ if($name){ print "おなまえ:$name名前変更
\n" ; }else{ print "おなまえ:
\n" ; } print <<"_HTML_"; $hiddenログ行数:$logw $kao リロード:$autow 秒
発言:
_HTML_ $num = @sanka3;#参加者表示 print "参加者($num):"; print "@sanka3
\n"; #ログ表示 &readlog if(!@lines); (@lines < $window) || (@lines = @lines[0 .. $window - 1]); print "@lines\n"; print "
ゆいちゃっと Mini(Free)
\n";#この行だけは消さないでっ!! }#html END sub write { return unless( ($ENV{'HTTP_REFERER'} eq '') || ($ENV{'HTTP_REFERER'} =~/$cgidir/)); &tag if ($chat=~s/\t/= 0 ){ $line = '' ; $c++; last if($c > $cmax); } } $chat = '♪〜'; } if ($chat eq '退室') { $value = "管理人 > $nameさん、またきておくれやすぅ。($date $host)
\n"; &writelog; print "Location: $endpage\n\n"; &ended; }else { $value = "$name > $chat $emoji($date $host)
\n"; } &writelog; }#write END sub tag{ #このタグ閉じは、正しく閉じてある場合も余分に閉じます。(苦笑) $chat =~ s/
]*)>(.*)/$1/;
		$tag =~s/^\/(.*)//;
		$tag =~s/^([^\s]*).*/$1/;
	} 
	$chat.='>' if($chat=~/<\/$/);	
	@tags = reverse( @tags );
	foreach $tag ( @tags ){
		next if($tag =~/(img|^hr$|^br$)/i);
		$chat.="" if($tag);
	}
	$chat.='">タグえらー?' if( ($chat=~/.*<\/A>/i) );
	$chat =~ s/;
close(LOG);
$flag=1;
foreach $line (@sanka) {
	($timerec, $handle, $host2,$dmy) = split(/\t/, $line);
	if( $times-60 > $timerec){$line = '';	next;}
		if(($host2 eq $host) && $flag){#ホスト名が同一の場合、時間と名前を最新のものにする。
			$line = "$times\t$name\t$host\td\n";
			$flag =0;$handle = $name;	$handle =~ s/☆/★/g;
		}
	push (@sanka3, "$handle☆") if($handle ne $host2); 
	}#foreach

	if($flag){	#新しい参加者は、加える
		$name =~ s/☆/★/g;
		push(@sanka,"$times\t$name\t$host\td\n");
		push (@sanka3, "$name☆") if($name ne $host); 
	}

undef(@sanka) if($chat eq 'sanka');
open(LOG,">$sanka_file")  || &ended;
	eval 'flock(LOG,2);';
	seek(LOG,0,0);	print LOG @sanka;
	eval 'flock(LOG,8);';
close(LOG);
}#sanka END

sub readlog{	#配列@linesにログを読み込む
	open(DB,"$chat_file") || &ended;
		seek(DB,0,0);  @lines = ;   close(DB);
}#readlog END

sub writelog{	#$valueを@linesに加えたのち、書き込む
	(@lines < $max-1) || (@lines = @lines[0 .. $max - 2]);
	unshift( @lines,$value);
	open(DB,">$chat_file") || &ended;
		eval 'flock(DB,2);';
		seek(DB,0,0);	print DB @lines;
		eval 'flock(DB,8);';
	close(DB);
}#writelog END
sub hide{	#HTML生成時に共有される部分を一つにまとめる。
$logw =<<"_HIDE_";

_HIDE_
$autow =<<"_HIDE_";

_HIDE_
$kao =<<"_HIDE_";
今のきもち:
_HIDE_
#顔文字は、最初の6個は残してね。
}#hide END
__END__