Пример #1
0
 /**
  * 結成・変更メイン
  * @param  [type] $hako [description]
  * @param  [type] $data [description]
  * @return [type]       [description]
  */
 function makeAllyMain($hako, $data)
 {
     global $init;
     $currentID = $data['ISLANDID'];
     $allyID = isset($data['ALLYID']) ? $data['ALLYID'] : "";
     $currentAnumber = isset($data['ALLYNUMBER']) ? $data['ALLYNUMBER'] : "";
     $allyName = htmlspecialchars($data['ALLYNAME']);
     $allyMark = $data['MARK'];
     $allyColor = "{$data['COLOR1']}{$data['COLOR2']}{$data['COLOR3']}{$data['COLOR4']}{$data['COLOR5']}{$data['COLOR6']}";
     $adminMode = 0;
     // パスワードチェック
     $data['OLDPASS'] = isset($data['OLDPASS']) ? $data['OLDPASS'] : "";
     if (AllyUtil::checkPassword("", $data['OLDPASS'])) {
         $adminMode = 1;
         if ($allyID > 200) {
             $max = $allyID;
             if ($hako->allyNumber) {
                 for ($i = 0; $i < count($hako->ally); $i++) {
                     if ($max <= $hako->ally[$i]['id']) {
                         $max = $hako->ally[$i]['id'] + 1;
                     }
                 }
             }
             $currentID = $max;
         } else {
             $currentID = $hako->ally[$currentAnumber]['id'];
         }
     }
     if (!$init->allyUse && !$adminMode) {
         HakoError::newAllyForbbiden();
         return;
     }
     // 同盟名があるかチェック
     if ($allyName == '') {
         HakoError::newAllyNoName();
         return;
     }
     // 同盟名が正当かチェック
     if (preg_match("/[,\\?\\(\\)\\<\\>\$]|^無人|^沈没\$/", $allyName)) {
         // 使えない名前
         HakoError::newIslandBadName();
         return;
     }
     // 名前の重複チェック
     $currentNumber = $hako->idToNumber[$currentID];
     if (!($adminMode && $allyID == '' && $allyID < 200) && (AllyUtil::nameToNumber($hako, $allyName) != -1 || AllyUtil::aNameToId($hako, $allyName) != -1 && AllyUtil::aNameToId($hako, $allyName) != $currentID)) {
         // すでに結成ずみ
         HakoError::newAllyAlready();
         return;
     }
     // マークの重複チェック
     if (!($adminMode && $allyID == '' && $allyID < 200) && (AllyUtil::aMarkToId($hako, $allyMark) != -1 && AllyUtil::aMarkToId($hako, $allyMark) != $currentID)) {
         // すでに使用ずみ
         HakoError::markAllyAlready();
         return;
     }
     // passwordの判定
     $island = $hako->islands[$currentNumber];
     if (!$adminMode && !AllyUtil::checkPassword($island['password'], $data['PASSWORD'])) {
         // password間違い
         HakoError::wrongPassword();
         return;
     }
     if (!$adminMode && $island['money'] < $init->costMakeAlly) {
         HakoError::noMoney();
         return;
     }
     $n = $hako->idToAllyNumber[$currentID];
     if ($n != '') {
         if ($adminMode && $allyID != '' && $allyID < 200) {
             $allyMember = $hako->ally[$n]['memberId'];
             $aIsland = $hako->islands[$hako->idToNumber[$allyID]];
             $flag = 0;
             foreach ($allyMember as $id) {
                 if ($id == $allyID) {
                     $flag = 1;
                     break;
                 }
             }
             if (!$flag) {
                 if ($aIsland['allyId'][0] == '') {
                     $flag = 2;
                 }
             }
             if (!$flag) {
                 echo "変更できません。\n";
                 return;
             }
             $hako->ally[$n]['id'] = $allyID;
             $hako->ally[$n]['oName'] = $aIsland['name'];
             if ($flag == 2) {
                 $hako->ally[$n]['password'] = $aIsland['password'];
                 $hako->ally[$n]['score'] = $aIsland['pop'];
                 $hako->ally[$n]['number']++;
                 array_push($hako->ally[$n]['memberId'], $aIsland['id']);
                 array_push($aIsland['allyId'], $aIsland['id']);
             }
         } else {
             // すでに結成ずみなら変更
         }
     } else {
         // 他の島の同盟に入っている場合は、結成できない
         $flag = 0;
         for ($i = 0; $i < $hako->allyNumber; $i++) {
             $allyMember = $hako->ally[$i]['memberId'];
             foreach ($allyMember as $id) {
                 if ($id == $currentID) {
                     $flag = 1;
                     break;
                 }
             }
             if ($flag) {
                 break;
             }
         }
         if ($flag) {
             HakoError::otherAlready();
             return;
         }
         if ($init->allyUse == 2 && !$adminMode && !AllyUtil::checkPassword("", $data['PASSWORD'])) {
             HakoError::newAllyForbbiden();
             return;
         }
         // 新規
         $n = $hako->allyNumber;
         $hako->ally[$n]['id'] = $currentID;
         $memberId = array();
         if ($allyID < 200) {
             $hako->ally[$n]['oName'] = $island['name'] . "島";
             $hako->ally[$n]['password'] = $island['password'];
             $hako->ally[$n]['number'] = 1;
             $memberId[0] = $currentID;
             $hako->ally[$n]['score'] = $island['pop'];
         } else {
             $hako->ally[$n]['oName'] = '';
             $hako->ally[$n]['password'] = AllyUtil::encode($data['PASSWORD']);
             $hako->ally[$n]['number'] = 0;
             $hako->ally[$n]['score'] = 0;
         }
         $hako->ally[$n]['occupation'] = 0;
         $hako->ally[$n]['memberId'] = $memberId;
         $island['allyId'] = $memberId;
         $ext = array(0);
         $hako->ally[$n]['ext'] = $ext;
         $hako->idToAllyNumber[$currentID] = $n;
         $hako->allyNumber++;
     }
     // 同盟の各種の値を設定
     $hako->ally[$n]['name'] = $allyName;
     $hako->ally[$n]['mark'] = $allyMark;
     $hako->ally[$n]['color'] = "{$allyColor}";
     // 費用をいただく
     if (!$adminMode) {
         $island['money'] -= $init->costMakeAlly;
     }
     // データ格納先へ
     $hako->islands[$currentNumber] = $island;
     // データ書き出し
     AllyUtil::allyOccupy($hako);
     AllyUtil::allySort($hako);
     $hako->writeAllyFile();
     // トップへ
     $html = new HtmlAlly();
     $html->allyTop($hako, $data);
 }