Example #1
0
 static function checkPassword($p1 = "", $p2 = "")
 {
     global $init;
     // nullチェック
     if (empty($p2)) {
         return false;
     }
     if (file_exists("{$init->passwordFile}")) {
         $fp = fopen("{$init->passwordFile}", "r");
         $masterPassword = chop(fgets($fp, READ_LINE));
         fclose($fp);
     }
     // マスターパスワードチェック
     if (strcmp($masterPassword, crypt($p2, 'ma')) == 0) {
         return true;
     }
     if (strcmp($p1, AllyUtil::encode($p2)) == 0) {
         return true;
     }
     return false;
 }
Example #2
0
    function newAllyTop($hako, $data)
    {
        global $init;
        $this_file = $init->baseDir . "/hako-ally.php";
        $adminMode = 0;
        $jsAllyList = "";
        $jsAllyIdList = "";
        $jsAllyMarkList = "";
        $jsAllyColorList = "";
        $data['defaultPassword'] = isset($data['defaultPassword']) ? $data['defaultPassword'] : "";
        if (AllyUtil::checkPassword("", $data['defaultPassword'])) {
            // 管理者の判定は、お菓子のパスワード、盟主の変更可
            $adminMode = 1;
        } elseif (!$init->allyUse) {
            $this->allyTop($hako, $data);
        }
        $jsIslandList = "";
        $num = (int) $hako->islandNumber;
        for ($i = 0; $i < $num; $i++) {
            $name = $hako->islands[$i]['name'];
            $name = preg_replace("/'/", "\\'", $name);
            $id = $hako->islands[$i]['id'];
            $jsIslandList .= "island[{$id}] = '{$name}';\n";
        }
        $data['defaultID'] = isset($data['defaultID']) ? $data['defaultID'] : "";
        $n = '';
        $n = isset($hako->idToAllyNumber[$data['defaultID']]) ? $hako->idToAllyNumber[$data['defaultID']] : "";
        if ($n == '') {
            $allyname = '';
            $defaultMark = $hako->ally[0];
            $defaultAllyId = '';
        } else {
            $allyname = $hako->ally[$n]['name'];
            $allyname = preg_replace("/'/", "\\'", $allyname);
            $defaultMark = $hako->ally[$n]['mark'];
            $defaultAllyId = $hako->ally[$n]['id'];
        }
        $defaultMark = '';
        $markList = "";
        foreach ($init->allyMark as $aMark) {
            $s = '';
            if ($aMark == $defaultMark) {
                $s = ' selected';
            }
            $markList .= "<option value=\"{$aMark}\"{$s}>{$aMark}</option>\n";
        }
        $hx = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F');
        $colorList = array('', '', '', '', '', '', '');
        for ($i = 1; $i < 7; $i++) {
            if ($n == '') {
                $allycolor[$i] = '0';
            } else {
                $allycolor[$i] = substr($hako->ally[$n]['color'], $i, 1);
            }
            for ($j = 0; $j < count($hx); $j++) {
                $s = '';
                if ($hx[$j] == $allycolor[$i]) {
                    $s = ' selected';
                }
                $colorList[$i] .= "<option value=\"{$hx[$j]}\"{$s}>{$hx[$j]}</option>\n";
            }
        }
        $max = 201;
        if ($hako->allyNumber) {
            $jsAllyList = "var ally = [";
            $jsAllyIdList = "var allyID = [";
            $jsAllyMarkList = "var allyMark = [";
            $jsAllyColorList = "var allyColor = [";
            for ($i = 0; $i < count($hako->ally); $i++) {
                $s = "";
                if ($hako->ally[$i]['id'] == $defaultAllyId) {
                    $s = ' selected';
                }
                $allyList = "";
                $allyList .= "<option value=\"{$i}\"{$s}>{$hako->ally[$i]['name']}</option>\n";
                $jsAllyList .= "'{$hako->ally[$i]['name']}'";
                $jsAllyIdList .= "{$hako->ally[$i]['id']}";
                $jsAllyMarkList .= "'{$hako->ally[$i]['mark']}'";
                $jsAllyColorList .= "[";
                for ($j = 0; $j < 6; $j++) {
                    $jsAllyColorList .= '\'' . substr($hako->ally[$i]['color'], $j, 1) . '\'';
                    if ($j < 5) {
                        $jsAllyColorList .= ',';
                    }
                }
                $jsAllyColorList .= "]";
                if ($i < count($hako->ally)) {
                    $jsAllyList .= ",\n";
                    $jsAllyIdList .= ",\n";
                    $jsAllyMarkList .= ",\n";
                    $jsAllyColorList .= ",\n";
                }
                if ($max <= $hako->ally[$i]['id']) {
                    $max = $hako->ally[$i]['id'] + 1;
                }
            }
            $jsAllyList .= "];\n";
            $jsAllyIdList .= "];\n";
            $jsAllyMarkList .= "];\n";
            $jsAllyColorList .= "];\n";
        }
        $str1 = $adminMode ? '(メンテナンス)' : $init->allyJoinComUse ? '' : '・加盟・脱退';
        $str2 = $adminMode ? '' : 'onChange="colorPack()" onClick="colorPack()"';
        $makeCost = $init->costMakeAlly ? "{$init->costMakeAlly}{$init->unitMoney}" : '無料';
        $keepCost = $init->costKeepAlly ? "{$init->costKeepAlly}{$init->unitMoney}" : '無料';
        $joinCost = isset($init->comCost[$init->comAlly]) ? "{$init->comCost[$init->comAlly]}{$init->unitMoney}" : '無料';
        $joinStr = $init->allyJoinComUse ? '' : "加盟・脱退の際の費用は、{$init->tagMoney_}{$joinCost}{$init->_tagMoney}です。<BR>";
        $str3 = $adminMode ? "特殊パスワードは?(必須)<BR>\n<INPUT TYPE=\"password\" NAME=\"OLDPASS\" VALUE=\"{$data['defaultPassword']}\" SIZE=32 MAXLENGTH=32 class=f><BR>同盟" : "<div class='alert alert-info'><span class='attention'>(注意)</span><BR>\n同盟の結成・変更の費用は、{$init->tagMoney_}{$makeCost}{$init->_tagMoney}です。<BR>\nまた、毎ターン必要とされる維持費は{$init->tagMoney_}{$keepCost}{$init->_tagMoney}です。<BR>\n(維持費は同盟に所属する島で均等に負担することになります)<BR>\n{$joinStr}\n</div>\n\nあなたの島は?(必須)<BR>\n<SELECT NAME=\"ISLANDID\" {$str2}>\n{$hako->islandList}\n</SELECT><BR>あなた";
        $str0 = $adminMode || $init->allyUse == 1 ? '結成・' : '';
        echo <<<END
<div class='text-center'>
{$init->tagBig_}同盟の{$str0}変更・解散{$str1}{$init->_tagBig}<br>
</div>

<DIV ID='changeInfo'>
<table border=0 width=50%><tr><td class="M"><P>
<FORM name="AcForm" action="{$this_file}" method="POST">
{$str3}のパスワードは?(必須)<BR>
<INPUT TYPE="password" NAME="PASSWORD" SIZE="32" MAXLENGTH="32" class="f" class="form-control">
END;
        if ($hako->allyNumber) {
            $str4 = $adminMode ? '・結成・変更' : $init->allyJoinComUse ? '' : '・加盟・脱退';
            $str5 = $adminMode || $init->allyJoinComUse ? '' : '<INPUT TYPE="submit" VALUE="加盟・脱退" NAME="JoinAllyButton" class="btn btn-default">';
            echo <<<END
<BR>
<BR><B>[解散{$str4}]</B>
<BR>どの同盟ですか?<BR>
<SELECT NAME="ALLYNUMBER" onChange="allyPack()" onClick="allyPack()">
{$allyList}
</SELECT>
<BR>
<INPUT TYPE="submit" VALUE="解散" NAME="DeleteAllyButton" class="btn btn-danger">
{$str5}
<BR>
END;
        }
        $str7 = $adminMode ? "盟主島の変更(上のメニューで同盟を選択)<BR> or 同盟の新規作成(上のメニューは無効)<BR><SELECT NAME=\"ALLYID\"><option value=\"{$max}\">新規作成\n{$hako->islandList}</option></SELECT><BR>" : "<BR><B>[{$str0}変更]</B><BR>";
        echo <<<END
<BR>
{$str7}
同盟の名前(変更)<small>(全角{$init->lengthAllyName}字まで)</small><BR>
<INPUT TYPE="text" NAME="ALLYNAME" VALUE="{$allyname}" SIZE=32 MAXLENGTH=32 class="form-control"><BR>
マーク(変更)<BR>
<SELECT NAME="MARK" onChange="colorPack()" onClick="colorPack()">{$markList}</SELECT>
<br>
<ilayer name="PARENT_CTBL" width="100%" height="100%">
   <layer name="CTBL" width="200"></layer>
   <span id="CTBL"></span>
</ilayer>
マークの色コード(変更)<BR>
<TABLE class="table table-bordered table-condensed">
<TR>
\t<TD align='center'>RED</TD>
\t<TD align='center'>GREEN</TD>
\t<TD align='center'>BLUE</TD>
</TR>
<TR>
\t<TD>
\t\t<SELECT NAME="COLOR1" onChange="colorPack()" onClick="colorPack()">{$colorList[1]}</SELECT>
\t\t<SELECT NAME="COLOR2" onChange="colorPack()" onClick="colorPack()">{$colorList[2]}</SELECT>
\t</TD>
\t<TD>
\t\t<SELECT NAME="COLOR3" onChange="colorPack()" onClick="colorPack()">{$colorList[3]}</SELECT>
\t\t<SELECT NAME="COLOR4" onChange="colorPack()" onClick="colorPack()">{$colorList[4]}</SELECT>
\t</TD>
\t<TD>
\t\t<SELECT NAME="COLOR5" onChange="colorPack()" onClick="colorPack()">{$colorList[5]}</SELECT>
\t\t<SELECT NAME="COLOR6" onChange="colorPack()" onClick="colorPack()">{$colorList[6]}</SELECT>
\t</TD>
</TR>
</TABLE>

<INPUT TYPE="submit" VALUE="結成 (変更)" NAME="NewAllyButton" class="btn btn-primary">
END;
        if (!$adminMode) {
            echo <<<END
<script>
function colorPack() {
\tvar island = new Array(128);
\t{$jsIslandList}
\tvar a = document.AcForm.COLOR1.value;
\tvar b = document.AcForm.COLOR2.value;
\tvar c = document.AcForm.COLOR3.value;
\tvar d = document.AcForm.COLOR4.value;
\tvar e = document.AcForm.COLOR5.value;
\tvar f = document.AcForm.COLOR6.value;
\tvar mark = document.AcForm.MARK.value;
\tvar number = document.AcForm.ISLANDID.value;

\tstr = "#" + a + b + c + d + e + f;

\tstr = '表示サンプル:『<B><span class="number"><FONT color="' + str +'">' + mark + '</FONT></B>'
\t\t+ island[number] + '島</span>』';

\tdocument.getElementById("CTBL").innerHTML = str;

\treturn true;
}
function allyPack() {
\t{$jsAllyList}
\t{$jsAllyMarkList}
\t{$jsAllyColorList}
\tdocument.AcForm.ALLYNAME.value = ally[document.AcForm.ALLYNUMBER.value];
\tdocument.AcForm.MARK.value     = allyMark[document.AcForm.ALLYNUMBER.value];
\tdocument.AcForm.COLOR1.value   = allyColor[document.AcForm.ALLYNUMBER.value][0];
\tdocument.AcForm.COLOR2.value   = allyColor[document.AcForm.ALLYNUMBER.value][1];
\tdocument.AcForm.COLOR3.value   = allyColor[document.AcForm.ALLYNUMBER.value][2];
\tdocument.AcForm.COLOR4.value   = allyColor[document.AcForm.ALLYNUMBER.value][3];
\tdocument.AcForm.COLOR5.value   = allyColor[document.AcForm.ALLYNUMBER.value][4];
\tdocument.AcForm.COLOR6.value   = allyColor[document.AcForm.ALLYNUMBER.value][5];
\tcolorPack();
\treturn true;
}
END;
        } else {
            echo <<<END

function colorPack() {
\tvar island = new Array(128);
\t{$jsIslandList}
\tvar a = document.AcForm.COLOR1.value;
\tvar b = document.AcForm.COLOR2.value;
\tvar c = document.AcForm.COLOR3.value;
\tvar d = document.AcForm.COLOR4.value;
\tvar e = document.AcForm.COLOR5.value;
\tvar f = document.AcForm.COLOR6.value;
\tvar mark = document.AcForm.MARK.value;

\tvar str = "#" + a + b + c + d + e + f;

\tstr = '表示サンプル:『<B><span class="number"><FONT color="' + str +'">' + mark + '</FONT></B>'
\t\t+ 'さんぷる島</span>』';

\tdocument.getElementById("CTBL").innerHTML = str;

\treturn true;
}

function allyPack() {
\t{$jsAllyList}
\t{$jsAllyIdList}
\t{$jsAllyMarkList}
\t{$jsAllyColorList}
\tdocument.AcForm.ALLYID.value   = allyID[document.AcForm.ALLYNUMBER.value];
\tdocument.AcForm.ALLYNAME.value = ally[document.AcForm.ALLYNUMBER.value];
\tdocument.AcForm.MARK.value     = allyMark[document.AcForm.ALLYNUMBER.value];
\tdocument.AcForm.COLOR1.value   = allyColor[document.AcForm.ALLYNUMBER.value][0];
\tdocument.AcForm.COLOR2.value   = allyColor[document.AcForm.ALLYNUMBER.value][1];
\tdocument.AcForm.COLOR3.value   = allyColor[document.AcForm.ALLYNUMBER.value][2];
\tdocument.AcForm.COLOR4.value   = allyColor[document.AcForm.ALLYNUMBER.value][3];
\tdocument.AcForm.COLOR5.value   = allyColor[document.AcForm.ALLYNUMBER.value][4];
\tdocument.AcForm.COLOR6.value   = allyColor[document.AcForm.ALLYNUMBER.value][5];
\tcolorPack();
\treturn true;
}
END;
        }
        echo <<<END
colorPack();
</script>
</form>

</td>
</tr>
</table>
</div>
END;
    }