public static function getOGameServerTime($overview_str) { //若找不到的話 回傳值會是0 $overview_dom = GlobalFunc::loadHTML($overview_str); $div_dom = $overview_dom->getElementById("bar"); if (!is_object($div_dom)) { echo "\nGlobalFunc::getOGameServerTime(): error, ogame_clock not found!!\n"; return false; } $li_doms = $div_dom->getELementsByTagName('li'); $li_doms_len = $li_doms->length; $ogame_clock = 0; for ($liIdx = 0; $liIdx < $li_doms_len; $liIdx++) { $li_dom = $li_doms->item($liIdx); $class_text = ""; $li_dom_class = $li_dom->attributes->getNamedItem('class'); // to avoid notice message if (isset($li_dom_class)) { $class_text = $li_dom_class->nodeValue; } if ($class_text == "OGameClock") { $span_dom = $li_dom->getELementsByTagName('span')->item(0); $ogame_clock = $span_dom->textContent; break; } } return $ogame_clock; }
private function getFleetsAmount($f1_page) { $f1 = GlobalFunc::loadHTML($f1_page); $military = $f1->getElementById("military"); $civil = $f1->getElementById("civil"); $this->fleets = null; if (!isset($military)) { echo "Error occur, military is not found. return & as uri.\n"; echo iconv("UTF-8", "big5", "船隊撤退失敗 請檢查星球上是否有可移動船隻\n"); return '&'; } if (!isset($civil)) { echo "Error occur, civil is not found. return & as uri.\n"; return '&'; } $result_uri = ""; $result_uri .= $this->getFleetAmountByCategory($military); $result_uri .= $this->getFleetAmountByCategory($civil); echo "Sent fleet result uri = " . $result_uri . "\n"; //var_dump($this->fleets); return $result_uri; }
function hasAttack() { $isAttacked = false; //get overview page //$over_page = GlobalFunc::getOverviewPage(); //read over_page string from file $last_update_time = file_get_contents($this->Config['DLastUpt'], true); echo "\n===== Detect if has attack file path =====\n"; echo "AttackDetector: [" . $this->PLANET[0] . ":" . $this->PLANET[1] . ":" . $this->PLANET[2] . "](" . $this->PLANET[3] . "):\n"; echo "File last updated time: " . date('H:i:s', $last_update_time) . "\n"; echo "ADOverview Path: " . $this->Config['ADOverview'] . "\n"; echo "ADEventList Path: " . $this->Config['ADEventList'] . "\n"; echo "====================================\n"; $over_page = file_get_contents($this->Config['ADOverview'], true); //read over_page string from file //echo "over_page result strlen: " . strlen($over_page) . "\n"; if (strlen($over_page) < $this->Config['AskPageLeastStrLen']) { echo "Request overview page failed, strlen: " . strlen($over_page) . ". may be attacked.\n"; return 1; // maybe has attacked but call latter program to check } $doc = GlobalFunc::loadHTML($over_page); //get body //$body = $doc->getElementsByTagName('body')->item(0); //get attack alert dom $attack_alert_dom = $doc->getElementById('attack_alert'); if (!is_object($attack_alert_dom)) { echo "Error occur, Attack Alert not found. return 1.\n"; return 1; } if ($attack_alert_dom->hasAttribute('class')) { $attack_alert_class = $attack_alert_dom->getAttribute('class'); //目前沒有人攻擊 if (strstr($attack_alert_class, "noAttack")) { $isAttacked = false; } else { $isAttacked = true; } } return $isAttacked; }