use username for multi games
Some checks failed
mapguesser/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Bence Pőcze 2023-09-24 22:34:34 +02:00
parent 751a86c823
commit 3deb76056d
Signed by: bence
GPG Key ID: DC5BD6E95A333E6D
4 changed files with 20 additions and 25 deletions

View File

@ -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:

View File

@ -131,12 +131,14 @@
}, formData);
};
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')) {
document.getElementById('challengeButton').onclick = function () {

View File

@ -190,13 +190,17 @@ class GameController implements IAuthenticationRequired
public function prepareMultiGame(): IContent
{
$roomId = \Container::$request->query('roomId');
$userName = \Container::$request->post('userName');
if (empty($userName)) {
$faker = Factory::create();
$userName = $faker->userName;
/**
* @var User $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([

View File

@ -9,9 +9,9 @@ TODO: condition!
<div id="playMode" class="modal">
<h2>Play map</h2>
<a id="singleButton" class="button fullWidth marginTop" href="" title="Single player">Single player</a>
<?php if ($isLoggedIn): ?>
<p class="bold center marginTop marginBottom">OR</p>
<button id="multiButton" class="fullWidth green" data-map-id="">Multiplayer (beta)</button>
<?php if ($isLoggedIn): ?>
<p class="bold center marginTop marginBottom">OR</p>
<button id="challengeButton" class="fullWidth yellow" data-map-id="" data-timer="">Challenge (gamma)</button>
<?php endif; ?>