Skip to content

Commit

Permalink
Merge pull request #324 from exodus4d/develop
Browse files Browse the repository at this point in the history
v1.1.5
  • Loading branch information
exodus4d authored Sep 24, 2016
2 parents c80db4d + b2641d9 commit 298a515
Show file tree
Hide file tree
Showing 66 changed files with 1,260 additions and 580 deletions.
11 changes: 9 additions & 2 deletions app/main/controller/api/github.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ public function releases($f3){
$md = \Markdown::instance();
foreach($releasesData as &$releaseData){
if(isset($releaseData->body)){
$body = $releaseData->body;

// remove "update information" from release text
// -> keep everything until first "***" -> horizontal line
if( ($pos = strpos($body, '***')) !== false){
$body = substr($body, 0, $pos);
}

// convert list style
$body = str_replace(' - ', '* ', $releaseData->body );
$body = str_replace(' - ', '* ', $body );

$releaseData->body = $md->convert( $body );
$releaseData->body = $md->convert( trim($body) );
}
}
$f3->set($cacheKey, $releasesData, $ttl);
Expand Down
3 changes: 2 additions & 1 deletion app/main/controller/api/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ protected function updateMapData(Model\CharacterModel $character, Model\MapModel
$systemPosX = 0;
$systemPosY = 30;

$sourceSystemId = (int)$this->getF3()->get(User::SESSION_KEY_CHARACTER_PREV_SYSTEM_ID);
$sessionCharacter = $this->getSessionCharacterData();
$sourceSystemId = (int)$sessionCharacter['PREV_SYSTEM_ID'];
$targetSystemId = (int)$log->systemId;

if($sourceSystemId){
Expand Down
11 changes: 10 additions & 1 deletion app/main/controller/api/route.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private function setDynamicJumpData($mapIds = [], $filterData = []){
$whereQuery = "";
$includeScopes = [];
$includeTypes = [];
$includeEOL = true;

if( $filterData['stargates'] === true){
// include "stargates" for search
Expand Down Expand Up @@ -146,6 +147,10 @@ private function setDynamicJumpData($mapIds = [], $filterData = []){
if( $filterData['wormholesCritical'] === true ){
$includeTypes[] = 'wh_critical';
}

if( $filterData['wormholesEOL'] === false ){
$includeEOL = false;
}
}

// search connections -------------------------------------------------------
Expand All @@ -157,6 +162,9 @@ private function setDynamicJumpData($mapIds = [], $filterData = []){
$whereQuery .= " `connection`.`type` REGEXP '" . implode("|", $includeTypes) . "' AND ";
}

if(!$includeEOL){
$whereQuery .= " `connection`.`eolUpdated` IS NULL AND ";
}

$query = "SELECT
`system_src`.`regionId` regionId,
Expand Down Expand Up @@ -521,7 +529,8 @@ public function search($f3){
'jumpbridges' => (bool) $routeData['jumpbridges'],
'wormholes' => (bool) $routeData['wormholes'],
'wormholesReduced' => (bool) $routeData['wormholesReduced'],
'wormholesCritical' => (bool) $routeData['wormholesCritical']
'wormholesCritical' => (bool) $routeData['wormholesCritical'],
'wormholesEOL' => (bool) $routeData['wormholesEOL']
];

$returnRoutData = [
Expand Down
4 changes: 2 additions & 2 deletions app/main/controller/api/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ class System extends \Controller\AccessController {
FROM
mapSolarSystems map_sys INNER JOIN
mapConstellations map_con ON
map_con.constellationID = map_sys.constellationID INNER JOIN
map_sys.constellationID = map_con.constellationID INNER JOIN
mapRegions map_reg ON
map_reg.regionID = map_sys.regionID";
map_con.regionID = map_reg.regionID";

private $whereQuery = "";

Expand Down
64 changes: 38 additions & 26 deletions app/main/controller/api/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,14 @@ class User extends Controller\Controller{
const SESSION_KEY_USER_NAME = 'SESSION.USER.NAME';

// character specific session keys
const SESSION_KEY_CHARACTER = 'SESSION.CHARACTER';
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_CHARACTERS = 'SESSION.CHARACTERS';

const SESSION_KEY_CHARACTER_ACCESS_TOKEN = 'SESSION.CHARACTER.ACCESS_TOKEN';
const SESSION_KEY_CHARACTER_REFRESH_TOKEN = 'SESSION.CHARACTER.REFRESH_TOKEN';
// temp login character ID (during HTTP redirects on login)
const SESSION_KEY_TEMP_CHARACTER_ID = 'SESSION.TEMP_CHARACTER_ID';

// log text
const LOG_LOGGED_IN = 'userId: [%10s], userName: [%30s], charId: [%20s], charName: %s';
const LOG_DELETE_ACCOUNT = 'userId: [%10s], userName: [%30s], ip: [%45s]';
const LOG_DELETE_ACCOUNT = 'userId: [%10s], userName: [%30s]';


/**
Expand All @@ -54,24 +50,40 @@ protected function loginByCharacter(Model\CharacterModel &$characterModel){
$login = false;

if($user = $characterModel->getUser()){
// set user/character data to session -------------------
$this->f3->set(self::SESSION_KEY_USER, [
'ID' => $user->_id,
'NAME' => $user->name
]);

$dateTime = new \DateTime();
$this->f3->set(self::SESSION_KEY_CHARACTER, [
'ID' => $characterModel->_id,
'NAME' => $characterModel->name,
'TIME' => $dateTime->getTimestamp()
]);

// save user login information ---------------------------
// check if character belongs to current user
// -> If there is already a logged in user! (e.g. multi character use)
$currentUser = $this->getUser();

$sessionCharacters = [
[
'ID' => $characterModel->_id,
'NAME' => $characterModel->name,
'TIME' => (new \DateTime())->getTimestamp()
]
];

if(
is_null($currentUser) ||
$currentUser->_id !== $user->_id
){
// user has changed OR new user ---------------------------------------------------
//-> set user/character data to session
$this->f3->set(self::SESSION_KEY_USER, [
'ID' => $user->_id,
'NAME' => $user->name
]);
}else{
// user has NOT changed -----------------------------------------------------------
$sessionCharacters = $characterModel::mergeSessionCharacterData($sessionCharacters);
}

$this->f3->set(self::SESSION_KEY_CHARACTERS, $sessionCharacters);

// save user login information --------------------------------------------------------
$characterModel->touch('lastLogin');
$characterModel->save();

// write login log --------------------------------------
// write login log --------------------------------------------------------------------
self::getLogger('LOGIN')->write(
sprintf(self::LOG_LOGGED_IN,
$user->_id,
Expand Down Expand Up @@ -210,7 +222,7 @@ public function saveAccount(\Base $f3){
if($activeCharacter = $this->getCharacter(0)){
$user = $activeCharacter->getUser();

// captcha is send -> check captcha ---------------------------------
// captcha is send -> check captcha -------------------------------------------
if(
isset($formData['captcha']) &&
!empty($formData['captcha'])
Expand Down Expand Up @@ -250,7 +262,7 @@ public function saveAccount(\Base $f3){
}
}

// sharing config ---------------------------------------------------
// sharing config -------------------------------------------------------------
if(isset($formData['share'])){
$privateSharing = 0;
$corporationSharing = 0;
Expand Down Expand Up @@ -343,7 +355,7 @@ public function deleteAccount(\Base $f3){
if($status){
// save log
self::getLogger('DELETE_ACCOUNT')->write(
sprintf(self::LOG_DELETE_ACCOUNT, $user->id, $user->name, $f3->get('IP'))
sprintf(self::LOG_DELETE_ACCOUNT, $user->id, $user->name)
);

// remove user
Expand Down
84 changes: 41 additions & 43 deletions app/main/controller/ccp/sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ class Sso extends Api\User{
const SESSION_KEY_SSO_STATE = 'SESSION.SSO.STATE';
const SESSION_KEY_SSO_FROM_MAP = 'SESSION.SSO.FROM_MAP';

// cache keys
const CACHE_KEY_LOCATION_DATA = 'CACHED.LOCATION.%s';

// error messages
const ERROR_CCP_SSO_URL = 'Invalid "ENVIRONMENT.[ENVIRONMENT].SSO_CCP_URL" url. %s';
const ERROR_CCP_CREST_URL = 'Invalid "ENVIRONMENT.[ENVIRONMENT].CCP_CREST_URL" url. %s';
Expand Down Expand Up @@ -115,6 +112,10 @@ public function requestAuthorization($f3){
if($loginCheck){
// set "login" cookie
$this->setLoginCookie($character);

// -> pass current character data to target page
$f3->set(Api\User::SESSION_KEY_TEMP_CHARACTER_ID, $character->_id);

// route to "map"
$f3->reroute('@map');
}
Expand Down Expand Up @@ -218,15 +219,18 @@ public function callbackAuthorization($f3){
// -> update character log (current location,...)
$characterModel = $characterModel->updateLog();

// check if there is already an active user logged in
if($activeCharacter = $this->getCharacter()){
// connect character with current user
$user = $activeCharacter->getUser();
}elseif( is_null( $user = $characterModel->getUser()) ){
// no user found (new character) -> create new user and connect to character
$user = Model\BasicModel::getNew('UserModel');
$user->name = $characterModel->name;
$user->save();
// connect character with current user
if( is_null($user = $this->getUser()) ){
// connect character with existing user (no changes)
if( is_null( $user = $characterModel->getUser()) ){
// no user found (new character) -> create new user and connect to character
/**
* @var $user Model\UserModel
*/
$user = Model\BasicModel::getNew('UserModel');
$user->name = $characterModel->name;
$user->save();
}
}

/**
Expand All @@ -251,6 +255,9 @@ public function callbackAuthorization($f3){
// set "login" cookie
$this->setLoginCookie($characterModel);

// -> pass current character data to target page
$f3->set(Api\User::SESSION_KEY_TEMP_CHARACTER_ID, $characterModel->_id);

// route to "map"
$f3->reroute('@map');
}else{
Expand Down Expand Up @@ -308,6 +315,10 @@ public function login(\Base $f3){
// login by character
$loginCheck = $this->loginByCharacter($character);
if($loginCheck){
// set character id
// -> pass current character data to target page
$f3->set(Api\User::SESSION_KEY_TEMP_CHARACTER_ID, $character->_id);

// route to "map"
$f3->reroute('@map');
}
Expand Down Expand Up @@ -617,49 +628,36 @@ public function getCharacterData($accessToken, $additionalOptions = []){
* get current character location data (result is cached!)
* -> solarSystem data where character is currently active
* @param $accessToken
* @param int $ttl
* @param array $additionalOptions
* @return array|mixed
* @return array
*/
public function getCharacterLocationData($accessToken, $ttl = 5, $additionalOptions = []){
public function getCharacterLocationData($accessToken, $additionalOptions = []){
// null == CREST call failed (e.g. timeout)
$locationData = [
'timeout' => false
];

// in addition to the cURL caching (based on cache-control headers,
// the final location data is cached additionally -> speed up
$cacheKey = sprintf(self::CACHE_KEY_LOCATION_DATA, 'TOKEN_' . hash('md5', $accessToken));

if( !$this->getF3()->exists($cacheKey) ){
$endpoints = $this->getEndpoints($accessToken, $additionalOptions);

$additionalOptions['accept'] = 'application/vnd.ccp.eve.CharacterLocation-v1+json';
$endpoint = $this->walkEndpoint($endpoints, $accessToken, [
'decode',
'character',
'location'
], $additionalOptions);

if( !is_null($endpoint) ){
// request succeeded (e.g. no timeout)

if(isset($endpoint['solarSystem'])){
$locationData['system'] = (new Mapper\CrestSystem($endpoint['solarSystem']))->getData();
}
$endpoints = $this->getEndpoints($accessToken, $additionalOptions);

if(isset($endpoint['station'])){
$locationData['station'] = (new Mapper\CrestStation($endpoint['station']))->getData();
}
$additionalOptions['accept'] = 'application/vnd.ccp.eve.CharacterLocation-v1+json';
$endpoint = $this->walkEndpoint($endpoints, $accessToken, [
'decode',
'character',
'location'
], $additionalOptions);

$this->getF3()->set($cacheKey, $locationData, $ttl);
}else{
// timeout
$locationData['timeout'] = true;
if( !is_null($endpoint) ){
// request succeeded (e.g. no timeout)
if(isset($endpoint['solarSystem'])){
$locationData['system'] = (new Mapper\CrestSystem($endpoint['solarSystem']))->getData();
}

if(isset($endpoint['station'])){
$locationData['station'] = (new Mapper\CrestStation($endpoint['station']))->getData();
}
}else{
$locationData = $this->getF3()->get($cacheKey);
// timeout
$locationData['timeout'] = true;
}

return $locationData;
Expand Down
Loading

0 comments on commit 298a515

Please sign in to comment.