WIP: Fortnite Support

parent 4483115b
Pipeline #1328 passed with stages
in 4 minutes and 44 seconds
......@@ -2,12 +2,19 @@ APP_ENV=local
APP_DEBUG=true
APP_DEBUGBAR=true
APP_KEY=SomeRandomString
BUNGIE_KEY=xxxx
GOOGLE_REDIRECT=http://pandalove.club/oauth2callback
GOOGLE_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
GOOGLE_ID=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
XBOXAPI_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
HALO5_KEY=xx
BUNGIE_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
HALO5_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
FORTNITE_LAUNCHER_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
FORTNITE_CLIENT_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
FORTNITE_USER_EMAIL=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
FORTNITE_USER_PASSWORD=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DB_HOST=127.0.0.1
DB_DATABASE=pandalove
......
<?php
namespace Onyx\Fortnite;
use Onyx\Fortnite\Helpers\Network\Http;
/**
* Class Client.
*/
class Client extends Http
{
/**
* @var array
*/
private $account_cached = [];
public function getAccountRoyaleStats(string $name, string $platform)
{
$this->getJson('test');
}
public function getAccountByTag(string $name, string $platform)
{
$this->getJson('test');
}
//---------------------------------------------------------------------------------
// Private Functions
//---------------------------------------------------------------------------------
}
<?php
namespace Onyx\Fortnite;
/**
* Class Constants
* @package Onyx\Fortnite
*/
class Constants
{
public static $oAuthToken = 'https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/token';
public static $oAuthExchange = 'https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/exchange';
public static $oAuthVerify = 'https://account-public-service-prod03.ol.epicgames.com/account/api/oauth/verify?includePerms=true';
public static $lookup = 'https://persona-public-service-prod06.ol.epicgames.com/persona/api/public/account/lookup?q=%s';
public static $PvE = 'https://fortnite-public-service-prod11.ol.epicgames.com/fortnite/api/game/v2/profile/%d/client/QueryProfile?profileId=athena&rvn=-1';
public static $PvP = 'https://fortnite-public-service-prod11.ol.epicgames.com/fortnite/api/stats/accountId/%d/bulk/window/alltime';
}
<?php
namespace Onyx\Fortnite\Helpers\Network;
use GuzzleHttp\Client as Guzzle;
use Onyx\Fortnite\Constants;
class Http
{
/**
* @var \GuzzleHttp\Client
*/
protected $guzzle;
/**
* @var array
*/
protected $config;
public function __construct()
{
$this->setupGuzzle();
$this->config = config('services.fortnite');
}
private function setupGuzzle()
{
$this->guzzle = new Guzzle();
}
public function getJson($url)
{
$this->oAuthLogin();
if (!$this->guzzle instanceof Guzzle) {
$this->setupGuzzle();
}
$response = $this->guzzle->get($url, [
'headers' => [
'Accept' => 'application/json',
],
]);
if ($response->getStatusCode() != 200) {
throw new FortniteApiNetworkException();
}
return json_decode($response->getBody(), true);
}
private function oAuthLogin()
{
$payload = [
'grant_type' => 'password',
'username' => $this->config['email'],
'password' => $this->config['password'],
'includePerms' => true
];
if (! $this->guzzle instanceof Guzzle) {
$this->setupGuzzle();
}
$response = $this->guzzle->post(Constants::$oAuthToken, [
'headers' => [
'Authorization' => 'Basic ' . $this->config['launcher'],
'Accept' => 'application/json',
],
'form_params' => $payload
]);
if ($response->getStatusCode() !== 200) {
throw new FortniteApiNetworkException();
}
$tokens = json_decode($response->getBody(), true);
if (isset($tokens['access_token'])) {
$this->oAuthExchange($tokens['access_token']);
}
}
private function oAuthExchange(string $accessToken): void
{
$response = $this->guzzle->get(Constants::$oAuthExchange, [
'headers' => [
'Authorization' => 'Bearer ' . $accessToken,
'Accept' => 'application/json'
]
]);
if ($response->getStatusCode() !== 200) {
throw new FortniteApiNetworkException();
}
$data = json_decode($response->getBody(), true);
if (isset($data['code'])) {
$this->oAuthEglToken($data['code']);
}
}
private function oAuthEglToken(string $exchangeCode): void
{
$payload = [
'grant_type' => 'exchange_code',
'exchange_code' => $exchangeCode,
'includePerms' => true,
'token_type' => 'egl'
];
$response = $this->guzzle->post(Constants::$oAuthToken, [
'headers' => [
'Authorization' => 'Basic ' . $this->config['client'],
'Accept' => 'application/json',
],
'form_params' => $payload
]);
if ($response->getStatusCode() !== 200) {
throw new FortniteApiNetworkException();
}
$data = json_decode($response->getBody(), true);
dd($data);
// TODO
}
}
class FortniteApiNetworkException extends \Exception
{
}
......@@ -15,10 +15,12 @@ use Onyx\Destiny\Objects\Game;
use Onyx\Destiny\PlayerNotFoundException;
use Onyx\Destiny2\Client as Destiny2Client;
use Onyx\Destiny2\Helpers\Network\Bungie2OfflineException;
use Onyx\Fortnite\Helpers\Network\FortniteApiNetworkException;
use Onyx\Halo5\Client as Halo5Client;
use Onyx\Halo5\H5PlayerNotFoundException;
use Onyx\Overwatch\Client as OverwatchClient;
use Onyx\Overwatch\Helpers\Network\OWApiNetworkException;
use Onyx\Fortnite\Client as FortniteClient;
use Onyx\User;
use Onyx\XboxLive\Client as XboxClient;
......@@ -115,6 +117,19 @@ class CustomValidator extends Validator
return true;
}
public function validateFortniteReal($attribute, $value, $parameters)
{
$client = new FortniteClient();
try {
$account = $client->getAccountByTag($value, $this->data['platform']);
} catch (FortniteApiNetworkException $ex) {
return false;
}
return true;
}
public function validateCharacterReal($attribute, $value, $parameters)
{
try {
......
......@@ -10,10 +10,12 @@ use Onyx\Halo5\Client as Halo5Client;
use Onyx\Halo5\H5PlayerNotFoundException;
use Onyx\Halo5\Objects\Data as Halo5Data;
use Onyx\Overwatch\Client as OverwatchClient;
use Onyx\Fortnite\Client as FortniteClient;
use PandaLove\Commands\UpdateDestinyAccount;
use PandaLove\Commands\UpdateHalo5Account;
use PandaLove\Http\Requests\AddDestiny2GamertagRequest;
use PandaLove\Http\Requests\AddDestinyGamertagRequest;
use PandaLove\Http\Requests\AddFortniteRequest;
use PandaLove\Http\Requests\AddHalo5GamertagRequest;
use PandaLove\Http\Requests\AddOverwatchRequest;
......@@ -85,6 +87,25 @@ class AccountController extends Controller
}
}
public function postAddFortniteGamertag(AddFortniteRequest $request)
{
try {
$client = new FortniteClient();
$gamertag = $request->request->get('gamertag');
$platform = $request->request->get('platform');
dd($gamertag, $platform);
} catch (\Exception $ex) {
return redirect('/account', [
'close' => true,
'type' => 'yellow',
'header' => 'Uh oh',
'body' => 'We could not find this name on either Xbox/PS/PC',
]);
}
}
public function postAddDestiny2Gamertag(AddDestiny2GamertagRequest $request)
{
try {
......
<?php
namespace PandaLove\Http\Requests;
/**
* Class AddFortniteRequest
* @package PandaLove\Http\Requests
*/
class AddFortniteRequest extends Request
{
protected $errorBag = 'fortnite';
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
\Input::merge(array_map('trim', \Input::all()));
return [
'gamertag' => 'required|min:3|fortnite-real',
'platform' => 'required|in:0,1,2',
];
}
}
......@@ -4,6 +4,8 @@ namespace PandaLove\Http\Requests;
class AddOverwatchRequest extends Request
{
protected $errorBag = 'overwatch';
/**
* Determine if the user is authorized to make this request.
*
......
......@@ -25,6 +25,8 @@ Route::get('/destiny2/profile/{console}/{gamertag}/{characterId?}', 'Destiny2\Pr
//# Xbox
Route::controller('/xbox/api/v1', 'Xbox\ApiV1Controller');
//# Fortnite
//# Halo 5
Route::controller('/h5/api/v1', 'Halo5\ApiV1Controller');
Route::controller('/h5/api/panda', 'Halo5\LeafApiController');
......
......@@ -52,4 +52,11 @@ return [
'key' => env('XBOXAPI_KEY'),
],
'fortnite' => [
'email' => env('FORTNITE_USER_EMAIL'),
'password' => env('FORTNITE_USER_PASSWORD'),
'launcher' => env('FORTNITE_LAUNCHER_TOKEN'),
'client' => env('FORTNITE_CLIENT_TOKEN'),
],
];
......@@ -92,7 +92,8 @@ supporting now 3 full games (Destiny, Halo 5 & Overwatch) with countless plugins
- Go here https://xboxapi.com/ - Get an XboxAPI API Key and put it in `XBOXAPI_KEY` in `.env` file.
- Go here https://www.bungie.net/en/User/API - Get a Destiny API Key and put it in `BUNGIE_KEY` in `.env` file.
- Go here https://developer.haloapi.com/ - Get a Halo API Key and put it in `HALO5_KEY` in `.env` file.
- Go here https://github.com/SunDwarf/OWAPI - You don't need an API key, but be reasonable. Toss the dev some money.
- Go here https://github.com/SunDwarf/OWAPI - You don't need an API key for Overwatch, but be reasonable. Toss the dev some money.
- Go here https://github.com/qlaffont/fortnite-api#init - You need the OAUTH keys harvested from an account.
- Now we need to utilize those APIs to get some data. If you don't have API keys for the above 3 systems. This will fail.
- `php artisan halo5:batch-metadata`
- Go here https://console.developers.google.com - "Create a Project"
......
......@@ -28,6 +28,17 @@
@include('includes.account.add-overwatch')
</div>
</div>
<div class="ui divider"></div>
<div class="ui two column very relaxed stackable grid">
<div class="column">
@include('includes.account.add-fortnite')
</div>
<div class="column">
<div class="ui info message">
TODO: Another game
</div>
</div>
</div>
</article>
</div>
@endsection
\ No newline at end of file
{!! Form::open(['action' => 'AccountController@postAddFortniteGamertag', 'class' => 'form']) !!}
@foreach ($errors->fortnite->all() as $error)
<p class="ui red message">{{ $error }}</p>
@endforeach
<div class="two fields">
<div class="field {{ $errors->fortnite->has('gamertag') ? 'error' : '' }}">
<label>Username</label>
<input type="text" name="gamertag" id="gamertag" placeholder="Username" />
</div>
<div class="field {{ $errors->fortnite->has('platform') ? 'error' : '' }}">
<label>Platform</label>
<div class="ui selection dropdown">
<input type="hidden" name="platform">
<i class="dropdown icon"></i>
<div class="default text">Platform</div>
<div class="menu">
<div class="item" data-value="{{ \Onyx\XboxLive\Enums\Console::Xbox }}">Xbox</div>
<div class="item" data-value="{{ \Onyx\XboxLive\Enums\Console::PSN }}">PSN</div>
<div class="item" data-value="{{ \Onyx\XboxLive\Enums\Console::PC }}">PC</div>
</div>
</div>
</div>
</div>
<br />
<ul class="actions">
<li><input type="submit" value="Add Fortnite Account" /></li>
</ul>
{!! Form::close() !!}
@section('inline-js')
<script type="text/javascript">
$(document).on('ready', function() {
$('.ui.dropdown')
.dropdown()
;
});
</script>
@append
\ No newline at end of file
{!! Form::open(['action' => 'AccountController@postAddOverwatchGamertag', 'class' => 'form']) !!}
@foreach ($errors->all() as $error)
@foreach ($errors->overwatch->all() as $error)
<p class="ui red message">{{ $error }}</p>
@endforeach
<div class="two fields">
<div class="field {{ $errors->has('gamertag') ? 'error' : '' }}">
<div class="field {{ $errors->overwatch->has('gamertag') ? 'error' : '' }}">
<label>Gamertag / PSN / PC</label>
<input type="text" name="gamertag" id="gamertag" placeholder="Gamertag" />
</div>
<div class="field {{ $errors->has('platform') ? 'error' : '' }}">
<div class="field {{ $errors->overwatch->has('platform') ? 'error' : '' }}">
<label>Platform</label>
<div class="ui selection dropdown">
<input type="hidden" name="platform">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment