#! /usr/bin/perl $Cgi_Main = "./jinro.cgi"; $Mode_Name{'01'} = "村人"; $Mode_Name{'05'} = "霊界"; $Mode_Name{'11'} = "人狼"; $Mode_Name{'15'} = "魔界"; $Mode_Name{'40'} = "妖精"; $Mode_Name{'50'} = "天界"; ##################### require './jcode.pl'; $Login_Index = 0; @Msg_Line = (); @Char_Name = (); @Char_Icon = (); @Char_Vote = (); @Char_Life = (); @Exec_Attack = (-1, -1); @Exec_Fortune = (-1, -1); @Exec_Guard = (-1, -1); ##################### Main &SYSIN_TIME; &STDIN_QUERY_STRING; if( $Query_Tbl{'mode'} ){ if( ($Query_Tbl{ 'msg' } ne "") or ($Query_Tbl{ 'msg0' } ne "") or ($Query_Tbl{ 'msg1' } ne "") ){ print "Content-type: text/html\n\n"; print "入力できませんごめんなさい。入力系の機能はオフにしてあります。
"; }else{ print "Location: $Cgi_Main\n\n"; } }else{ &FILEIN_MSG; &STDOUT_HTML; } exit(0); ##################### sub FILEIN_MSG { if( open( LOGFILE, "<./msg.txt" ) ){ flock( LOGFILE, 1 ); $line = ; $line =~ s/\r//g; ($Vil_Name, $Vil_Img, $Vil_Css) = split( /<>/, $line); $Day_Count = $Query_Tbl{'day'}; $Day_Count_Max = -1; while($line = ){ $line =~ s/\r//g; ($Line_Day, $Line_Type, $Line_Char_Index, $Line_Time, @data) = split( /<>/, $line); if($Line_Type == 51){ $Char_Vote[$Line_Char_Index] = $data[0]; }elsif($Line_Type == 52){ $Exec_Attack[0] = $data[0]; $Exec_Attack[1] = $data[1]; }elsif($Line_Type == 53){ $Exec_Fortune[0] = $data[0]; $Exec_Fortune[1] = $data[1]; }elsif($Line_Type == 54){ $Exec_Guard[0] = $data[0]; $Exec_Guard[1] = $data[1]; }elsif($Line_Type == 81){ push(@Char_Name, $data[0]); push(@Char_Icon, $data[1]); push(@Char_Vote, -1); push(@Char_Life, 0); }elsif($Line_Type == 82 || $Line_Type == 83){ $Char_Life[$Line_Char_Index] = 1; } if($Day_Count_Max < $Line_Day){ $Day_Count_Max = $Line_Day; foreach $vote (@Char_Vote) { $vote = -1; } @Exec_Attack = (-1, -1); @Exec_Fortune = (-1, -1); @Exec_Guard = (-1, -1); } push(@Msg_Line, $line); } if($Day_Count == -1){ $Day_Count = $Day_Count_Max; } close( LOGFILE ); } } ##################### sub STDOUT_HTML { &STDOUT_HEADER; &STDOUT_DAY_LIST( "header" ); foreach $line (@Msg_Line){ ($Line_Day, $Line_Type) = split( /<>/, $line); if($Line_Day == $Day_Count){ if($Line_Type == 80){ &STDOUT_SYS( $line ); }elsif($Line_Type == 81){ &STDOUT_ENTRY( $line ); }elsif($Line_Type == 82){ &STDOUT_DEATH( $line ); }elsif($Line_Type == 83){ &STDOUT_KILL( $line ); }elsif($Line_Type == 51){ &STDOUT_VOTE( $line ); }elsif($Line_Type == 52){ &STDOUT_ATTACK( $line ); }elsif($Line_Type == 53){ &STDOUT_FORTUNE( $line ); }elsif($Line_Type == 54){ &STDOUT_GUARD( $line ); }else{ &STDOUT_MSG( $line ); } } } if($Day_Count == $Day_Count_Max){ &STDOUT_VOTE_FORM; &STDOUT_ATTACK_FORM; &STDOUT_FORTUNE_FORM; &STDOUT_GUARD_FORM; &STDOUT_MSG_FORM( "01" ); &STDOUT_MSG_FORM( "05" ); &STDOUT_MSG_FORM( "11" ); &STDOUT_MSG_FORM( "15" ); &STDOUT_MSG_FORM( "40" ); &STDOUT_MSG_FORM( "50" ); } &STDOUT_DAY_LIST( "footer" ); &STDOUT_FOOTER; } ##################### sub STDOUT_HEADER { print "Content-type: text/html\n\n"; print "人狼BBS - $Vil_Name\n"; print "\n"; print "\n"; print "
\n"; print "\"人狼BBS\"
\n"; } ##################### sub STDOUT_FOOTER { print "
\n"; print "\n"; } ##################### sub STDOUT_MSG { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time, $Msg_Text) = split( /<>/, @_[0] ); print "
\n"; print "\"$Char_Name[$Msg_Char_Index]\"
\n"; print "
$Char_Name[$Msg_Char_Index] $Mode_Name{$Msg_Type}メッセージ [$Msg_Time]
\n"; print "
$Msg_Text

\n"; print "
\n"; } ##################### sub STDOUT_VOTE { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time, $Exec_Target) = split( /<>/, @_[0] ); print "
\n"; print "\"$Char_Name[$Msg_Char_Index]\"
\n"; print "
$Char_Name[$Msg_Char_Index] $Mode_Name{'50'}メッセージ [$Msg_Time]
\n"; print "
$Char_Name[$Exec_Target]に投票します。

\n"; print "
\n"; } ##################### sub STDOUT_ATTACK { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time, $Exec_Target1, $Exec_Target2) = split( /<>/, @_[0] ); print "
\n"; print "\"$Char_Name[$Msg_Char_Index]\"
\n"; print "
$Char_Name[$Msg_Char_Index] $Mode_Name{'50'}メッセージ [$Msg_Time]
\n"; print "
$Char_Name[$Exec_Target1]を襲撃の第1候補、$Char_Name[$Exec_Target2]を襲撃の第2候補にします。

\n"; print "
\n"; } ##################### sub STDOUT_FORTUNE { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time, $Exec_Target1, $Exec_Target2) = split( /<>/, @_[0] ); print "
\n"; print "\"$Char_Name[$Msg_Char_Index]\"
\n"; print "
$Char_Name[$Msg_Char_Index] $Mode_Name{'50'}メッセージ [$Msg_Time]
\n"; print "
$Char_Name[$Exec_Target1]を占いの第1候補、$Char_Name[$Exec_Target2]を占いの第2候補にします。

\n"; print "
\n"; } ##################### sub STDOUT_GUARD { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time, $Exec_Target1, $Exec_Target2) = split( /<>/, @_[0] ); print "
\n"; print "\"$Char_Name[$Msg_Char_Index]\"
\n"; print "
$Char_Name[$Msg_Char_Index] $Mode_Name{'50'}メッセージ [$Msg_Time]
\n"; print "
$Char_Name[$Exec_Target1]を護衛の第1候補、$Char_Name[$Exec_Target2]を護衛の第2候補にします。

\n"; print "
\n"; } ##################### sub STDOUT_SYS { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time, $Msg_Text) = split( /<>/, @_[0] ); print "
\n"; print "
システムメッセージ [$Msg_Time]
\n"; print "
$Msg_Text

\n"; print "
\n"; } ##################### sub STDOUT_ENTRY { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time) = split( /<>/, @_[0] ); $Char_Number = $Msg_Char_Index + 1; print "
\n"; print "
システムメッセージ [$Msg_Time]
\n"; print "
$Char_Number番目の村人 $Char_Name[$Msg_Char_Index]

\n"; print "
\n"; } ##################### sub STDOUT_DEATH { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time) = split( /<>/, @_[0] ); print "
\n"; print "
システムメッセージ [$Msg_Time]
\n"; print "
$Char_Name[$Msg_Char_Index]は投票の結果、処刑されました。

\n"; print "
\n"; } ##################### sub STDOUT_KILL { ($Msg_Date, $Msg_Type, $Msg_Char_Index, $Msg_Time) = split( /<>/, @_[0] ); print "
\n"; print "
システムメッセージ [$Msg_Time]
\n"; print "
夜明け、$Char_Name[$Msg_Char_Index]は無残な姿で発見されました。

\n"; print "
\n"; } ##################### sub STDOUT_DAY_LIST { print "
\n"; print "
$Vil_Name
\n"; print "
    \n"; if($Day_Count == 0){ print "
  • プロローグ
  • "; }else{ print "
  • プロローグ
  • "; } for($index = 1; $index <= $Day_Count_Max; $index++){ if($index == $Day_Count){ print "
  • $index日目
  • "; }else{ print "
  • $index日目
  • "; } } print "

\n"; print "
\n"; } ##################### sub STDOUT_MSG_FORM { print "
\n"; print "\"$Char_Name[$Login_Index]\"
\n"; print "
$Char_Name[$Login_Index] $Mode_Name{@_[0]}メッセージ
\n"; print "
\n"; print "\n"; print "
\n"; print "\n"; print "

\n"; print "
\n"; } ##################### sub STDOUT_VOTE_FORM { print "
\n"; print "\"$Char_Name[$Login_Index]\"
\n"; print "
$Char_Name[$Login_Index] の投票
\n"; print "
\n"; print "\n"; if($Char_Vote[$Login_Index] > -1){ print "あなたは$Char_Name[$Char_Vote[$Login_Index]]に投票しようとしています。
\n"; &STDOUT_VOTE_SELECT; print "\n"; }else{ print "投票先を選んでください。選ばない場合、あなたの投票先はランダムに決定されます。
\n"; &STDOUT_VOTE_SELECT; print "\n"; } print "

\n"; print "
\n"; } ##################### sub STDOUT_VOTE_SELECT { print "\n"; } ##################### sub STDOUT_ATTACK_FORM { print "
\n"; print "\"$Char_Name[$Login_Index]\"
\n"; print "
人狼の襲撃
\n"; print "
\n"; print "\n"; if($Exec_Attack[0] > -1 && $Exec_Attack[1] > -1 ){ print "人狼は$Char_Name[$Exec_Attack[0]]を襲撃の第1候補に、$Char_Name[$Exec_Attack[1]]を襲撃の第2候補に選んでいます。
\n"; print "第1候補 "; &STDOUT_ATTACK_SELECT(0); print " 第2候補 "; &STDOUT_ATTACK_SELECT(1); print "\n"; }else{ print "襲撃先を選んでください。選ばない場合、貴方の襲撃先はランダムに決定されます。
\n"; print "第1候補 "; &STDOUT_ATTACK_SELECT(0); print " 第2候補 "; &STDOUT_ATTACK_SELECT(1); print "\n"; } print "

\n"; print "
\n"; } ##################### sub STDOUT_ATTACK_SELECT { print "\n"; } ##################### sub STDOUT_FORTUNE_FORM { print "
\n"; print "\"$Char_Name[$Login_Index]\"
\n"; print "
$Char_Name[$Login_Index] の占い
\n"; print "
\n"; print "\n"; if($Exec_Fortune[0] > -1 && $Exec_Fortune[1] > -1 ){ print "貴方は$Char_Name[$Exec_Fortune[0]]を占いの第1候補に、$Char_Name[$Exec_Fortune[1]]を占いの第2候補に選んでいます。
\n"; print "第1候補 "; &STDOUT_FORTUNE_SELECT(0); print " 第2候補 "; &STDOUT_FORTUNE_SELECT(1); print "\n"; }else{ print "占い先を選んでください。選ばない場合、貴方の占い先はランダムに決定されます。
\n"; print "第1候補 "; &STDOUT_FORTUNE_SELECT(0); print " 第2候補 "; &STDOUT_FORTUNE_SELECT(1); print "\n"; } print "

\n"; print "
\n"; } ##################### sub STDOUT_FORTUNE_SELECT { print "\n"; } ##################### sub STDOUT_GUARD_FORM { print "
\n"; print "\"$Char_Name[$Login_Index]\"
\n"; print "
$Char_Name[$Login_Index] の護衛
\n"; print "
\n"; print "\n"; if($Exec_Guard[0] > -1 && $Exec_Guard[1] > -1 ){ print "貴方は$Char_Name[$Exec_Guard[0]]を護衛の第1候補に、$Char_Name[$Exec_Guard[1]]を護衛の第2候補に選んでいます。
\n"; print "第1候補 "; &STDOUT_GUARD_SELECT(0); print " 第2候補 "; &STDOUT_GUARD_SELECT(1); print "\n"; }else{ print "護衛先を選んでください。選ばない場合、貴方の護衛先はランダムに決定されます。
\n"; print "第1候補 "; &STDOUT_GUARD_SELECT(0); print " 第2候補 "; &STDOUT_GUARD_SELECT(1); print "\n"; } print "

\n"; print "
\n"; } ##################### sub STDOUT_GUARD_SELECT { print "\n"; } ##################### sub FILEOUT_MSG { $temp = "$Day_Count_Max<>$Query_Tbl{'mode'}<>$Login_Index<>$Time_Stamp<>$Query_Tbl{'msg'}\n"; open( LOGFILE, ">>./msg.txt"); flock( LOGFILE, 2 ); print LOGFILE $temp; close( LOGFILE ); } ##################### sub FILEOUT_VOTE { $temp = "$Day_Count_Max<>$Query_Tbl{'mode'}<>$Login_Index<>$Time_Stamp<>$Query_Tbl{'msg'}\n"; open( LOGFILE, ">>./msg.txt"); flock( LOGFILE, 2 ); print LOGFILE $temp; close( LOGFILE ); } ##################### sub FILEOUT_ATTACK { $temp = "$Day_Count_Max<>$Query_Tbl{'mode'}<>$Login_Index<>$Time_Stamp<>$Query_Tbl{'msg0'}<>$Query_Tbl{'msg1'}\n"; open( LOGFILE, ">>./msg.txt"); flock( LOGFILE, 2 ); print LOGFILE $temp; close( LOGFILE ); } ##################### sub FILEOUT_FORTUNE { $temp = "$Day_Count_Max<>$Query_Tbl{'mode'}<>$Login_Index<>$Time_Stamp<>$Query_Tbl{'msg0'}<>$Query_Tbl{'msg1'}\n"; open( LOGFILE, ">>./msg.txt"); flock( LOGFILE, 2 ); print LOGFILE $temp; close( LOGFILE ); } ##################### sub FILEOUT_GUARD { $temp = "$Day_Count_Max<>$Query_Tbl{'mode'}<>$Login_Index<>$Time_Stamp<>$Query_Tbl{'msg0'}<>$Query_Tbl{'msg1'}\n"; open( LOGFILE, ">>./msg.txt"); flock( LOGFILE, 2 ); print LOGFILE $temp; close( LOGFILE ); } ##################### sub STDIN_QUERY_STRING { $Query_Tbl{'day'} = -1; $Query_Tbl{'mode'} = ""; $Query_Tbl{'msg'} = ""; $Query_Tbl{'msg0'} = ""; $Query_Tbl{'msg1'} = ""; if( $ENV{'REQUEST_METHOD'} eq "POST" ){ read( STDIN, $query, $ENV{'CONTENT_LENGTH'} ); }else{ $query = $ENV{'QUERY_STRING'}; } @pairs = split( /&/, $query ); foreach $pair (@pairs) { local($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/ge; &jcode'convert(*value,'euc'); $value =~ s/\r\n/\n/g; $value =~ s/\r|\n/\n/g; $value =~ s//>/g; $value =~ s/\"/"/g; $value =~ s/\n/
/g; $Query_Tbl{ $name } = $value; } } #################### sub SYSIN_TIME{ ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time); $Time_Stamp = sprintf("%02d:%02d", $hour, $min); }