diff --git a/Jenkinsfile b/Jenkinsfile index 2ae2461..9f41bf0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -37,7 +37,7 @@ pipeline { sh 'vendor/bin/phpunit --log-junit unit_test_results.xml --testdox tests' } post { - success { + always { archiveArtifacts 'unit_test_results.xml' } } @@ -56,7 +56,7 @@ pipeline { sh 'php -d memory_limit=1G vendor/bin/phpstan analyse -c phpstan.neon --error-format=prettyJson > static_code_analysis_results.json' } post { - success { + always { archiveArtifacts 'static_code_analysis_results.json' } } diff --git a/public/static/js/game.js b/public/static/js/game.js index 8d73f7f..1f16f4a 100644 --- a/public/static/js/game.js +++ b/public/static/js/game.js @@ -231,17 +231,6 @@ const GameType = Object.freeze({ 'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2 }); prepare: function () { var data = new FormData(); - var userNames; - - if (roomId) { - var userNames = localStorage.userNames ? JSON.parse(localStorage.userNames) : {}; - if (!userNames.hasOwnProperty(roomId)) { - userNames[roomId] = prompt('Your name: '); - localStorage.userNames = JSON.stringify(userNames); - } - - data.append('userName', userNames[roomId]); - } document.getElementById('loading').style.visibility = 'visible'; var url = Game.getGameIdentifier() + '/prepare.json'; @@ -618,7 +607,7 @@ const GameType = Object.freeze({ 'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2 }); break; case 'anonymous_user': - MapGuesser.showModalWithContent('Error', 'You have to login to join a challenge!'); + MapGuesser.showModalWithContent('Error', 'You have to login to join this game!'); break; default: diff --git a/public/static/js/maps.js b/public/static/js/maps.js index d8f7a9f..f027b26 100644 --- a/public/static/js/maps.js +++ b/public/static/js/maps.js @@ -131,11 +131,13 @@ }, formData); }; - document.getElementById('multiButton').onclick = function () { - MapGuesser.showModal('multi'); - document.getElementById('createNewRoomButton').href = '/multiGame/new/' + this.dataset.mapId; - document.getElementById('multiForm').elements.roomId.select(); - document.getElementById('playMode').style.visibility = 'hidden'; + if (document.getElementById('multiButton')) { + document.getElementById('multiButton').onclick = function () { + MapGuesser.showModal('multi'); + document.getElementById('createNewRoomButton').href = '/multiGame/new/' + this.dataset.mapId; + document.getElementById('multiForm').elements.roomId.select(); + document.getElementById('playMode').style.visibility = 'hidden'; + } } if (document.getElementById('challengeButton')) { diff --git a/src/Controller/GameController.php b/src/Controller/GameController.php index ef3fd5f..3c2896c 100644 --- a/src/Controller/GameController.php +++ b/src/Controller/GameController.php @@ -1,7 +1,6 @@ query('roomId'); - $userName = \Container::$request->post('userName'); - if (empty($userName)) { - $faker = Factory::create(); - $userName = $faker->userName; + /** + * @var User|null $user + */ + $user = \Container::$request->user(); + if ($user === null) + { + return new JsonContent(['error' => 'anonymous_user']); } + $roomId = \Container::$request->query('roomId'); + $room = $this->multiRoomRepository->getByRoomId($roomId); if (!isset($room)) { @@ -225,7 +229,7 @@ class GameController implements IAuthenticationRequired $this->multiConnector->sendMessage('join_room', [ 'roomId' => $roomId, 'token' => $token, - 'userName' => $userName + 'userName' => $user->getDisplayName() ]); return new JsonContent([ diff --git a/views/maps.php b/views/maps.php index 8f5e2d4..d1256bd 100644 --- a/views/maps.php +++ b/views/maps.php @@ -9,9 +9,9 @@ TODO: condition!