From ce29ac1067559f95a88871a071e5f4901f37672f Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sat, 7 Apr 2018 21:41:18 +0200 Subject: [PATCH 1/3] - set a fixed version for "react/zmq" and "ext-zmq" composer dependency --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 32a55a5..79d635d 100644 --- a/composer.json +++ b/composer.json @@ -16,8 +16,8 @@ }, "require": { "php-64bit": ">=7.0", - "ext-zmq": "1.1.*", + "ext-zmq": ">=1.1.3", "cboden/ratchet": "0.4.x", - "react/zmq": "dev-master" + "react/zmq": "0.3.*" } } \ No newline at end of file From fff801498366eee415c2aa555816314aaad8f4e7 Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 8 Apr 2018 16:04:33 +0200 Subject: [PATCH 2/3] - fixed a bug where characters could not access a fresh created map - fixed missing "mapUserData" broadcast to clients after map "access" has changed --- app/Main/MapUpdate.php | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/app/Main/MapUpdate.php b/app/Main/MapUpdate.php index 90db91e..b69d172 100644 --- a/app/Main/MapUpdate.php +++ b/app/Main/MapUpdate.php @@ -204,6 +204,11 @@ class MapUpdate implements MessageComponentInterface { if($characterData = $this->checkCharacterAccess($characterId, $characterToken)){ $this->characters[$characterId][$conn->resourceId] = $conn; + // insert/update characterData cache + // -> even if characterId does not have access to a map "yet" + // -> no maps found but character can get map access at any time later + $this->setCharacterData($characterData); + // valid character -> check map access $changedSubscriptionsMapIds = []; foreach((array)$subscribeData['mapData'] as $data){ @@ -215,9 +220,6 @@ class MapUpdate implements MessageComponentInterface { if( $this->checkMapAccess($characterId, $mapId, $mapToken) ){ // valid map subscribe request $this->subscriptions[$mapId][$characterId] = $characterId; - // insert/update characterData cache - $this->setCharacterData($characterData); - $changedSubscriptionsMapIds[] = $mapId; } } @@ -606,7 +608,7 @@ class MapUpdate implements MessageComponentInterface { * @return int count of connected characters */ private function setAccess(string $task, $accessData) : int { - $NewMapCharacterIds = []; + $newMapCharacterIds = []; if($mapId = (int)$accessData['id']){ $characterIds = (array)$accessData['characterIds']; @@ -618,27 +620,32 @@ class MapUpdate implements MessageComponentInterface { !empty($this->characters[$characterId]) && !empty($this->getCharacterData($characterId)) ){ - $NewMapCharacterIds[$characterId] = $characterId; + $newMapCharacterIds[$characterId] = $characterId; } } $currentMapCharacterIds = (array)$this->subscriptions[$mapId]; // broadcast "map delete" to no longer valid characters --------------------------------------------------- - $removedMapCharacterIds = array_diff(array_keys($currentMapCharacterIds), array_keys($NewMapCharacterIds)); + $removedMapCharacterIds = array_keys(array_diff_key($currentMapCharacterIds, $newMapCharacterIds)); $removedMapCharacterConnections = $this->getConnectionsByCharacterIds($removedMapCharacterIds); $this->broadcastData($removedMapCharacterConnections, $task, $mapId, $removedMapCharacterIds); // update map subscriptions ------------------------------------------------------------------------------- - if( !empty($NewMapCharacterIds) ){ + if( !empty($newMapCharacterIds) ){ // set new characters that have map access (overwrites existing subscriptions for that map) - $this->subscriptions[$mapId] = $NewMapCharacterIds; + $this->subscriptions[$mapId] = $newMapCharacterIds; + + // check if subscriptions have changed + if( !$this->arraysEqualKeys($currentMapCharacterIds, $newMapCharacterIds) ){ + $this->broadcastMapSubscriptions('mapSubscriptions', [$mapId]); + } }else{ // no characters (left) on this map unset($this->subscriptions[$mapId]); } } - return count($NewMapCharacterIds); + return count($newMapCharacterIds); } /** @@ -682,6 +689,17 @@ class MapUpdate implements MessageComponentInterface { return $response; } + /** + * compare two assoc arrays by keys. Key order is ignored + * -> if all keys from array1 exist in array2 && all keys from array2 exist in array 1, arrays are supposed to be equal + * @param array $array1 + * @param array $array2 + * @return bool + */ + protected function arraysEqualKeys(array $array1, array $array2) : bool { + return !array_diff_key($array1, $array2) && !array_diff_key($array2, $array1); + } + /** * dispatch log writing to a LogFileHandler * @param array $meta From 5285c86a7576472a0a3569e432cc675e35a9b94d Mon Sep 17 00:00:00 2001 From: Mark Friedrich Date: Sun, 8 Apr 2018 16:20:34 +0200 Subject: [PATCH 3/3] - fixed PHP notice "Undefined index" --- app/Main/Formatter/SubscriptionFormatter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/Main/Formatter/SubscriptionFormatter.php b/app/Main/Formatter/SubscriptionFormatter.php index 2302106..cef76b3 100644 --- a/app/Main/Formatter/SubscriptionFormatter.php +++ b/app/Main/Formatter/SubscriptionFormatter.php @@ -20,7 +20,11 @@ class SubscriptionFormatter{ $data = []; foreach($charactersData as $characterId => $characterData){ // check if characterData has an active log (active system for character) - $systemId = (int)$characterData['log']['system']['id']; + $systemId = 0; + if(isset($characterData['log']['system']['id'])){ + $systemId = (int)$characterData['log']['system']['id']; + } + if( !isset($data[$systemId]) ){ $systemData = (object)[]; $systemData->id = $systemId;