#!/usr/local/bin/perl
#====================================================================================================
# コメント部
#====================================================================================================
#==================================================
# 変更履歴(20060203以降)
# 200602032115 関係項目ハイライト
# 200602032225 文字列外部読み込み
# 200602032310 総プレイヤー数表示、チーム成績中チーム表示部を右寄せ
# 200602032320 POST情報取得処理変更、プレイヤー名末尾空白除去
# 200602040000 注目プレイヤー用文字列投稿ルーチン
# 200602040010 ハイライト部分微調整
# 200602041130 特殊文字処理変更、最終更新日表示
# 200602041400 登録文字列集へのリンク追加
# 200602041605 リザルト保存
# 200602041740 保存バグ修正
# 200602041830 resultstat.cgi へのリンク追加
# 200602050100 不完全なリザルト入力への対処
# 200602051445 リザルト保存順のバグ修正
# 200602051800 全面的ルーチン整理、エラー制御強化、一部表示方法の変更
# 200602061350 ちょっとしたfix
# 200602231210 個人戦バージョンへのリンク
# 200602232300 テスト
# 200603072200 ファイルロック処理を厳密にした
# 200603141300 リザルト保存時等のルーチンを主に判別効率面から見直し
#==================================================
#====================================================================================================
# メイン
#====================================================================================================
#==================================================
# 初期設定
#==================================================
use Fcntl qw(:DEFAULT :flock);
use POSIX;
use strict;
use vars qw (%FORM @playerinfo @playerinfosort @chumokusiru @blue @red $lastupdate $debug);
$lastupdate = '0603141300';
$debug = 0;
#==================================================
# POST情報取得,整形,汚染除去(null)
#==================================================
{
my ($name, $value, $buffer);
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
foreach (split /&/,$buffer) {
($name, $value) = split /=/;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('H2',$1)/eg;
# $value =~ s/&/&/g;
$value =~ s/</g;
$value =~ s/>/>/g;
$value =~ s/"/"/g;
$value =~ tr/ / /s;
DispError('エラー:不正な入力です') if ($value =~ /\x00/);
$FORM{$name} = $value;
}
}
#==================================================
# 不正排除(必要に応じて)
#==================================================
&DispError('エラー') if ($debug == 99);
#==================================================
# 機能分岐、メイン終了処理
#==================================================
{
$FORM{'result'} = "Blue 1284 - Red 0\n\nPLAYER HITS SHOTS KILLS DIED SUIC FLAGS/TRIES/SAVES \nGP-VIP坂下 [red]0 (0%) 50 0 1110 251 0/14/0 \nFamicomUchujin2 (DJ) [blue]640 (800%) 80 859 0 0 85/85/14 " if($debug == 1);
if($FORM{'result'}){
&showresult;
}elsif($FORM{'word0'} || $FORM{'word1'} || $FORM{'word2'}){
&addwords;
}else{
&showmain;
}
exit;
}
#====================================================================================================
# 一次サブルーチン
#====================================================================================================
#==================================================
# リザルト表示ルーチン
#==================================================
sub showresult{
my $playernum = 0;
my @listresult = split(/\n/, $FORM{'result'});
# リザルト情報解析、チーム成績取得
# @{$playerinfo[x]}: 0:NAME 1:TEAM 2:HITS 3:HITR 4:SHOT 5:KILL 6:DIE 7:SUIC 8:FLAG 9:TRY 10:SAVE
$red[11] = 0;
$blue[11] = 0;
foreach my $line (@listresult) {
if(reverse($line) =~ /^([^]]+)\]([bdelru]+)\[(.+)$/){
my $score = reverse($1);
$playerinfo[$playernum][1] = reverse($2);
$playerinfo[$playernum][0] = reverse($3);
$playerinfo[$playernum][0] =~ s/\s*$//g;
if($score =~ /^\s*(\d+)\s+\((\d+)\%\)\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\/(\d+)\/(\d+)\s*$/){
@{$playerinfo[$playernum]}[2..10] = ($1, $2, $3, $4, $5, $6, $7, $8, $9);
if($playerinfo[$playernum][1] eq 'red'){
$red[2] += $playerinfo[$playernum][2];
$red[4] += $playerinfo[$playernum][4];
$red[5] += $playerinfo[$playernum][5];
$red[6] += $playerinfo[$playernum][6];
$red[7] += $playerinfo[$playernum][7];
$red[8] += $playerinfo[$playernum][8];
$red[9] += $playerinfo[$playernum][9];
$red[10] += $playerinfo[$playernum][10];
$red[11]++;
}else{
$blue[2] += $playerinfo[$playernum][2];
$blue[4] += $playerinfo[$playernum][4];
$blue[5] += $playerinfo[$playernum][5];
$blue[6] += $playerinfo[$playernum][6];
$blue[7] += $playerinfo[$playernum][7];
$blue[8] += $playerinfo[$playernum][8];
$blue[9] += $playerinfo[$playernum][9];
$blue[10] += $playerinfo[$playernum][10];
$blue[11]++;
}
}else{
&DispError("リザルト入力エラー(score):$score");
}
#注目すべき値を適当に設定
$chumokusiru[0] += $playerinfo[$playernum][3];
$chumokusiru[1] += $playerinfo[$playernum][2];
$chumokusiru[2] += $playerinfo[$playernum][4];
$chumokusiru[3] += $playerinfo[$playernum][6];
$playernum++;
}elsif($line =~ /^Blue (\d+) - Red (\d+)/){
$blue[1] = $1;
$red[1] = $2;
}elsif(($line !~ /^\s*$/) && ($line !~ /^PLAYER\s*HITS\s*SHOTS\s*KILLS\s*DIED\s*SUIC\s*FLAGS\/TRIES\/SAVES\s*$/)){
&DispError("リザルト入力エラー:$line");
}
}
# リザルト情報エラー
&DispError('リザルト入力エラー:プレイヤーが一人もいません') if(!$playerinfo[0][0]);
&DispError('リザルト入力エラー:チーム点数が取得できません') if(($blue[1] !~ /^\d+$/) || ($red[1] !~ /^\d+$/));
# リザルト情報保存
if(($blue[1] != 1284) || ($playernum != 2)){
&saveresult;
}
# ページ前半HTML
&print01;
&print05;
# チーム成績HTML
&teamanlys;
# 各項目別成績HTML
@playerinfosort = @playerinfo;
&writetable('Result');
@playerinfosort = sort { $b->[2] <=> $a->[2] } @playerinfo;
&writetable('Hits');
@playerinfosort = sort { $b->[4] <=> $a->[4] } @playerinfo;
&writetable('Shots');
# HIT数偏差取得
@playerinfosort = sort { $b->[2] <=> $a->[2] } @playerinfo;
my $shotsthr = &shotstouke;
# HIT数一定数以下の切り捨て
for ($playernum = 0; $playernum <= $#playerinfosort; $playernum++){
last if($playerinfosort[$playernum][2] < $shotsthr);
}
splice(@playerinfosort, $playernum);
@playerinfosort = sort { $b->[3] <=> $a->[3] } @playerinfosort;
&writetable("Hit/Shot (%) (ex. [$shotsthr > hit])");
@playerinfosort = sort { $b->[5] <=> $a->[5] } @playerinfo;
&writetable('Kills');
@playerinfosort = sort { $b->[6] <=> $a->[6] } @playerinfo;
&writetable('Died');
@playerinfosort = sort { $b->[8] <=> $a->[8] } @playerinfo;
&writetable('Flags');
@playerinfosort = sort { $b->[9] <=> $a->[9] } @playerinfo;
&writetable('Tries');
@playerinfosort = sort { $b->[10] <=> $a->[10] } @playerinfo;
&writetable('Saves');
# 注目プレイヤー
&chumoku;
# フッタ等HTML
&print09;
}
#==================================================
# 注目プレイヤー用文字列登録ルーチン
#==================================================
sub addwords{
my $addlist;
$FORM{'word0'} =~ tr/\n\r/ /s;
$FORM{'word1'} =~ tr/\n\r/ /s;
$FORM{'word2'} =~ tr/\n\r/ /s;
$FORM{'word0'} =~ s/[\s ]+$//;
$FORM{'word1'} =~ s/[\s ]+$//;
$FORM{'word2'} =~ s/[\s ]+$//;
if($FORM{'word0'} ne ''){$addlist = "0,$FORM{'word0'}\n";}
if($FORM{'word1'} ne ''){$addlist .= "1,$FORM{'word1'}\n";}
if($FORM{'word2'} ne ''){$addlist .= "2,$FORM{'word2'}\n";}
&DispError('文字列投稿エラー:空白文字列です') if($addlist eq '');
open(OUT,'>>wordslist.txt');
flock OUT, LOCK_EX;
binmode OUT;
print OUT $addlist;
close(OUT);
&print01;
print <
以下の文字列を登録しました
$addlist
戻る
EOM
# フッタ等HTML
&print09;
}
#==================================================
# デフォルト画面表示ルーチン
#==================================================
sub showmain{
&print01;
&print05;
&print09;
}
#====================================================================================================
# 二次サブルーチン
#====================================================================================================
#==================================================
# ヘッダ部分等HTML表示ルーチン
#==================================================
sub print01{
print <
FaMiCoM tAnKmAnIa rEsUlT Team
FaMiCoM tAnKmAnIa rEsUlT Team
統計バージョンはこちら
個人戦バージョンはこちら
EOM
}
#==================================================
# リザルト入力部分HTML表示ルーチン
#==================================================
sub print05{
print <
リザルトが表示されたら、一番最初(点数の部分)から最後までコピーして、ここに貼付け下のボタンを押してください。
EOM
}
#==================================================
# 作成者情報等(ページ終了部)HTML表示ルーチン
#==================================================
sub print09{
print <
lastupdate: $lastupdate
ソースコード