From 46967e8934c5e69bafcb70a4f2903cbb8bbc73d3 Mon Sep 17 00:00:00 2001 From: soneill Date: Tue, 27 Jul 2021 22:14:37 +1200 Subject: [PATCH 1/8] updates controller/api/map.php to get maps from all logged in characters --- app/Controller/Api/Map.php | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/app/Controller/Api/Map.php b/app/Controller/Api/Map.php index 94406397..2760dbc5 100644 --- a/app/Controller/Api/Map.php +++ b/app/Controller/Api/Map.php @@ -467,7 +467,17 @@ class Map extends Controller\AccessController { $activeCharacter = $this->getCharacter(); $characterData = $activeCharacter->getData(true); - $maps = $activeCharacter->getMaps(); + $sessionCharacterIds = array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID'); + $maps = []; + $mapIds = []; + foreach($activeCharacter->getAll($sessionCharacterIds) as $character){ + foreach($character->getMaps() as $map){ + if(!in_array($map->_id, $mapIds)){ + array_push($maps, $map); + array_push($mapIds, $map->_id); + } + } + } // some character data is not required (in WebSocket) -> unset() and keep return small if(isset($characterData->corporation->rights)){ @@ -521,7 +531,17 @@ class Map extends Controller\AccessController { $return->mapData = []; $mapIdsChanged = []; - $maps = $character->getMaps(); + $sessionCharacterIds = array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID'); + $maps = []; + $mapIds = []; + foreach($character->getAll($sessionCharacterIds) as $char){ + foreach($char->getMaps() as $map){ + if(!in_array($map->_id, $mapIds)){ + array_push($maps, $map); + array_push($mapIds, $map->_id); + } + } + } if(!empty($mapsData) && !empty($maps)){ // loop all $mapsData that should be saved From c92526af7697725d4785f1141b0f773e3b96659e Mon Sep 17 00:00:00 2001 From: soneill Date: Wed, 28 Jul 2021 13:41:49 +1200 Subject: [PATCH 2/8] restores controller/api/map.php and reimplements changes in model/pathfinder/CharacterModel#getMaps() --- app/Controller/Api/Map.php | 24 +--------- app/Model/Pathfinder/CharacterModel.php | 59 ++++++++++++++++--------- 2 files changed, 41 insertions(+), 42 deletions(-) diff --git a/app/Controller/Api/Map.php b/app/Controller/Api/Map.php index 2760dbc5..94406397 100644 --- a/app/Controller/Api/Map.php +++ b/app/Controller/Api/Map.php @@ -467,17 +467,7 @@ class Map extends Controller\AccessController { $activeCharacter = $this->getCharacter(); $characterData = $activeCharacter->getData(true); - $sessionCharacterIds = array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID'); - $maps = []; - $mapIds = []; - foreach($activeCharacter->getAll($sessionCharacterIds) as $character){ - foreach($character->getMaps() as $map){ - if(!in_array($map->_id, $mapIds)){ - array_push($maps, $map); - array_push($mapIds, $map->_id); - } - } - } + $maps = $activeCharacter->getMaps(); // some character data is not required (in WebSocket) -> unset() and keep return small if(isset($characterData->corporation->rights)){ @@ -531,17 +521,7 @@ class Map extends Controller\AccessController { $return->mapData = []; $mapIdsChanged = []; - $sessionCharacterIds = array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID'); - $maps = []; - $mapIds = []; - foreach($character->getAll($sessionCharacterIds) as $char){ - foreach($char->getMaps() as $map){ - if(!in_array($map->_id, $mapIds)){ - array_push($maps, $map); - array_push($mapIds, $map->_id); - } - } - } + $maps = $character->getMaps(); if(!empty($mapsData) && !empty($maps)){ // loop all $mapsData that should be saved diff --git a/app/Model/Pathfinder/CharacterModel.php b/app/Model/Pathfinder/CharacterModel.php index ac6af0df..18aaaa2a 100644 --- a/app/Model/Pathfinder/CharacterModel.php +++ b/app/Model/Pathfinder/CharacterModel.php @@ -1292,30 +1292,49 @@ class CharacterModel extends AbstractPathfinderModel { * @return MapModel[] */ public function getMaps() : array { - $maps = []; - - if($alliance = $this->getAlliance()){ - $maps = array_merge($maps, $alliance->getMaps()); - } - - if($corporation = $this->getCorporation()){ - $maps = array_merge($maps, $corporation->getMaps()); - } - - if(is_object($this->characterMaps)){ - $mapCountPrivate = 0; - foreach($this->characterMaps as $characterMap){ - if( - $mapCountPrivate < Config::getMapsDefaultConfig('private')['max_count'] && - $characterMap->mapId->isActive() - ){ - $maps[] = $characterMap->mapId; - $mapCountPrivate++; + $maps = ["maps" => [], "characters" => [], "mapIds" => []]; + + foreach($this->getAll(array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID')) as $character){ + $charId = $character->_id; + if(in_array($character->_id, $maps["characters"])){ + continue; + } + if($alliance = $character->getAlliance()){ + foreach($alliance->getMaps() as $map){ + if(!in_array($map->_id, $maps["mapIds"])){ + array_push($maps["maps"], $map); + array_push($maps["mapIds"], $map->id); + } } } + + if($corporation = $character->getCorporation()){ + foreach($corporation->getMaps() as $map){ + if(!in_array($map->_id, $maps["mapIds"])){ + array_push($maps["maps"], $map); + array_push($maps["mapIds"], $map->id); + } + } + } + + if(is_object($character->characterMaps)){ + $mapCountPrivate = 0; + foreach($character->characterMaps as $characterMap){ + if( + $mapCountPrivate < Config::getMapsDefaultConfig('private')['max_count'] && + $characterMap->mapId->isActive() && + !in_array($map->_id, $maps["mapIds"]) + ){ + array_push($maps["maps"], $characterMap->mapId); + array_push($maps["mapIds"], $map->id); + $mapCountPrivate++; + } + } + } + array_push($maps["characters"], $character->_id); } - return $maps; + return $maps["maps"]; } /** From 671a16572fe42fc1660ecfe096a941f798fe0e1d Mon Sep 17 00:00:00 2001 From: soneill Date: Wed, 28 Jul 2021 15:09:25 +1200 Subject: [PATCH 3/8] extracts session maps into new getSessionCharacterMaps method --- app/Model/Pathfinder/CharacterModel.php | 49 +++++++++++++++++++++---- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/app/Model/Pathfinder/CharacterModel.php b/app/Model/Pathfinder/CharacterModel.php index 18aaaa2a..4d8bc15f 100644 --- a/app/Model/Pathfinder/CharacterModel.php +++ b/app/Model/Pathfinder/CharacterModel.php @@ -1292,13 +1292,47 @@ class CharacterModel extends AbstractPathfinderModel { * @return MapModel[] */ public function getMaps() : array { - $maps = ["maps" => [], "characters" => [], "mapIds" => []]; - - foreach($this->getAll(array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID')) as $character){ - $charId = $character->_id; - if(in_array($character->_id, $maps["characters"])){ - continue; + if(Config::getPathfinderData('experiments.session_sharing') === 1){ + $maps = $this->getSessionCharacterMaps(); + }else{ + $maps = []; + + if($alliance = $this->getAlliance()){ + $maps = array_merge($maps, $alliance->getMaps()); } + + if($corporation = $this->getCorporation()){ + $maps = array_merge($maps, $corporation->getMaps()); + } + + if(is_object($this->characterMaps)){ + $mapCountPrivate = 0; + foreach($this->characterMaps as $characterMap){ + if( + $mapCountPrivate < Config::getMapsDefaultConfig('private')['max_count'] && + $characterMap->mapId->isActive() + ){ + $maps[] = $characterMap->mapId; + $mapCountPrivate++; + } + } + } + } + + return $maps; + } + + /** + * get all accessible map models for all characters in session + * using mapIds and characters index arrays to track what has already been processed + * @return MapModel[] + */ + public function getSessionCharacterMaps() : array { + $maps = ["maps" => [], "mapIds" => []]; + + // get all characters in session and iterate over them + foreach($this->getAll(array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID')) as $character){ + if($alliance = $character->getAlliance()){ foreach($alliance->getMaps() as $map){ if(!in_array($map->_id, $maps["mapIds"])){ @@ -1331,7 +1365,6 @@ class CharacterModel extends AbstractPathfinderModel { } } } - array_push($maps["characters"], $character->_id); } return $maps["maps"]; @@ -1443,4 +1476,4 @@ class CharacterModel extends AbstractPathfinderModel { return (new self())->find($query); } -} \ No newline at end of file +} \ No newline at end of file From 144e08f7e735535f128aa6d25610b28822d06e7c Mon Sep 17 00:00:00 2001 From: soneill Date: Wed, 28 Jul 2021 15:10:41 +1200 Subject: [PATCH 4/8] adds login.session_sharing option to pathfinder.ini --- app/pathfinder.ini | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/pathfinder.ini b/app/pathfinder.ini index ea258348..db69b436 100644 --- a/app/pathfinder.ini +++ b/app/pathfinder.ini @@ -70,6 +70,13 @@ COOKIE_EXPIRE = 30 ; Default: 0 MODE_MAINTENANCE = 0 +; Share maps between logged in characters in the same session +; If enabled this will grant the active character access to any maps +; that other characters from the "switch character" menu have access to +; Syntax 0 | 1 +; Default 0 +SESSION_SHARING = 1 + ; Login restrictions (white lists) ; Login/registration can be restricted to specific groups. ; Use comma separated strings for CCP Ids (e.g. 1000166,1000080). From 335b33916f74ac8efdd25da5eed1fdf1a6587c40 Mon Sep 17 00:00:00 2001 From: soneill Date: Wed, 28 Jul 2021 15:11:09 +1200 Subject: [PATCH 5/8] updates config key in getMaps --- app/Model/Pathfinder/CharacterModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Model/Pathfinder/CharacterModel.php b/app/Model/Pathfinder/CharacterModel.php index 4d8bc15f..778ecacc 100644 --- a/app/Model/Pathfinder/CharacterModel.php +++ b/app/Model/Pathfinder/CharacterModel.php @@ -1292,7 +1292,7 @@ class CharacterModel extends AbstractPathfinderModel { * @return MapModel[] */ public function getMaps() : array { - if(Config::getPathfinderData('experiments.session_sharing') === 1){ + if(Config::getPathfinderData('login.session_sharing') === 1){ $maps = $this->getSessionCharacterMaps(); }else{ $maps = []; From bd55ba8316e88c97b3a5ee5eb3c0d279aff4c495 Mon Sep 17 00:00:00 2001 From: soneill Date: Wed, 28 Jul 2021 15:51:51 +1200 Subject: [PATCH 6/8] removes indexing of characterMaps --- app/Model/Pathfinder/CharacterModel.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Model/Pathfinder/CharacterModel.php b/app/Model/Pathfinder/CharacterModel.php index 778ecacc..7279734b 100644 --- a/app/Model/Pathfinder/CharacterModel.php +++ b/app/Model/Pathfinder/CharacterModel.php @@ -1331,8 +1331,7 @@ class CharacterModel extends AbstractPathfinderModel { $maps = ["maps" => [], "mapIds" => []]; // get all characters in session and iterate over them - foreach($this->getAll(array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID')) as $character){ - + foreach($this->getAll(array_column($this->getF3()->get(User::SESSION_KEY_CHARACTERS), 'ID')) as $character){ if($alliance = $character->getAlliance()){ foreach($alliance->getMaps() as $map){ if(!in_array($map->_id, $maps["mapIds"])){ @@ -1356,11 +1355,9 @@ class CharacterModel extends AbstractPathfinderModel { foreach($character->characterMaps as $characterMap){ if( $mapCountPrivate < Config::getMapsDefaultConfig('private')['max_count'] && - $characterMap->mapId->isActive() && - !in_array($map->_id, $maps["mapIds"]) + $characterMap->mapId->isActive() ){ array_push($maps["maps"], $characterMap->mapId); - array_push($maps["mapIds"], $map->id); $mapCountPrivate++; } } From 567eedc9f830a4abbb10e09ac53a7fb9c5ff2ae0 Mon Sep 17 00:00:00 2001 From: soneill Date: Thu, 29 Jul 2021 15:47:43 +1200 Subject: [PATCH 7/8] alters Model/Pathfinder/CharacterModel#isAuthorized() to authorize characters based on session --- app/Model/Pathfinder/CharacterModel.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/Model/Pathfinder/CharacterModel.php b/app/Model/Pathfinder/CharacterModel.php index 7279734b..db0b8ac5 100644 --- a/app/Model/Pathfinder/CharacterModel.php +++ b/app/Model/Pathfinder/CharacterModel.php @@ -655,6 +655,12 @@ class CharacterModel extends AbstractPathfinderModel { ){ // no corp/ally restrictions set -> any character is allowed to login $authStatus = 'OK'; + }elseif( + Config::getPathfinderData('login.session_sharing') === 1 && + is_array($this->getF3()->get(User::SESSION_KEY_CHARACTERS)) + ){ + // authorized character is already logged in -> any subsequent character is allowed to login + $authStatus = 'OK'; }else{ // check if character is set in whitelist if( From a64fc78f75168ea1431045fb63231054ea0fc36b Mon Sep 17 00:00:00 2001 From: soneill Date: Thu, 29 Jul 2021 15:48:34 +1200 Subject: [PATCH 8/8] alters Model/Pathfinder/CharacterModel#isAuthorized() to authorize characters based on session --- app/Model/Pathfinder/CharacterModel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Model/Pathfinder/CharacterModel.php b/app/Model/Pathfinder/CharacterModel.php index db0b8ac5..332c74c9 100644 --- a/app/Model/Pathfinder/CharacterModel.php +++ b/app/Model/Pathfinder/CharacterModel.php @@ -656,6 +656,7 @@ class CharacterModel extends AbstractPathfinderModel { // no corp/ally restrictions set -> any character is allowed to login $authStatus = 'OK'; }elseif( + // check if session_sharing is enabled and if a character is saved in session Config::getPathfinderData('login.session_sharing') === 1 && is_array($this->getF3()->get(User::SESSION_KEY_CHARACTERS)) ){