From d3b9028eecd2d6f9f92bae0d524a4bae21b3aa76 Mon Sep 17 00:00:00 2001 From: Quentin Bellus Date: Mon, 3 Sep 2018 17:21:27 +0200 Subject: [PATCH] Auto accept EULA for new accounts --- src/Account.php | 23 ++++++++++++++++++++++- src/Auth.php | 7 +++++-- src/FortniteClient.php | 1 + src/Status.php | 12 ++++++++++++ 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/Account.php b/src/Account.php index cf79821..62f700c 100644 --- a/src/Account.php +++ b/src/Account.php @@ -10,8 +10,11 @@ class Account { - public function __construct($access_token) { + private $account_id; + + public function __construct($access_token,$account_id) { $this->access_token = $access_token; + $this->account_id = $account_id; } public static function getDisplayNameFromID($id, $access_token) { @@ -41,4 +44,22 @@ public function getDisplayNamesFromID($id) { public function killSession() { FortniteClient::sendFortniteDeleteRequest(FortniteClient::FORTNITE_ACCOUNT_API . "oauth/sessions/kill/" . $this->access_token, $this->access_token); } + + public function acceptEULA(){ + try { + $data = FortniteClient::sendFortniteGetRequest(FortniteClient::FORTNITE_EULA_API . "public/agreements/fn/account/" . $this->account_id .'?locale=en-US', + $this->access_token); + + FortniteClient::sendFortnitePostRequest(FortniteClient::FORTNITE_EULA_API . "public/agreements/fn/version/".$data->version."/account/".$this->account_id."/accept?locale=en", + $this->access_token,new \StdClass()); + + FortniteClient::sendFortnitePostRequest(FortniteClient::FORTNITE_API.'game/v2/grant_access/'.$this->account_id, + $this->access_token,new \StdClass()); + + return true; + } catch (GuzzleException $e) { + if ($e->getResponse()->getStatusCode() == 404) throw new \Exception('Could not read or accept EULA for account id ' . $this->account_id); + throw $e; + } + } } \ No newline at end of file diff --git a/src/Auth.php b/src/Auth.php index 3965fad..52375f1 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -32,12 +32,15 @@ private function __construct($access_token, $in_app_id, $refresh_token, $account $this->refresh_token = $refresh_token; $this->account_id = $account_id; $this->expires_in = $expires_in; + $this->account = new Account($this->access_token,$this->account_id); + $this->status = new Status($this->access_token); + if ($this->status->allowedToPlay() === false){ + $this->account->acceptEULA(); + } $this->profile = new Profile($this->access_token, $this->account_id); - $this->account = new Account($this->access_token); $this->leaderboard = new Leaderboard($this->access_token, $this->in_app_id, $this->account); $this->store = new Store($this->access_token); $this->news = new News($this->access_token); - $this->status = new Status($this->access_token); } /** diff --git a/src/FortniteClient.php b/src/FortniteClient.php index 0717aaf..3bf5f41 100644 --- a/src/FortniteClient.php +++ b/src/FortniteClient.php @@ -34,6 +34,7 @@ class FortniteClient { const FORTNITE_ACCOUNT_API = "https://account-public-service-prod03.ol.epicgames.com/account/api/"; const FORTNITE_NEWS_API = "https://fortnitecontent-website-prod07.ol.epicgames.com/content/api/"; const FORTNITE_STATUS_API = "https://lightswitch-public-service-prod06.ol.epicgames.com/lightswitch/api/"; + const FORTNITE_EULA_API = "https://eulatracking-public-service-prod-m.ol.epicgames.com/eulatracking/api/"; diff --git a/src/Status.php b/src/Status.php index 2f20f8a..8ec67cc 100644 --- a/src/Status.php +++ b/src/Status.php @@ -27,4 +27,16 @@ public function get() throw $e; } } + + public function allowedToPlay(){ + try { + $data = FortniteClient::sendFortniteGetRequest(FortniteClient::FORTNITE_STATUS_API . 'service/bulk/status?serviceId=Fortnite', + $this->access_token); + + return !empty($data[0]->allowedActions) && in_array('PLAY',$data[0]->allowedActions); + } catch (GuzzleException $e) { + if ($e->getResponse()->getStatusCode() == 404) throw new \Exception('Unable to obtain Fortnite status.'); + throw $e; + } + } } \ No newline at end of file