private function updateChars() { if (empty($this->chars)) { return $this->chars; } foreach ($this->chars as $char) { // check if chars eveid exists in kb $sql = 'select plts.plt_id, plts.plt_externalid from kb3_pilots plts where plts.plt_name = "' . $char['Name'] . '"'; $qry = DBFactory::getDBQuery(); $qry->execute($sql); if ($qry->recordCount() != 0) { // pilot is in kb db, check he has his char id $row = $qry->getRow(); $pilot_id = $row['plt_id']; $pilot_external_id = $row['plt_externalid']; if ($pilot_external_id == 0 && $pilot_id != 0) { // update DB with ID $qry->execute("UPDATE kb3_pilots SET plt_externalid = " . intval($char['charID']) . "\n WHERE plt_id = " . $pilot_id); } } else { // pilot is not in DB // Set Corp $pilotscorp = Corporation::lookup($char['corpName']); // Check Corp was set, if not, add the Corp if (!$pilotscorp->getID()) { $ialliance = Alliance::add('None'); $pilotscorp = Corporation::add($char['corpName'], $ialliance, gmdate("Y-m-d H:i:s")); } Pilot::add($char['Name'], $pilotscorp, gmdate("Y-m-d H:i:s"), intval($char['charID'])); } } return; }
/** * @param SimpleXMLElement $inv * @param Kill $kill * @param string $time YYYY-mm-dd hh:ss * @return boolean false on error */ private function processInvolved($inv, &$kill, $time) { if (!(int) $inv['shipTypeID'] && !(int) $inv['weaponTypeID'] && !(int) $inv['characterID'] && !(string) $inv['characterName']) { $this->parsemsg[] = "Involved party blank."; return false; } $npc = false; $ship = Ship::getByID((int) $inv['shipTypeID']); $weapon = Cacheable::factory('Item', (int) $inv['weaponTypeID']); $alliance = new Alliance(); if ((int) $inv['allianceID']) { $alliance = Alliance::add(strval($inv['allianceName']), (int) $inv['allianceID']); } else { if ((int) $inv['factionID']) { $alliance = Alliance::add(strval($inv['factionName']), (int) $inv['factionID']); } else { $alliance = Alliance::add("None"); } } // get alliance from corp if ship is any kind of tower $shipClassID = $ship->getClass()->getID(); if ($shipClassID == 35 || $shipClassID == 36 || $shipClassID == 37) { $corpByName = Corporation::lookup(strval($inv['corporationName'])); if ($corpByName) { $alliance = $corpByName->getAlliance(); } } $corp = Corporation::add(strval($inv['corporationName']), $alliance, $time, (int) $inv['corporationID']); $charid = (int) $inv['characterID']; $charname = (string) $inv['characterName']; // Allow for blank names for consistency with CCP API. if (preg_match("/(Mobile (Large|Medium|Small) Warp Disruptor I?I?|\\w+ Control Tower( \\w+)?)/", $charname)) { $charname = $inv['corporationName'] . ' - ' . $charname; $charid = 0; } else { if ($charname == "" && preg_match("/(Mobile \\w+ Warp|\\w+ Control Tower( \\w+)?)/", $weapon->getName())) { $charname = $inv['corporationName'] . ' - ' . $weapon->getName(); $charid = 0; } else { if ($charname == "" && !$charid) { // NPC ship $ship = Ship::lookup("Unknown"); $weapon = Item::getByID((int) $inv['shipTypeID']); $charname = $weapon->getName(); $npc = true; $charid = $weapon->getID(); } else { if ($charname == "" && $charid) { // Bugged kill $this->parsemsg[] = "Involved party has blank pilot name."; return false; } } } } $pilot = Pilot::add((string) $charname, $corp, $time, $charid); $iparty = new InvolvedParty($pilot->getID(), $corp->getID(), $alliance->getID(), (double) $inv['securityStatus'], $ship->getID(), $weapon->getID(), (int) $inv['damageDone']); $kill->addInvolvedParty($iparty); if ((int) $inv['finalBlow'] == 1) { $kill->setFBPilotID($pilot->getID()); } $this->npcOnly = $this->npcOnly && $npc; return true; }
/** * Return corporation from cached list or look up a new name. * * @param string $corpname Alliance name to look up. * @return Corporation Corporation object matching input name. */ private static function fetchCorp($corpname, $alliance = null, $timestamp = null) { if (isset(self::$corps[$corpname])) { if (!is_null($timestamp) && self::$corps[$corpname]->isUpdatable($timestamp)) { self::$corps[$corpname]->add($corpname, $alliance, $timestamp, 0, self::$loadExternals); } $corp = self::$corps[$corpname]; } else { if ($alliance == null) { $corp = Corporation::lookup($corpname); // If the corporation is new and the alliance unknown (structure) // fetch the alliance from the API. if (!$corp) { $corp = Corporation::add($corpname, Alliance::add("None"), $timestamp); if (!$corp->getExternalID()) { $corp = false; } else { $corp->execQuery(); } } } else { $corp = Corporation::add($corpname, $alliance, $timestamp, 0, self::$loadExternals); self::$corps[$corpname] = $corp; } } return $corp; }