#!/usr/bin/perl
require '/home/rexi-jp/public_html/jj/lib/lib.pl';
require '/home/rexi-jp/public_html/jj/lib/scenario.pl';
require '/home/rexi-jp/public_html/jj/lib/mobile.pl';
$mycgi = 'replay.cgi';
$mid = $uid;
$uid = '';
use CGI;
use CGI::Carp qw(fatalsToBrowser);
$ip = $ENV{'REMOTE_ADDR'};
$host = gethostbyaddr(pack("C4", split(/\./, $ip)), 2);
$host ||= $ENV{'REMOTE_HOST'};
$host ||= $ip;
$referer=$ENV{'HTTP_REFERER'};
$script=$ENV{'SCRIPT_NAME'};
$uid = &get_usr_cookie;
$pcid = &get_pcid_cookie;
$query = CGI->new;
my @params = $query->param();#全てのパラメータ名を取得 なのでこれを$inにしてしまえば$inで使用可能
foreach my $param (@params) {
$in{$param} = $query->param($param);
}
$dbh = &connectDB($mainDB);
#PC情報取得
$sql = "select name1,name3,attribute,class,sex,birth from character where pcid = '$pcid';";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
($out{'name1'},$name3,$attribute,$pcclass,$pcsex,$pcbirth)=@{$ref->[0]};
$pcicon = &def_icon($pcclass,$attribute);
if ($in{'mode'} eq ''){
⊤
}
elsif ($in{'mode'} eq 'bbs_say'){
&bbs_say;
}
elsif ($in{'mode'} eq 'res_del'){
&res_del;
}
else{
&err("不正なパラメータ");
}
&disconDB($dbh);
exit;
#---------------------------------------
# HTML出力
#---------------------------------------
sub html_out {
$file = $_[0];
open FILE,$file;
print $header;
while(){
s/!(\w+)!/$out{$1}/g;
print;
}
close FILE;
exit;
}
#---------------------------------------
# TOP表示
#---------------------------------------
sub top {
&date_rtn;
if ($in{'seq'} eq ''){&err("不正なパラメータ");}
$sql = "select a.type,a.title,a.text,a.comment,op_illust,a.difficulty,a.source,a.attribute1,a.attribute2,a.reserve_close,a.playing_close,a.member_max,b.name,a.replay,a.replay_open_date + '7 days',a.option1,a.npc from scenario a,master b where a.seq = $in{'seq'} and a.state = 0 and a.msid = b.id and a.replay_open_date is not null and a.replay_open_date <= now() and a.scenario_state = 3;";
$ref = $dbh->selectall_arrayref($sql) or &opening_err("エラーが発生しました。");
($type,$out{'title'},$out{'text'},$out{'ms_comment'},$out{'op_illust'},$difficulty,$source,$attribute1,$attribute2,$reserve_close,$playing_close,$out{'member_max'},$out{'msname'},$out{'replay_str'},$replay_open_date,$option1,$npc)=@{$ref->[0]};
if ($out{'title'} eq ''){&err("該当シナリオが見つかりませんでした。");}
$out{'type'} = @sc_type_icon[$type];
$out{'source'} = @source_list[$source];
$out{'difficulty'} = @dif[$difficulty];
@npc_list = split(/\,/,$npc);
foreach(@npc_list){
$npc_id = $_;
$npc_mypage = "$npc_id";
$out{'replay_str'} =~ s/$npc_id/$npc_mypage/g;
}
if ($type eq 3){
$out{'a_atb'} = '―';
$out{'b_atb'} = 'spacer.gif';
$out{'member_max'} = '―';
}
else{
if ($attribute1 eq 100){$t = 1;}
elsif ($attribute1 eq 70){$t = 2;}
elsif ($attribute1 eq 50){$t = 3;}
elsif ($attribute1 eq 30){$t = 4;}
elsif ($attribute1 eq 0){$t = 5;}
$out{'a_atb'} = @atb_str[$t];
$out{'b_atb'} = @atb_icon[$t];
}
$out{'text'} =~ s/\n/
/g;
$out{'ms_comment'} =~ s/\n/
/g;
@rep_dat = split(/\n/,$out{'replay_str'});
$out{'replay_str'} =~ s/\n/
/g;
&date_rtn;
$replay_open_date =~ s/\-//g;
$replay_open_date = substr($replay_open_date,0,8);
$playing_flg = 0;
if ($replay_open_date >= "$g_year$g_mon$g_mday"){$playing_flg = 1;}
#参加者一覧
$out{'mem_num'} = 0;
@member_pcid = ();
$sql = "select b.pcid,b.name1,b.name3,b.sex,b.birth,b.attribute from scenario_member a,character b where a.scenario_seq = $in{'seq'} and a.entry_state = 1 and a.pcid = b.pcid order by a.pcid;";
$ref = $dbh->selectall_arrayref($sql) or &opening_err("エラーが発生しました。");
foreach(@$ref) {
($m_pcid,$m_name1,$m_name2,$m_sex,$m_birth,$m_attribute)=@{$_};
push member_pcid,$m_pcid;
$m_age = &calcAge($m_birth);
if ($m_sex eq 1){$m_sex = '♂';}
elsif ($m_sex eq 2){$m_sex = '♀';}
if ($m_attribute eq 1){$m_attribute = '善';}
elsif ($m_attribute eq 2){$m_attribute = '悪';}
if ($option1 ne 2 && $type ne 3 && $type ne 5){
$pfile = "/home/rexi-jp/public_html/jj/scenario/playing/$in{'seq'}/$m_pcid.dat";
$playing = "";
if (-e $pfile){
open FILE,$pfile;
while(){
$playing .= $_;
}
close FILE;
$playing =~ s/\x0D\x0A|\x0D|\x0A/
/g;
}
}
$out{'member'} .=<<"EOT";
($m_pcid)$m_name1($m_name2)・$m_attribute・$m_sex・$m_age
EOT
if ($playing_flg eq 1 && $type ne 5 && $type ne 3 && $option1 ne 2){
$out{'member'} .=<<"EOT";
$playing
EOT
}
$out{'mem_num'}++;
if ($pcid eq $m_pcid){
$out{'btn'} =<<"EOT";
EOT
}
}
$i = 0;
$sql = "select a.pcid,a.file,a.url,b.name1,b.name3,c.crname,a.replay_row,a.left_right from scenario_pinup a,character b,stars_data c where a.scenario_seq = $in{'seq'} and a.pcid = b.pcid and a.file = c.file_name order by a.reg_date desc;";
$ref = $dbh->selectall_arrayref($sql) or &err("エラーが発生しました。");
%rep_pin = ();
%rep_pin_lr = ();
%rep_pin_pcid = ();
foreach(@$ref) {
($p_pcid,$file,$url,$p_name1,$p_name2,$crname,$replay_row,$left_right)=@{$_};
$rep_pin{$replay_row} = $file;
$rep_pin_lr{$replay_row} = $left_right;
$rep_pin_pcid{$replay_row} = $p_pcid;
}
$out{'pin'} = '';
$r = 1;
$out{'replay_str'} = '';
foreach(@rep_dat){
$r_tmp = $_;
foreach(@member_pcid){
$mem_pcid = $_;
$mem_pcid2 = "(" . $mem_pcid . ')';
$r_tmp =~ s/($mem_pcid)/$mem_pcid2/g;
}
if ($rep_pin{$r} ne ''){
if ($rep_pin_pcid{$r} eq $pcid){
$delbtn =<<"EOT";
EOT
}
else{$delbtn = '';}
if ($rep_pin_lr{$r} eq 1){
# $img_d = $_;
$rep_p = &rep_pin_size($rep_pin{$r});
$out{'replay_str'} .=<<"EOT";
$r_tmp
EOT
}
elsif ($rep_pin_lr{$r} eq 2){
$rep_p = &rep_pin_size($rep_pin{$r});
$out{'replay_str'} .=<<"EOT";
$r_tmp
EOT
}
else{$out{'replay_str'} .= $r_tmp . '
';}
}
else{$out{'replay_str'} .= $r_tmp . '
';}
$r++;
}
if ($rep_pin{0} ne 0){
$rep_p = &rep_pin_size($rep_pin{0});
if ($rep_pin_lr{0} eq 1){$out{'replay_str'} .= "" . '
';}
elsif ($rep_pin_lr{0} eq 2){$out{'replay_str'} .= "" . '
';}
}
if ($mid eq ''){$html_file = 'replay01.html';}
else{$html_file = 'replay01_m.html';}
&out_enc;
&html_out($html_file);
}
#---------------------------------------
# ピンナップサイズ調整
#---------------------------------------
sub rep_pin_size {
my $rep_p_file = $_[0];
$p_file1 = "/home/rexi-jp/public_html/stars/data/jj/" . $rep_p_file;
$p_file2 = "/home/rexi-jp/public_html/jj/scenario/rep_pin_sum/" . $rep_p_file;
$rtn_file = "http://rexi.jp/stars/data/jj/$rep_p_file";
($format,$width,$height) = &GetImageSize($p_file1);
if ($width > 450){
if (!-e $p_file2){
system "convert -resize 450 +profile iptc -quality 100% $p_file1 $p_file2";
}
$rtn_file = "http://rexi.jp/jj/scenario/rep_pin_sum/$rep_p_file";
}
return $rtn_file;
}