예제 #1
0
 /**
  * Return the SolarSystem this kill took place in.
  * @return SolarSystem
  */
 function getSystem()
 {
     if (isset($this->solarsystem)) {
         return $this->solarsystem;
     } else {
         $this->solarsystem = SolarSystem::getByID($this->solarsystemid);
     }
     return $this->solarsystem;
 }
예제 #2
0
         $corp = new Corporation($ctrTypeID);
         $name = $corp->getName();
         $typeURL = edkURI::page('corp_detail', $ctrTypeID, 'crp_id');
         break;
     case "alliance":
         $alliance = new Alliance($ctrTypeID);
         $name = $alliance->getName();
         $typeURL = edkURI::page('alliance_detail', $ctrTypeID, 'all_id');
         break;
     case "region":
         $region = new Region($ctrTypeID);
         $name = $region->getName();
         $typeURL = edkURI::page('detail_view', $ctrTypeID, 'region_id');
         break;
     case "system":
         $system = new SolarSystem($ctrTypeID);
         $name = $system->getName();
         $typeURL = edkURI::page('system_detail', $ctrTypeID, 'sys_id');
         break;
 }
 if ($typeURL) {
     $html .= '<tr class=kb-table-row-odd><td class=kb-table-cell><b><a href="' . $typeURL . '">' . $name . '</b></td><td class=kb-table-cell align=center>';
 } else {
     $html .= "<tr class=kb-table-row-odd><td class=kb-table-cell><b>" . $name . "</b></td><td class=kb-table-cell align=center>";
 }
 if ($type == "corp") {
     $html .= "x";
 }
 $html .= "</td><td class=kb-table-cell align=center>";
 if ($type == "alliance") {
     $html .= "x";
예제 #3
0
 function generate()
 {
     global $smarty;
     if ($table = $this->getTableStats()) {
         // filtering
         $solarSystem = SolarSystem::lookup($this->filterSystemName);
         $smarty->assign('contract_getactive', 1);
         $smarty->assign('version', config::get('fleet_battles_mod_version'));
         $stats = array();
         if (!config::get('fleet_battles_mod_cache')) {
             $smarty->assign('caching', 0);
             $stats['tbattles'] = $this->metric_total;
             $stats['ainvolved'] = $this->inv_all_time;
             $stats['akills'] = $this->kll_all_time;
             $stats['alosses'] = $this->lss_all_time;
             $stats['akillisk'] = $this->kll_isk_all_time;
             $stats['alossisk'] = $this->lss_isk_all_time;
         } else {
             $smarty->assign('caching', 1);
             $statq = DBFactory::getDBQuery();
             $whereSql = "";
             if ($this->isFiltered) {
                 $filterTerms = $this->getFilterArgumentsWhereSql();
                 // build filter-string
                 if (!empty($filterTerms)) {
                     $whereSql = "WHERE " . implode(" AND ", $filterTerms);
                 }
             }
             $statsql = "SELECT \n                                                    COUNT(*) as tbattles, SUM(involved) as ainvolved, SUM(losses) as alosses, SUM(kills) as akills, SUM(killisk) as akillisk, SUM(lossisk) as alossisk, SUM(ownersInvolved) as ainvolvedowners\n                                                FROM kb3_battles_cache bc\n                                                    INNER JOIN kb3_systems sys ON sys.sys_name = bc.system\n                                                    INNER JOIN kb3_constellations con ON con.con_id = sys.sys_con_id\n                                                    INNER JOIN kb3_regions reg ON reg.reg_id = con.con_reg_id\n                                                {$whereSql}";
             $statq->execute($statsql);
             $stats = $statq->getRow();
         }
         $smarty->assign('tbattles', $stats['tbattles']);
         $smarty->assign('ainvolved', $stats['ainvolved'] / $stats['tbattles']);
         $smarty->assign('akills', $stats['akills'] / $stats['tbattles']);
         $smarty->assign('alosses', $stats['alosses'] / $stats['tbattles']);
         $smarty->assign('ainvolvedowners', $stats['ainvolvedowners'] / $stats['tbattles']);
         $stats['aefficiency'] = round($stats['akillisk'] / ($stats['akillisk'] + $stats['alossisk']) * 100, 2);
         $stats['abar'] = new BarGraph($stats['aefficiency'], 100, 75);
         $smarty->assign('abar', $stats['abar']->generate());
         $smarty->assign('aefficiency', $stats['aefficiency']);
         // filter
         $smarty->assign("filterSystem", $this->filterSystemName);
         $smarty->assign("filterRegionId", $this->filterRegionId);
         $smarty->assign("filterMonthSelected", $this->filterMonth);
         $smarty->assign("filterKillsComparatorSelected", $this->filterKillsComparator);
         $smarty->assign("filterKillsCount", $this->filterKillsCount);
         $smarty->assign("filterLossesComparatorSelected", $this->filterLossesComparator);
         $smarty->assign("filterLossesCount", $this->filterLossesCount);
         $smarty->assign("filterEfficiencyComparatorSelected", $this->filterEfficiencyComparator);
         $smarty->assign("filterEfficiencyCount", $this->filterEfficiencyCount);
         $smarty->assign("filterInvolvedOwnersComparatorSelected", $this->filterInvolvedOwnersComparator);
         $smarty->assign("filterInvolvedOwnersCount", $this->filterInvolvedOwnersCount);
         $smarty->assign("filterRegions", array_merge(array(array("name" => "All", "id" => -1)), $this->getRegions()));
         $smarty->assign("filterMonths", array_merge(array(array("name" => "All", "month" => "1-1")), $this->getMonths()));
         $smarty->assign("filterMonths", array_merge(array(array("name" => "All", "month" => "1-1")), $this->getMonths()));
         $filterKillsCompatators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $filterLossesComparators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $filterEfficiencyComparators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $filterInvolvedOwnersComparators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $smarty->assign("filterKillsComparators", $filterKillsCompatators);
         $smarty->assign("filterLossesComparators", $filterLossesComparators);
         $smarty->assign("filterEfficiencyComparators", $filterEfficiencyComparators);
         $smarty->assign("filterInvolvedOwnersComparators", $filterInvolvedOwnersComparators);
         if (config::get('fleet_battles_mod_displaymetrics')) {
             $smarty->assign('minkills', config::get('fleet_battles_mod_minkills'));
             $smarty->assign('minisk', config::get('fleet_battles_mod_minisk'));
             $smarty->assign('maxtime', config::get('fleet_battles_mod_maxtime'));
         }
         if (config::get('fleet_battles_mod_cache') && !$this->isFiltered) {
             // paginate
             if (is_numeric($this->poffset_) && is_numeric($this->plimit_) && $this->plimit_ > 0) {
                 $table = array_slice($table, $this->poffset_, $this->plimit_);
             }
         }
         $smarty->assign_by_ref('battles', $table);
         return $smarty->fetch(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'battlelisttable_filter.tpl') . $smarty->fetch(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'battlelisttable.tpl');
     } else {
         $smarty->assign('tbattles', 0);
         $smarty->assign('ainvolved', 0);
         $smarty->assign('akills', 0);
         $smarty->assign('alosses', 0);
         $smarty->assign('ainvolvedowners', 0);
         $stats['aefficiency'] = 0;
         $stats['abar'] = new BarGraph(0, 100, 75);
         $smarty->assign('abar', $stats['abar']->generate());
         $smarty->assign('aefficiency', 0);
         $smarty->assign('battles', array());
         // filter
         $smarty->assign("filterSystem", $this->filterSystemName);
         $smarty->assign("filterRegionId", $this->filterRegionId);
         $smarty->assign("filterMonthSelected", $this->filterMonth);
         $smarty->assign("filterKillsComparatorSelected", $this->filterKillsComparator);
         $smarty->assign("filterKillsCount", $this->filterKillsCount);
         $smarty->assign("filterLossesComparatorSelected", $this->filterLossesComparator);
         $smarty->assign("filterLossesCount", $this->filterLossesCount);
         $smarty->assign("filterEfficiencyComparatorSelected", $this->filterEfficiencyComparator);
         $smarty->assign("filterEfficiencyCount", $this->filterEfficiencyCount);
         $smarty->assign("filterInvolvedOwnersComparatorSelected", $this->filterInvolvedOwnersComparator);
         $smarty->assign("filterInvolvedOwnersCount", $this->filterInvolvedOwnersCount);
         $smarty->assign("filterRegions", array_merge(array(array("name" => "All", "id" => -1)), $this->getRegions()));
         $smarty->assign("filterMonths", array_merge(array(array("name" => "All", "month" => "1-1")), $this->getMonths()));
         $smarty->assign("filterMonths", array_merge(array(array("name" => "All", "month" => "1-1")), $this->getMonths()));
         $filterKillsCompatators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $filterLossesComparators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $filterEfficiencyComparators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $filterInvolvedOwnersComparators = array(array("name" => "gt", "symbol" => ">="), array("name" => "lt", "symbol" => "<="));
         $smarty->assign("filterKillsComparators", $filterKillsCompatators);
         $smarty->assign("filterLossesComparators", $filterLossesComparators);
         $smarty->assign("filterEfficiencyComparators", $filterEfficiencyComparators);
         $smarty->assign("filterInvolvedOwnersComparators", $filterInvolvedOwnersComparators);
         return $smarty->fetch(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'battlelisttable_filter.tpl') . $smarty->fetch(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'template' . DIRECTORY_SEPARATOR . 'battlelisttable.tpl');
     }
 }
예제 #4
0
 /**
  * @param SimpleXMLElement $row The row for a single kill.
  */
 private function processKill($row)
 {
     $skip = false;
     $dup = false;
     $errorstring = "";
     $internalID = (int) $row['killInternalID'];
     $externalID = (int) $row['killID'];
     $id = 0;
     if (config::get('filter_apply') && config::get('filter_date') > strtotime(strval($row['killTime']))) {
         $skip = true;
     } else {
         $kill = new Kill();
         if ($externalID) {
             $kill->setExternalID($externalID);
             $id = $kill->getDupe();
             //speedy dup check based on external id only
             if ($id > 0) {
                 //duplicate found
                 $qry = DBFactory::getDBQuery(true);
                 $qry->execute("INSERT IGNORE INTO kb3_mails (`kll_id`," . " `kll_timestamp`, `kll_external_id`, `kll_modified_time`)" . "VALUES({$id}, '" . $kill->getTimeStamp() . "', {$externalID},  UTC_TIMESTAMP())");
                 $qry->execute("UPDATE kb3_kills SET kb3_kills.kll_external_id = {$externalID} WHERE kb3_kills.kll_id = {$id} AND kb3_kills.kll_external_id IS NULL");
                 $dup = true;
             }
         }
         if (!$dup) {
             $kill->setTimeStamp(strval($row['killTime']));
             $sys = SolarSystem::getByID((int) $row['solarSystemID']);
             if (!$sys->getName()) {
                 $errorstring .= " Invalid solar system";
                 $skip = true;
             }
             $kill->setSolarSystem($sys);
             if (!$this->processVictim($row, $kill, strval($row['killTime']))) {
                 $errorstring .= " Invalid victim.";
                 $skip = true;
             }
             if (!$skip) {
                 //skipping intensive involved party processing
                 $this->npcOnly = true;
                 //there's no real check for this anymore?
                 foreach ($row->rowset[0]->row as $inv) {
                     if (!$this->processInvolved($inv, $kill, strval($row['killTime']))) {
                         $errorstring .= " Invalid involved party.";
                         $skip = true;
                         break;
                     }
                 }
                 // Don't post NPC only kills if configured.
                 if ($this->npcOnly && Config::get('post_no_npc_only')) {
                     $errorstring .= " NPC Only mail.";
                     $skip = true;
                 }
                 if (!$skip) {
                     //skipping intensive items processing
                     if (isset($row->rowset[1]->row[0])) {
                         foreach ($row->rowset[1]->row as $item) {
                             $this->processItem($item, $kill);
                         }
                     }
                     $authorized = false;
                     if (config::get('cfg_allianceid') && in_array($kill->getVictimAllianceID(), config::get('cfg_allianceid'))) {
                         $authorized = true;
                     } else {
                         if (config::get('cfg_corpid') && in_array($kill->getVictimCorpID(), config::get('cfg_corpid'))) {
                             $authorized = true;
                         } else {
                             if (config::get('cfg_pilotid') && in_array($kill->getVictimID(), config::get('cfg_pilotid'))) {
                                 $authorized = true;
                             }
                         }
                     }
                     foreach ($kill->getInvolved() as $inv) {
                         if (config::get('cfg_allianceid') && in_array($inv->getAllianceID(), config::get('cfg_allianceid'))) {
                             $authorized = true;
                         } else {
                             if (config::get('cfg_corpid') && in_array($inv->getCorpID(), config::get('cfg_corpid'))) {
                                 $authorized = true;
                             } else {
                                 if (config::get('cfg_pilotid') && in_array($inv->getPilotID(), config::get('cfg_pilotid'))) {
                                     $authorized = true;
                                 }
                             }
                         }
                     }
                     if (!$authorized) {
                         $skip = true;
                     } else {
                         $id = $kill->add();
                         if ($kill->getDupe(true)) {
                             $dup = true;
                         } else {
                             $this->posted[] = array($externalID, $internalID, $id);
                             // Prepare text for the log.
                             if ($this->url) {
                                 $logaddress = "ID:" . $this->url;
                                 if (strpos($logaddress, "?")) {
                                     $logaddress = substr($logaddress, 0, strpos($logaddress, "?"));
                                 }
                                 if ($kill->getExternalID()) {
                                     $logaddress .= "?a=kill_detail&kll_ext_id=" . $kill->getExternalID();
                                 } else {
                                     if ($internalID) {
                                         $logaddress .= "?a=kill_detail&kll_id=" . $internalID;
                                     }
                                 }
                             } else {
                                 if ($this->name) {
                                     $logaddress = $this->name;
                                     if ($kill->getExternalID()) {
                                         $logaddress .= ":kll_ext_id=" . $kill->getExternalID();
                                     } else {
                                         if ($internalID) {
                                             $logaddress .= ":kll_id=" . $internalID;
                                         }
                                     }
                                 } else {
                                     $logaddress = "ID: local input";
                                 }
                             }
                             logger::logKill($id, $logaddress);
                         }
                     }
                 }
             }
         }
     }
     if ($skip) {
         $this->skipped[] = array($externalID, $internalID, $id);
         if ($errorstring) {
             $errorstring .= " Kill not added. killID =  {$externalID}" . ($internalID ? ", killInternalID = {$internalID}." : ".");
             $this->parsemsg[] = $errorstring;
         }
     }
     if ($dup) {
         $this->duplicate[] = array($externalID, $internalID, $id);
     }
     if ($this->lastReturned < $externalID) {
         $this->lastReturned = $externalID;
     }
     if ($this->lastInternalReturned < $internalID) {
         $this->lastInternalReturned = $internalID;
     }
 }
예제 #5
0
 /**
  * @return string HTML string for the summary overview of the battle.
  */
 public function overview()
 {
     global $smarty;
     $smarty->assignByRef('pilots_a', $this->pilots['a']);
     $smarty->assignByRef('pilots_e', $this->pilots['e']);
     $pod = Ship::getByID(670);
     $smarty->assign('podpic', $pod->getImage(32));
     $smarty->assign('friendlycnt', count($this->pilots['a']));
     $smarty->assign('hostilecnt', count($this->pilots['e']));
     if ($classified) {
         $smarty->assign('system', 'Classified System');
     } else {
         if (!$this->adjacent) {
             $smarty->assign('system', $this->kill->getSolarSystemName());
         } else {
             $sysnames = array();
             foreach ($this->systems as $sys_id) {
                 $system = SolarSystem::getByID($sys_id);
                 $sysnames[] = $system->getName();
             }
             $smarty->assign('system', implode(', ', $sysnames));
         }
     }
     $smarty->assign('firstts', $this->firstts);
     $smarty->assign('lastts', $this->lastts);
     $smarty->assign('killURL', edkURI::page('kill_detail'));
     return $smarty->fetch(get_tpl('kill_related_battle_overview'));
 }
예제 #6
0
 /** 
  * adds meta tags for Twitter Summary Card and OpenGraph tags
  * to the HTML header
  */
 function metaTags()
 {
     $referenceSystem = SolarSystem::getByID(reset($this->systems));
     // meta tag: title
     $metaTagTitle = $referenceSystem->getName() . " | " . $referenceSystem->getRegionName() . " | Battle Report";
     $this->page->addHeader('<meta name="og:title" content="' . $metaTagTitle . '">');
     $this->page->addHeader('<meta name="twitter:title" content="' . $metaTagTitle . '">');
     // build description
     $date = gmdate("Y-m-d", strtotime($this->firstts));
     $startTime = gmdate("H:i", strtotime($this->firstts));
     $endTime = gmdate("H:i", strtotime($this->lastts));
     $totalIskDestroyedM = round(($this->summaryTable->getTotalKillISK() + $this->summaryTable->getTotalLossISK()) / 1000000, 2);
     $metaTagDescription = "Battle Report for " . $referenceSystem->getName() . " (" . $referenceSystem->getRegionName() . ") from " . $date . " (" . $startTime . " - " . $endTime . "): ";
     $metaTagDescription .= "Involved Pilots: " . (count($this->pilots['a']) + count($this->pilots['e'])) . ", Total ISK destroyed: " . $totalIskDestroyedM . "M ISK";
     $this->page->addHeader('<meta name="description" content="' . $metaTagDescription . '">');
     $this->page->addHeader('<meta name="og:description" content="' . $metaTagDescription . '">');
     // meta tag: image
     $this->page->addHeader('<meta name="og:image" content="' . imageURL::getURL('Type', 3802, 64) . '">');
     $this->page->addHeader('<meta name="twitter:image" content="' . imageURL::getURL('Type', 3802, 64) . '">');
     $this->page->addHeader('<meta name="og:site_name" content="EDK - ' . config::get('cfg_kbtitle') . '">');
     // meta tag: URL
     $this->page->addHeader('<meta name="og:url" content="' . edkURI::build(array('kll_id', $this->kll_id, true)) . '">');
     // meta tag: Twitter summary
     $this->page->addHeader('<meta name="twitter:card" content="summary">');
 }
예제 #7
0
 function parse($checkauth = true)
 {
     $qry = DBFactory::getDBQuery();
     $timestamp = substr($this->killmail_, 0, 16);
     $timestamp = str_replace('.', '-', $timestamp);
     //trim out any multiple spaces that may exist -
     //$this->killmail_ = preg_replace('/ +/', ' ', $this->killmail_);
     // header section
     $involvedpos = strpos($this->killmail_, "Involved parties:");
     if ($involvedpos == 0) {
         $this->error("Mail lacks Involved parties header.");
         return 0;
     }
     $header = substr($this->killmail_, 0, $involvedpos);
     $timestamp = substr($header, 0, 16);
     $victim = explode("\n", trim(substr($this->killmail_, 0, $involvedpos)));
     $upper_limit = count($victim);
     $victimname = "Unknown";
     //lovely default values
     $factionname = "None";
     $alliancename = "None";
     $corpname = "Unknown";
     $shipname = "Unknown";
     $systemname = "Unknown";
     $systemsec = "0.0";
     $dmgtaken = '0';
     $this->dmgtaken = '0';
     $pos = 0;
     $moon = "";
     for ($counter = 0; $counter <= $upper_limit; $counter++) {
         if (preg_match("/Victim: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 $victimname = $matches[1];
             }
         } elseif (preg_match("/Corp: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 $corpname = $matches[1];
             }
         } elseif (preg_match("/Alliance: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 $alliancename = $matches[1];
             }
             if ($alliancename == "Unknown") {
                 $alliancename = "None";
             }
         } elseif (preg_match("/Faction: (.*)/", $victim[$counter], $matches)) {
             if (strlen($matches[1]) > 5 && $matches[1] != "Unknown") {
                 //catches faction mails from -A-
                 $factionname = $matches[1];
             } else {
                 $factionname = "None";
             }
         } elseif (preg_match("/Destroyed: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 $shipname = $matches[1];
             }
         } elseif (preg_match("/System: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 //bad assumption here - moon has to come before security.
                 $systemname = $matches[1];
                 if (strcmp($moon, 'Unknown') == 0 && $pos == 1) {
                     $moon = $matches[1];
                     $victimname = $matches[1];
                 }
             }
         } elseif (preg_match("/Security: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 $systemsec = (double) $matches[1];
             }
         } elseif (preg_match("/Damage Taken: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 $dmgtaken = (int) $matches[1];
                 $this->dmgtaken = $dmgtaken;
             }
         } elseif (preg_match("/Moon: (.*)/", $victim[$counter], $matches)) {
             if ($matches[1]) {
                 $moon = $matches[1];
                 $victimname = $matches[1];
                 $pos = 1;
             } else {
                 //if the system is valid, it will pick this up, provided it features after
                 //the moon is listed - which is unlikely unless the mail format
                 //drastically changes... again :)
                 $moon = 'Unknown';
                 $victimname = 'Unknown';
                 $pos = 1;
             }
         }
     }
     //faction warfare stuff
     if (strcasecmp($alliancename, 'None') == 0) {
         $alliancename = $factionname;
     }
     //report the errors for the things that make sense.
     //we need pilot names, corp names, ship types, and the system to be sure
     //the rest aren't required but for completeness, you'd want them in :)
     // Customs Offices don't have names. Hack a fix in by accepting mails with
     // no victim name but that do have a system.
     if (strcmp($victimname, 'Unknown') == 0) {
         if (strcmp($systemname, 'Unknown') == 0) {
             $this->error('Victim has no name.');
             unset($victimname);
             //we unset the variable so that it fails the next check
             $this->error('Killmail lacks solar system information.');
             unset($systemname);
         } else {
             $victimname = $systemname;
         }
     }
     if (strcmp($corpname, 'Unknown') == 0) {
         $this->error('Victim has no corp.');
         unset($corpname);
     }
     if (strcmp($shipname, 'Unknown') == 0) {
         $this->error('Victim has no ship type.');
         unset($shipname);
     }
     if (strcmp($systemname, 'Unknown') == 0) {
         $this->error('Killmail lacks solar system information.');
         unset($systemname);
     }
     if ($pos == 1) {
         $victimname = $moon;
     }
     if (!isset($timestamp) || !isset($factionname) || !isset($alliancename) || !isset($corpname) || !isset($victimname) || !isset($shipname) || !isset($systemname) || !isset($systemsec)) {
         return 0;
     }
     if ($checkauth) {
         $authorized = false;
     } else {
         $authorized = true;
     }
     // populate/update database
     $alliance = $this->fetchAlliance($alliancename);
     $corp = $this->fetchCorp($corpname, $alliance, $timestamp);
     $victim = $this->fetchPilot($victimname, $corp, $timestamp);
     $system = SolarSystem::lookup($systemname);
     if (!$system || !$system->getID()) {
         $this->error('System not found.', $systemname);
         $system = new SolarSystem();
     }
     $ship = Ship::lookup($shipname);
     if (!$ship || !$ship->getID()) {
         $this->error('Ship not found.', $shipname);
         $ship = new Ship();
     }
     $kill = new Kill();
     if ($this->externalID) {
         $kill->setExternalID($this->externalID);
     }
     $kill->setTimeStamp($timestamp);
     $kill->setVictim($victim);
     $kill->setVictimID($victim->getID());
     $kill->setVictimCorpID($corp->getID());
     $kill->setVictimAllianceID($alliance->getID());
     $kill->setVictimShip($ship);
     $kill->setSolarSystem($system);
     if ($dmgtaken) {
         $kill->set('dmgtaken', $dmgtaken);
     }
     if (config::get('cfg_allianceid') && in_array($alliance->getID(), config::get('cfg_allianceid'))) {
         $authorized = true;
     } elseif (config::get('cfg_corpid') && in_array($corp->getID(), config::get('cfg_corpid'))) {
         $authorized = true;
     } elseif (config::get('cfg_pilotid') && in_array($victim->getID(), config::get('cfg_pilotid'))) {
         $authorized = true;
     }
     // involved parties section
     $end = strpos($this->killmail_, "Destroyed items:");
     if ($end == 0) {
         $end = strpos($this->killmail_, "Dropped items:");
         if ($end == 0) {
             //try to parse to the end of the mail in the event sections are missing
             $end = strlen($this->killmail_);
         }
     }
     $involved = explode("\n", trim(substr($this->killmail_, strpos($this->killmail_, "Involved parties:") + 17, $end - (strpos($this->killmail_, "Involved parties:") + 17))));
     $ipilot_count = 0;
     //allows us to be a bit more specific when errors strike
     $i = 0;
     $topdamage = 0;
     $order = 0;
     while ($i < count($involved)) {
         $iparts = count($involved);
         $finalblow = 0;
         while ($i < $iparts) {
             $ipilot_count++;
             $ipname = "Unknown";
             $ianame = "None";
             $ifname = "None";
             $icname = "None";
             $isname = "Unknown";
             $iwname = "Unknown";
             $idmgdone = '0';
             $secstatus = "0.0";
             while ($involved[$i] == '') {
                 //compensates for multiple blank lines between involved parties
                 $i++;
                 if ($i > count($involved)) {
                     $this->error("Involved parties section prematurely ends.");
                     return 0;
                 }
             }
             for ($counter = $i; $counter <= $iparts; $counter++) {
                 if (preg_match("/Name: (.*)/", $involved[$counter], $matches)) {
                     if ($matches[1]) {
                         if (stristr($involved[$counter], '/')) {
                             $slash = strpos($involved[$counter], '/');
                             $name = trim(substr($involved[$counter], 5, $slash - 5));
                             $corporation = trim(substr($involved[$counter], $slash + 1, strlen($involved[$counter]) - $slash + 1));
                             //now if the corp bit has final blow info, note it
                             preg_match("/(.*) \\(laid the final blow\\)/", $corporation, $matched);
                             if ($matched[1]) {
                                 $finalblow = 1;
                                 $iwname = $name;
                                 $end = strpos($corporation, '(') - 1;
                                 $corporation = substr($corporation, 0, $end);
                             } else {
                                 $finalblow = 0;
                                 $iwname = $name;
                             }
                             //alliance lookup for warp disruptors - normal NPCs aren't to be bundled in
                             $crp = $this->fetchCorp($corporation);
                             if ($crp && $crp->getExternalID(true) > 0) {
                                 if ($crp->fetchCorp()) {
                                     $al = $crp->getAlliance();
                                     $alName = $al->getName();
                                     if (trim($alName) != "") {
                                         $ianame = $al->getName();
                                     }
                                 }
                                 // else check db for kills with that corp at the same time?
                             }
                             $ipname = $name;
                             $icname = $corporation;
                         } else {
                             $ipname = $matches[1];
                             preg_match("/(.*)\\s*\\(laid the final blow\\)/", $ipname, $matches);
                             if (isset($matches[1])) {
                                 $ipname = trim($matches[1]);
                                 $finalblow = 1;
                             } else {
                                 $finalblow = 0;
                             }
                         }
                     }
                 } else {
                     if (preg_match("/Alliance: (.*)/", $involved[$counter], $matches)) {
                         if ($matches[1]) {
                             $ianame = $matches[1];
                         }
                         if ($ianame == "Unknown") {
                             $ianame = "None";
                         }
                     } else {
                         if (preg_match("/Faction: (.*)/", $involved[$counter], $matches)) {
                             if (strlen($matches[1]) > 5 && $matches[1] != "Unknown") {
                                 //catches faction mails from -A-
                                 $ifname = $matches[1];
                             } else {
                                 $ifname = "NONE";
                             }
                         } else {
                             if (preg_match("/Corp: (.*)/", $involved[$counter], $matches)) {
                                 if ($matches[1]) {
                                     $icname = $matches[1];
                                 }
                             } else {
                                 if (preg_match("/Ship: (.*)/", $involved[$counter], $matches)) {
                                     if ($matches[1]) {
                                         $isname = $matches[1];
                                     }
                                 } else {
                                     if (preg_match("/Weapon: (.*)/", $involved[$counter], $matches)) {
                                         if ($matches[1]) {
                                             $iwname = $matches[1];
                                         }
                                     } else {
                                         if (preg_match("/Security: (.*)/", $involved[$counter], $matches)) {
                                             if ($matches[1]) {
                                                 $secstatus = (double) $matches[1];
                                             }
                                         } else {
                                             if (preg_match("/Damage Done: (.*)/", $involved[$counter], $matches)) {
                                                 if ($matches[1]) {
                                                     $idmgdone = (int) $matches[1];
                                                 }
                                                 if ($idmgdone > $topdamage) {
                                                     $topdamage = $idmgdone;
                                                 }
                                             } else {
                                                 if ($involved[$counter] == '') {
                                                     //allows us to process the involved party. This is the empty line after the
                                                     //involved party section
                                                     $counter++;
                                                     $i = $counter;
                                                     break;
                                                 } else {
                                                     //skip over this entry, it could read anything, we don't care. Handy if/when
                                                     //new mail fields get added and we aren't handling them yet.
                                                     $counter++;
                                                     $i = $counter;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 if ($this->needs_final_blow_) {
                     $finalblow = 1;
                     $this->needs_final_blow_ = 0;
                 }
             }
             // Faction Warfare stuff
             if (strcasecmp($ianame, "None") == 0) {
                 $ianame = $ifname;
             }
             // end faction warfare stuff
             $ialliance = $this->fetchAlliance($ianame);
             if (strcmp($icname, 'None') == 0) {
                 //don't add corp, because pilots have to be in corps.
                 $this->error('Involved party has no corp. (Party No. ' . $ipilot_count . ')');
                 $icorp = new Corporation();
             } else {
                 $icorp = $this->fetchCorp($icname, $ialliance, $kill->getTimeStamp());
             }
             if (preg_match("/^(Mobile \\w+ Warp|\\w+ Control Tower( \\w+)?)/", $iwname)) {
                 //for involved parties parsed that lack a pilot, but are actually POS or mobile warp disruptors
                 $ipname = $icname . ' - ' . $iwname;
                 $ipilot = $this->fetchPilot($ipname, $icorp, $timestamp);
             } elseif (strcmp($ipname, 'Unknown') == 0 || empty($ipname)) {
                 $ipilot = new Pilot();
                 $this->error('Involved party has no name. (Party No. ' . $ipilot_count . ')');
             } else {
                 //don't add pilot if the pilot's unknown or dud
                 $ipilot = $this->fetchPilot($ipname, $icorp, $timestamp);
             }
             $iship = Ship::lookup($isname);
             if (!$iship || !$iship->getName()) {
                 $this->error('Ship not found.', $isname);
             }
             if (strcmp($iwname, 'Unknown') == 0 && $iship && $iship->getID()) {
                 $iwname = $iship->getName();
             }
             $iweapon = Item::lookup($iwname);
             if (strcmp($iwname, 'Unknown') == 0) {
                 $this->error('No weapon found for pilot "' . $ipname . '"');
                 $iweapon = new Item();
             } else {
                 if (!$iweapon || !$iweapon->getID()) {
                     $this->error('Weapon not found.', $iwname);
                     $iweapon = new Item();
                 }
             }
             if (config::get('cfg_allianceid') && in_array($ialliance->getID(), config::get('cfg_allianceid'))) {
                 $authorized = true;
             } elseif (config::get('cfg_corpid') && in_array($icorp->getID(), config::get('cfg_corpid'))) {
                 $authorized = true;
             } elseif (config::get('cfg_pilotid') && in_array($ipilot->getID(), config::get('cfg_pilotid'))) {
                 $authorized = true;
             }
             if (!$authorized) {
                 if ($string = config::get('post_permission')) {
                     if ($string == 'all') {
                         $authorized = true;
                     } else {
                         $tmp = explode(',', $string);
                         foreach ($tmp as $item) {
                             if (!$item) {
                                 continue;
                             }
                             $typ = substr($item, 0, 1);
                             $id = substr($item, 1);
                             if ($typ == 'a') {
                                 if ($ialliance->getID() == $id || $kill->getVictimAllianceID() == $id) {
                                     $authorized = true;
                                     break;
                                 }
                             } elseif ($typ == 'c') {
                                 if ($icorp->getID() == $id || $kill->getVictimCorpID() == $id) {
                                     $authorized = true;
                                     break;
                                 }
                             } elseif ($typ == 'p') {
                                 if ($ipilot->getID() == $id || $kill->getVictimID() == $id) {
                                     $authorized = true;
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
             $iparty = new InvolvedParty($ipilot->getID(), $icorp->getID(), $ialliance->getID(), $secstatus, $iship->getID(), $iweapon->getID(), $idmgdone);
             $kill->addInvolvedParty($iparty);
             if ($finalblow == 1) {
                 $kill->setFBPilotID($ipilot->getID());
                 $kill->setFBCorpID($icorp->getID());
                 $kill->setFBAllianceID($ialliance->getID());
             }
             if ($topdamage == $idmgdone) {
                 $kill->setTDPilotID($ipilot->getID());
                 $kill->setFBCorpID($icorp->getID());
                 $kill->setFBAllianceID($ialliance->getID());
             }
         }
     }
     // Duplicate check does not use items so it's safe to check now
     if ($id = $kill->getDupe()) {
         $this->dupeid_ = $id;
         if ($this->dupeid_ > 0 && $this->externalID) {
             //if this is a duplicate and we have an external id then update the existing kill
             $qry->execute("UPDATE kb3_kills SET kll_external_id = " . $this->externalID . " WHERE kll_id = " . $this->dupeid_);
             $qry->execute("UPDATE kb3_mails SET kll_external_id = " . $this->externalID . ", kll_modified_time = UTC_TIMESTAMP() " . "WHERE kll_id = " . $this->dupeid_ . " AND kll_external_id IS NULL");
         }
         return -1;
     }
     // destroyed items section
     $destroyedpos = strpos($this->killmail_, "Destroyed items:");
     if ($destroyedpos) {
         $endpos = strlen($this->killmail_) - $destroyedpos + 16;
         $pos = strpos($this->killmail_, "Dropped items:");
         if ($pos === false) {
             $pos = strlen($this->killmail_);
         }
         $endpos = $pos - $destroyedpos - 16;
         $destroyed = explode("\n", trim(substr($this->killmail_, $destroyedpos + 16, $endpos)));
         $destroyed_items = $this->scanForItems($destroyed);
         foreach ($destroyed_items as $item) {
             $ditem = new DestroyedItem($item['item'], $item['quantity'], '', $item['location'], true);
             $kill->addDestroyedItem($ditem);
         }
     }
     $startpos = strpos($this->killmail_, "Dropped items:");
     if ($startpos) {
         $endpos = strlen($this->killmail_) - $startpos + 14;
         $dropped = explode("\n", trim(substr($this->killmail_, $startpos + 14, $endpos)));
         $dropped_items = $this->scanForItems($dropped);
         foreach ($dropped_items as $item) {
             $ditem = new DestroyedItem($item['item'], $item['quantity'], '', $item['location'], true);
             $kill->addDroppedItem($ditem);
         }
     }
     if (!$authorized) {
         return -2;
     }
     if ($this->getError()) {
         return 0;
     }
     if ($this->returnmail) {
         return $kill;
     }
     $id = $kill->add();
     if ($id == -2) {
         $this->error("An error has occurred. Please try again later.");
         $id = 0;
     }
     return $id;
 }