Skip to content
This repository has been archived by the owner on Feb 15, 2020. It is now read-only.

Commit

Permalink
Auto accept EULA for new accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin Bellus committed Sep 3, 2018
1 parent f46ee7d commit d3b9028
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
23 changes: 22 additions & 1 deletion src/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
}
7 changes: 5 additions & 2 deletions src/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/FortniteClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/";



Expand Down
12 changes: 12 additions & 0 deletions src/Status.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}

0 comments on commit d3b9028

Please sign in to comment.