- added build files for upcoming version 1.1.2

- improved ajax authentication check and "logout" notification | closed #198
- improved logging, added missing log file configuration to pathfinder.ini
- added  logging for "unauthorized" requests | closed #198
- updated js "jQuery" 1.11.3 -> 3.0.0 | #206
- updated js "datatables" plugin 1.10.7 -> 1.10.12 | #206
- updated js "mCustomScrollbar" 3.1.14 -> 3.1.4 | #206
This commit is contained in:
Exodus4D
2016-07-11 20:35:25 +02:00
parent f943f31d9a
commit cdd1846431
72 changed files with 1732 additions and 10632 deletions

View File

@@ -39,56 +39,53 @@ class Connection extends Controller\AccessController{
$activeCharacter = $this->getCharacter();
if($activeCharacter){
// get map model and check map access
/**
* @var Model\MapModel $map
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById( (int)$mapData['id'] );
// get map model and check map access
/**
* @var Model\MapModel $map
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById( (int)$mapData['id'] );
if( $map->hasAccess($activeCharacter) ){
$source = $map->getSystemById( $connectionData['source'] );
$target = $map->getSystemById( $connectionData['target'] );
if( $map->hasAccess($activeCharacter) ){
$source = $map->getSystemById( $connectionData['source'] );
$target = $map->getSystemById( $connectionData['target'] );
if(
!is_null($source) &&
!is_null($target)
){
/**
* @var $connection Model\ConnectionModel
*/
$connection = Model\BasicModel::getNew('ConnectionModel');
$connection->getById( (int)$connectionData['id'] );
if(
!is_null($source) &&
!is_null($target)
){
/**
* @var $connection Model\ConnectionModel
*/
$connection = Model\BasicModel::getNew('ConnectionModel');
$connection->getById( (int)$connectionData['id'] );
// search if systems are neighbors
$routeController = new Route();
$routeController->initJumpData();
$route = $routeController->findRoute($connectionData['sourceName'], $connectionData['targetName'], 1);
// search if systems are neighbors
$routeController = new Route();
$routeController->initJumpData();
$route = $routeController->findRoute($connectionData['sourceName'], $connectionData['targetName'], 1);
if($route['routePossible'] == true){
// systems are next to each other
$connectionData['scope'] = 'stargate';
$connectionData['type'] = ['stargate'];
}elseif($connectionData['scope'] == 'stargate'){
// connection scope changed -> this can not be a stargate
$connectionData['scope'] = 'wh';
$connectionData['type'] = ['wh_fresh'];
}
if($route['routePossible'] == true){
// systems are next to each other
$connectionData['scope'] = 'stargate';
$connectionData['type'] = ['stargate'];
}elseif($connectionData['scope'] == 'stargate'){
// connection scope changed -> this can not be a stargate
$connectionData['scope'] = 'wh';
$connectionData['type'] = ['wh_fresh'];
}
$connectionData['mapId'] = $map;
$connectionData['mapId'] = $map;
// "updated" should not be set by client e.g. after manual drag&drop
unset($connectionData['updated']);
// "updated" should not be set by client e.g. after manual drag&drop
unset($connectionData['updated']);
$connection->setData($connectionData);
$connection->setData($connectionData);
if( $connection->isValid() ){
$connection->save();
if( $connection->isValid() ){
$connection->save();
$newConnectionData = $connection->getData();
}
$newConnectionData = $connection->getData();
}
}
}
@@ -104,18 +101,17 @@ class Connection extends Controller\AccessController{
*/
public function delete(\Base $f3){
$connectionIds = $f3->get('POST.connectionIds');
$activeCharacter = $this->getCharacter();
if($activeCharacter = $this->getCharacter()){
/**
* @var Model\ConnectionModel $connection
*/
$connection = Model\BasicModel::getNew('ConnectionModel');
foreach($connectionIds as $connectionId){
$connection->getById($connectionId);
$connection->delete( $activeCharacter );
/**
* @var Model\ConnectionModel $connection
*/
$connection = Model\BasicModel::getNew('ConnectionModel');
foreach($connectionIds as $connectionId){
$connection->getById($connectionId);
$connection->delete( $activeCharacter );
$connection->reset();
}
$connection->reset();
}
echo json_encode([]);

View File

@@ -208,117 +208,111 @@ class Map extends Controller\AccessController {
){
$activeCharacter = $this->getCharacter();
if($activeCharacter){
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
/**
* @var $system Model\SystemModel
*/
$system = Model\BasicModel::getNew('SystemModel');
/**
* @var $system Model\SystemModel
*/
$system = Model\BasicModel::getNew('SystemModel');
/**
* @var $connection Model\ConnectionModel
*/
$connection = Model\BasicModel::getNew('ConnectionModel');
foreach($importData['mapData'] as $mapData){
if(
isset($mapData['config']) &&
isset($mapData['data'])
){
/**
* @var $connection Model\ConnectionModel
*/
$connection = Model\BasicModel::getNew('ConnectionModel');
foreach($importData['mapData'] as $mapData){
if(
isset($mapData['config']) &&
isset($mapData['data'])
isset($mapData['data']['systems']) &&
isset($mapData['data']['connections'])
){
if(isset($mapData['config']['id'])){
unset($mapData['config']['id']);
}
$map->setData($mapData['config']);
$map->typeId = (int)$importData['typeId'];
$map->save();
if(
isset($mapData['data']['systems']) &&
isset($mapData['data']['connections'])
){
if(isset($mapData['config']['id'])){
unset($mapData['config']['id']);
// new system IDs will be generated
// therefore we need to temp store a mapping between IDs
$tempSystemIdMapping = [];
foreach($mapData['data']['systems'] as $systemData){
if(isset($systemData['id'])){
$oldId = (int)$systemData['id'];
unset($systemData['id']);
$system->setData($systemData);
$system->mapId = $map;
$system->createdCharacterId = $activeCharacter;
$system->updatedCharacterId = $activeCharacter;
$system->save();
$tempSystemIdMapping[$oldId] = $system->id;
$system->reset();
}
}
$map->setData($mapData['config']);
$map->typeId = (int)$importData['typeId'];
$map->save();
// new system IDs will be generated
// therefore we need to temp store a mapping between IDs
$tempSystemIdMapping = [];
foreach($mapData['data']['systems'] as $systemData){
if(isset($systemData['id'])){
$oldId = (int)$systemData['id'];
unset($systemData['id']);
$system->setData($systemData);
$system->mapId = $map;
$system->createdCharacterId = $activeCharacter;
$system->updatedCharacterId = $activeCharacter;
$system->save();
$tempSystemIdMapping[$oldId] = $system->id;
$system->reset();
foreach($mapData['data']['connections'] as $connectionData){
// check if source and target IDs match with new system ID
if(
isset( $tempSystemIdMapping[$connectionData['source']] ) &&
isset( $tempSystemIdMapping[$connectionData['target']] )
){
if(isset($connectionData['id'])){
unset($connectionData['id']);
}
$connection->setData($connectionData);
$connection->mapId = $map;
$connection->source = $tempSystemIdMapping[$connectionData['source']];
$connection->target = $tempSystemIdMapping[$connectionData['target']];
$connection->save();
$connection->reset();
}
}
foreach($mapData['data']['connections'] as $connectionData){
// check if source and target IDs match with new system ID
if(
isset( $tempSystemIdMapping[$connectionData['source']] ) &&
isset( $tempSystemIdMapping[$connectionData['target']] )
){
if(isset($connectionData['id'])){
unset($connectionData['id']);
}
$connection->setData($connectionData);
$connection->mapId = $map;
$connection->source = $tempSystemIdMapping[$connectionData['source']];
$connection->target = $tempSystemIdMapping[$connectionData['target']];
$connection->save();
$connection->reset();
}
// map access info should not automatically imported
if($map->isPrivate()){
$map->setAccess($activeCharacter);
}elseif($map->isCorporation()){
if($corporation = $activeCharacter->getCorporation()){
$map->setAccess($corporation);
}
// map access info should not automatically imported
if($map->isPrivate()){
$map->setAccess($activeCharacter);
}elseif($map->isCorporation()){
if($corporation = $activeCharacter->getCorporation()){
$map->setAccess($corporation);
}
}elseif($map->isAlliance()){
if($alliance = $activeCharacter->getAlliance()){
$map->setAccess($alliance);
}
}elseif($map->isAlliance()){
if($alliance = $activeCharacter->getAlliance()){
$map->setAccess($alliance);
}
}else{
// systems || connections missing
$missingConfigError = (object) [];
$missingConfigError->type = 'error';
$missingConfigError->message = 'Map data not valid (systems || connections) missing';
$return->error[] = $missingConfigError;
}
}else{
// map config || systems/connections missing
// systems || connections missing
$missingConfigError = (object) [];
$missingConfigError->type = 'error';
$missingConfigError->message = 'Map data not valid (config || data) missing';
$missingConfigError->message = 'Map data not valid (systems || connections) missing';
$return->error[] = $missingConfigError;
}
$map->reset();
}else{
// map config || systems/connections missing
$missingConfigError = (object) [];
$missingConfigError->type = 'error';
$missingConfigError->message = 'Map data not valid (config || data) missing';
$return->error[] = $missingConfigError;
}
}else{
// user not found
$return->error[] = $this->getLogoutError();
$map->reset();
}
}else{
// map data missing
@@ -345,143 +339,140 @@ class Map extends Controller\AccessController {
if( isset($formData['id']) ){
$activeCharacter = $this->getCharacter(0);
if($activeCharacter){
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById( (int)$formData['id'] );
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById( (int)$formData['id'] );
if(
$map->dry() ||
$map->hasAccess($activeCharacter)
){
// new map
$map->setData($formData);
$map = $map->save();
if(
$map->dry() ||
$map->hasAccess($activeCharacter)
){
// new map
$map->setData($formData);
$map = $map->save();
// save global map access. Depends on map "type"
if($map->isPrivate()){
// save global map access. Depends on map "type"
if($map->isPrivate()){
// share map between characters -> set access
if(isset($formData['mapCharacters'])){
// avoid abuse -> respect share limits
$accessCharacters = array_slice( $formData['mapCharacters'], 0, $f3->get('PATHFINDER.MAX_SHARED_CHARACTER') );
// share map between characters -> set access
if(isset($formData['mapCharacters'])){
// clear map access. In case something has removed from access list
$map->clearAccess();
/**
* @var $tempCharacter Model\CharacterModel
*/
$tempCharacter = Model\BasicModel::getNew('CharacterModel');
foreach($accessCharacters as $characterId){
$tempCharacter->getById( (int)$characterId );
if(
!$tempCharacter->dry() &&
$tempCharacter->shared == 1 // check if map shared is enabled
){
$map->setAccess($tempCharacter);
}
$tempCharacter->reset();
}
}
// the current character itself should always have access
// just in case he removed himself :)
$map->setAccess($activeCharacter);
}elseif($map->isCorporation()){
$corporation = $activeCharacter->getCorporation();
if($corporation){
// the current user has to have a corporation when
// working on corporation maps!
// share map between corporations -> set access
if(isset($formData['mapCorporations'])){
// avoid abuse -> respect share limits
$accessCharacters = array_slice( $formData['mapCharacters'], 0, $f3->get('PATHFINDER.MAX_SHARED_CHARACTER') );
$accessCorporations = array_slice( $formData['mapCorporations'], 0, $f3->get('PATHFINDER.MAX_SHARED_CORPORATION') );
// clear map access. In case something has removed from access list
$map->clearAccess();
/**
* @var $tempCharacter Model\CharacterModel
* @var $tempCorporation Model\CorporationModel
*/
$tempCharacter = Model\BasicModel::getNew('CharacterModel');
$tempCorporation = Model\BasicModel::getNew('CorporationModel');
foreach($accessCharacters as $characterId){
$tempCharacter->getById( (int)$characterId );
foreach($accessCorporations as $corporationId){
$tempCorporation->getById( (int)$corporationId );
if(
!$tempCharacter->dry() &&
$tempCharacter->shared == 1 // check if map shared is enabled
!$tempCorporation->dry() &&
$tempCorporation->shared == 1 // check if map shared is enabled
){
$map->setAccess($tempCharacter);
$map->setAccess($tempCorporation);
}
$tempCharacter->reset();
$tempCorporation->reset();
}
}
// the current character itself should always have access
// just in case he removed himself :)
$map->setAccess($activeCharacter);
}elseif($map->isCorporation()){
$corporation = $activeCharacter->getCorporation();
if($corporation){
// the current user has to have a corporation when
// working on corporation maps!
// share map between corporations -> set access
if(isset($formData['mapCorporations'])){
// avoid abuse -> respect share limits
$accessCorporations = array_slice( $formData['mapCorporations'], 0, $f3->get('PATHFINDER.MAX_SHARED_CORPORATION') );
// clear map access. In case something has removed from access list
$map->clearAccess();
/**
* @var $tempCorporation Model\CorporationModel
*/
$tempCorporation = Model\BasicModel::getNew('CorporationModel');
foreach($accessCorporations as $corporationId){
$tempCorporation->getById( (int)$corporationId );
if(
!$tempCorporation->dry() &&
$tempCorporation->shared == 1 // check if map shared is enabled
){
$map->setAccess($tempCorporation);
}
$tempCorporation->reset();
}
}
// the corporation of the current user should always have access
$map->setAccess($corporation);
}
}elseif($map->isAlliance()){
$alliance = $activeCharacter->getAlliance();
if($alliance){
// the current user has to have a alliance when
// working on alliance maps!
// share map between alliances -> set access
if(isset($formData['mapAlliances'])){
// avoid abuse -> respect share limits
$accessAlliances = array_slice( $formData['mapAlliances'], 0, $f3->get('PATHFINDER.MAX_SHARED_ALLIANCE') );
// clear map access. In case something has removed from access list
$map->clearAccess();
/**
* @var $tempAlliance Model\AllianceModel
*/
$tempAlliance = Model\BasicModel::getNew('AllianceModel');
foreach($accessAlliances as $allianceId){
$tempAlliance->getById( (int)$allianceId );
if(
!$tempAlliance->dry() &&
$tempAlliance->shared == 1 // check if map shared is enabled
){
$map->setAccess($tempAlliance);
}
$tempAlliance->reset();
}
}
// the alliance of the current user should always have access
$map->setAccess($alliance);
}
// the corporation of the current user should always have access
$map->setAccess($corporation);
}
// reload the same map model (refresh)
// this makes sure all data is up2date
$map->getById( $map->id, 0 );
}elseif($map->isAlliance()){
$alliance = $activeCharacter->getAlliance();
$return->mapData = $map->getData();
}else{
// map access denied
$captchaError = (object) [];
$captchaError->type = 'error';
$captchaError->message = 'Access denied';
$return->error[] = $captchaError;
if($alliance){
// the current user has to have a alliance when
// working on alliance maps!
// share map between alliances -> set access
if(isset($formData['mapAlliances'])){
// avoid abuse -> respect share limits
$accessAlliances = array_slice( $formData['mapAlliances'], 0, $f3->get('PATHFINDER.MAX_SHARED_ALLIANCE') );
// clear map access. In case something has removed from access list
$map->clearAccess();
/**
* @var $tempAlliance Model\AllianceModel
*/
$tempAlliance = Model\BasicModel::getNew('AllianceModel');
foreach($accessAlliances as $allianceId){
$tempAlliance->getById( (int)$allianceId );
if(
!$tempAlliance->dry() &&
$tempAlliance->shared == 1 // check if map shared is enabled
){
$map->setAccess($tempAlliance);
}
$tempAlliance->reset();
}
}
// the alliance of the current user should always have access
$map->setAccess($alliance);
}
}
// reload the same map model (refresh)
// this makes sure all data is up2date
$map->getById( $map->id, 0 );
$return->mapData = $map->getData();
}else{
// map access denied
$captchaError = (object) [];
$captchaError->type = 'error';
$captchaError->message = 'Access denied';
$return->error[] = $captchaError;
}
}else{
// map id field missing
@@ -502,14 +493,12 @@ class Map extends Controller\AccessController {
$mapData = (array)$f3->get('POST.mapData');
$activeCharacter = $this->getCharacter();
if($activeCharacter){
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapData['id']);
$map->delete( $activeCharacter );
}
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapData['id']);
$map->delete( $activeCharacter );
echo json_encode([]);
}
@@ -527,121 +516,116 @@ class Map extends Controller\AccessController {
$return = (object) [];
$return->error = [];
if($activeCharacter){
$cacheKey = $this->getMapDataCacheKey($activeCharacter);
// if there is any system/connection change data submitted -> save new data
if(
!empty($mapData) ||
!$f3->exists($cacheKey)
){
// get current map data ===============================================================================
$maps = $activeCharacter->getMaps();
$cacheKey = $this->getMapDataCacheKey($activeCharacter);
// loop all submitted map data that should be saved
// -> currently there will only be ONE map data change submitted -> single loop
foreach($mapData as $data){
// if there is any system/connection change data submitted -> save new data
if(
!empty($mapData) ||
!$f3->exists($cacheKey)
){
// get current map data ===============================================================================
$maps = $activeCharacter->getMaps();
$systems = [];
$connections = [];
// loop all submitted map data that should be saved
// -> currently there will only be ONE map data change submitted -> single loop
foreach($mapData as $data){
// check whether system data and/or connection data is send
// empty arrays are not included in ajax requests
if( isset($data['data']['systems']) ){
$systems = (array)$data['data']['systems'];
}
$systems = [];
$connections = [];
if( isset($data['data']['connections']) ){
$connections = (array)$data['data']['connections'];
}
// check whether system data and/or connection data is send
// empty arrays are not included in ajax requests
if( isset($data['data']['systems']) ){
$systems = (array)$data['data']['systems'];
}
// check if system data or connection data is send
if(
count($systems) > 0 ||
count($connections) > 0
){
if( isset($data['data']['connections']) ){
$connections = (array)$data['data']['connections'];
}
// map changes expected =======================================================================
// check if system data or connection data is send
if(
count($systems) > 0 ||
count($connections) > 0
){
// loop current user maps and check for changes
foreach($maps as $map){
// map changes expected =======================================================================
// update system data ---------------------------------------------------------------------
foreach($systems as $i => $systemData){
// loop current user maps and check for changes
foreach($maps as $map){
// check if current system belongs to the current map
$map->filter('systems', ['id = ?', $systemData['id'] ]);
$filteredMap = $map->find(
['id = ?', $map->id ],
['limit' => 1]
);
// update system data ---------------------------------------------------------------------
foreach($systems as $i => $systemData){
// this should never fail
if(is_object($filteredMap)){
$filteredMap = $filteredMap->current();
// check if current system belongs to the current map
$map->filter('systems', ['id = ?', $systemData['id'] ]);
$filteredMap = $map->find(
['id = ?', $map->id ],
['limit' => 1]
);
// system belongs to the current map
if(is_object($filteredMap->systems)){
// update
unset($systemData['updated']);
$system = $filteredMap->systems->current();
$system->setData($systemData);
$system->updatedCharacterId = $activeCharacter;
$system->save();
// this should never fail
if(is_object($filteredMap)){
$filteredMap = $filteredMap->current();
// a system belongs to ONE map -> speed up for multiple maps
unset($systemData[$i]);
}
// system belongs to the current map
if(is_object($filteredMap->systems)){
// update
unset($systemData['updated']);
$system = $filteredMap->systems->current();
$system->setData($systemData);
$system->updatedCharacterId = $activeCharacter;
$system->save();
// a system belongs to ONE map -> speed up for multiple maps
unset($systemData[$i]);
}
}
}
// update connection data -----------------------------------------------------------------
foreach($connections as $i => $connectionData){
// update connection data -----------------------------------------------------------------
foreach($connections as $i => $connectionData){
// check if the current connection belongs to the current map
$map->filter('connections', ['id = ?', $connectionData['id'] ]);
$filteredMap = $map->find(
['id = ?', $map->id ],
['limit' => 1]
);
// check if the current connection belongs to the current map
$map->filter('connections', ['id = ?', $connectionData['id'] ]);
$filteredMap = $map->find(
['id = ?', $map->id ],
['limit' => 1]
);
// this should never fail
if(is_object($filteredMap)){
$filteredMap = $filteredMap->current();
// this should never fail
if(is_object($filteredMap)){
$filteredMap = $filteredMap->current();
// connection belongs to the current map
if(is_object($filteredMap->connections)){
// update
unset($connectionData['updated']);
$connection = $filteredMap->connections->current();
$connection->setData($connectionData);
$connection->save();
// connection belongs to the current map
if(is_object($filteredMap->connections)){
// update
unset($connectionData['updated']);
$connection = $filteredMap->connections->current();
$connection->setData($connectionData);
$connection->save();
// a connection belongs to ONE map -> speed up for multiple maps
unset($connectionData[$i]);
}
// a connection belongs to ONE map -> speed up for multiple maps
unset($connectionData[$i]);
}
}
}
}
}
// format map Data for return
$return->mapData = self::getFormattedMapData($maps);
// cache time(s) per user should be equal or less than this function is called
// prevent request flooding
$responseTTL = (int)$f3->get('PATHFINDER.TIMER.UPDATE_SERVER_MAP.DELAY') / 1000;
$f3->set($cacheKey, $return, $responseTTL);
}else{
// get from cache
$return = $f3->get($cacheKey);
}
// format map Data for return
$return->mapData = self::getFormattedMapData($maps);
// cache time(s) per user should be equal or less than this function is called
// prevent request flooding
$responseTTL = (int)$f3->get('PATHFINDER.TIMER.UPDATE_SERVER_MAP.DELAY') / 1000;
$f3->set($cacheKey, $return, $responseTTL);
}else{
// user logged off
$return->error[] = $this->getLogoutError();
// get from cache
$return = $f3->get($cacheKey);
}
echo json_encode( $return );
@@ -680,71 +664,68 @@ class Map extends Controller\AccessController {
$return = (object) [];
$return->error = [];
if( $activeCharacter = $this->getCharacter(0) ){
$postData = $f3->get('POST');
if( !empty($mapIds = (array)$postData['mapIds']) ){
// IMPORTANT for now -> just update a single map (save performance)
$mapId = (int)reset($mapIds);
// get map and check map access
$map = $activeCharacter->getMap( (int)$mapId);
$activeCharacter = $this->getCharacter(0);
if( !is_null($map) ){
$characterMapData = (array)$postData['characterMapData'];
$postData = $f3->get('POST');
if( !empty($mapIds = (array)$postData['mapIds']) ){
// IMPORTANT for now -> just update a single map (save performance)
$mapId = (int)reset($mapIds);
// get map and check map access
$map = $activeCharacter->getMap( (int)$mapId);
// check if data for specific system is requested
$systemData = (array)$postData['systemData'];
// if data is requested extend the cache key in order to get new data
$requestSystemData = (object) [];
$requestSystemData->mapId = isset($systemData['mapId']) ? (int) $systemData['mapId'] : 0;
$requestSystemData->systemId = isset($systemData['systemData']['id']) ? (int) $systemData['systemData']['id'] : 0;
if( !is_null($map) ){
$characterMapData = (array)$postData['characterMapData'];
// update current location
// -> suppress temporary timeout errors
$activeCharacter = $activeCharacter->updateLog(['suppressTimeoutErrors' => true]);
// check if data for specific system is requested
$systemData = (array)$postData['systemData'];
// if data is requested extend the cache key in order to get new data
$requestSystemData = (object) [];
$requestSystemData->mapId = isset($systemData['mapId']) ? (int) $systemData['mapId'] : 0;
$requestSystemData->systemId = isset($systemData['systemData']['id']) ? (int) $systemData['systemData']['id'] : 0;
// check character log (current system) and manipulate map (e.g. add new system)
if( (bool)$characterMapData['mapTracking'] ){
$map = $this->updateMapData($activeCharacter, $map);
}
// update current location
// -> suppress temporary timeout errors
$activeCharacter = $activeCharacter->updateLog(['suppressTimeoutErrors' => true]);
$cacheKey = $this->getUserDataCacheKey($mapId, $requestSystemData->systemId);
if( !$f3->exists($cacheKey) ){
$return->mapUserData[] = $map->getUserData();
// check character log (current system) and manipulate map (e.g. add new system)
if( (bool)$characterMapData['mapTracking'] ){
$map = $this->updateMapData($activeCharacter, $map);
}
// request signature data for a system if user has map access!
if( $mapId === $requestSystemData->mapId ){
$system = $map->getSystemById( $requestSystemData->systemId );
$cacheKey = $this->getUserDataCacheKey($mapId, $requestSystemData->systemId);
if( !$f3->exists($cacheKey) ){
$return->mapUserData[] = $map->getUserData();
if( !is_null($system) ){
// data for currently selected system
$return->system = $system->getData();
$return->system->signatures = $system->getSignaturesData();
}
// request signature data for a system if user has map access!
if( $mapId === $requestSystemData->mapId ){
$system = $map->getSystemById( $requestSystemData->systemId );
if( !is_null($system) ){
// data for currently selected system
$return->system = $system->getData();
$return->system->signatures = $system->getSignaturesData();
}
// cache time (seconds) should be equal or less than request trigger time
// prevent request flooding
$responseTTL = (int)$f3->get('PATHFINDER.TIMER.UPDATE_SERVER_USER_DATA.DELAY') / 1000;
// cache response
$f3->set($cacheKey, $return, $responseTTL);
}else{
// get from cache
// this should happen if a user has multiple program instances running
// with the same main char
$return = $f3->get($cacheKey);
}
// cache time (seconds) should be equal or less than request trigger time
// prevent request flooding
$responseTTL = (int)$f3->get('PATHFINDER.TIMER.UPDATE_SERVER_USER_DATA.DELAY') / 1000;
// cache response
$f3->set($cacheKey, $return, $responseTTL);
}else{
// get from cache
// this should happen if a user has multiple program instances running
// with the same main char
$return = $f3->get($cacheKey);
}
}
// get current user data -> this should not be cached because each user has different personal data
// even if they have multiple characters using the same map!
$return->userData = $activeCharacter->getUser()->getData();
}else{
// user logged off
$return->error[] = $this->getLogoutError();
}
// get current user data -> this should not be cached because each user has different personal data
// even if they have multiple characters using the same map!
$return->userData = $activeCharacter->getUser()->getData();
echo json_encode( $return );
}
@@ -755,7 +736,7 @@ class Map extends Controller\AccessController {
* @param Model\MapModel $map
* @return Model\MapModel
*/
protected function updateMapData($character, $map){
protected function updateMapData(Model\CharacterModel $character, Model\MapModel $map){
// update "map data" cache in case of map (system/connection) changes
$clearMapDataCache = false;

View File

@@ -531,10 +531,7 @@ class Route extends \Controller\AccessController {
$return->error = [];
$return->routesData = [];
if(
$activeCharacter &&
!empty($requestData['routeData'])
){
if( !empty($requestData['routeData']) ){
$routesData = (array)$requestData['routeData'];

View File

@@ -35,22 +35,20 @@ class Signature extends Controller\AccessController{
if( !empty($systemIds) ){
$activeCharacter = $this->getCharacter();
if($activeCharacter){
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
foreach($systemIds as $systemId){
$system->getById($systemId);
if(
!$system->dry() &&
$system->hasAccess($activeCharacter)
){
$signatureData = $system->getSignaturesData();
}
$system->reset();
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
foreach($systemIds as $systemId){
$system->getById($systemId);
if(
!$system->dry() &&
$system->hasAccess($activeCharacter)
){
$signatureData = $system->getSignaturesData();
}
$system->reset();
}
}
@@ -86,141 +84,138 @@ class Signature extends Controller\AccessController{
if( !is_null($signatureData) ){
$activeCharacter = $this->getCharacter();
if($activeCharacter){
// signature ids that were updated/created
$updatedSignatureIds = [];
// signature ids that were updated/created
$updatedSignatureIds = [];
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
// update/add all submitted signatures
foreach($signatureData as $data){
// this key should not be saved (it is an obj)
unset($data['updated']);
// update/add all submitted signatures
foreach($signatureData as $data){
// this key should not be saved (it is an obj)
unset($data['updated']);
$system->getById( (int)$data['systemId']);
$system->getById( (int)$data['systemId']);
if( !$system->dry() ){
// update/save signature
if( !$system->dry() ){
// update/save signature
/**
* @var $signature Model\SystemSignatureModel
*/
$signature = null;
if( isset($data['pk']) ){
// try to get system by "primary key"
$signature = $system->getSignatureById($activeCharacter, (int)$data['pk']);
}elseif( isset($data['name']) ){
$signature = $system->getSignatureByName($activeCharacter, $data['name']);
}
/**
* @var $signature Model\SystemSignatureModel
*/
$signature = null;
if( isset($data['pk']) ){
// try to get system by "primary key"
$signature = $system->getSignatureById($activeCharacter, (int)$data['pk']);
}elseif( isset($data['name']) ){
$signature = $system->getSignatureByName($activeCharacter, $data['name']);
}
if( is_null($signature) ){
$signature = Model\BasicModel::getNew('SystemSignatureModel');
}
if( is_null($signature) ){
$signature = Model\BasicModel::getNew('SystemSignatureModel');
}
if($signature->dry()){
// new signature
$signature->systemId = $system;
$signature->updatedCharacterId = $activeCharacter;
$signature->createdCharacterId = $activeCharacter;
$signature->setData($data);
}else{
// update signature
if(
isset($data['name']) &&
isset($data['value'])
){
// update single key => value pair
$newData = [
$data['name'] => $data['value']
];
// if groupID changed -> typeID set to 0
if($data['name'] == 'groupId'){
$newData['typeId'] = 0;
}
if($signature->dry()){
// new signature
$signature->systemId = $system;
$signature->updatedCharacterId = $activeCharacter;
$signature->createdCharacterId = $activeCharacter;
$signature->setData($data);
}else{
// update signature
// update complete signature (signature reader dialog)
// systemId should not be updated
unset( $data['systemId'] );
// description should not be updated
unset( $data['description'] );
// prevent some data from overwrite manually changes
// wormhole typeID can not figured out/saved by the sig reader dialog
// -> type could not be identified -> do not overwrite them (e.g. sig update)
if(
isset($data['name']) &&
isset($data['value'])
$data['groupId'] == 5 ||
$data['typeId'] == 0
){
// update single key => value pair
$newData = [
$data['name'] => $data['value']
];
// if groupID changed -> typeID set to 0
if($data['name'] == 'groupId'){
$newData['typeId'] = 0;
}
}else{
// update complete signature (signature reader dialog)
// systemId should not be updated
unset( $data['systemId'] );
// description should not be updated
unset( $data['description'] );
// prevent some data from overwrite manually changes
// wormhole typeID can not figured out/saved by the sig reader dialog
// -> type could not be identified -> do not overwrite them (e.g. sig update)
if(
$data['groupId'] == 5 ||
$data['typeId'] == 0
){
unset( $data['typeId'] );
}
// "sig reader" should not overwrite signature group information
if(
$data['groupId'] == 0 &&
$signature->groupId > 0
){
unset($data['groupId']);
}
$newData = $data;
unset( $data['typeId'] );
}
if( $signature->hasChanged($newData) ){
// Character should only be changed if something else has changed
$signature->updatedCharacterId = $activeCharacter;
$signature->setData($newData);
// "sig reader" should not overwrite signature group information
if(
$data['groupId'] == 0 &&
$signature->groupId > 0
){
unset($data['groupId']);
}
$newData = $data;
}
$signature->save();
$updatedSignatureIds[] = $signature->id;
// get a fresh signature object with the new data. This is a bad work around!
// but i could not figure out what the problem was when using the signature model, saved above :(
// -> some caching problems
/**
* @var $newSignature Model\SystemSignatureModel
*/
$newSignature = Model\BasicModel::getNew('SystemSignatureModel');
$newSignature->getById( $signature->id, 0);
$return->signatures[] = $newSignature->getData();
$signature->reset();
if( $signature->hasChanged($newData) ){
// Character should only be changed if something else has changed
$signature->updatedCharacterId = $activeCharacter;
$signature->setData($newData);
}
}
$system->reset();
$signature->save();
$updatedSignatureIds[] = $signature->id;
// get a fresh signature object with the new data. This is a bad work around!
// but i could not figure out what the problem was when using the signature model, saved above :(
// -> some caching problems
/**
* @var $newSignature Model\SystemSignatureModel
*/
$newSignature = Model\BasicModel::getNew('SystemSignatureModel');
$newSignature->getById( $signature->id, 0);
$return->signatures[] = $newSignature->getData();
$signature->reset();
}
// delete "old" signatures ------------------------------------------------------------------
$system->reset();
}
// delete "old" signatures ------------------------------------------------------------------
if(
$deleteOldSignatures &&
$systemId
){
$system->getById($systemId);
if(
$deleteOldSignatures &&
$systemId
!$system->dry() &&
$system->hasAccess($activeCharacter)
){
$system->getById($systemId);
if(
!$system->dry() &&
$system->hasAccess($activeCharacter)
){
$allSignatures = $system->getSignatures();
foreach($allSignatures as $tempSignature){
if( !in_array($tempSignature->id, $updatedSignatureIds)){
$tempSignature->delete( $activeCharacter );
}
$allSignatures = $system->getSignatures();
foreach($allSignatures as $tempSignature){
if( !in_array($tempSignature->id, $updatedSignatureIds)){
$tempSignature->delete( $activeCharacter );
}
}
}
}
}

View File

@@ -201,47 +201,45 @@ class System extends \Controller\AccessController {
){
$activeCharacter = $this->getCharacter();
if($activeCharacter){
$systemData = (array)$postData['systemData'];
$mapData = (array)$postData['mapData'];
$systemData = (array)$postData['systemData'];
$mapData = (array)$postData['mapData'];
if( isset($systemData['id']) ){
// update existing system (e.g. changed system description) -------------------
if( isset($systemData['id']) ){
// update existing system (e.g. changed system description) -------------------
/**
* @var $system Model\SystemModel
*/
$system = Model\BasicModel::getNew('SystemModel');
$system->getById($systemData['id']);
if( !$system->dry() ){
if( $system->hasAccess($activeCharacter) ){
// system model found
$systemModel = $system;
}
/**
* @var $system Model\SystemModel
*/
$system = Model\BasicModel::getNew('SystemModel');
$system->getById($systemData['id']);
if( !$system->dry() ){
if( $system->hasAccess($activeCharacter) ){
// system model found
$systemModel = $system;
}
}elseif( isset($mapData['id']) ){
// save NEW system ------------------------------------------------------------
}
}elseif( isset($mapData['id']) ){
// save NEW system ------------------------------------------------------------
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapData['id']);
if(
!$map->dry() &&
$map->hasAccess($activeCharacter)
){
// make sure system is not already on map
// --> (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 = $map->getNewSystem($systemData['systemId']);
$systemModel->createdCharacterId = $activeCharacter;
}
// map is not changeable for a system! (security)
$systemData['mapId'] = $map;
/**
* @var $map Model\MapModel
*/
$map = Model\BasicModel::getNew('MapModel');
$map->getById($mapData['id']);
if(
!$map->dry() &&
$map->hasAccess($activeCharacter)
){
// make sure system is not already on map
// --> (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 = $map->getNewSystem($systemData['systemId']);
$systemModel->createdCharacterId = $activeCharacter;
}
// map is not changeable for a system! (security)
$systemData['mapId'] = $map;
}
}
}
@@ -318,27 +316,25 @@ class System extends \Controller\AccessController {
$return->error = [];
$return->systemData = [];
if( $activeCharacter = $this->getCharacter() ){
$constellationId = 0;
$constellationId = 0;
// check for search parameter
if( isset($params['arg1']) ){
$constellationId = (int)$params['arg1'];
}
$cacheKey = 'CACHE_CONSTELLATION_SYSTEMS_' . self::formatHiveKey($constellationId);
// check for search parameter
if( isset($params['arg1']) ){
$constellationId = (int)$params['arg1'];
}
$cacheKey = 'CACHE_CONSTELLATION_SYSTEMS_' . self::formatHiveKey($constellationId);
if($f3->exists($cacheKey)){
$return->systemData = $f3->get($cacheKey);
}else{
if($constellationId > 0){
$systemModels = $this->getSystemModelByIds([$constellationId], 'constellationID');
if($f3->exists($cacheKey)){
$return->systemData = $f3->get($cacheKey);
}else{
if($constellationId > 0){
$systemModels = $this->getSystemModelByIds([$constellationId], 'constellationID');
foreach($systemModels as $systemModel){
$return->systemData[] = $systemModel->getData();
}
$f3->set($cacheKey, $return->systemData, $f3->get('PATHFINDER.CACHE.CONSTELLATION_SYSTEMS') );
foreach($systemModels as $systemModel){
$return->systemData[] = $systemModel->getData();
}
$f3->set($cacheKey, $return->systemData, $f3->get('PATHFINDER.CACHE.CONSTELLATION_SYSTEMS') );
}
}
@@ -356,10 +352,9 @@ class System extends \Controller\AccessController {
$return->error = [];
$return->systemData = [];
if(
($activeCharacter = $this->getCharacter()) &&
!empty($postData['systemData'])
){
if( !empty($postData['systemData'] )){
$activeCharacter = $this->getCharacter();
$return->clearOtherWaypoints = (bool)$postData['clearOtherWaypoints'];
$return->first = (bool)$postData['first'];
@@ -390,17 +385,16 @@ class System extends \Controller\AccessController {
*/
public function delete(\Base $f3){
$systemIds = (array)$f3->get('POST.systemIds');
$activeCharacter = $this->getCharacter();
if($activeCharacter = $this->getCharacter()){
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
foreach((array)$systemIds as $systemId){
$system->getById($systemId);
$system->delete($activeCharacter);
$system->reset();
}
/**
* @var Model\SystemModel $system
*/
$system = Model\BasicModel::getNew('SystemModel');
foreach((array)$systemIds as $systemId){
$system->getById($systemId);
$system->delete($activeCharacter);
$system->reset();
}
echo json_encode([]);

View File

@@ -70,7 +70,7 @@ class User extends Controller\Controller{
$characterModel->save();
// write login log --------------------------------------
self::getLogger( $this->f3->get('PATHFINDER.LOGFILES.LOGIN') )->write(
self::getLogger('LOGIN')->write(
sprintf(self::LOG_LOGGED_IN,
$user->_id,
$user->name,
@@ -162,8 +162,7 @@ class User extends Controller\Controller{
* @param \Base $f3
*/
public function deleteLog(\Base $f3){
$activeCharacter = $this->getCharacter();
if($activeCharacter){
if($activeCharacter = $this->getCharacter()){
if($characterLog = $activeCharacter->getLog()){
$characterLog->erase();
}
@@ -177,6 +176,10 @@ class User extends Controller\Controller{
public function logout(\Base $f3){
$this->deleteLog($f3);
parent::logout($f3);
$return = (object) [];
$return->reroute = rtrim(self::getEnvironmentData('URL'), '/') . $f3->alias('login');
echo json_encode($return);
}
/**
@@ -338,7 +341,7 @@ class User extends Controller\Controller{
if($status){
// save log
$logText = "id: %s, name: %s, ip: %s";
self::getLogger( $this->f3->get('PATHFINDER.LOGFILES.DELETE_ACCOUNT') )->write(
self::getLogger('DELETE_ACCOUNT')->write(
sprintf($logText, $user->id, $user->name, $f3->get('IP'))
);