hakoniwa2/hako-mente.cgi
mitsudori de60df87e0 new file: css/main.css
new file:   hako-main.cgi
	new file:   hako-map.cgi
	new file:   hako-mente.cgi
	new file:   hako-readme.txt
	new file:   hako-top.cgi
	new file:   hako-turn.cgi
	new file:   images/black.gif
	new file:   images/f02.gif
	new file:   images/hakoniwa.gif
	new file:   images/land0.gif
	new file:   images/land1.gif
	new file:   images/land10.gif
	new file:   images/land11.gif
	new file:   images/land12.gif
	new file:   images/land13.gif
	new file:   images/land14.gif
	new file:   images/land15.gif
	new file:   images/land16.gif
	new file:   images/land2.gif
	new file:   images/land3.gif
	new file:   images/land4.gif
	new file:   images/land5.gif
	new file:   images/land6.gif
	new file:   images/land7.gif
	new file:   images/land8.gif
	new file:   images/land9.gif
	new file:   images/monster0.gif
	new file:   images/monster1.gif
	new file:   images/monster2.gif
	new file:   images/monster3.gif
	new file:   images/monster4.gif
	new file:   images/monster5.gif
	new file:   images/monster6.gif
	new file:   images/monster7.gif
	new file:   images/monster8.gif
	new file:   images/monument0.gif
	new file:   images/monument1.gif
	new file:   images/monument2.gif
	new file:   images/prize0.gif
	new file:   images/prize1.gif
	new file:   images/prize10.gif
	new file:   images/prize11.gif
	new file:   images/prize2.gif
	new file:   images/prize3.gif
	new file:   images/prize4.gif
	new file:   images/prize5.gif
	new file:   images/prize6.gif
	new file:   images/prize7.gif
	new file:   images/prize8.gif
	new file:   images/prize9.gif
	new file:   images/space.gif
	new file:   images/space0.gif
	new file:   images/space1.gif
	new file:   images/space10.gif
	new file:   images/space11.gif
	new file:   images/space2.gif
	new file:   images/space3.gif
	new file:   images/space4.gif
	new file:   images/space5.gif
	new file:   images/space6.gif
	new file:   images/space7.gif
	new file:   images/space8.gif
	new file:   images/space9.gif
	new file:   images/spacep.gif
	new file:   images/xbar.gif
	new file:   jcode.pl
	new file:   manual/advanced.html
	new file:   manual/beginner.html
	new file:   manual/intermediate.html
	new file:   manual/man-discovered.png
	new file:   manual/man-goto.png
	new file:   manual/man-listed.png
	new file:   manual/man-name.png
	new file:   manual/man-new.png
	new file:   manual/man-owner.png
	new file:   manual/man-ownerm.png
	new file:   manual/man-register.png
	new file:   manual/man-tourist.png
2024-12-03 02:32:59 -03:00

342 lines
7.6 KiB
Perl

#!/usr/bin/perl
# ↑はサーバーに合わせて変更して下さい。
#----------------------------------------------------------------------
# 箱庭諸島 ver2.30
# メンテナンスツール(ver1.01)
# 使用条件、使用方法等は、hako-readme.txtファイルを参照
#
# 箱庭諸島のページ: http://www.bekkoame.ne.jp/~tokuoka/hakoniwa.html
#----------------------------------------------------------------------
# ――――――――――――――――――――――――――――――
# 各種設定値
# ――――――――――――――――――――――――――――――
# マスターパスワード
my($masterpassword) = '';
# 1ターンが何秒か
my($unitTime) = 21600; # 6時間
# ディレクトリのパーミッション
my($dirMode) = 0755;
# このファイル
my($thisFile) = 'http://path/hako-mente.cgi';
# データディレクトリの名前
# hakojima.cgi中のものと合わせてください。
my($dirName) = 'data';
# use Time::Localが使えない環境では、'use Time::Local'の行を消して下さい。
# ただし、更新時間の変更が'秒指定で変更'しかできなくなります。
use Time::Local;
# ――――――――――――――――――――――――――――――
# 設定項目は以上
# ――――――――――――――――――――――――――――――
# 各種変数
my($mainMode);
my($inputPass);
my($deleteID);
my($currentID);
my($ctYear);
my($ctMon);
my($ctDate);
my($ctHour);
my($ctMin);
my($ctSec);
print <<END;
Content-type: text/html
<HTML>
<HEAD>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/global.css">
<link rel="stylesheet" href="/hakoniwa2/css/main.css">
<link rel="shortcut icon" href="/favicon.ico">
<TITLE>Hakoniwa Islands 2 Maintenance Tool</TITLE>
</HEAD>
<BODY>
END
cgiInput();
if($mainMode eq 'delete') {
if(passCheck()) {
deleteMode();
}
} elsif($mainMode eq 'current') {
if(passCheck()) {
currentMode();
}
} elsif($mainMode eq 'time') {
if(passCheck()) {
timeMode();
}
} elsif($mainMode eq 'stime') {
if(passCheck()) {
stimeMode();
}
} elsif($mainMode eq 'new') {
if(passCheck()) {
newMode();
}
}
mainMode();
print <<END;
</FORM>
</BODY>
</HTML>
END
sub myrmtree {
my($dn) = @_;
opendir(DIN, "$dn/");
my($fileName);
while($fileName = readdir(DIN)) {
unlink("$dn/$fileName");
}
closedir(DIN);
rmdir($dn);
}
sub currentMode {
myrmtree "${dirName}";
mkdir("${dirName}", $dirMode);
opendir(DIN, "${dirName}.bak$currentID/");
my($fileName);
while($fileName = readdir(DIN)) {
fileCopy("${dirName}.bak$currentID/$fileName", "${dirName}/$fileName");
}
closedir(DIN);
}
sub deleteMode {
if($deleteID eq '') {
myrmtree "${dirName}";
} else {
myrmtree "${dirName}.bak$deleteID";
}
unlink "hakojimalockflock";
}
sub newMode {
mkdir($dirName, $dirMode);
# 現在の時間を取得
my($now) = time;
$now = $now - ($now % ($unitTime));
open(OUT, ">$dirName/hakojima.dat"); # ファイルを開く
print OUT "1\n"; # ターン数1
print OUT "$now\n"; # 開始時間
print OUT "0\n"; # 島の数
print OUT "1\n"; # 次に割り当てるID
# ファイルを閉じる
close(OUT);
}
sub timeMode {
$ctMon--;
$ctYear -= 1900;
$ctSec = timelocal($ctSec, $ctMin, $ctHour, $ctDate, $ctMon, $ctYear);
stimeMode();
}
sub stimeMode {
my($t) = $ctSec;
open(IN, "${dirName}/hakojima.dat");
my(@lines);
@lines = <IN>;
close(IN);
$lines[1] = "$t\n";
open(OUT, ">${dirName}/hakojima.dat");
print OUT @lines;
close(OUT);
}
sub mainMode {
opendir(DIN, "./");
print <<END;
<FORM action="$thisFile" method="POST">
<H1>Hakoniwa Islands 2 Maintenance Tool</H1>
<B>Password:</B><INPUT TYPE=password SIZE=32 MAXLENGTH=32 NAME=PASSWORD></TD>
END
# 現役データ
if(-d "${dirName}") {
dataPrint("");
} else {
print <<END;
<HR>
<INPUT TYPE="submit" VALUE="Create new data" NAME="NEW">
END
}
# バックアップデータ
my($dn);
while($dn = readdir(DIN)) {
if($dn =~ /^${dirName}.bak(.*)/) {
dataPrint($1);
}
}
closedir(DIN);
}
# 表示モード
sub dataPrint {
my($suf) = @_;
print "<HR>";
if($suf eq "") {
open(IN, "${dirName}/hakojima.dat");
print "<H1>Currently active data</H1>";
} else {
open(IN, "${dirName}.bak$suf/hakojima.dat");
print "<H1>Backup $suf</H1>";
}
my($lastTurn);
$lastTurn = <IN>;
my($lastTime);
$lastTime = <IN>;
my($timeString) = timeToString($lastTime);
print <<END;
<B>Turn $lastTurn</B><BR>
<B>Time of last update</B>: $timeString<BR>
<B>Time of last update (in seconds)</B>: $lastTime seconds since 1970/01/01<BR>
<INPUT TYPE="submit" VALUE="Delete this data" NAME="DELETE$suf">
END
if($suf eq "") {
my($sec, $min, $hour, $date, $mon, $year, $day, $yday, $dummy) =
localtime($lastTime);
$mon++;
$year += 1900;
$sec = sprintf("%02d", $sec);
$min = sprintf("%02d", $min);
$hour = sprintf("%02d", $hour);
$date = sprintf("%02d", $date);
$mon = sprintf("%02d", $mon);
print <<END;
<H2>Change last update time</H2>
<INPUT TYPE="text" SIZE=4 NAME="YEAR" VALUE="$year">/<INPUT TYPE="text" SIZE=2 NAME="MON" VALUE="$mon">/<INPUT TYPE="text" SIZE=2 NAME="DATE" VALUE="$date">
<INPUT TYPE="text" SIZE=2 NAME="HOUR" VALUE="$hour">:<INPUT TYPE="text" SIZE=2 NAME="MIN" VALUE="$min">:<INPUT TYPE="text" SIZE=2 NAME="NSEC" VALUE="$sec">
<INPUT TYPE="submit" VALUE="Change" NAME="NTIME"><BR>
<INPUT TYPE="text" SIZE=32 NAME="SSEC" VALUE="$lastTime"> seconds since 1970/01/01
<INPUT TYPE="submit" VALUE="Change by specifying seconds" NAME="STIME">
END
} else {
print <<END;
<INPUT TYPE="submit" VALUE="Activate this data" NAME="CURRENT$suf">
END
}
}
sub timeToString {
my($sec, $min, $hour, $date, $mon, $year, $day, $yday, $dummy) =
localtime($_[0]);
$mon++;
$year += 1900;
$sec = sprintf("%02d", $sec);
$min = sprintf("%02d", $min);
$hour = sprintf("%02d", $hour);
$date = sprintf("%02d", $date);
$mon = sprintf("%02d", $mon);
return "${year}/${mon}/${date} ${hour}:${min}:${sec}";
}
# CGIの読みこみ
sub cgiInput {
my($line);
# 入力を受け取る
$line = <>;
$line =~ tr/+/ /;
$line =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
if($line =~ /DELETE([0-9]*)/) {
$mainMode = 'delete';
$deleteID = $1;
} elsif($line =~ /CURRENT([0-9]*)/) {
$mainMode = 'current';
$currentID = $1;
} elsif($line =~ /NEW/) {
$mainMode = 'new';
} elsif($line =~ /NTIME/) {
$mainMode = 'time';
if($line =~ /YEAR=([0-9]*)/) {
$ctYear = $1;
}
if($line =~ /MON=([0-9]*)/) {
$ctMon = $1;
}
if($line =~ /DATE=([0-9]*)/) {
$ctDate = $1;
}
if($line =~ /HOUR=([0-9]*)/) {
$ctHour = $1;
}
if($line =~ /MIN=([0-9]*)/) {
$ctMin = $1;
}
if($line =~ /NSEC=([0-9]*)/) {
$ctSec = $1;
}
} elsif($line =~ /STIME/) {
$mainMode = 'stime';
if($line =~ /SSEC=([0-9]*)/) {
$ctSec = $1;
}
}
if($line =~ /PASSWORD=([^\&]*)\&/) {
$inputPass = $1;
}
}
# ファイルのコピー
sub fileCopy {
my($src, $dist) = @_;
open(IN, $src);
open(OUT, ">$dist");
while(<IN>) {
print OUT;
}
close(IN);
close(OUT);
}
# パスチェック
sub passCheck {
if($inputPass eq $masterpassword) {
return 1;
} else {
print <<END;
<span style="font-size:3em">Password is incorrect.</span>
END
return 0;
}
}
1;