Esempio n. 1
0
 /**
  * Releases the lock.
  *
  * @param bool $semRelease If true then will be released the semaphore when counter of lockings equals 0
  */
 private function unlock($semRelease = false)
 {
     if ($this->numberLocks === 0) {
         return;
     }
     $this->numberLocks--;
     if ($this->numberLocks === 0 || $semRelease) {
         $this->semaphore->release();
     }
 }
Esempio n. 2
0
 /**
  * Returns a raw mail, that it gets from the getArray function
  *
  * @static
  * @param $killID the ID of the kill
  * @return string
  */
 public static function getRawMail($killID, $array = array(), $edk = true)
 {
     $cacheName = $killID;
     $sem = Semaphore::fetch($killID);
     if ($edk) {
         $cacheName = $killID . "EDK";
     }
     // Check if the mail has already been generated, then return it from the cache..
     $Cache = Cache::get($cacheName);
     if ($Cache) {
         Semaphore::release($sem);
         return $Cache;
     }
     // Find all groupIDs where they contain Deadspace
     $deadspaceIDs = array();
     $dIDs = Db::query("SELECT groupID FROM ccp_invGroups WHERE groupName LIKE '%deadspace%' OR groupName LIKE 'FW%' OR groupName LIKE 'Asteroid%'");
     foreach ($dIDs as $dd) {
         $deadspaceIDs[] = $dd["groupID"];
     }
     // ADD ALL THE FLAGS!!!!!!!!!!!
     //$flags = array("(Cargo)" => 5, "(Drone Bay)" => 87, "(Implant)" => 89);
     $dbFlags = Db::query("SELECT flagText, flagID FROM ccp_invFlags", array(), 3600);
     $flags = array();
     foreach ($dbFlags as $f) {
         $flags[(int) $f["flagID"]] = $f["flagText"];
     }
     if (!$array) {
         $k = self::getArray($killID);
     } else {
         $k = $array;
     }
     $mail = $k["killTime"] . "\n";
     $mail .= "\n";
     $mail .= "Victim: " . $k["victim"]["characterName"] . "\n";
     $mail .= "Corp: " . $k["victim"]["corporationName"] . "\n";
     if (!isset($k["victim"]["allianceName"]) || $k["victim"]["allianceName"] == "") {
         $k["victim"]["allianceName"] = "None";
     }
     $mail .= "Alliance: " . $k["victim"]["allianceName"] . "\n";
     if (!isset($k["victim"]["factionName"]) || $k["victim"]["factionName"] == "") {
         $k["victim"]["factionName"] = "None";
     }
     $mail .= "Faction: " . $k["victim"]["factionName"] . "\n";
     if (!isset($k["victim"]["shipName"]) || $k["victim"]["shipName"] == "") {
         $k["victim"]["shipName"] = "None";
     }
     $mail .= "Destroyed: " . $k["victim"]["shipName"] . "\n";
     if (!isset($k["solarSystemName"]) || $k["solarSystemName"] == "") {
         $k["solarSystemName"] = "None";
     }
     $mail .= "System: " . $k["solarSystemName"] . "\n";
     if (!isset($k["solarSystemSecurity"]) || $k["solarSystemSecurity"] == "") {
         $k["solarSystemSecurity"] = (int) 0;
     }
     $mail .= "Security: " . $k["solarSystemSecurity"] . "\n";
     if (!isset($k["victim"]["damageTaken"]) || $k["victim"]["damageTaken"] == "") {
         $k["victim"]["damageTaken"] = (int) 0;
     }
     $mail .= "Damage Taken: " . $k["victim"]["damageTaken"] . "\n\n";
     if (isset($k["attackers"])) {
         $mail .= "Involved parties:\n\n";
         foreach ($k["attackers"] as $inv) {
             // find groupID for the ship
             if (!isset($inv["shipName"])) {
                 $inv["shipName"] = "Unknown";
             }
             $groupID = Db::queryField("SELECT groupID FROM ccp_invTypes WHERE typeName LIKE :shipName", "groupID", array(":shipName" => $inv["shipName"]));
             if (in_array($groupID, $deadspaceIDs)) {
                 // shipName isn't set, but it's an npc.. fml..
                 if ($inv["finalBlow"] == 1) {
                     $mail .= "Name: " . $inv["shipName"] . " / " . $inv["corporationName"] . " (laid the final blow)\n";
                 } else {
                     $mail .= "Name: " . $inv["shipName"] . " / " . $inv["corporationName"] . "\n";
                 }
                 $mail .= "Damage Done: " . $inv["damageDone"] . "\n\n";
             } else {
                 if ($inv["finalBlow"] == 1) {
                     $mail .= "Name: " . $inv["characterName"] . " (laid the final blow)\n";
                 } else {
                     if (strlen($inv["characterName"])) {
                         $mail .= "Name: " . $inv["characterName"] . "\n";
                     }
                 }
                 if (strlen($inv["characterName"])) {
                     $mail .= "Security: " . $inv["securityStatus"] . "\n";
                 }
                 $mail .= "Corp: " . $inv["corporationName"] . "\n";
                 if (!isset($inv["allianceName"]) || $inv["allianceName"] == "") {
                     $inv["allianceName"] = "None";
                 }
                 $mail .= "Alliance: " . $inv["allianceName"] . "\n";
                 if (!isset($inv["factionName"]) || $inv["factionName"] == "") {
                     $inv["factionName"] = "None";
                 }
                 $mail .= "Faction: " . $inv["factionName"] . "\n";
                 if (!isset($inv["shipName"]) || $inv["shipName"] == "") {
                     $inv["shipName"] = "None";
                 }
                 $mail .= "Ship: " . $inv["shipName"] . "\n";
                 if (!isset($inv["weaponName"]) || $inv["weaponName"] == "") {
                     $inv["weaponName"] = $inv["shipName"];
                 }
                 $mail .= "Weapon: " . $inv["weaponName"] . "\n";
                 $mail .= "Damage Done: " . $inv["damageDone"] . "\n\n";
             }
         }
     }
     $mail .= "\n";
     $dropped = array();
     $destroyed = array();
     if (isset($k["items"])) {
         foreach ($k["items"] as $itm) {
             // Take the flags we get from $itemToSlot and replace it with the proper flag from the database
             $itm["flagName"] = $flags[$itm["flag"]];
             // create the flag!
             $copy = null;
             if ($itm["singleton"] == 2) {
                 $copy = " (Copy)";
             }
             $edkValidFlags = array("Cargo", "Drone Bay");
             if ($edk && !in_array($itm["flagName"], $edkValidFlags)) {
                 $flagName = null;
             } else {
                 $flagName = " (" . $itm["flagName"] . ")";
             }
             if ($itm["qtyDropped"]) {
                 $line = $itm["typeName"] . ", Qty: " . $itm["qtyDropped"] . $flagName . ($copy ? $copy : null);
                 $dropped[] = $line;
             }
             if ($itm["qtyDestroyed"]) {
                 $line = $itm["typeName"] . ", Qty: " . $itm["qtyDestroyed"] . $flagName . ($copy ? $copy : null);
                 $destroyed[] = $line;
             }
             if (isset($itm["items"])) {
                 foreach ($itm["items"] as $key => $sub) {
                     if ($sub["qtyDropped"]) {
                         $line = $sub["typeName"] . ", Qty: " . $sub["qtyDropped"] . $flagName . ($copy ? $copy : null) . " (In Container)";
                         $dropped[] = $line;
                     }
                     if ($sub["qtyDestroyed"]) {
                         $line = $sub["typeName"] . ", Qty: " . $sub["qtyDestroyed"] . $flagName . ($copy ? $copy : null) . " (In Container)";
                         $destroyed[] = $line;
                     }
                 }
             }
         }
     }
     if ($destroyed) {
         $mail .= "Destroyed items:\n\n";
         foreach ($destroyed as $items) {
             $mail .= $items . "\n";
         }
     }
     $mail .= "\n";
     if ($dropped) {
         $mail .= "Dropped items:\n\n";
         foreach ($dropped as $items) {
             $mail .= $items . "\n";
         }
     }
     // Store the generated mail in cache
     Cache::set($cacheName, $mail, 604800);
     Semaphore::release($sem);
     return $mail;
 }
Esempio n. 3
0
 /**
  * Unlock shared memory
  * 
  * @return boolean    True if unlocked, otherwise false
  */
 public function release()
 {
     return $this->mutex->release();
 }
Esempio n. 4
0
 /**
  * @param $kills
  * @param array $parameters
  * @param $key
  * @return array
  */
 public static function buildSummary(&$kills, $parameters = array(), $key)
 {
     if ($kills == null || !is_array($kills) || sizeof($kills) == 0) {
         return array();
     }
     $sem = Semaphore::fetch($parameters["solarSystemID"]);
     $key = "related:{$key}";
     $mc = Cache::get($key);
     if ($mc) {
         Semaphore::release($sem);
         return $mc;
     }
     $teamAKills = array();
     $teamBKills = array();
     $teamAList = array();
     $teamBList = array();
     $killHash = array();
     self::determineSides($kills, $teamAKills, $teamBKills);
     foreach ($kills as $kill) {
         self::addRelatedPilots($killHash, $kill, $kill["victim"]);
     }
     //$teamAEntities = self::getEntities($teamAKills);
     //$teamBEntities = self::getEntities($teamBKills);
     //$killHash = array_keys($killHash);
     $teamATotals = self::getStatsKillList($teamAKills);
     $teamBTotals = self::getStatsKillList($teamBKills);
     self::hashPilots($teamBKills, $teamBList, $teamAList);
     self::hashPilots($teamAKills, $teamAList, $teamBList);
     $teamATotals["pilotCount"] = self::getUniquePilotCount($teamAList);
     $teamBTotals["pilotCount"] = self::getUniquePilotCount($teamBList);
     foreach ($teamAList as $a => $value) {
         if (in_array($a, array_keys($teamBList))) {
             unset($teamAList[$a]);
         }
     }
     foreach ($teamBList as $b => $value) {
         if (in_array($b, array_keys($teamAList))) {
             unset($teamBList[$b]);
         }
     }
     uksort($teamAList, "self::shipGroupSort");
     uksort($teamBList, "self::shipGroupSort");
     $teamAList = self::addInfo($teamAList, $killHash);
     $teamBList = self::addInfo($teamBList, $killHash);
     $retValue = array("teamA" => array("list" => $teamAList, "kills" => $teamAKills, "totals" => $teamATotals), "teamB" => array("list" => $teamBList, "kills" => $teamBKills, "totals" => $teamBTotals));
     //$teamAScore = log($retValue["teamA"]["totals"]["total_price"] + 1) * (log($retValue["teamA"]["totals"]["total_points"]) + 1);
     //$teamBScore = log($retValue["teamB"]["totals"]["total_price"] + 1) * (log($retValue["teamA"]["totals"]["total_points"]) + 1);
     /*if ($teamBScore > $teamAScore) {
       $temp = $retValue["teamB"];
       $retValue["teamB"] = $retValue["teamA"];
       $retValue["teamA"] = $temp;
       }*/
     Semaphore::release($sem);
     Cache::set($key, $retValue, 900);
     return $retValue;
 }