Exemplo n.º 1
0
 /**
  *
  * @param KillList $killList
  * @return string KillList as XML
  */
 public static function killListToXML($killList)
 {
     global $idfeedversion;
     $qry = DBFactory::getDBQuery();
     $date = gmdate('Y-m-d H:i:s');
     $xml = "<?xml version='1.0' encoding='UTF-8'?>\n\t\t<eveapi version='2' edkapi='" . $idfeedversion . "'>\n\t\t</eveapi>";
     $sxe = new SimpleXMLElement($xml);
     // Let's start making the xml.
     $sxe->addChild('currentTime', $date);
     $result = $sxe->addChild('result');
     $kills = $result->addChild('rowset');
     $kills->addAttribute('name', 'kills');
     $kills->addAttribute('key', 'killID');
     $kills->addAttribute('columns', 'killID,solarSystemID,killTime,moonID,hash,trust');
     $count = 0;
     $timing = '';
     while ($kill = $killList->getKill()) {
         if (config::get('km_cache_enabled') && CacheHandler::exists($kill->getID() . ".xml", 'mails')) {
             $cachedRow = new SimpleXMLElement(CacheHandler::get($kill->getID() . ".xml", 'mails'));
             IDFeed::addXMLElement($kills, $cachedRow);
             continue;
         }
         $count++;
         if ($kill->isClassified()) {
             continue;
         }
         //$kill = Kill::getByID($kill->getID());
         $row = $kills->addChild('row');
         $row->addAttribute('killID', intval($kill->getExternalID()));
         $row->addAttribute('killInternalID', intval($kill->getID()));
         $row->addAttribute('solarSystemID', $kill->getSystem()->getExternalID());
         $row->addAttribute('killTime', $kill->getTimeStamp());
         $row->addAttribute('moonID', '0');
         $row->addAttribute('hash', bin2hex(IDFeed::getHash($kill, true)));
         $row->addAttribute('trust', 3);
         $victim = Pilot::getByID($kill->getVictimID());
         $victimCorp = Corporation::getByID($kill->getVictimCorpID());
         $victimAlliance = Alliance::getByID($kill->getVictimAllianceID());
         $victimrow = $row->addChild('victim');
         if ($victim->getName() == $kill->getVictimShipName()) {
             $victimrow->addAttribute('characterID', "0");
             $victimrow->addAttribute('characterName', "");
         } else {
             $victimrow->addAttribute('characterID', $victim->getExternalID());
             $victimrow->addAttribute('characterName', $victim->getName());
         }
         $victimrow->addAttribute('corporationID', $victimCorp->getExternalID());
         $victimrow->addAttribute('corporationName', $victimCorp->getName());
         if ($victimAlliance->isFaction()) {
             $victimrow->addAttribute('allianceID', 0);
             $victimrow->addAttribute('allianceName', '');
             $victimrow->addAttribute('factionID', $victimAlliance->getFactionID());
             $victimrow->addAttribute('factionName', $victimAlliance->getName());
         } else {
             $victimrow->addAttribute('allianceID', $victimAlliance->getExternalID());
             $victimrow->addAttribute('allianceName', $victimAlliance->getName());
             $victimrow->addAttribute('factionID', 0);
             $victimrow->addAttribute('factionName', '');
         }
         $victimrow->addAttribute('damageTaken', $kill->getDamageTaken());
         $victimrow->addAttribute('shipTypeID', $kill->getVictimShipExternalID());
         $involved = $row->addChild('rowset');
         $involved->addAttribute('name', 'attackers');
         $involved->addAttribute('columns', 'characterID,characterName,corporationID,corporationName,allianceID,allianceName,factionID,factionName,securityStatus,damageDone,finalBlow,weaponTypeID,shipTypeID');
         $sql = "SELECT ind_sec_status, ind_all_id, ind_crp_id,\n\t\t\t\tind_shp_id, ind_wep_id, ind_order, ind_dmgdone, plt_id, plt_name,\n\t\t\t\tplt_externalid, crp_name, crp_external_id,\n\t\t\t\twtype.typeName AS wep_name FROM kb3_inv_detail\n\t\t\t\tJOIN kb3_pilots ON (plt_id = ind_plt_id)\n\t\t\t\tJOIN kb3_corps ON (crp_id = ind_crp_id)\n\t\t\t\tJOIN kb3_invtypes wtype ON (ind_wep_id = wtype.typeID)\n\t\t\t\tWHERE ind_kll_id = " . $kill->getID() . " ORDER BY ind_order ASC";
         $qry->execute($sql);
         while ($inv = $qry->getRow()) {
             $invrow = $involved->addChild('row');
             if (strpos($inv['plt_name'], '- ') !== false) {
                 $inv['plt_name'] = substr($inv['plt_name'], strpos($inv['plt_name'], '- ') + 2);
             } else {
                 if (strpos($inv['plt_name'], '#') !== false) {
                     $name = explode("#", $inv['plt_name']);
                     $inv['plt_name'] = $name[3];
                 }
             }
             if ($inv['plt_name'] == $inv['wep_name']) {
                 $invrow->addAttribute('characterID', 0);
                 $invrow->addAttribute('characterName', "");
                 $invrow->addAttribute('weaponTypeID', 0);
                 $invrow->addAttribute('shipTypeID', $inv['ind_wep_id']);
             } else {
                 $invrow->addAttribute('characterID', $inv['plt_externalid']);
                 $invrow->addAttribute('characterName', $inv['plt_name']);
                 $invrow->addAttribute('weaponTypeID', $inv['ind_wep_id']);
                 $invrow->addAttribute('shipTypeID', $inv['ind_shp_id']);
             }
             $invrow->addAttribute('corporationID', $inv['crp_external_id']);
             $invrow->addAttribute('corporationName', $inv['crp_name']);
             $invAlliance = Alliance::getByID($inv['ind_all_id']);
             if ($invAlliance->isFaction()) {
                 $invrow->addAttribute('allianceID', 0);
                 $invrow->addAttribute('allianceName', '');
                 $invrow->addAttribute('factionID', $invAlliance->getFactionID());
                 $invrow->addAttribute('factionName', $invAlliance->getName());
             } else {
                 if (strcasecmp($invAlliance->getName(), "None") == 0) {
                     $invrow->addAttribute('allianceID', 0);
                     $invrow->addAttribute('allianceName', "");
                 } else {
                     $invrow->addAttribute('allianceID', $invAlliance->getExternalID());
                     $invrow->addAttribute('allianceName', $invAlliance->getName());
                 }
                 $invrow->addAttribute('factionID', 0);
                 $invrow->addAttribute('factionName', '');
             }
             $invrow->addAttribute('securityStatus', number_format($inv['ind_sec_status'], 1));
             $invrow->addAttribute('damageDone', $inv['ind_dmgdone']);
             if ($inv['plt_id'] == $kill->getFBPilotID()) {
                 $final = 1;
             } else {
                 $final = 0;
             }
             $invrow->addAttribute('finalBlow', $final);
         }
         $sql = "SELECT * FROM kb3_items_destroyed WHERE itd_kll_id = " . $kill->getID();
         $qry->execute($sql);
         $qry2 = DBFactory::getDBQuery();
         $sql = "SELECT * FROM kb3_items_dropped WHERE itd_kll_id = " . $kill->getID();
         $qry2->execute($sql);
         if ($qry->recordCount() || $qry2->recordCount()) {
             $items = $row->addChild('rowset');
             $items->addAttribute('name', 'items');
             $items->addAttribute('columns', 'typeID,flag,qtyDropped,qtyDestroyed, singleton');
             while ($iRow = $qry->getRow()) {
                 $itemRow = $items->addChild('row');
                 $itemRow->addAttribute('typeID', $iRow['itd_itm_id']);
                 $itemRow->addAttribute('flag', $iRow['itd_itl_id']);
                 if ($iRow['itd_itl_id'] == -1) {
                     $itemRow->addAttribute('singleton', 2);
                 } else {
                     $itemRow->addAttribute('singleton', 0);
                 }
                 $itemRow->addAttribute('qtyDropped', 0);
                 $itemRow->addAttribute('qtyDestroyed', $iRow['itd_quantity']);
             }
             while ($iRow = $qry2->getRow()) {
                 $itemRow = $items->addChild('row');
                 $itemRow->addAttribute('typeID', $iRow['itd_itm_id']);
                 $itemRow->addAttribute('flag', $iRow['itd_itl_id']);
                 if ($iRow['itd_itl_id'] == -1) {
                     $itemRow->addAttribute('singleton', 2);
                 } else {
                     $itemRow->addAttribute('singleton', 0);
                 }
                 $itemRow->addAttribute('qtyDropped', $iRow['itd_quantity']);
                 $itemRow->addAttribute('qtyDestroyed', 0);
             }
         }
         if (config::get('km_cache_enabled')) {
             CacheHandler::put($kill->getID() . ".xml", $row->asXML(), 'mails');
         }
         $timing .= $kill->getID() . ": " . (microtime(true) - $starttime) . "<br />";
     }
     $sxe->addChild('cachedUntil', $date);
     return $sxe->asXML();
 }
Exemplo n.º 2
0
 /**
  * Really add the kill.
  * @param integer $id If set, use the given id to post this kill.
  * @return integer
  */
 protected function realadd($id = null)
 {
     if ($this->timestamp == "" || !$this->getVictim()->getID() || !$this->victimship->getName() || !$this->solarsystem->getID() || !$this->victimallianceid || !$this->victimcorpid || !$this->getFBPilotID()) {
         return 0;
     }
     // TODO: Redo accounting for ammo (see kill_detail).
     //		// Check slot counts.
     //		$locations = array();
     //		foreach ($this->droppeditems_ as $dest) {
     //			$locations[$dest->getLocationID()] += $dest->getQuantity();
     //		}
     //		foreach ($this->destroyeditems_ as $dest) {
     //			$locations[$dest->getLocationID()] += $dest->getQuantity();
     //		}
     //		$dogma = Cacheable::factory('dogma', $this->victimship->getID());
     //		$lowcount = (int)$dogma->attrib['lowSlots']['value'];
     //		$medcount = (int)$dogma->attrib['medSlots']['value'];
     //		$hicount = (int)$dogma->attrib['hiSlots']['value'];
     //		// Is there anything flyable that has no rig slots?
     //		$rigcount = (int)($dogma->attrib['rigSlots']['value'] ?
     //				$dogma->attrib['rigSlots']['value'] : 3);
     //		$subcount = 5;
     //		if ($lowcount
     //				&& ($locations[1] > $hicount
     //				|| $locations[2] > $medcount
     //				||  $locations[3] > $lowcount
     //				|| $locations[5] > $rigcount)
     //				) {
     //			return 0;
     //		} else if ((!$lowcount && $locations[7])
     //				&& ($locations[7] > $subcount
     //				|| $locations[5] > $rigcount)
     //				) {
     //			return 0;
     //		}
     if ($id == null) {
         $qid = 'null';
     } else {
         $qid = $id;
     }
     if (!$this->dmgtaken) {
         $this->dmgtaken = 0;
     }
     $qry = DBFactory::getDBQuery();
     $sql = "INSERT INTO kb3_kills\n            (kll_id , kll_timestamp , kll_victim_id , kll_all_id , kll_crp_id , kll_ship_id , kll_system_id , kll_fb_plt_id , kll_td_plt_id , kll_points , kll_dmgtaken, kll_external_id, kll_isk_loss, kll_isk_loot)\n            VALUES (" . $qid . ",\n\t\t\tdate_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'),\n            " . $this->victimid . ",\n            " . $this->victimallianceid . ",\n            " . $this->victimcorpid . ",\n            " . $this->victimship->getID() . ",\n            " . $this->solarsystem->getID() . ",\n            " . $this->getFBPilotID() . ",\n\t\t\t" . $this->getTDPilotID() . ",\n            " . $this->calculateKillPoints() . ",\n            " . $this->dmgtaken . ", ";
     if ($this->externalid) {
         $sql .= $this->externalid . ", ";
     } else {
         $sql .= "NULL, ";
     }
     $sql .= $this->getISKLoss() . ", ";
     $sql .= $this->getISKLoot() . " )";
     $qry->autocommit(false);
     if (!$qry->execute($sql)) {
         return $this->rollback($qry);
     }
     if ($id) {
         $this->id = $id;
     } else {
         $this->id = $qry->getInsertID();
     }
     if (!$this->id) {
         return $this->rollback($qry);
     }
     // involved
     $order = 0;
     $invall = array();
     $invcrp = array();
     $involveddsql = 'insert into kb3_inv_detail
                 (ind_kll_id, ind_timestamp, ind_plt_id, ind_sec_status, ind_all_id, ind_crp_id, ind_shp_id, ind_wep_id, ind_order, ind_dmgdone )
                 values ';
     $involvedasql = 'insert into kb3_inv_all
                 (ina_kll_id, ina_all_id, ina_timestamp) values ';
     $involvedcsql = 'insert into kb3_inv_crp
                 (inc_kll_id, inc_crp_id, inc_timestamp) values ';
     $notfirstd = false;
     $notfirsta = false;
     $notfirstc = false;
     // Make sure involved parties are ordered by damage done.
     usort($this->involvedparties_, array('Kill', 'involvedComparator'));
     foreach ($this->involvedparties_ as $inv) {
         $ship = $inv->getShip();
         $weapon = $inv->getWeapon();
         if (!$inv->getPilotID() || !$inv->getAllianceID() || !$inv->getCorpID() || !$ship->getName() || !$weapon->getID()) {
             return $this->rollback();
         }
         if ($notfirstd) {
             $involveddsql .= ", ";
         }
         $involveddsql .= "( " . $this->getID() . ", date_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'), " . $inv->getPilotID() . ", '" . $inv->getSecStatus() . "', " . $inv->getAllianceID() . ", " . $inv->getCorpID() . ", " . $ship->getID() . ", " . $weapon->getID() . ", " . $order++ . ", " . $inv->getDamageDone() . ")";
         $notfirstd = true;
         if (!in_array($inv->getAllianceID(), $invall)) {
             if ($notfirsta) {
                 $involvedasql .= ", ";
             }
             $involvedasql .= "( " . $this->getID() . ", " . $inv->getAllianceID() . ", date_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'))";
             $notfirsta = true;
             $invall[] = $inv->getAllianceID();
         }
         if (!in_array($inv->getCorpID(), $invcrp)) {
             if ($notfirstc) {
                 $involvedcsql .= ", ";
             }
             $involvedcsql .= "( " . $this->getID() . ", " . $inv->getCorpID() . ", date_format('" . $this->timestamp . "', '%Y.%m.%d %H:%i:%s'))";
             $notfirstc = true;
             $invcrp[] = $inv->getCorpID();
         }
     }
     if ($notfirstd && !$qry->execute($involveddsql)) {
         return $this->rollback($qry);
     }
     if ($notfirsta && !$qry->execute($involvedasql)) {
         return $this->rollback($qry);
     }
     if ($notfirstc && !$qry->execute($involvedcsql)) {
         return $this->rollback($qry);
     }
     // destroyed
     $notfirstitd = false;
     $itdsql = "insert into kb3_items_destroyed (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id) values ";
     foreach ($this->destroyeditems_ as $dest) {
         $item = $dest->getItem();
         $loc_id = $dest->getLocationID();
         if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id)) {
             trigger_error('error with destroyed item.', E_USER_WARNING);
             var_dump($dest);
             exit;
             continue;
         }
         if ($notfirstitd) {
             $itdsql .= ", ";
         }
         $itdsql .= "( " . $this->getID() . ", " . $item->getID() . ", " . $dest->getQuantity() . ", " . $loc_id . " )";
         $notfirstitd = true;
     }
     if ($notfirstitd && !$qry->execute($itdsql)) {
         return $this->rollback($qry);
     }
     // dropped
     $notfirstitd = false;
     $itdsql = "insert into kb3_items_dropped (itd_kll_id, itd_itm_id, itd_quantity, itd_itl_id) values ";
     foreach ($this->droppeditems_ as $dest) {
         $item = $dest->getItem();
         $loc_id = $dest->getLocationID();
         if (!is_numeric($this->getID()) || !is_numeric($item->getID()) || !is_numeric($dest->getQuantity()) || !is_numeric($loc_id)) {
             trigger_error('error with dropped item.', E_USER_WARNING);
             var_dump($dest);
             exit;
             continue;
         }
         if ($notfirstitd) {
             $itdsql .= ", ";
         }
         $itdsql .= "( " . $this->getID() . ", " . $item->getID() . ", " . $dest->getQuantity() . ", " . $loc_id . " )";
         $notfirstitd = true;
     }
     if ($notfirstitd && !$qry->execute($itdsql)) {
         return $this->rollback($qry);
     }
     $sql = "INSERT INTO kb3_mails (`kll_id`, `kll_timestamp`, `kll_external_id`, `kll_hash`, `kll_modified_time`)" . "VALUES(" . $this->getID() . ", '" . $this->getTimeStamp() . "', ";
     if ($this->externalid) {
         $sql .= $this->externalid . ", ";
     } else {
         $sql .= "NULL, ";
     }
     $sql .= "'" . $qry->escape(IDFeed::getHash($this)) . "', UTC_TIMESTAMP())";
     if (!@$qry->execute($sql)) {
         return $this->rollback($qry);
     }
     //Update cache tables.
     summaryCache::addKill($this);
     $qry->autocommit(true);
     // call the event that we added this mail
     event::call('killmail_added', $this);
     return $this->id;
 }