use username for multi games
This commit is contained in:
parent
751a86c823
commit
752ea12810
@ -231,17 +231,6 @@ const GameType = Object.freeze({ 'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2 });
|
|||||||
|
|
||||||
prepare: function () {
|
prepare: function () {
|
||||||
var data = new FormData();
|
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';
|
document.getElementById('loading').style.visibility = 'visible';
|
||||||
var url = Game.getGameIdentifier() + '/prepare.json';
|
var url = Game.getGameIdentifier() + '/prepare.json';
|
||||||
@ -618,7 +607,7 @@ const GameType = Object.freeze({ 'SINGLE': 0, 'MULTI': 1, 'CHALLENGE': 2 });
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'anonymous_user':
|
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;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -131,11 +131,13 @@
|
|||||||
}, formData);
|
}, formData);
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById('multiButton').onclick = function () {
|
if (document.getElementById('multiButton')) {
|
||||||
MapGuesser.showModal('multi');
|
document.getElementById('multiButton').onclick = function () {
|
||||||
document.getElementById('createNewRoomButton').href = '/multiGame/new/' + this.dataset.mapId;
|
MapGuesser.showModal('multi');
|
||||||
document.getElementById('multiForm').elements.roomId.select();
|
document.getElementById('createNewRoomButton').href = '/multiGame/new/' + this.dataset.mapId;
|
||||||
document.getElementById('playMode').style.visibility = 'hidden';
|
document.getElementById('multiForm').elements.roomId.select();
|
||||||
|
document.getElementById('playMode').style.visibility = 'hidden';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.getElementById('challengeButton')) {
|
if (document.getElementById('challengeButton')) {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?php namespace MapGuesser\Controller;
|
<?php namespace MapGuesser\Controller;
|
||||||
|
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Faker\Factory;
|
|
||||||
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
use SokoWeb\Interfaces\Authentication\IAuthenticationRequired;
|
||||||
use SokoWeb\Response\HtmlContent;
|
use SokoWeb\Response\HtmlContent;
|
||||||
use SokoWeb\Response\JsonContent;
|
use SokoWeb\Response\JsonContent;
|
||||||
@ -12,6 +11,7 @@ use MapGuesser\PersistentData\Model\Challenge;
|
|||||||
use MapGuesser\PersistentData\Model\MultiRoom;
|
use MapGuesser\PersistentData\Model\MultiRoom;
|
||||||
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
use MapGuesser\PersistentData\Model\PlaceInChallenge;
|
||||||
use MapGuesser\PersistentData\Model\UserInChallenge;
|
use MapGuesser\PersistentData\Model\UserInChallenge;
|
||||||
|
use MapGuesser\PersistentData\Model\User;
|
||||||
use MapGuesser\Repository\ChallengeRepository;
|
use MapGuesser\Repository\ChallengeRepository;
|
||||||
use MapGuesser\Repository\MapRepository;
|
use MapGuesser\Repository\MapRepository;
|
||||||
use MapGuesser\Repository\MultiRoomRepository;
|
use MapGuesser\Repository\MultiRoomRepository;
|
||||||
@ -190,13 +190,17 @@ class GameController implements IAuthenticationRequired
|
|||||||
|
|
||||||
public function prepareMultiGame(): IContent
|
public function prepareMultiGame(): IContent
|
||||||
{
|
{
|
||||||
$roomId = \Container::$request->query('roomId');
|
/**
|
||||||
$userName = \Container::$request->post('userName');
|
* @var User|null $user
|
||||||
if (empty($userName)) {
|
*/
|
||||||
$faker = Factory::create();
|
$user = \Container::$request->user();
|
||||||
$userName = $faker->userName;
|
if ($user === null)
|
||||||
|
{
|
||||||
|
return new JsonContent(['error' => 'anonymous_user']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$roomId = \Container::$request->query('roomId');
|
||||||
|
|
||||||
$room = $this->multiRoomRepository->getByRoomId($roomId);
|
$room = $this->multiRoomRepository->getByRoomId($roomId);
|
||||||
|
|
||||||
if (!isset($room)) {
|
if (!isset($room)) {
|
||||||
@ -225,7 +229,7 @@ class GameController implements IAuthenticationRequired
|
|||||||
$this->multiConnector->sendMessage('join_room', [
|
$this->multiConnector->sendMessage('join_room', [
|
||||||
'roomId' => $roomId,
|
'roomId' => $roomId,
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'userName' => $userName
|
'userName' => $user->getDisplayName()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return new JsonContent([
|
return new JsonContent([
|
||||||
|
@ -9,9 +9,9 @@ TODO: condition!
|
|||||||
<div id="playMode" class="modal">
|
<div id="playMode" class="modal">
|
||||||
<h2>Play map</h2>
|
<h2>Play map</h2>
|
||||||
<a id="singleButton" class="button fullWidth marginTop" href="" title="Single player">Single player</a>
|
<a id="singleButton" class="button fullWidth marginTop" href="" title="Single player">Single player</a>
|
||||||
<p class="bold center marginTop marginBottom">OR</p>
|
|
||||||
<button id="multiButton" class="fullWidth green" data-map-id="">Multiplayer (beta)</button>
|
|
||||||
<?php if ($isLoggedIn): ?>
|
<?php if ($isLoggedIn): ?>
|
||||||
|
<p class="bold center marginTop marginBottom">OR</p>
|
||||||
|
<button id="multiButton" class="fullWidth green" data-map-id="">Multiplayer (beta)</button>
|
||||||
<p class="bold center marginTop marginBottom">OR</p>
|
<p class="bold center marginTop marginBottom">OR</p>
|
||||||
<button id="challengeButton" class="fullWidth yellow" data-map-id="" data-timer="">Challenge (gamma)</button>
|
<button id="challengeButton" class="fullWidth yellow" data-map-id="" data-timer="">Challenge (gamma)</button>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
Loading…
Reference in New Issue
Block a user