Exemplo n.º 1
0
 public function _canCancelWarTask($taskType, $taskId)
 {
     if (!QueueTask::iscancelabletask($taskType)) {
         return FALSE;
     }
     $timeout = QueueTask::getmaxcanceltimeout($taskType);
     if (0 - 1 < $timeout) {
         $_task = NULL;
         foreach ($this->queueModel->tasksInQueue[$taskType] as $t) {
             if (!($t['id'] == $taskId)) {
                 continue;
             }
             $_task = $t;
             break;
             break;
         }
         if ($_task == NULL) {
             return FALSE;
         }
         $elapsedTime = $t['elapsedTime'];
         if ($timeout < $elapsedTime) {
             return FALSE;
         }
     }
     return TRUE;
 }
Exemplo n.º 2
0
 public function cancelTask($playerId, $taskId)
 {
     $GameMetadata = $GLOBALS['GameMetadata'];
     $row = $this->provider->fetchRow("SELECT \r\n\t\t\t\tq.id,\r\n\t\t\t\tq.player_id,\r\n\t\t\t\tq.village_id,\r\n\t\t\t\tq.to_player_id,\r\n\t\t\t\tq.to_village_id,\r\n\t\t\t\tq.building_id,\r\n\t\t\t\tq.proc_type,\r\n\t\t\t\tq.proc_params,\r\n\t\t\t\tq.threads,\r\n\t\t\t\t(q.execution_time - TIME_TO_SEC(TIMEDIFF(q.end_date, NOW()))) elapsedTime,\r\n\t\t\t\tTIME_TO_SEC(TIMEDIFF(q.end_date, NOW())) remainingSeconds\r\n\t\t\tFROM p_queue q \r\n\t\t\tWHERE \r\n\t\t\t\tq.id=%s AND q.player_id=%s", array($taskId, $playerId));
     if ($row == NULL) {
         return;
     }
     $taskType = $row['proc_type'];
     $elapsedTime = $row['elapsedTime'];
     if (!QueueTask::iscancelabletask($taskType)) {
         return;
     }
     $timeout = QueueTask::getmaxcanceltimeout($taskType);
     if (0 - 1 < $timeout && $timeout < $elapsedTime) {
         return;
     }
     if ($taskType != QS_WAR_REINFORCE && $taskType != QS_WAR_ATTACK && $taskType != QS_WAR_ATTACK_PLUNDER && $taskType != QS_WAR_ATTACK_SPY) {
         $this->provider->executeQuery("DELETE FROM p_queue WHERE id=%s", array($taskId));
     } else {
         if ($taskType == QS_WAR_REINFORCE) {
             $proc_params = $row['proc_params'];
             $arr = explode("|", $proc_params);
             if ($arr[sizeof($arr) - 1] == 1) {
             }
         }
     }
     if ($taskType == QS_LEAVEOASIS) {
         unset($Var_1896[$row['building_id']]);
     } else {
         $i = 0;
         $c = sizeof($this->tasksInQueue[$taskType]);
         while ($i < $c) {
             $qtask = $this->tasksInQueue[$taskType][$i];
             if ($qtask['id'] == $taskId) {
                 if ($taskType == QS_BUILD_CREATEUPGRADE && isset($this->tasksInQueue[QS_BUILD_CREATEUPGRADE])) {
                     $dualBuild = $GameMetadata['tribes'][$this->page->data['tribe_id']]['dual_build'];
                     $j = $i + 1;
                     while ($j < $c) {
                         $_qt = $this->tasksInQueue[$taskType][$j];
                         if ($_qt['remainingSeconds'] <= $qtask['remainingSeconds']) {
                             continue;
                         }
                         if ($dualBuild) {
                             if ($qtask['building_id'] <= 4 && $_qt['building_id'] <= 4 || 4 < $qtask['building_id'] && 4 < $_qt['building_id']) {
                                 $this->tasksInQueue[$taskType][$j]['remainingSeconds'] -= $qtask['remainingSeconds'];
                             }
                         } else {
                             $this->tasksInQueue[$taskType][$j]['remainingSeconds'] -= $qtask['remainingSeconds'];
                         }
                         ++$j;
                     }
                 }
                 unset($Var_4224[$i]);
                 break;
             }
             ++$i;
         }
     }
     if (sizeof($this->tasksInQueue[$taskType]) == 0) {
         unset($this->tasksInQueue[$taskType]);
     } else {
         if ($taskType != QS_LEAVEOASIS) {
             usort($this->tasksInQueue[$taskType], array($this, "_compareTask"));
         }
     }
     switch ($taskType) {
         case QS_ACCOUNT_DELETE:
             break;
             switch ($taskType) {
                 case QS_BUILD_DROP:
                     $this->_changeUpdateKey();
                     break;
                     switch ($taskType) {
                         case QS_BUILD_CREATEUPGRADE:
                             --$this->tasksInQueue[4 < intval($row['building_id']) ? "buildsNum" : "fieldsNum"];
                             $buildingLevels = $GameMetadata['items'][$row['building_id']]['levels'];
                             $curResources = 0 < $this->page->buildings[$row['proc_params']]['level'] ? $buildingLevels[$this->page->buildings[$row['proc_params']]['level'] - 1]['resources'] : array("1" => 0, "2" => 0, "3" => 0, "4" => 0);
                             $nextResources = $buildingLevels[$this->page->buildings[$row['proc_params']]['level'] - 1 + $this->page->buildings[$row['proc_params']]['update_state']]['resources'];
                             foreach ($nextResources as $k => $v) {
                                 $this->page->resources[$k]['current_value'] += $v - $curResources[$k];
                             }
                             if ($this->page->buildings[$row['proc_params']]['level'] == 0 && $this->page->buildings[$row['proc_params']]['update_state'] == 1 && 4 < $this->page->buildings[$row['proc_params']]['item_id']) {
                                 $this->page->buildings[$row['proc_params']]['item_id'] = 0;
                                 if ($row['building_id'] == 40) {
                                     $this->page->buildings[26]['item_id'] = 0;
                                     $this->page->buildings[29]['item_id'] = 0;
                                     $this->page->buildings[30]['item_id'] = 0;
                                     $this->page->buildings[33]['item_id'] = 0;
                                 }
                             }
                             --$this->page->buildings[$row['proc_params']]['update_state'];
                             if ($row['building_id'] == 40) {
                                 --$this->page->buildings[26]['update_state'];
                                 --$this->page->buildings[29]['update_state'];
                                 --$this->page->buildings[30]['update_state'];
                                 --$this->page->buildings[33]['update_state'];
                             }
                             $this->_updateVillage(TRUE);
                             $dualBuild = $GameMetadata['tribes'][$this->page->data['tribe_id']]['dual_build'];
                             $expr = "";
                             if ($dualBuild) {
                                 $expr = 4 < $row['building_id'] ? " AND q.building_id>4" : " AND q.building_id<=4";
                             }
                             $this->provider->executeQuery("UPDATE p_queue q \r\n\t\t\t\t\tSET\r\n\t\t\t\t\t\tq.end_date=(q.end_date - INTERVAL %s SECOND)\r\n\t\t\t\t\tWHERE \r\n\t\t\t\t\t\tq.proc_type=%s AND q.player_id=%s AND q.village_id=%s\r\n\t\t\t\t\t\tAND TIME_TO_SEC(TIMEDIFF(q.end_date, NOW())) > %s" . $expr, array($row['remainingSeconds'], $row['proc_type'], $row['player_id'], $row['village_id'], $row['remainingSeconds']));
                             break;
                             switch ($taskType) {
                                 case QS_WAR_REINFORCE:
                                 case QS_WAR_ATTACK:
                                 case QS_WAR_ATTACK_PLUNDER:
                                 case QS_WAR_ATTACK_SPY:
                                     $proc_params = $row['proc_params'];
                                     $arr = explode("|", $proc_params);
                                     $arr[sizeof($arr) - 1] = 1;
                                     $proc_params = implode("|", $arr);
                                     $this->provider->executeQuery("UPDATE p_queue q \r\n\t\t\t\t\tSET\r\n\t\t\t\t\t\tq.player_id=%s,\r\n\t\t\t\t\t\tq.village_id=%s,\r\n\t\t\t\t\t\tq.to_player_id=%s,\r\n\t\t\t\t\t\tq.to_village_id=%s,\r\n\t\t\t\t\t\tq.proc_type=%s,\r\n\t\t\t\t\t\tq.proc_params='%s',\r\n\t\t\t\t\t\tq.execution_time=%s,\r\n\t\t\t\t\t\tq.end_date=(NOW() + INTERVAL %s SECOND)\r\n\t\t\t\t\tWHERE \r\n\t\t\t\t\t\tq.id=%s", array(intval($row['to_player_id']) == 0 ? "NULL" : $row['to_player_id'], intval($row['to_village_id']) == 0 ? "NULL" : $row['to_village_id'], intval($row['player_id']) == 0 ? "NULL" : $row['player_id'], intval($row['village_id']) == 0 ? "NULL" : $row['village_id'], QS_WAR_REINFORCE, $proc_params, $row['elapsedTime'], $row['elapsedTime'], $taskId));
                                     --$this->tasksInQueue['war_troops_summary']['total_number'];
                                     if (isset($this->tasksInQueue['war_troops']['from_village'])) {
                                         $i = 0;
                                         $_c = sizeof($this->tasksInQueue['war_troops']['from_village']);
                                         while ($i < $_c) {
                                             if ($this->tasksInQueue['war_troops']['from_village'][$i]['id'] == $taskId) {
                                                 unset($this->from_village[$i]);
                                                 break;
                                             }
                                             ++$i;
                                         }
                                     }
                                     $tmp = $row['to_player_id'];
                                     $row['to_player_id'] = $row['player_id'];
                                     $row['player_id'] = $tmp;
                                     $tmp = $row['to_village_id'];
                                     $row['to_village_id'] = $row['village_id'];
                                     $row['village_id'] = $tmp;
                                     $row['proc_type'] = QS_WAR_REINFORCE;
                                     $row['proc_params'] = $proc_params;
                                     $row['execution_time'] = $row['remainingSeconds'] = $row['elapsedTime'];
                                     $row['elapsedTime'] = 0;
                                     $this->_enqueueTask($row);
                                     if (0 < sizeof($this->tasksInQueue['war_troops']['to_village'])) {
                                         usort($this->tasksInQueue['war_troops']['to_village'], array($this, "_compareTask"));
                                     }
                                     break;
                                     switch ($taskType) {
                                         case QS_LEAVEOASIS:
                                     }
                             }
                     }
             }
     }
     unset($row);
 }
Exemplo n.º 3
0
 public function canCancelPlayerDeletionProcess()
 {
     if (!QueueTask::iscancelabletask(QS_ACCOUNT_DELETE)) {
         return FALSE;
     }
     $timeout = QueueTask::getmaxcanceltimeout(QS_ACCOUNT_DELETE);
     if (0 - 1 < $timeout) {
         $elapsedTime = $this->queueModel->tasksInQueue[QS_ACCOUNT_DELETE][0]['elapsedTime'];
         if ($timeout < $elapsedTime) {
             return FALSE;
         }
     }
     return TRUE;
 }