Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
exodus4d committed Jun 14, 2016
2 parents ecd505a + 5a39829 commit e6cd694
Show file tree
Hide file tree
Showing 81 changed files with 875 additions and 580 deletions.
347 changes: 284 additions & 63 deletions app/main/controller/api/map.php

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions app/main/controller/api/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function _getQuery(){
* @return Model\SystemModel[]
* @throws \Exception
*/
protected function _getSystemModelByIds($columnIDs = [], $column = 'solarSystemID'){
public function getSystemModelByIds($columnIDs = [], $column = 'solarSystemID'){

$systemModels = [];

Expand All @@ -112,8 +112,7 @@ protected function _getSystemModelByIds($columnIDs = [], $column = 'solarSystemI
$rows = $ccpDB->exec($query, null, 60 * 60 * 24);

// format result
$mapper = new Mapper\CcpSystemsMapper($rows);
$ccpSystemsData = $mapper->getData();
$ccpSystemsData = (new Mapper\CcpSystemsMapper($rows))->getData();

foreach($ccpSystemsData as $ccpSystemData){
/**
Expand Down Expand Up @@ -236,7 +235,7 @@ public function save(\Base $f3){
// --> (e.g. multiple simultaneously save() calls for the same system)
if( is_null( $systemModel = $map->getSystemByCCPId($systemData['systemId']) ) ){
// system not found on map -> get static system data (CCP DB)
$systemModel = array_values( $this->_getSystemModelByIds([$systemData['systemId']]) )[0];
$systemModel = $map->getNewSystem($systemData['systemId']);
$systemModel->createdCharacterId = $activeCharacter;
}

Expand Down Expand Up @@ -332,7 +331,7 @@ public function constellationData(\Base $f3, $params){
$return->systemData = $f3->get($cacheKey);
}else{
if($constellationId > 0){
$systemModels = $this->_getSystemModelByIds([$constellationId], 'constellationID');
$systemModels = $this->getSystemModelByIds([$constellationId], 'constellationID');

foreach($systemModels as $systemModel){
$return->systemData[] = $systemModel->getData();
Expand Down
1 change: 1 addition & 0 deletions app/main/controller/api/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class User extends Controller\Controller{
const SESSION_KEY_CHARACTER_ID = 'SESSION.CHARACTER.ID';
const SESSION_KEY_CHARACTER_NAME = 'SESSION.CHARACTER.NAME';
const SESSION_KEY_CHARACTER_TIME = 'SESSION.CHARACTER.TIME';
const SESSION_KEY_CHARACTER_PREV_SYSTEM_ID = 'SESSION.CHARACTER.PREV_SYSTEM_ID';

const SESSION_KEY_CHARACTER_ACCESS_TOKEN = 'SESSION.CHARACTER.ACCESS_TOKEN';
const SESSION_KEY_CHARACTER_REFRESH_TOKEN = 'SESSION.CHARACTER.REFRESH_TOKEN';
Expand Down
104 changes: 59 additions & 45 deletions app/main/controller/ccp/sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public function verifyCharacterData($accessToken){
*/
protected function getEndpoints($accessToken = '', $additionalOptions = []){
$crestUrl = self::getCrestEndpoint();
$additionalOptions['accept'] = 'application/vnd.ccp.eve.Api-v3+json';
$additionalOptions['accept'] = 'application/vnd.ccp.eve.Api-v5+json';
$endpoint = $this->getEndpoint($crestUrl, $accessToken, $additionalOptions);

return $endpoint;
Expand Down Expand Up @@ -677,48 +677,63 @@ public function setWaypoint( Model\CharacterModel $character, $systemId, $option
$waypointData = [];

if( $crestUrlParts ){
$endpointUrl = self::getCrestEndpoint() . '/characters/' . $character->_id . '/navigation/waypoints/';
$systemEndpoint = self::getCrestEndpoint() . '/solarsystems/' . $systemId . '/';

// request body
$content = [
'clearOtherWaypoints' => (bool)$options['clearOtherWaypoints'],
'first' => (bool)$options['first'],
'solarSystem' => [
'href' => $systemEndpoint,
'id' => (int)$systemId
]
];

$requestOptions = [
'timeout' => self::CREST_TIMEOUT,
'method' => 'POST',
'user_agent' => $this->getUserAgent(),
'header' => [
'Scope: characterNavigationWrite',
'Authorization: Bearer ' . $character->getAccessToken(),
'Host: ' . $crestUrlParts['host'],
'Content-Type: application/vnd.ccp.eve.PostWaypoint-v1+json;charset=utf-8',
],
'content' => json_encode($content, JSON_UNESCAPED_SLASHES)
];
$accessToken = $character->getAccessToken();
$endpoints = $this->getEndpoints($accessToken);

$apiResponse = Lib\Web::instance()->request($endpointUrl, $requestOptions);

if( isset($apiResponse['body']) ){
$responseData = json_decode($apiResponse['body']);
// get endpoint list for "ui" endpoints
$uiEndpoints = $endpoint = $this->walkEndpoint($endpoints, $accessToken, [
'decode',
'character',
'ui'
]);

if( empty($responseData) ){
$waypointData['systemId'] = (int)$systemId;
}elseif(
isset($responseData->message) &&
isset($responseData->key)
){
// waypoint could not be set...
$error = (object) [];
$error->type = 'error';
$error->message = $responseData->key;
$waypointData['error'] = $error;
if(
isset($uiEndpoints['setWaypoints']) &&
isset($uiEndpoints['setWaypoints']['href'])
){
$endpointUrl = $uiEndpoints['setWaypoints']['href'];
$systemEndpoint = self::getCrestEndpoint() . '/solarsystems/' . $systemId . '/';

// request body
$content = [
'clearOtherWaypoints' => (bool)$options['clearOtherWaypoints'],
'first' => (bool)$options['first'],
'solarSystem' => [
'href' => $systemEndpoint,
'id' => (int)$systemId
]
];

$requestOptions = [
'timeout' => self::CREST_TIMEOUT,
'method' => 'POST',
'user_agent' => $this->getUserAgent(),
'header' => [
'Scope: characterNavigationWrite',
'Authorization: Bearer ' . $character->getAccessToken(),
'Host: ' . $crestUrlParts['host'],
'Content-Type: application/vnd.ccp.eve.PostWaypoint-v1+json;charset=utf-8',
],
'content' => json_encode($content, JSON_UNESCAPED_SLASHES)
];

$apiResponse = Lib\Web::instance()->request($endpointUrl, $requestOptions);

if( isset($apiResponse['body']) ){
$responseData = json_decode($apiResponse['body']);

if( empty($responseData) ){
$waypointData['systemId'] = (int)$systemId;
}elseif(
isset($responseData->message) &&
isset($responseData->key)
){
// waypoint could not be set...
$error = (object) [];
$error->type = 'error';
$error->message = $responseData->key;
$waypointData['error'] = $error;
}
}
}
}
Expand Down Expand Up @@ -800,13 +815,12 @@ public function getCrestServerStatus(){
$endpoint = $this->walkEndpoint($endpoints, '', ['serviceStatus']);
if( !empty($endpoint) ){
$data->crestOffline = false;
$data->serviceStatus = (new Mapper\CrestServiceStatus($endpoint))->getData();
$data->serviceStatus = (string) $endpoint;
}

$endpoint = $this->walkEndpoint($endpoints, '', ['userCounts']);
$endpoint = $this->walkEndpoint($endpoints, '', ['userCount_str']);
if( !empty($endpoint) ){
$data->crestOffline = false;
$data->userCounts = (new Mapper\CrestUserCounts($endpoint))->getData();
$data->userCounts = (string) $endpoint;
}
return $data;
}
Expand Down
2 changes: 1 addition & 1 deletion app/main/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ static function getController($className){
}

/**
* check weather the page is IGB trusted or not
* check whether the page is IGB trusted or not
* @return boolean
*/
static function isIGBTrusted(){
Expand Down
15 changes: 0 additions & 15 deletions app/main/controller/mailcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ public function __construct(){
$this->set('Content-Type', 'text/html; charset=ISO-8859-1');
}

/**
* send invite key mail
* @param $to
* @param $msg
* @return bool
*/
public function sendInviteKey($to, $msg){
$this->set('To', '<' . $to . '>');
$this->set('From', 'Pathfinder <' . Controller::getEnvironmentData('SMTP_FROM') . '>');
$this->set('Subject', 'Registration Key');
$status = $this->send($msg);

return $status;
}

/**
* send mail to removed user account
* @param $to
Expand Down
23 changes: 21 additions & 2 deletions app/main/model/basicmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ public function __construct($db = NULL, $table = NULL, $fluid = NULL, $ttl = 0){

// events -----------------------------------------
$this->afterinsert(function($self){
$self->afterinsertEvent($self);
$self->clearCacheData();
});

$this->afterupdate( function($self){
$self->afterupdateEvent($self);
$self->clearCacheData();
});

Expand Down Expand Up @@ -317,7 +319,6 @@ public function clearCacheData(){
if( $f3->exists($cacheKey) ){
$f3->clear($cacheKey);
}

}
}

Expand Down Expand Up @@ -360,7 +361,7 @@ public function getById($id, $ttl = 3) {
}

/**
* checks weather this model is active or not
* checks whether this model is active or not
* each model should have an "active" column
* @return bool
*/
Expand Down Expand Up @@ -413,6 +414,24 @@ public function beforeInsertEvent(){
return true;
}

/**
* Event "Hook" function
* can be overwritten
* return false will stop any further action
*/
public function afterinsertEvent(){
return true;
}

/**
* Event "Hook" function
* can be overwritten
* return false will stop any further action
*/
public function afterupdateEvent(){
return true;
}

/**
* Event "Hook" function
* can be overwritten
Expand Down
32 changes: 32 additions & 0 deletions app/main/model/characterlogmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Model;

use Controller\Api\User;
use Controller\Controller;
use DB\SQL\Schema;

class CharacterLogModel extends BasicModel {
Expand Down Expand Up @@ -190,4 +192,34 @@ public function getData(){
return $logData;
}

public function set_systemId($systemId){
if($systemId > 0){
$this->updateCharacterSessionLocation($systemId);
}
return $systemId;
}

/**
* update session data for active character
* @param int $systemId
*/
protected function updateCharacterSessionLocation($systemId){
$controller = new Controller();
$f3 = $this->getF3();
$systemId = (int)$systemId;

if(
( $activeCharacter = $controller->getCharacter() ) &&
( $activeCharacter->_id === $this->characterId->_id )
){
$prevSystemId = (int)$f3->get( User::SESSION_KEY_CHARACTER_PREV_SYSTEM_ID);

if($prevSystemId === 0){
$f3->set( User::SESSION_KEY_CHARACTER_PREV_SYSTEM_ID, $systemId);
}else{
$f3->set( User::SESSION_KEY_CHARACTER_PREV_SYSTEM_ID, (int)$this->systemId);
}
}
}

}
6 changes: 3 additions & 3 deletions app/main/model/charactermodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public function updateLog($additionalOptions = []){
}

if($updateLogData == false){
// ... IGB Header data not found OR character does not match current active character
// ... No IGB Header data found OR character does not match current active character
// -> try to pull data from CREST

$ssoController = new Sso();
Expand Down Expand Up @@ -533,12 +533,12 @@ public function getMaps(){

if($this->characterMaps){
$mapCountPrivate = 0;
foreach($this->characterMaps as &$characterMap){
foreach($this->characterMaps as $characterMap){
if(
$mapCountPrivate < self::getF3()->get('PATHFINDER.MAX_MAPS_PRIVATE') &&
$characterMap->mapId->isActive()
){
$maps[] = &$characterMap->mapId;
$maps[] = $characterMap->mapId;
$mapCountPrivate++;
}
}
Expand Down
Loading

0 comments on commit e6cd694

Please sign in to comment.