- added "inactive/offline-inGame" pilot information to map view, closed #567

This commit is contained in:
Mark Friedrich
2018-04-06 21:05:32 +02:00
parent 5b9f939137
commit df1e54ee5c
20 changed files with 658 additions and 385 deletions

View File

@@ -24,7 +24,7 @@ class Map extends Controller\AccessController {
// cache keys
const CACHE_KEY_INIT = 'CACHED_INIT';
const CACHE_KEY_MAP_DATA = 'CACHED.MAP_DATA.%s';
const CACHE_KEY_USER_DATA = 'CACHED.USER_DATA.%s_%s';
const CACHE_KEY_USER_DATA = 'CACHED.USER_DATA.%s';
const CACHE_KEY_HISTORY = 'CACHED_MAP_HISTORY_%s';
@@ -52,11 +52,10 @@ class Map extends Controller\AccessController {
/**
* get user data cache key
* @param int $mapId
* @param int $systemId
* @return string
*/
protected function getUserDataCacheKey($mapId, $systemId = 0): string {
return sprintf(self::CACHE_KEY_USER_DATA, 'MAP_' . $mapId, 'SYS_' . $systemId);
protected function getUserDataCacheKey(int $mapId): string {
return sprintf(self::CACHE_KEY_USER_DATA, 'MAP_' . $mapId);
}
/**
@@ -652,11 +651,18 @@ class Map extends Controller\AccessController {
$return = (object) [];
$activeCharacter = $this->getCharacter();
$characterData = $activeCharacter->getData(true);
$maps = $activeCharacter->getMaps();
// some character data is not required (in WebSocket) -> unset() and keep return small
if(isset($characterData->corporation->rights)){
unset($characterData->corporation->rights);
}
$return->data = [
'id' => $activeCharacter->_id,
'token' => bin2hex(random_bytes(16)), // token for character access
'characterData' => $characterData,
'mapData' => []
];
@@ -851,61 +857,51 @@ class Map extends Controller\AccessController {
* @throws Exception\PathfinderException
*/
public function updateUserData(\Base $f3){
$return = (object) [];
$postData = (array)$f3->get('POST');
$mapIds = (array)$postData['mapIds'];
$getMapUserData = (bool)$postData['getMapUserData'];
$mapTracking = (bool)$postData['mapTracking'];
$systemData = (array)$postData['systemData'];
$activeCharacter = $this->getCharacter(0);
$postData = $f3->get('POST');
if( !empty($mapIds = (array)$postData['mapIds']) ){
$return = (object)[];
// update current location
// -> suppress temporary timeout errors
$activeCharacter = $activeCharacter->updateLog(['suppressHTTPErrors' => true]);
if( !empty($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);
if( !is_null($map) ){
$characterMapData = (array)$postData['characterMapData'];
// 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;
// update current location
// -> suppress temporary timeout errors
$activeCharacter = $activeCharacter->updateLog(['suppressHTTPErrors' => true]);
if( !is_null($map = $activeCharacter->getMap($mapId)) ){
// check character log (current system) and manipulate map (e.g. add new system)
if( (bool)$characterMapData['mapTracking'] ){
if($mapTracking){
$map = $this->updateMapData($activeCharacter, $map);
}
// get from cache
// this should happen if a user has multiple program instances running
// with the same main char
$cacheKey = $this->getUserDataCacheKey($mapId, $requestSystemData->systemId);
if( !$f3->exists($cacheKey, $return) ){
$return = (object) [];
$return->mapUserData[] = $map->getUserData();
// mapUserData ----------------------------------------------------------------------------------------
if($getMapUserData){
$cacheKey = $this->getUserDataCacheKey($mapId);
if( !$f3->exists($cacheKey, $mapUserData) ){
$mapUserData = $map->getUserData();
// 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)Config::getPathfinderData('timer.update_server_user_data.delay') / 1000;
$f3->set($cacheKey, $mapUserData, $responseTTL);
}
$return->mapUserData[] = $mapUserData;
}
// cache time (seconds) should be equal or less than request trigger time
// prevent request flooding
$responseTTL = (int)Config::getPathfinderData('timer.update_server_user_data.delay') / 1000;
// cache response
$f3->set($cacheKey, $return, $responseTTL);
// systemData -----------------------------------------------------------------------------------------
if(
$mapId === (int)$systemData['mapId'] &&
!is_null($system = $map->getSystemById((int)$systemData['systemData']['id']))
){
// data for currently selected system
$return->system = $system->getData();
$return->system->signatures = $system->getSignaturesData();
}
}
}