コード例 #1
0
ファイル: DebugController.php プロジェクト: boweiliu/seat
 public function postQuery()
 {
     // We will validate the key pairs as we dont want to cause unneeded errors
     $validation = new APIKeyValidator();
     if ($validation->passes()) {
         // Bootstrap the Pheal Instance
         BaseApi::bootstrap();
         $pheal = new Pheal(Input::get('keyID'), Input::get('vCode'));
         $pheal->scope = strtolower(Input::get('api'));
         // Prepare an array with the arguements that we have received.
         // first the character
         $arguements = array();
         if (strlen(Input::get('characterid')) > 0) {
             $arguements = array('characterid' => Input::get('characterid'));
         }
         // Next, process the option arrays
         if (strlen(Input::get('optional1')) > 0) {
             $arguements[Input::get('optional1')] = Input::get('optional1value');
         }
         if (strlen(Input::get('optional2')) > 0) {
             $arguements[Input::get('optional2')] = Input::get('optional2value');
         }
         // Compute the array for the view to sample the pheal call that will be made
         $call_sample = array('keyID' => Input::get('keyID'), 'vCode' => Input::get('vCode'), 'scope' => Input::get('api'), 'call' => Input::get('call'), 'args' => $arguements);
         try {
             $method = Input::get('call');
             $response = $pheal->{$method}($arguements);
         } catch (Exception $e) {
             return View::make('debug.ajax.result')->with('call_sample', $call_sample)->with('exception', $e);
         }
         return View::make('debug.ajax.result')->with('call_sample', $call_sample)->with('response', $response->toArray());
     } else {
         return View::make('debug.ajax.result')->withErrors($validation->errors);
     }
 }
コード例 #2
0
ファイル: Api.php プロジェクト: boweiliu/seat
 public static function Update()
 {
     BaseApi::bootstrap();
     $pheal = new Pheal();
     $calllist = $pheal->apiScope->calllist();
     return $calllist;
 }
コード例 #3
0
ファイル: EveAllianceList.php プロジェクト: boweiliu/seat
 public static function Update()
 {
     BaseApi::bootstrap();
     $scope = 'Eve';
     $api = 'AllianceList';
     // Prepare the Pheal instance
     $pheal = new Pheal();
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $alliance_list = $pheal->eveScope->AllianceList();
     } catch (Exception $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $alliance_list->cached_until)) {
         // Really crappy method to do this I guess. But oh well.
         \EveEveAllianceListMemberCorporations::truncate();
         foreach ($alliance_list->alliances as $alliance) {
             $alliance_check = \EveEveAllianceList::where('allianceID', '=', $alliance->allianceID)->first();
             if (!$alliance_check) {
                 $alliance_data = new \EveEveAllianceList();
             } else {
                 $alliance_data = $alliance_check;
             }
             $alliance_data->name = $alliance->name;
             $alliance_data->shortName = $alliance->shortName;
             $alliance_data->allianceID = $alliance->allianceID;
             $alliance_data->executorCorpID = $alliance->executorCorpID;
             $alliance_data->memberCount = $alliance->memberCount;
             $alliance_data->startDate = $alliance->startDate;
             $alliance_data->save();
             $alliance_data->save();
             // And repopulate the current members
             foreach ($alliance->memberCorporations as $corporation) {
                 $member_corp = new \EveEveAllianceListMemberCorporations();
                 $member_corp->corporationID = $corporation->corporationID;
                 $member_corp->startDate = $corporation->startDate;
                 $alliance_data->members()->save($member_corp);
             }
         }
         // Set the cached entry time
         BaseApi::setDbCache($scope, $api, $alliance_list->cached_until);
     }
     return $alliance_list;
 }
コード例 #4
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Account';
     $api = 'AccountStatus';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Need to check that this is not a Corporation Key...
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $status_info = $pheal->accountScope->AccountStatus();
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $status_info->cached_until, $keyID)) {
         $check_status = \EveAccountAccountStatus::where('keyID', '=', $keyID)->first();
         if (!$check_status) {
             $status_data = new \EveAccountAccountStatus();
         } else {
             $status_data = $check_status;
         }
         $status_data->keyID = $keyID;
         $status_data->paidUntil = $status_info->paidUntil;
         $status_data->createDate = $status_info->createDate;
         $status_data->logonCount = $status_info->logonCount;
         $status_data->logonMinutes = $status_info->logonMinutes;
         $status_data->save();
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $status_info->cached_until, $keyID);
     }
     return $status_info;
 }
コード例 #5
0
ファイル: HelperController.php プロジェクト: boweiliu/seat
 public function postResolveNames()
 {
     // Create an array from the ids and make them unique
     $ids = explode(',', Input::get('ids'));
     $ids = array_unique($ids);
     // Set the array that we will eventually return, containing the resolved
     // names
     $return = array();
     // Start by doing a cache lookups for each of the ids to see what we have
     // already resolved
     foreach ($ids as $id) {
         if (Cache::has('nameid_' . $id)) {
             // Retreive the name from the cache and place it in the results.
             $return[$id] = Cache::get('nameid_' . $id);
             // Remove it from the $ids array as we don't need to lookup
             // this one.
             unset($ids[$id]);
         }
     }
     // Check if there is anything left to lookup, and prepare a pheal instance
     // to handle the API call for this
     if (count($ids) > 0) {
         // Get pheal ready
         BaseApi::bootstrap();
         $pheal = new Pheal();
         // Loop over the ids for a max of 30 ids, and resolve the names
         foreach (array_chunk($ids, 15) as $resolvable) {
             // Attempt actual API lookups
             try {
                 $names = $pheal->eveScope->CharacterName(array('ids' => implode(',', $resolvable)));
             } catch (Exception $e) {
                 throw $e;
             }
             // Add the results to the cache and the $return array
             foreach ($names->characters as $lookup_result) {
                 Cache::forever('nameid_' . $lookup_result->characterID, $lookup_result->name);
                 $return[$lookup_result->characterID] = $lookup_result->name;
             }
         }
     }
     // With all the work out of the way, return the $return array as Json
     return Response::json($return);
 }
コード例 #6
0
ファイル: ServerServerStatus.php プロジェクト: boweiliu/seat
 public static function Update()
 {
     BaseApi::bootstrap();
     $scope = 'Server';
     $api = 'ServerStatus';
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope)) {
         $lockhash = BaseApi::lockCall($api, $scope);
     } else {
         return;
     }
     // Do the call
     $pheal = new Pheal();
     try {
         $server_status = $pheal->serverScope->ServerStatus();
     } catch (Exception $e) {
         throw $e;
     }
     if (!BaseApi::checkDbCache($scope, $api, $server_status->cached_until)) {
         // Update the Database
         $existing_status = \EveServerServerStatus::find(1);
         if (isset($existing_status)) {
             // Update the ServerStatus
             $existing_status->currentTime = $server_status->request_time;
             $existing_status->serverOpen = $server_status->serverOpen;
             $existing_status->onlinePlayers = $server_status->onlinePlayers;
             $existing_status->save();
         } else {
             // Create a ServerStatus entry
             \EveServerServerStatus::create(array('currentTime' => $server_status->request_time, 'serverOpen' => $server_status->serverOpen, 'onlinePlayers' => $server_status->onlinePlayers));
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $server_status->cached_until);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $server_status;
 }
コード例 #7
0
ファイル: MapSovereignty.php プロジェクト: boweiliu/seat
 public static function Update()
 {
     BaseApi::bootstrap();
     $scope = 'Map';
     $api = 'Sovereignty';
     // Prepare the Pheal instance
     $pheal = new Pheal();
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $sovereignty = $pheal->mapScope->Sovereignty();
     } catch (Exception $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $sovereignty->cached_until)) {
         // Update the Database while we loop over the solarSystem results
         foreach ($sovereignty->solarSystems as $solarSystem) {
             // Find the system to check if we need to update || insert
             $system = \EveMapSovereignty::where('solarSystemID', '=', $solarSystem->solarSystemID)->first();
             if (!$system) {
                 $system_data = new \EveMapSovereignty();
             } else {
                 $system_data = $system;
             }
             // Update the system
             $system_data->solarSystemID = $solarSystem->solarSystemID;
             $system_data->allianceID = $solarSystem->allianceID;
             $system_data->factionID = $solarSystem->factionID;
             $system_data->solarSystemName = $solarSystem->solarSystemName;
             $system_data->corporationID = $solarSystem->corporationID;
             $system_data->save();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $sovereignty->cached_until);
     }
     return $sovereignty;
 }
コード例 #8
0
 public static function Update()
 {
     BaseApi::bootstrap();
     $scope = 'Eve';
     $api = 'ConquerableStationList';
     // Prepare the Pheal instance
     $pheal = new Pheal();
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $station_list = $pheal->eveScope->ConquerableStationList();
     } catch (Exception $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $station_list->cached_until)) {
         // Update the Database while we loop over the results
         foreach ($station_list->outposts as $outpost) {
             // Check if we need to update || insert
             $outpost_check = \EveEveConquerableStationList::where('stationID', '=', $outpost->stationID)->first();
             if (!$outpost_check) {
                 $outpost_data = new \EveEveConquerableStationList();
             } else {
                 $outpost_data = $outpost_check;
             }
             $outpost_data->stationID = $outpost->stationID;
             $outpost_data->stationName = $outpost->stationName;
             $outpost_data->stationTypeID = $outpost->stationTypeID;
             $outpost_data->solarSystemID = $outpost->solarSystemID;
             $outpost_data->corporationID = $outpost->corporationID;
             $outpost_data->corporationName = $outpost->corporationName;
             $outpost_data->save();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $station_list->cached_until);
     }
     return $station_list;
 }
コード例 #9
0
ファイル: EveRefTypes.php プロジェクト: boweiliu/seat
 public static function Update()
 {
     BaseApi::bootstrap();
     $scope = 'Eve';
     $api = 'RefTypes';
     // Prepare the Pheal instance
     $pheal = new Pheal();
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $ref_types = $pheal->eveScope->RefTypes();
     } catch (Exception $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $ref_types->cached_until)) {
         // Update the Database while we loop over the results
         foreach ($ref_types->refTypes as $ref_type) {
             // Check if we need to update || insert
             $type_check = \EveEveRefTypes::where('refTypeID', '=', $ref_type->refTypeID)->first();
             if (!$type_check) {
                 $type_data = new \EveEveRefTypes();
             } else {
                 $type_data = $type_check;
             }
             // Update the system
             $type_data->refTypeID = $ref_type->refTypeID;
             $type_data->refTypeName = $ref_type->refTypeName;
             $type_data->save();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $ref_types->cached_until);
     }
     return $ref_types;
 }
コード例 #10
0
ファイル: EveErrorList.php プロジェクト: boweiliu/seat
 public static function Update()
 {
     BaseApi::bootstrap();
     $scope = 'Eve';
     $api = 'ErrorList';
     // Prepare the Pheal instance
     $pheal = new Pheal();
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $error_list = $pheal->eveScope->ErrorList();
     } catch (Exception $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $error_list->cached_until)) {
         // Update the Database while we loop over the solarSystem results
         foreach ($error_list->errors as $error) {
             // Find the system to check if we need to update || insert
             $error_check = \EveEveErrorList::where('errorCode', '=', $error->errorCode)->first();
             if (!$error_check) {
                 $error_data = new \EveEveErrorList();
             } else {
                 $error_data = $error_check;
             }
             // Update the system
             $error_data->errorCode = $error->errorCode;
             $error_data->errorText = $error->errorText;
             $error_data->save();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $error_list->cached_until);
     }
     return $error_list;
 }
コード例 #11
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'StarbaseDetail';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // We now need to loop over the starbases that we have for this corporation
     // and update the details as needed.
     foreach (\EveCorporationStarbaseList::where('corporationID', '=', $corporationID)->get() as $starbase) {
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $starbase_detail = $pheal->corpScope->StarbaseDetail(array('characterID' => $characters[0], 'itemID' => $starbase->itemID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // In the odd chance that we get a old/invalid ID, catch only that error
             // else go boom
             if ($e->getCode() == 114) {
                 \Log::error('API Exception caught but continuing. Error: ' . $e->getCode() . ': ' . $e->getMessage(), array('src' => __CLASS__));
                 continue;
             }
             // I suspect that there is a caching specific thing here that I don't understand. I know
             // this is a bad thing, but for now, just continue when this occurs, and write a entry
             // to the application log about it.
             //
             // Error: 221: Illegal page request! Please verify the access granted by the key you are using!
             // ^~~~ this after we just got the starbase list... :(
             if ($e->getCode() == 221) {
                 \Log::error('API Exception caught but continuing. Error: ' . $e->getCode() . ': ' . $e->getMessage(), array('src' => __CLASS__));
                 continue;
             }
             // Lastly, go boom as something out of the ordinary is wrong.
             throw $e;
         } catch (\Pheal\Exceptions\PhealException $e) {
             // Lets add some information to the original exception and raise it
             $new_error = $e->getMessage() . ' - Current starbaseID: ' . $starbase->itemID;
             throw new \Exception($new_error, $e->getCode());
         }
         // Update the details
         $starbase_data = \EveCorporationStarbaseDetail::where('corporationID', '=', $corporationID)->where('itemID', '=', $starbase->itemID)->first();
         if (!$starbase_data) {
             $starbase_data = new \EveCorporationStarbaseDetail();
         }
         $starbase_data->corporationID = $corporationID;
         $starbase_data->itemID = $starbase->itemID;
         // Fromt he outer loop
         $starbase_data->state = $starbase_detail->state;
         $starbase_data->stateTimestamp = $starbase_detail->stateTimestamp;
         $starbase_data->onlineTimestamp = $starbase_detail->onlineTimestamp;
         $starbase_data->usageFlags = $starbase_detail->generalSettings->usageFlags;
         $starbase_data->deployFlags = $starbase_detail->generalSettings->deployFlags;
         $starbase_data->allowCorporationMembers = $starbase_detail->generalSettings->allowCorporationMembers;
         $starbase_data->allowAllianceMembers = $starbase_detail->generalSettings->allowAllianceMembers;
         $starbase_data->useStandingsFrom = $starbase_detail->combatSettings->useStandingsFrom->ownerID;
         $starbase_data->onStandingDrop = $starbase_detail->combatSettings->onStandingDrop->standing;
         $starbase_data->onStatusDropEnabled = $starbase_detail->combatSettings->onStatusDrop->enabled;
         $starbase_data->onStatusDropStanding = $starbase_detail->combatSettings->onStatusDrop->standing;
         $starbase_data->onAggression = $starbase_detail->combatSettings->onAggression->enabled;
         $starbase_data->onCorporationWar = $starbase_detail->combatSettings->onCorporationWar->enabled;
         // Add the fuel to the various fields
         foreach ($starbase_detail->fuel as $fuel) {
             if ($fuel->typeID == 16275) {
                 $starbase_data->strontium = $fuel->quantity;
             }
             // Four different fuel block typeIDs
             // 4051     Caldari Fuel Block
             // 4246     Minmatar Fuel Block
             // 4247     Amarr Fuel Block
             // 4312     Gallente Fuel Block
             if (in_array($fuel->typeID, array('4051', '4246', '4247', '4312'))) {
                 $starbase_data->fuelBlocks = $fuel->quantity;
             }
             // Various starbase charters
             // 24592    Amarr Empire Starbase Charter
             // 24593    Caldari State Starbase Charter
             // 24594    Gallente Federation Starbase Charter
             // 24595    Minmatar Republic Starbase Charter
             // 24596    Khanid Kingdom Starbase Charter
             // 24597    Ammatar Mandate Starbase Charter
             if (in_array($fuel->typeID, array('24592', '24593', '24594', '24595', '24596', '24597'))) {
                 $starbase_data->starbaseCharter = $fuel->quantity;
             }
         }
         $starbase_data->save();
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return null;
 }
コード例 #12
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'MemberMedals';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $medals = $pheal->corpScope->MemberMedals(array('characterID' => $characters[0]));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $medals->cached_until, $corporationID)) {
         foreach ($medals->issuedMedals as $medal) {
             $medal_data = \EveCorporationMemberMedals::where('corporationID', '=', $corporationID)->where('medalID', '=', $medal->medalID)->where('characterID', '=', $medal->characterID)->first();
             if (!$medal_data) {
                 $medal_data = new \EveCorporationMemberMedals();
             }
             $medal_data->corporationID = $corporationID;
             $medal_data->medalID = $medal->medalID;
             $medal_data->characterID = $medal->characterID;
             $medal_data->reason = $medal->reason;
             $medal_data->status = $medal->status;
             $medal_data->issuerID = $medal->issuerID;
             $medal_data->issued = $medal->issued;
             $medal_data->save();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $medals->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $medals;
 }
コード例 #13
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'Notifications';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $notifications = $pheal->charScope->Notifications(array('characterID' => $characterID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // If we cant get account status information, prevent us from calling
             // this API again
             BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
             return;
         } catch (\Pheal\Exceptions\PhealException $e) {
             throw $e;
         }
         // Check if the data in the database is still considered up to date.
         // checkDbCache will return true if this is the case
         if (!BaseApi::checkDbCache($scope, $api, $notifications->cached_until, $characterID)) {
             // Loop over the list we got from the api and update the db,
             // remebering the messageID's for downloading the bodies too
             $texts = array();
             foreach ($notifications->notifications as $notification) {
                 $notification_data = \EveCharacterNotifications::where('characterID', '=', $characterID)->where('notificationID', '=', $notification->notificationID)->first();
                 if (!$notification_data) {
                     $new_notification = new \EveCharacterNotifications();
                     $texts[] = $notification->notificationID;
                     // Record the notificationID to download later
                 } else {
                     // Check if we have the body for this existing message, else
                     // we will add it to the list to download
                     if (!\EveCharacterNotificationTexts::where('notificationID', '=', $notification->notificationID)) {
                         $texts[] = $notification->notificationID;
                     }
                     continue;
                 }
                 $new_notification->characterID = $characterID;
                 $new_notification->notificationID = $notification->notificationID;
                 $new_notification->typeID = $notification->typeID;
                 $new_notification->senderID = $notification->senderID;
                 $new_notification->senderName = $notification->senderName;
                 $new_notification->sentDate = $notification->sentDate;
                 $new_notification->read = $notification->read;
                 $new_notification->save();
             }
             // Split the text we need to download into chunks of 10 each. Pheal-NG will
             // log the whole request as a file name for chaching...
             // which is tooooooo looooooooooooong
             $texts = array_chunk($texts, 10);
             // Iterate over the chunks.
             foreach ($texts as $chunk) {
                 try {
                     $notification_texts = $pheal->charScope->NotificationTexts(array('characterID' => $characterID, 'ids' => implode(',', $chunk)));
                 } catch (\Pheal\Exceptions\PhealException $e) {
                     throw $e;
                 }
                 // Loop over the received texts
                 foreach ($notification_texts->notifications as $text) {
                     // Actually, this check is pretty redundant, so maybe remove it
                     $text_data = \EveCharacterNotificationTexts::where('notificationID', '=', $text->notificationID)->first();
                     if (!$text_data) {
                         $new_text = new \EveCharacterNotificationTexts();
                     } else {
                         continue;
                     }
                     $new_text->notificationID = $text->notificationID;
                     $new_text->text = $text->__toString();
                     $new_text->save();
                 }
             }
             // Update the cached_until time in the database for this api call
             BaseApi::setDbCache($scope, $api, $notifications->cached_until, $characterID);
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $notifications;
 }
コード例 #14
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'AssetList';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $asset_list = $pheal->corpScope->AssetList(array('characterID' => $characters[0]));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $asset_list->cached_until, $corporationID)) {
         // TODO: Look as how we update this. As per https://neweden-dev.com/Character/Asset_List, the itemID
         // may change. So, we cant really just update existing ids. For now, we just trash all and recreate the
         // assets :<
         // Maybe do this in one big transaction? lel
         \EveCorporationAssetList::where('corporationID', '=', $corporationID)->delete();
         \EveCorporationAssetListContents::where('corporationID', '=', $corporationID)->delete();
         // Note about /corp/Locations
         //
         // We will build a list of itemID's to update the location information about
         // while we loop over the assets. This will be stored in location_retreive and
         // processed here [1]
         $location_retreive = array();
         // Populate the assets for this corporation as well as the contents.
         foreach ($asset_list->assets as $asset) {
             // Add the asset to the location retreival array
             $location_retreive[] = $asset->itemID;
             // Process the rest of the database population
             $asset_data = new \EveCorporationAssetList();
             $asset_data->corporationID = $corporationID;
             $asset_data->itemID = $asset->itemID;
             $asset_data->locationID = $asset->locationID;
             $asset_data->typeID = $asset->typeID;
             $asset_data->quantity = $asset->quantity;
             $asset_data->flag = $asset->flag;
             $asset_data->singleton = $asset->singleton;
             $asset_data->save();
             // Process the contents if there are any
             if (isset($asset->contents)) {
                 foreach ($asset->contents as $content) {
                     $content_data = new \EveCorporationAssetListContents();
                     $content_data->corporationID = $corporationID;
                     $content_data->itemID = $asset_data->itemID;
                     $content_data->typeID = $content->typeID;
                     $content_data->quantity = $content->quantity;
                     $content_data->flag = $content->flag;
                     $content_data->singleton = $content->singleton;
                     $content_data->rawQuantity = isset($content->rawQuantity) ? $content->rawQuantity : 0;
                     $asset_data->contents()->save($content_data);
                 }
             }
         }
         // Now empty and process the locations as per [1]
         \EveCorporationAssetListLocations::where('corporationID', '=', $corporationID)->delete();
         $location_retreive = array_chunk($location_retreive, 1);
         // Iterate over the chunks.
         foreach ($location_retreive as $chunk) {
             try {
                 $locations = $pheal->corpScope->Locations(array('characterID' => $characters[0], 'ids' => implode(',', $chunk)));
             } catch (\Pheal\Exceptions\PhealException $e) {
                 // Temp hack to check the asset list thingie
                 // TBH, I am not 100% sure yet why the freaking call would fail for a id we **just**
                 // got from the previous API call...
                 if ($e->getCode() == 135 || $e->getCode() == 221) {
                     // 135 "not the owner" | 221 "illegal page request"
                     continue;
                 } else {
                     throw $e;
                 }
             }
             // Loop over the locations, check their closest celestial
             // and add the data to the database
             foreach ($locations->locations as $location) {
                 $closest_moon = BaseApi::findClosestMoon($location->itemID, $location->x, $location->y, $location->z);
                 $location_data = new \EveCorporationAssetListLocations();
                 $location_data->corporationID = $corporationID;
                 $location_data->itemID = $location->itemID;
                 $location_data->itemName = $location->itemName;
                 $location_data->x = $location->x;
                 $location_data->y = $location->y;
                 $location_data->z = $location->z;
                 $location_data->mapID = $closest_moon['id'];
                 $location_data->mapName = $closest_moon['name'];
                 $location_data->save();
             }
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $asset_list->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $asset_list;
 }
コード例 #15
0
ファイル: SeatDiagnose.php プロジェクト: boweiliu/seat
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     // Start by printing some information about what the version
     $this->info('Running SeAT ' . \Config::get('seat.version') . ' Diagnostics');
     $this->line('');
     // It is important to run the command as the user that the workers are running as.
     // This way, the checks that ensure file permissions are right are executed
     // properly. If this is not the case, notify the user
     $this->comment('If you are not already doing so, it is recommended that you run this as the user the workers are running as.');
     $this->comment('Eg: `sudo -u apache php artisan seat:diagnose`.');
     $this->comment('This helps to check whether the permissions are correct.');
     $this->line('');
     // Go ahead and get the configuration information using
     // the \Config helper and print that
     $this->info('SeAT configuration:');
     if (\Config::get('app.debug')) {
         $this->comment('[warning] Debug Mode On: Yes. It is recommended that you set this to false in app/config/app.php');
     } else {
         $this->line('[ok] Debug Mode On: No');
     }
     $this->line('Url: ' . \Config::get('app.url'));
     $this->line('Failed API limit: ' . \Config::get('seat.ban_limit'));
     $this->line('Ban count time: ' . \Config::get('seat.ban_grace') . ' minutes');
     $this->line('');
     // Check that the log files are writable
     $this->info('Logging:');
     if (is_writable(storage_path() . '/logs/laravel.log')) {
         $this->line('[ok] ' . storage_path() . '/logs/laravel.log is writable.');
     } else {
         $this->error('[error] ' . storage_path() . '/logs/laravel.log is not writable.');
     }
     $this->line('');
     // Grab the database configurations from the config,
     // obviously hashing out the password
     $this->info('Database configuration:');
     $this->line('Database driver: ' . \Config::get('database.default'));
     $this->line('MySQL Host: ' . \Config::get('database.connections.mysql.host'));
     $this->line('MySQL Database: ' . \Config::get('database.connections.mysql.database'));
     $this->line('MySQL Username: '******'database.connections.mysql.username'));
     $this->line('MySQL Password: '******'*', strlen(\Config::get('database.connections.mysql.password'))));
     $this->line('');
     // Test the database connection. An exception will be
     // thrown if this fails, so we can catch it and
     // warn accordingly
     $this->info('Database connection test...');
     try {
         $this->line('[ok] Successfully connected to database `' . \DB::connection()->getDatabaseName() . '` (did not test schema)');
     } catch (\Exception $e) {
         $this->error('[error] Unable to obtain a MySQL connection. The error was: ' . $e->getCode() . ': ' . $e->getMessage());
     }
     $this->line('');
     // Get the Redis cache configuration and print it
     $this->info('Redis configuration:');
     $this->line('Redis Host: ' . \Config::get('database.redis.default.host'));
     $this->line('Redis Port: ' . \Config::get('database.redis.default.port'));
     $this->line('');
     // Test using the Redis cache. Failure should again
     // throw an exception, so catch this also and
     // warn accordingly.
     $this->info('Redis connection test...');
     // Create a random string as the key we will try
     // to read and write
     $key_test = str_random(40);
     try {
         // Make use of the underlying Predis library to
         // connect directly to the Redis cache
         $redis = new \Predis\Client(array('host' => \Config::get('database.redis.default.host'), 'port' => \Config::get('database.redis.default.port')));
         // Set a new key, and modify its expiry
         $redis->set($key_test, \Carbon\Carbon::now());
         $redis->expire($key_test, 10);
         $this->line('[ok] Successfully set the key: ' . $key_test . ' and set it to expire in 10 seconds');
         // Attempt to read the newly place key
         $value_test = $redis->get($key_test);
         $this->line('[ok] Successfully retreived key: ' . $key_test . ' which has value: ' . $value_test);
     } catch (\Exception $e) {
         $this->error('[error] Redis test failed. The last error was: ' . $e->getCode() . ': ' . $e->getMessage());
     }
     $this->line('');
     // Testing Pheal
     $this->info('EVE API call test with phealng...');
     // Bootstrap a new Pheal instance for use
     BaseApi::bootstrap();
     $pheal = new Pheal();
     // Test that Pheal usage is possible by calling the
     // ServerStatus() API
     try {
         $server_status = $pheal->serverScope->ServerStatus();
         $this->line('[ok] Testing the ServerStatus API call returned a response reporting ' . $server_status->onlinePlayers . ' online players, with the result cache expiring ' . \Carbon\Carbon::parse($server_status->cached_until)->diffForHumans());
     } catch (\Exception $e) {
         $this->error('[error] API Call test failed. The last error was: ' . $e->getCode() . ': ' . $e->getMessage());
     }
     $this->line('');
 }
コード例 #16
0
ファイル: CharacterKillMails.php プロジェクト: boweiliu/seat
 public static function Update($keyID, $vCode)
 {
     // To start processing this API Updater, lets take a moment and
     // examine a sample XML for a kill (taken 2014-12-04 15:24:40):
     // <rowset name="kills" key="killID" columns="killID,solarSystemID,killTime,moonID">
     //   <row killID="4" solarSystemID="3" killTime="2013-11-30 14:36:00" moonID="0">
     //     <victim characterID="9" characterName="J" corporationID="9" corporationName="S" allianceID="9" allianceName="I" factionID="0" factionName="" damageTaken="48243" shipTypeID="33475" />
     //     <rowset name="attackers" columns="characterID,characterName,corporationID,corporationName,allianceID,allianceName,factionID,factionName,securityStatus,damageDone,finalBlow,weaponTypeID,shipTypeID">
     //       <row characterID="1" characterName="K" corporationID="8" corporationName="T" allianceID="1" allianceName="T" factionID="0" factionName="" securityStatus="0.88117301707494" damageDone="11610" finalBlow="1" weaponTypeID="2905" shipTypeID="11198" />
     //     </rowset>
     //     <rowset name="items" columns="typeID,flag,qtyDropped,qtyDestroyed,singleton">
     //       <row typeID="15331" flag="5" qtyDropped="5" qtyDestroyed="18" singleton="0" />
     //       <row typeID="2510" flag="5" qtyDropped="100" qtyDestroyed="0" singleton="0" />
     //     </rowset>
     //   </row>
     // </rowset>
     // Based on the above, we can see we have 3 sections that need to be kept up to date.
     // We also need to think about scenarios where we have 2 API's, where the one will
     // reflect a kill as a loss, and the other as a kill. For that reason we keep
     // a seperate table to map characterID<->killID, and then record the kill
     // and all the details seperately. That way, we only store the specific
     // killID and its details once, and it can be called by iether the
     // killer or the loser.
     // It is also possible to do 'Journal Walking' on the killmails, meaning that we can
     // pull all the history as far back as 2560 [1] entries. With that in mind, we
     // will set a MAX_INT value as a starting point, and then grab the fromID in
     // the responses to start the walking backwards while updating the db.
     $row_count = 1000;
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'KillMails';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Here we will start a infinite loop for the Journal Walking to take
         // place. Once we receive less entrues than the expected $row_count
         // we know we reached the end of the walk and can safely break
         // out of the loop. Some database cached_until checks are
         // actually not done here. We are relying entirely on
         // pheal-ng to handle it.
         $first_request = true;
         $from_id = PHP_INT_MAX;
         while (true) {
             // Check if this is the first request. If so, don't use a fromID.
             try {
                 if ($first_request) {
                     $kill_mails = $pheal->charScope->KillMails(array('characterID' => $characterID, 'rowCount' => $row_count));
                     // flip the first_request as those that get processed from here need to be from the `fromID`
                     $first_request = false;
                 } else {
                     $kill_mails = $pheal->charScope->KillMails(array('characterID' => $characterID, 'rowCount' => $row_count, 'fromID' => $from_id));
                 }
             } catch (\Pheal\Exceptions\APIException $e) {
                 // If we cant get account status information, prevent us from calling
                 // this API again
                 BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
                 return;
             } catch (\Pheal\Exceptions\PhealException $e) {
                 throw $e;
             }
             // With $kill_mails now populated, get started in updating the database
             // with all of the information that we now have. While we update the
             // database, we also need to check that we get the lowest possible
             // $from_id (killID) for the Journal Walking to occur
             foreach ($kill_mails->kills as $kill) {
                 // Ensure $from_id is at its lowest
                 $from_id = min($kill->killID, $from_id);
                 // With all of that work done, we can finally get to actually
                 // populating the database with data!
                 // Determine if we already know about this killID for this characterID
                 $character_kill_mail = \EveCharacterKillMails::where('characterID', $characterID)->where('killID', $kill->killID)->first();
                 // If we know about it, assume we have all the details already recorded,
                 // otherwise we will record it
                 if (!$character_kill_mail) {
                     $character_kill_mail = new \EveCharacterKillMails();
                 } else {
                     continue;
                 }
                 $character_kill_mail->characterID = $characterID;
                 $character_kill_mail->killID = $kill->killID;
                 $character_kill_mail->save();
                 // With record of the killmail, check if we have the details recorded
                 // for it. If we do, we assume the attackers and items will be the
                 // same and not need any update
                 $killmail_detail = \EveCharacterKillMailDetail::where('killID', $kill->killID)->first();
                 // The same as the killmail record for a character applies here. If
                 // we already know about it, asssume that it is up to date and
                 // continue with the next killmail.
                 if (!$killmail_detail) {
                     $killmail_detail = new \EveCharacterKillMailDetail();
                 } else {
                     continue;
                 }
                 // Assuming we got all the way here, its safe to assume we want to
                 // record the details for this killmail.
                 $killmail_detail->killID = $kill->killID;
                 $killmail_detail->solarSystemID = $kill->solarSystemID;
                 $killmail_detail->killTime = $kill->killTime;
                 $killmail_detail->moonID = $kill->moonID;
                 $killmail_detail->characterID = $kill->victim->characterID;
                 $killmail_detail->characterName = $kill->victim->characterName;
                 $killmail_detail->corporationID = $kill->victim->corporationID;
                 $killmail_detail->corporationName = $kill->victim->corporationName;
                 $killmail_detail->allianceID = $kill->victim->allianceID;
                 $killmail_detail->allianceName = $kill->victim->allianceName;
                 $killmail_detail->factionID = $kill->victim->factionID;
                 $killmail_detail->factionName = $kill->victim->factionName;
                 $killmail_detail->damageTaken = $kill->victim->damageTaken;
                 $killmail_detail->shipTypeID = $kill->victim->shipTypeID;
                 $killmail_detail->save();
                 // Update the attackers
                 foreach ($kill->attackers as $attacker) {
                     $attacker_information = new \EveCharacterKillMailAttackers();
                     // $attacker_information->killID = $kill->killID;
                     $attacker_information->characterID = $attacker->characterID;
                     $attacker_information->characterName = $attacker->characterName;
                     $attacker_information->corporationID = $attacker->corporationID;
                     $attacker_information->corporationName = $attacker->corporationName;
                     $attacker_information->allianceID = $attacker->allianceID;
                     $attacker_information->allianceName = $attacker->allianceName;
                     $attacker_information->factionID = $attacker->factionID;
                     $attacker_information->factionName = $attacker->factionName;
                     $attacker_information->securityStatus = $attacker->securityStatus;
                     $attacker_information->damageDone = $attacker->damageDone;
                     $attacker_information->finalBlow = $attacker->finalBlow;
                     $attacker_information->weaponTypeID = $attacker->weaponTypeID;
                     $attacker_information->shipTypeID = $attacker->shipTypeID;
                     // Add the attacker information to the killmail
                     $killmail_detail->attackers()->save($attacker_information);
                 }
                 // Finally, update the dropped items
                 foreach ($kill->items as $item) {
                     $item_information = new \EveCharacterKillMailItems();
                     // $item_information->killID = $kill->killID;
                     $item_information->flag = $item->flag;
                     $item_information->qtyDropped = $item->qtyDropped;
                     $item_information->qtyDestroyed = $item->qtyDestroyed;
                     $item_information->singleton = $item->singleton;
                     // Add the item information to the killmail
                     $killmail_detail->items()->save($item_information);
                 }
             }
             // Check how many entries we got back. If it is less than $row_count, we know we have
             // walked back the entire journal
             if (count($kill_mails->kills) < $row_count) {
                 break;
             }
             // Break the while loop
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $kill_mails;
 }
コード例 #17
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'CharacterSheet';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $character_sheet = $pheal->charScope->CharacterSheet(array('characterID' => $characterID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // If we cant get account status information, prevent us from calling
             // this API again
             BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
             return;
         } catch (\Pheal\Exceptions\PhealException $e) {
             throw $e;
         }
         // Check if the data in the database is still considered up to date.
         // checkDbCache will return true if this is the case
         if (!BaseApi::checkDbCache($scope, $api, $character_sheet->cached_until, $characterID)) {
             $character_data = \EveCharacterCharacterSheet::where('characterID', '=', $characterID)->first();
             if (!$character_data) {
                 $new_data = new \EveCharacterCharacterSheet();
             } else {
                 $new_data = $character_data;
             }
             $new_data->characterID = $character_sheet->characterID;
             $new_data->name = $character_sheet->name;
             $new_data->DoB = $character_sheet->DoB;
             $new_data->race = $character_sheet->race;
             $new_data->bloodLine = $character_sheet->bloodLine;
             $new_data->ancestry = $character_sheet->ancestry;
             $new_data->gender = $character_sheet->gender;
             $new_data->corporationName = $character_sheet->corporationName;
             $new_data->corporationID = $character_sheet->corporationID;
             $new_data->balance = $character_sheet->balance;
             $new_data->intelligence = $character_sheet->attributes->intelligence;
             $new_data->memory = $character_sheet->attributes->memory;
             $new_data->charisma = $character_sheet->attributes->charisma;
             $new_data->perception = $character_sheet->attributes->perception;
             $new_data->willpower = $character_sheet->attributes->willpower;
             // New stuff from Phoebe
             $new_data->homeStationID = $character_sheet->homeStationID;
             $new_data->factionName = $character_sheet->factionName;
             $new_data->factionID = $character_sheet->factionID;
             $new_data->freeRespecs = $character_sheet->freeRespecs;
             $new_data->cloneJumpDate = $character_sheet->cloneJumpDate;
             $new_data->lastRespecDate = $character_sheet->lastRespecDate;
             $new_data->lastTimedRespec = $character_sheet->lastTimedRespec;
             $new_data->remoteStationDate = $character_sheet->remoteStationDate;
             $new_data->jumpActivation = $character_sheet->jumpActivation;
             $new_data->jumpFatigue = $character_sheet->jumpFatigue;
             $new_data->jumpLastUpdate = $character_sheet->jumpLastUpdate;
             // Save the information
             $new_data->save();
             // Update the characters skills
             foreach ($character_sheet->skills as $skill) {
                 $skill_data = \EveCharacterCharacterSheetSkills::where('characterID', '=', $characterID)->where('typeID', '=', $skill->typeID)->first();
                 if (!$skill_data) {
                     $skill_info = new \EveCharacterCharacterSheetSkills();
                 } else {
                     $skill_info = $skill_data;
                 }
                 $skill_info->characterID = $characterID;
                 $skill_info->typeID = $skill->typeID;
                 $skill_info->skillpoints = $skill->skillpoints;
                 $skill_info->level = $skill->level;
                 $skill_info->published = $skill->published;
                 $new_data->skills()->save($skill_info);
             }
             // Update the Jump Clones.
             // First thing we need to do is clear out all of the  known clones for
             // this character. We cant really say that clones will remain, so to
             // be safe, clear all of the clones, and populate the new ones.
             // So, lets get to the deletion part. We need to keep in mind that a characterID
             // my have multiple jumpClones. Each clone in turn may have multiple implants
             // which in turn are linked back to a jumpClone and then to a chacterID
             \EveCharacterCharacterSheetJumpClones::where('characterID', $characterID)->delete();
             \EveCharacterCharacterSheetJumpCloneImplants::where('characterID', $characterID)->delete();
             // Next, loop over the clones we got in the API response
             foreach ($character_sheet->jumpClones as $jump_clone) {
                 $clone_data = new \EveCharacterCharacterSheetJumpClones();
                 $clone_data->jumpCloneID = $jump_clone->jumpCloneID;
                 $clone_data->characterID = $characterID;
                 $clone_data->typeID = $jump_clone->typeID;
                 $clone_data->locationID = $jump_clone->locationID;
                 $clone_data->cloneName = $jump_clone->cloneName;
                 $clone_data->save();
             }
             // With the jump clones populated, we move on to the implants per
             // jump clone.
             foreach ($character_sheet->jumpCloneImplants as $jump_clone_implants) {
                 $implant_data = new \EveCharacterCharacterSheetJumpCloneImplants();
                 $implant_data->jumpCloneID = $jump_clone_implants->jumpCloneID;
                 $implant_data->characterID = $characterID;
                 $implant_data->typeID = $jump_clone_implants->typeID;
                 $implant_data->typeName = $jump_clone_implants->typeName;
                 $implant_data->save();
             }
             // Finally, we update the character with the implants that they have.
             // Again, we can not assume that the implants they had in the
             // previous update is the same as the current, so, delete
             // everything and populate again.
             \EveCharacterCharacterSheetImplants::where('characterID', $characterID)->delete();
             // Now, loop over the implants from the API response and populate them.
             foreach ($character_sheet->implants as $implant) {
                 $implant_data = new \EveCharacterCharacterSheetImplants();
                 $implant_data->characterID = $characterID;
                 $implant_data->typeID = $implant->typeID;
                 $implant_data->typeName = $implant->typeName;
                 $implant_data->save();
             }
             // Update the cached_until time in the database for this api call
             BaseApi::setDbCache($scope, $api, $character_sheet->cached_until, $characterID);
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $character_sheet;
 }
コード例 #18
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'ContactList';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $contact_list = $pheal->charScope->ContactList(array('characterID' => $characterID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // If we cant get account status information, prevent us from calling
             // this API again
             BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
             return;
         } catch (\Pheal\Exceptions\PhealException $e) {
             throw $e;
         }
         // Check if the data in the database is still considered up to date.
         // checkDbCache will return true if this is the case
         if (!BaseApi::checkDbCache($scope, $api, $contact_list->cached_until, $characterID)) {
             // The ContactList API will potentially return the characters:
             // a) personal contacts,
             // b) corporation contacts,
             // c) alliance contracts.
             // TODO: Think about maybe doing this in a transaction?
             // First, the personal contacts
             // Remove the current contacts
             \EveCharacterContactList::where('characterID', '=', $characterID)->delete();
             // Loop over the list we got from the api and update the db
             foreach ($contact_list->contactList as $contact) {
                 $new_contact = new \EveCharacterContactList();
                 $new_contact->characterID = $characterID;
                 $new_contact->contactID = $contact->contactID;
                 $new_contact->contactName = $contact->contactName;
                 $new_contact->inWatchlist = $contact->inWatchlist == True ? 1 : 0;
                 $new_contact->standing = $contact->standing;
                 $new_contact->contactTypeID = $contact->contactTypeID;
                 $new_contact->save();
             }
             // Second, the corporate contacts
             // Remove the current contacts
             \EveCharacterContactListCorporate::where('characterID', '=', $characterID)->delete();
             // Loop over the list we got from the api and update the db
             foreach ($contact_list->corporateContactList as $contact) {
                 $new_contact = new \EveCharacterContactListCorporate();
                 $new_contact->characterID = $characterID;
                 $new_contact->contactID = $contact->contactID;
                 $new_contact->contactName = $contact->contactName;
                 $new_contact->standing = $contact->standing;
                 $new_contact->contactTypeID = $contact->contactTypeID;
                 $new_contact->save();
             }
             // Third, the alliance contacts
             // Remove the current contacts
             \EveCharacterContactListAlliance::where('characterID', '=', $characterID)->delete();
             // Loop over the list we got from the api and update the db
             foreach ($contact_list->allianceContactList as $contact) {
                 $new_contact = new \EveCharacterContactListAlliance();
                 $new_contact->characterID = $characterID;
                 $new_contact->contactID = $contact->contactID;
                 $new_contact->contactName = $contact->contactName;
                 $new_contact->standing = $contact->standing;
                 $new_contact->contactTypeID = $contact->contactTypeID;
                 $new_contact->save();
             }
             // Update the cached_until time in the database for this api call
             BaseApi::setDbCache($scope, $api, $contact_list->cached_until, $characterID);
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $contact_list;
 }
コード例 #19
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'IndustryJobs';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $industry_jobs = $pheal->corpScope->IndustryJobs(array('characterID' => $characters[0]));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $industry_jobs->cached_until, $corporationID)) {
         // Populate the jobs for this character
         foreach ($industry_jobs->jobs as $job) {
             $job_data = \EveCorporationIndustryJobs::where('corporationID', '=', $corporationID)->where('jobID', '=', $job->jobID)->first();
             if (!$job_data) {
                 $job_data = new \EveCorporationIndustryJobs();
             }
             $job_data->corporationID = $corporationID;
             $job_data->jobID = $job->jobID;
             $job_data->outputLocationID = $job->outputLocationID;
             $job_data->installerID = $job->installerID;
             $job_data->runs = $job->runs;
             $job_data->activityID = $job->activityID;
             $job_data->installerName = $job->installerName;
             $job_data->facilityID = $job->facilityID;
             $job_data->solarSystemID = $job->solarSystemID;
             $job_data->solarSystemName = $job->solarSystemName;
             $job_data->stationID = $job->stationID;
             $job_data->blueprintID = $job->blueprintID;
             $job_data->blueprintTypeID = $job->blueprintTypeID;
             $job_data->blueprintTypeName = $job->blueprintTypeName;
             $job_data->blueprintLocationID = $job->blueprintLocationID;
             $job_data->cost = $job->cost;
             $job_data->teamID = $job->teamID;
             $job_data->licensedRuns = $job->licensedRuns;
             $job_data->probability = $job->probability;
             $job_data->productTypeID = $job->productTypeID;
             $job_data->productTypeName = $job->productTypeName;
             $job_data->status = $job->status;
             $job_data->timeInSeconds = $job->timeInSeconds;
             $job_data->startDate = $job->startDate;
             $job_data->endDate = $job->endDate;
             $job_data->pauseDate = $job->pauseDate;
             $job_data->completedDate = $job->completedDate;
             $job_data->completedCharacterID = $job->completedCharacterID;
             $job_data->save();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $industry_jobs->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $industry_jobs;
 }
コード例 #20
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'Contracts';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $contracts = $pheal->corpScope->Contracts(array('characterID' => $characters[0]));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Before we start looping over the contracts, we need to add some more
     // logic to this Updater. The ContractItems call seems to be flaky
     // in the sense that when we call the corp/Contracts API, we get
     // a list of contractID's. These ID's are checked for existence
     // in the database and updated accordingly. If its a new
     // contract, we call ContractItems to get the details.
     // This is where shit falls apart and :ccp: thiks its
     // clever to error out for ID's we *JUST* got back.
     //
     // So, to reduce the chances of getting the calling IP banned due to
     // ~reasons~, we will have a local counter to limit the amount of
     // errors caused by this this call. If we hit this limit, we
     // return the function, and wait for the next run to update
     // again. We will also run banCall() so that the global
     // error counter is also aware of this.
     $error_limit = 25;
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $contracts->cached_until, $corporationID)) {
         // Loop over the contracts and update
         foreach ($contracts->contractList as $contract) {
             $contract_data = \EveCorporationContracts::where('corporationID', '=', $corporationID)->where('contractID', '=', $contract->contractID)->first();
             // If we an existing contract that we are just going to update, then dont bother
             // running /char/ContractItems. I *think* this will be the same all the time
             // and can only change by creating a new contract
             if (!$contract_data) {
                 $new_data = new \EveCorporationContracts();
                 $get_items = true;
                 // [1]
             } else {
                 $new_data = $contract_data;
                 $get_items = false;
             }
             $new_data->corporationID = $corporationID;
             $new_data->contractID = $contract->contractID;
             $new_data->issuerID = $contract->issuerID;
             $new_data->issuerCorpID = $contract->issuerCorpID;
             $new_data->assigneeID = $contract->assigneeID;
             $new_data->acceptorID = $contract->acceptorID;
             $new_data->startStationID = $contract->startStationID;
             $new_data->endStationID = $contract->endStationID;
             $new_data->type = $contract->type;
             $new_data->status = $contract->status;
             $new_data->title = strlen($contract->title) > 0 ? $contract->title : null;
             $new_data->forCorp = $contract->forCorp;
             $new_data->availability = $contract->availability;
             $new_data->dateIssued = $contract->dateIssued;
             $new_data->dateExpired = strlen($contract->dateExpired) > 0 ? $contract->dateExpired : null;
             $new_data->dateAccepted = strlen($contract->dateAccepted) > 0 ? $contract->dateAccepted : null;
             $new_data->numDays = $contract->numDays;
             $new_data->dateCompleted = strlen($contract->dateCompleted) > 0 ? $contract->dateCompleted : null;
             $new_data->price = $contract->price;
             $new_data->reward = $contract->reward;
             $new_data->collateral = $contract->collateral;
             $new_data->buyout = $contract->buyout;
             $new_data->volume = $contract->volume;
             $new_data->save();
             // [1] New contracts will have their 'items' updated too. Do it
             if ($get_items) {
                 try {
                     $contracts_items = $pheal->corpScope->ContractItems(array('characterID' => $characters[0], 'contractID' => $contract->contractID));
                     // :ccp: Seems to give you a list of ID's for a call, and then
                     // complain seconds later that the itemID is incorrect. This
                     // after we *just* got it from them! ffs. Anyways, we will
                     // process banning here so that the global error counter
                     // in the \Cache::has('eve_api_error_count') can inc
                     // and we dont cause too many exceptions.
                     //
                     // We will also dec the $error_limit and break if we hit 0.
                 } catch (\Pheal\Exceptions\APIException $e) {
                     // Dec $error_limit
                     $error_limit--;
                     // Process the banning for the update of the global eve_api_error_count
                     BaseApi::banCall('ContractItems', $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
                     // Check the state of the $error_limit and decide what to do
                     if ($error_limit <= 0) {
                         return;
                     } else {
                         continue;
                     }
                 } catch (\Pheal\Exceptions\PhealException $e) {
                     throw $e;
                 }
                 // Loop over the items in contracts and save it
                 foreach ($contracts_items->itemList as $item) {
                     $items = new \EveCorporationContractsItems();
                     $items->corporationID = $corporationID;
                     $items->contractID = $contract->contractID;
                     $items->recordID = $item->recordID;
                     $items->typeID = $item->typeID;
                     $items->quantity = $item->quantity;
                     $items->rawQuantity = isset($item->rawQuantity) ? $item->rawQuantity : null;
                     $items->singleton = $item->singleton;
                     $items->included = $item->included;
                     $new_data->items()->save($items);
                 }
             }
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $contracts->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $contracts;
 }
コード例 #21
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'CorporationSheet';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $corporation_sheet = $pheal->corpScope->CorporationSheet(array('characterID' => $characters[0]));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $corporation_sheet->cached_until, $corporationID)) {
         $corporation_data = \EveCorporationCorporationSheet::where('corporationID', '=', $corporationID)->first();
         if (!$corporation_data) {
             $corporation_data = new \EveCorporationCorporationSheet();
         }
         $corporation_data->corporationID = $corporation_sheet->corporationID;
         $corporation_data->corporationName = $corporation_sheet->corporationName;
         $corporation_data->ticker = $corporation_sheet->ticker;
         $corporation_data->ceoID = $corporation_sheet->ceoID;
         $corporation_data->ceoName = $corporation_sheet->ceoName;
         $corporation_data->stationID = $corporation_sheet->stationID;
         $corporation_data->stationName = $corporation_sheet->stationName;
         $corporation_data->description = $corporation_sheet->description;
         $corporation_data->url = $corporation_sheet->url;
         $corporation_data->allianceID = $corporation_sheet->allianceID;
         $corporation_data->factionID = $corporation_sheet->factionID;
         $corporation_data->allianceName = $corporation_sheet->allianceName;
         $corporation_data->taxRate = $corporation_sheet->taxRate;
         $corporation_data->memberCount = $corporation_sheet->memberCount;
         $corporation_data->memberLimit = $corporation_sheet->memberLimit;
         $corporation_data->shares = $corporation_sheet->shares;
         $corporation_data->graphicID = $corporation_sheet->logo->graphicID;
         $corporation_data->shape1 = $corporation_sheet->logo->shape1;
         $corporation_data->shape2 = $corporation_sheet->logo->shape2;
         $corporation_data->shape3 = $corporation_sheet->logo->shape3;
         $corporation_data->color1 = $corporation_sheet->logo->color1;
         $corporation_data->color2 = $corporation_sheet->logo->color2;
         $corporation_data->color3 = $corporation_sheet->logo->color3;
         $corporation_data->corporationID = $corporation_sheet->corporationID;
         $corporation_data->save();
         // Update the Divisions
         foreach ($corporation_sheet->divisions as $division) {
             $division_data = \EveCorporationCorporationSheetDivisions::where('corporationID', '=', $corporationID)->where('accountKey', '=', $division->accountKey)->first();
             if (!$division_data) {
                 $division_data = new \EveCorporationCorporationSheetDivisions();
             }
             $division_data->corporationID = $corporationID;
             $division_data->accountKey = $division->accountKey;
             $division_data->description = $division->description;
             $corporation_data->divisions()->save($division_data);
         }
         // Update the Wallet Divisions
         foreach ($corporation_sheet->walletDivisions as $division) {
             $division_data = \EveCorporationCorporationSheetWalletDivisions::where('corporationID', '=', $corporationID)->where('accountKey', '=', $division->accountKey)->first();
             if (!$division_data) {
                 $division_data = new \EveCorporationCorporationSheetWalletDivisions();
             }
             $division_data->corporationID = $corporationID;
             $division_data->accountKey = $division->accountKey;
             $division_data->description = $division->description;
             $corporation_data->walletdivisions()->save($division_data);
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $corporation_sheet->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $corporation_sheet;
 }
コード例 #22
0
ファイル: CharacterStandings.php プロジェクト: boweiliu/seat
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'Standings';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $standings = $pheal->charScope->Standings(array('characterID' => $characterID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // If we cant get account status information, prevent us from calling
             // this API again
             BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
             return;
         } catch (\Pheal\Exceptions\PhealException $e) {
             throw $e;
         }
         // Check if the data in the database is still considered up to date.
         // checkDbCache will return true if this is the case
         if (!BaseApi::checkDbCache($scope, $api, $standings->cached_until, $characterID)) {
             // Populate the agents standings for this character
             foreach ($standings->characterNPCStandings->agents as $standing) {
                 $standing_data = \EveCharacterStandingsAgents::where('characterID', '=', $characterID)->where('fromID', '=', $standing->fromID)->first();
                 if (!$standing_data) {
                     $standing_data = new \EveCharacterStandingsAgents();
                 }
                 $standing_data->characterID = $characterID;
                 $standing_data->fromID = $standing->fromID;
                 $standing_data->fromName = $standing->fromName;
                 $standing_data->standing = $standing->standing;
                 $standing_data->save();
             }
             // Populate the faction standings for this character
             foreach ($standings->characterNPCStandings->factions as $standing) {
                 $standing_data = \EveCharacterStandingsFactions::where('characterID', '=', $characterID)->where('fromID', '=', $standing->fromID)->first();
                 if (!$standing_data) {
                     $standing_data = new \EveCharacterStandingsFactions();
                 }
                 $standing_data->characterID = $characterID;
                 $standing_data->fromID = $standing->fromID;
                 $standing_data->fromName = $standing->fromName;
                 $standing_data->standing = $standing->standing;
                 $standing_data->save();
             }
             // Populate the NPCCorporation standings for this character
             foreach ($standings->characterNPCStandings->NPCCorporations as $standing) {
                 $standing_data = \EveCharacterStandingsNPCCorporations::where('characterID', '=', $characterID)->where('fromID', '=', $standing->fromID)->first();
                 if (!$standing_data) {
                     $standing_data = new \EveCharacterStandingsNPCCorporations();
                 }
                 $standing_data->characterID = $characterID;
                 $standing_data->fromID = $standing->fromID;
                 $standing_data->fromName = $standing->fromName;
                 $standing_data->standing = $standing->standing;
                 $standing_data->save();
             }
             // Update the cached_until time in the database for this api call
             BaseApi::setDbCache($scope, $api, $standings->cached_until, $characterID);
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $standings;
 }
コード例 #23
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'MemberSecurityLog';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $member_security_log = $pheal->corpScope->MemberSecurityLog(array('characterID' => $characters[0]));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $member_security_log->cached_until, $corporationID)) {
         foreach ($member_security_log->roleHistory as $log) {
             // Generate a log hash to lookup
             $loghash = md5(implode(',', array($log->changeTime, $log->characterID, $log->roleLocationType)));
             $log_data = \EveCorporationMemberSecurityLog::where('hash', '=', $loghash)->first();
             if (!$log_data) {
                 $log_data = new \EveCorporationMemberSecurityLog();
             } else {
                 // We already have this log entry recorded, so just move along
                 continue;
             }
             // Record the log entry
             $log_data->corporationID = $corporationID;
             $log_data->characterID = $log->characterID;
             $log_data->characterName = $log->characterName;
             $log_data->changeTime = $log->changeTime;
             $log_data->issuerID = $log->issuerID;
             $log_data->issuerName = $log->issuerName;
             $log_data->roleLocationType = $log->roleLocationType;
             $log_data->hash = $loghash;
             $log_data->save();
             // Generate the oldRoles & newRoles entries. Well just make some
             // lazy ass json entries.
             $oldRoles = array();
             foreach ($log->oldRoles as $entry) {
                 $oldRoles[$entry->roleID] = $entry->roleName;
             }
             $newRoles = array();
             foreach ($log->newRoles as $entry) {
                 $newRoles[$entry->roleID] = $entry->roleName;
             }
             // Save the log details
             $entry_data = new \EveCorporationMemberSecurityLogDetails();
             $entry_data->hash = $loghash;
             $entry_data->oldRoles = json_encode($oldRoles);
             $entry_data->newRoles = json_encode($newRoles);
             $log_data->details()->save($entry_data);
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $member_security_log->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $member_security_log;
 }
コード例 #24
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'MailingLists';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $mailing_lists = $pheal->charScope->MailingLists(array('characterID' => $characterID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // If we cant get account status information, prevent us from calling
             // this API again
             BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
             return;
         } catch (\Pheal\Exceptions\PhealException $e) {
             throw $e;
         }
         // Check if the data in the database is still considered up to date.
         // checkDbCache will return true if this is the case
         if (!BaseApi::checkDbCache($scope, $api, $mailing_lists->cached_until, $characterID)) {
             foreach ($mailing_lists->mailingLists as $list) {
                 $list_data = \EveCharacterMailingLists::where('characterID', '=', $characterID)->where('listID', '=', $list->listID)->first();
                 // Start a new \EveCharacterMailingLists instance, else, just continue.
                 // Doesn't look like ML's can be renamed, and we want to keep old ones
                 // to be able to lookup old ML id's.
                 if (!$list_data) {
                     $new_list = new \EveCharacterMailingLists();
                 } else {
                     continue;
                 }
                 $new_list->characterID = $characterID;
                 $new_list->listID = $list->listID;
                 $new_list->displayName = $list->displayName;
                 $new_list->save();
             }
             // Update the cached_until time in the database for this api call
             BaseApi::setDbCache($scope, $api, $mailing_lists->cached_until, $characterID);
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $mailing_lists;
 }
コード例 #25
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'SkillInTraining';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $skill_in_training = $pheal->charScope->SkillInTraining(array('characterID' => $characterID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // If we cant get account status information, prevent us from calling
             // this API again
             BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
             return;
         } catch (\Pheal\Exceptions\PhealException $e) {
             throw $e;
         }
         // Check if the data in the database is still considered up to date.
         // checkDbCache will return true if this is the case
         if (!BaseApi::checkDbCache($scope, $api, $skill_in_training->cached_until, $characterID)) {
             $character_data = \EveCharacterSkillInTraining::where('characterID', '=', $characterID)->first();
             if (!$character_data) {
                 $character_data = new \EveCharacterSkillInTraining();
             }
             if ($skill_in_training->skillInTraining == 1) {
                 $character_data->characterID = $characterID;
                 $character_data->currentTQTime = $skill_in_training->currentTQTime->_value;
                 $character_data->trainingEndTime = $skill_in_training->trainingEndTime;
                 $character_data->trainingStartTime = $skill_in_training->trainingStartTime;
                 $character_data->trainingTypeID = $skill_in_training->trainingTypeID;
                 $character_data->trainingStartSP = $skill_in_training->trainingStartSP;
                 $character_data->trainingDestinationSP = $skill_in_training->trainingDestinationSP;
                 $character_data->trainingToLevel = $skill_in_training->trainingToLevel;
                 $character_data->skillInTraining = $skill_in_training->skillInTraining;
                 $character_data->save();
             } else {
                 $character_data->characterID = $characterID;
                 $character_data->skillInTraining = 0;
                 $character_data->save();
             }
             // Update the cached_until time in the database for this api call
             BaseApi::setDbCache($scope, $api, $skill_in_training->cached_until, $characterID);
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $skill_in_training;
 }
コード例 #26
0
ファイル: ApiKeyController.php プロジェクト: boweiliu/seat
 public function postNewKey()
 {
     if (Request::ajax()) {
         // We will validate the key pais as we dont want to cause unneeded errors
         $validation = new APIKeyValidator();
         if ($validation->passes()) {
             // Setup a pheal instance and get some API data :D
             BaseApi::bootstrap();
             $pheal = new Pheal(Input::get('keyID'), Input::get('vCode'));
             // Get API Key Information
             try {
                 $key_info = $pheal->accountScope->APIKeyInfo();
             } catch (\Pheal\Exceptions\PhealException $e) {
                 return View::make('keys.ajax.errors')->withErrors(array('error' => $e->getCode() . ': ' . $e->getMessage()));
             }
             // Here, based on the type of key, we will either call some further information,
             // or just display what we have learned so far.
             if ($key_info->key->type == 'Corporation') {
                 // Just return the view for corporation keys
                 return View::make('keys.ajax.corporation')->with('keyID', Input::get('keyID'))->with('vCode', Input::get('vCode'))->with('key_info', $key_info)->with('existance', SeatKey::where('keyID', Input::get('keyID'))->count());
             } elseif ($key_info->key->accessMask < Settings::getSetting('required_mask')) {
                 return View::make('keys.ajax.errors')->withErrors(array('error' => 'Invalid API Mask!'));
             }
             // Get API Account Status Information
             try {
                 $status_info = $pheal->accountScope->AccountStatus();
             } catch (\Pheal\Exceptions\PhealException $e) {
                 return View::make('keys.ajax.errors')->withErrors(array('error' => $e->getCode() . ': ' . $e->getMessage()));
             }
             // Return the view
             return View::make('keys.ajax.character')->with('keyID', Input::get('keyID'))->with('vCode', Input::get('vCode'))->with('key_info', $key_info)->with('status_info', $status_info)->with('existance', SeatKey::where('keyID', Input::get('keyID'))->count());
         } else {
             return View::make('keys.ajax.errors')->withErrors($validation->errors);
         }
     }
 }
コード例 #27
0
ファイル: AccountAPIKeyInfo.php プロジェクト: boweiliu/seat
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     $scope = 'Account';
     $api = 'APIKeyInfo';
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $key_info = $pheal->accountScope->APIKeyInfo();
     } catch (\Pheal\Exceptions\APIException $e) {
         // Some API responses require some rather important actions
         // SeATs perspective. For eg. Expired keys, IP bans, rate
         // limits etc. As APIKeyInfo is probably one of the
         // most called eveapi Updater, we will add the
         // logic here to check for these types of
         // responses.
         // Source: https://api.eveonline.com/Eve/ErrorList.xml.aspx
         switch ($e->getCode()) {
             // "API key authentication failure."
             case 202:
                 // "Authentication failure."
             // "Authentication failure."
             case 203:
             case 204:
                 // "Authentication failure."
             // "Authentication failure."
             case 205:
                 // "Authentication failure."
             // "Authentication failure."
             case 210:
                 // "Authentication failure (final pass)."
             // "Authentication failure (final pass)."
             case 212:
                 // The API is probably entirely wrong.
                 BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage());
                 return;
                 // "Invalid Corporation Key. Key owner does not fullfill role
                 // requirements anymore."
             // "Invalid Corporation Key. Key owner does not fullfill role
             // requirements anymore."
             case 220:
                 // Owner of the corporation key doesnt have hes roles anymore?
                 BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage());
                 return;
                 // "Illegal page request! Please verify the access granted by the key you are using!."
             // "Illegal page request! Please verify the access granted by the key you are using!."
             case 221:
                 // Not 100% sure how to handle this one. This call has no
                 // access mask requirement...
                 return;
                 // "Key has expired. Contact key owner for access renewal."
             // "Key has expired. Contact key owner for access renewal."
             case 222:
                 // We have a invalid key. Expired or deleted.
                 BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage());
                 return;
                 // "Authentication failure. Legacy API keys can no longer be
                 // used. Please create a new key on support.eveonline.com
                 // and make sure your application supports Customizable
                 // API Keys."
             // "Authentication failure. Legacy API keys can no longer be
             // used. Please create a new key on support.eveonline.com
             // and make sure your application supports Customizable
             // API Keys."
             case 223:
                 // The API we are working with is waaaaaay too old.
                 BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage());
                 return;
                 // "Web site database temporarily disabled."
             // "Web site database temporarily disabled."
             case 901:
                 // The EVE API Database is apparently down, so mark the
                 // server as 'down' in the cache so that subsequent
                 // calls don't fail because of this.
                 \Cache::put('eve_api_down', true, 30);
                 return;
                 // "EVE backend database temporarily disabled.""
             // "EVE backend database temporarily disabled.""
             case 902:
                 // The EVE API Database is apparently down, so mark the
                 // server as 'down' in the cache so that subsequent
                 // calls don't fail because of this.
                 \Cache::put('eve_api_down', true, 30);
                 return;
                 // "Your IP address has been temporarily blocked because it
                 // is causing too many errors. See the cacheUntil
                 // timestamp for when it will be opened again.
                 // IPs that continually cause a lot of errors
                 // in the API will be permanently banned,
                 // please take measures to minimize
                 // problematic API calls from your
                 // application."
             // "Your IP address has been temporarily blocked because it
             // is causing too many errors. See the cacheUntil
             // timestamp for when it will be opened again.
             // IPs that continually cause a lot of errors
             // in the API will be permanently banned,
             // please take measures to minimize
             // problematic API calls from your
             // application."
             case 904:
                 // If we are rate limited, set the status of the eveapi
                 // server to 'down' in the cache so that subsequent
                 // calls don't fail because of this.
                 // Get time of IP ban in minutes, rounded up to the next whole minute
                 $time = round(($e->cached_until_unixtime - $e->request_time_unixtime) / 60, 0, PHP_ROUND_HALF_UP);
                 \Cache::put('eve_api_down', true, $time);
                 return;
                 // We got a problem we don't know what to do with, so log
                 // and throw the exception so that the can debug it.
             // We got a problem we don't know what to do with, so log
             // and throw the exception so that the can debug it.
             default:
                 \Log::error('Call to APIKeyInfo for ' . $keyID . ' failed with: ' . $e->getCode() . ':' . $e->getMessage(), array('src' => __CLASS__));
                 throw $e;
                 break;
         }
         // Process a ban request as needed
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $key_info->cached_until, $keyID)) {
         $key_data = \EveAccountAPIKeyInfo::where('keyID', '=', $keyID)->first();
         if (!$key_data) {
             $key_data = new \EveAccountAPIKeyInfo();
         }
         $key_data->keyID = $keyID;
         $key_data->accessMask = $key_info->key->accessMask;
         $key_data->type = $key_info->key->type;
         $key_data->expires = strlen($key_info->key->expires) > 0 ? $key_info->key->expires : null;
         // hack much?
         $key_data->save();
         // Check if we have any knowledge of any characters for this key. We will remove values from this
         // array as we move along to determine which characters we should delete that are possibly no
         // longer on this key
         $known_characters = array();
         foreach (\EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->get() as $character) {
             $known_characters[] = $character->characterID;
         }
         $known_characters = array_flip($known_characters);
         // Update the key characters
         foreach ($key_info->key->characters as $character) {
             // Check if we need to update || insert
             $character_data = \EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->where('characterID', '=', $character->characterID)->first();
             if (!$character_data) {
                 $character_data = new \EveAccountAPIKeyInfoCharacters();
             }
             // else, add/update
             $character_data->characterID = $character->characterID;
             $character_data->characterName = $character->characterName;
             $character_data->corporationID = $character->corporationID;
             $character_data->corporationName = $character->corporationName;
             $key_data->characters()->save($character_data);
             // Remove this characterID from the known_characters as its still on
             // the key
             if (array_key_exists($character->characterID, $known_characters)) {
                 unset($known_characters[$character->characterID]);
             }
         }
         // Delete the characters that are no longer part of this key
         foreach (array_flip($known_characters) as $oldcharacter) {
             \EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->where('characterID', '=', $oldcharacter)->delete();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $key_info->cached_until, $keyID);
     }
     return $key_info;
 }
コード例 #28
0
ファイル: CharacterSkillQueue.php プロジェクト: boweiliu/seat
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Char';
     $api = 'SkillQueue';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // Next, start our loop over the characters and upate the database
     foreach ($characters as $characterID) {
         // Prepare the Pheal instance
         $pheal = new Pheal($keyID, $vCode);
         // Do the actual API call. pheal-ng actually handles some internal
         // caching too.
         try {
             $skill_queue = $pheal->charScope->SkillQueue(array('characterID' => $characterID));
         } catch (\Pheal\Exceptions\APIException $e) {
             // If we cant get account status information, prevent us from calling
             // this API again
             BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
             return;
         } catch (\Pheal\Exceptions\PhealException $e) {
             throw $e;
         }
         // Check if the data in the database is still considered up to date.
         // checkDbCache will return true if this is the case
         if (!BaseApi::checkDbCache($scope, $api, $skill_queue->cached_until, $characterID)) {
             // Remove the current Queue
             \EveCharacterSkillQueue::where('characterID', '=', $characterID)->delete();
             // Add the current queue information
             foreach ($skill_queue->skillqueue as $queue) {
                 // Start a new queue entry for this character
                 $character_data = new \EveCharacterSkillQueue();
                 // And populate the fields for him.
                 $character_data->characterID = $characterID;
                 $character_data->queuePosition = $queue->queuePosition;
                 $character_data->typeID = $queue->typeID;
                 $character_data->level = $queue->level;
                 $character_data->startSP = $queue->startSP;
                 $character_data->endSP = $queue->endSP;
                 $character_data->startTime = strlen($queue->startTime) > 0 ? $queue->startTime : null;
                 $character_data->endTime = strlen($queue->endTime) > 0 ? $queue->endTime : null;
                 $character_data->save();
             }
             // Update the cached_until time in the database for this api call
             BaseApi::setDbCache($scope, $api, $skill_queue->cached_until, $characterID);
         }
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $skill_queue;
 }
コード例 #29
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'StarbaseList';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $starbase_list = $pheal->corpScope->StarbaseList(array('characterID' => $characters[0]));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $starbase_list->cached_until, $corporationID)) {
         // So for this call I dont think we should just trash all of the posses and their
         // details. Instead, cause I'm bad, well get all of the current posses for the corp
         // and delete the values that we know of. The resulting array will be the ones we delete
         // as they are probably removed/killed posses
         $old_starbases = array();
         foreach (\EveCorporationStarbaseList::where('corporationID', '=', $corporationID)->get() as $item) {
             $old_starbases[] = $item->itemID;
         }
         // Arrayflip hax to get the starbaseID's as keys
         $old_starbases = array_flip($old_starbases);
         // <-- help a noob please :<
         // Next, loop over the starbases from the API and populate/update the db
         foreach ($starbase_list->starbases as $starbase) {
             $starbase_data = \EveCorporationStarbaseList::where('corporationID', '=', $corporationID)->where('itemID', '=', $starbase->itemID)->first();
             if (!$starbase_data) {
                 $starbase_data = new \EveCorporationStarbaseList();
             }
             $starbase_data->corporationID = $corporationID;
             $starbase_data->itemID = $starbase->itemID;
             $starbase_data->typeID = $starbase->typeID;
             $starbase_data->locationID = $starbase->locationID;
             $starbase_data->moonID = $starbase->moonID;
             $starbase_data->state = $starbase->state;
             $starbase_data->stateTimestamp = $starbase->stateTimestamp;
             $starbase_data->onlineTimestamp = $starbase->onlineTimestamp;
             $starbase_data->standingOwnerID = $starbase->standingOwnerID;
             $starbase_data->save();
             // Update the old_starbases list by removing the ones that still
             // exist
             if (array_key_exists($starbase->itemID, $old_starbases)) {
                 unset($old_starbases[$starbase->itemID]);
             }
         }
         // Delete old starbases if there are any
         if (count($old_starbases) > 0) {
             // Delete the old starbase...
             foreach (array_flip($old_starbases) as $starbase_id) {
                 \EveCorporationStarbaseList::where('itemID', '=', $starbase_id)->delete();
             }
             // ... and its details
             foreach (array_flip($old_starbases) as $starbase_id) {
                 \EveCorporationStarbaseDetail::where('itemID', '=', $starbase_id)->delete();
             }
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $starbase_list->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $starbase_list;
 }
コード例 #30
0
 public static function Update($keyID, $vCode)
 {
     // Start and validate they key pair
     BaseApi::bootstrap();
     BaseApi::validateKeyPair($keyID, $vCode);
     // Set key scopes and check if the call is banned
     $scope = 'Corp';
     $api = 'MemberTracking';
     if (BaseApi::isBannedCall($api, $scope, $keyID)) {
         return;
     }
     // Get the characters for this key
     $characters = BaseApi::findKeyCharacters($keyID);
     // Check if this key has any characters associated with it
     if (!$characters) {
         return;
     }
     // Lock the call so that we are the only instance of this running now()
     // If it is already locked, just return without doing anything
     if (!BaseApi::isLockedCall($api, $scope, $keyID)) {
         $lockhash = BaseApi::lockCall($api, $scope, $keyID);
     } else {
         return;
     }
     // So I think a corporation key will only ever have one character
     // attached to it. So we will just use that characterID for auth
     // things, but the corporationID for locking etc.
     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
     // Prepare the Pheal instance
     $pheal = new Pheal($keyID, $vCode);
     // Do the actual API call. pheal-ng actually handles some internal
     // caching too.
     try {
         $member_tracking = $pheal->corpScope->MemberTracking(array('characterID' => $characters[0], 'extended' => 1));
     } catch (\Pheal\Exceptions\APIException $e) {
         // If we cant get account status information, prevent us from calling
         // this API again
         BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage());
         return;
     } catch (\Pheal\Exceptions\PhealException $e) {
         throw $e;
     }
     // Check if the data in the database is still considered up to date.
     // checkDbCache will return true if this is the case
     if (!BaseApi::checkDbCache($scope, $api, $member_tracking->cached_until, $corporationID)) {
         // Get a list of the current corporation members. Once we are done with the member
         // updates, we will just go and delete the members that are left in this array, assuming
         // that they are  no longer in this corporation.
         $existing_members = array();
         foreach (\EveCorporationMemberTracking::where('corporationID', $corporationID)->get() as $member) {
             $existing_members[] = $member->characterID;
         }
         // Flip the array so that the keys are the characterID's
         $existing_members = array_flip($existing_members);
         // Process the results from the API call
         foreach ($member_tracking->members as $member) {
             $member_data = \EveCorporationMemberTracking::where('characterID', '=', $member->characterID)->where('corporationID', '=', $corporationID)->first();
             if (!$member_data) {
                 $member_data = new \EveCorporationMemberTracking();
             }
             $member_data->characterID = $member->characterID;
             $member_data->corporationID = $corporationID;
             $member_data->name = $member->name;
             $member_data->startDateTime = $member->startDateTime;
             $member_data->baseID = $member->baseID;
             $member_data->base = $member->base;
             $member_data->title = $member->title;
             $member_data->logonDateTime = $member->logonDateTime;
             $member_data->logoffDateTime = $member->logoffDateTime;
             $member_data->locationID = $member->locationID;
             $member_data->location = $member->location;
             $member_data->shipTypeID = $member->shipTypeID;
             $member_data->shipType = $member->shipType;
             $member_data->roles = $member->roles;
             $member_data->grantableRoles = $member->grantableRoles;
             $member_data->save();
             // Remove this member from the existing members
             unset($existing_members[$member->characterID]);
         }
         // Next, remove the members that were not in the API call.
         if (count($existing_members) > 0) {
             \EveCorporationMemberTracking::whereIn('characterID', array_keys($existing_members))->delete();
         }
         // Update the cached_until time in the database for this api call
         BaseApi::setDbCache($scope, $api, $member_tracking->cached_until, $corporationID);
     }
     // Unlock the call
     BaseApi::unlockCall($lockhash);
     return $member_tracking;
 }