Suite du jeu et toujours pas fin
This commit is contained in:
@@ -6,6 +6,7 @@ import { User } from 'src/users/entities/user.entity';
|
||||
import { UsersService } from 'src/users/users.service';
|
||||
import { GrantTicketDto } from './dto/grantTicket.dto';
|
||||
import { ValidateTicketDto } from './dto/validateTicket.dto';
|
||||
import { TokenGame } from './entity/tokenGame.entity';
|
||||
import { GameService } from './game.service';
|
||||
|
||||
@Controller('game')
|
||||
@@ -25,13 +26,13 @@ export class GameController {
|
||||
return this.gameService.generateToken(user, grantTicketDto);
|
||||
}
|
||||
|
||||
@Get('requested')
|
||||
@Post('requested')
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
async requestIfAnotherUserHasRespondToquestForGame(@Req() req, @Body('playerTwoUsername') body)
|
||||
async requestIfAnotherUserHasRespondToquestForGame(@Req() req, @Body('token') token)
|
||||
{
|
||||
const user : User = req.user;
|
||||
return this.gameService.requestIfAnotherUserHasRespondToquestForGame(user, body);
|
||||
return this.gameService.requestIfAnotherUserHasRespondToquestForGame(user, token);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ export class GameService {
|
||||
if (user.status === "In Game")
|
||||
return new HttpException("You can't do that.", HttpStatus.BAD_REQUEST)
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
||||
.andWhere('tokenGame.token = :token', {token : token})
|
||||
.where('tokenGame.token = :token', {token : token})
|
||||
.andWhere('tokenGame.isSecondUserAcceptedRequest = :isSecondUserAcceptedRequest', {isSecondUserAcceptedRequest : true})
|
||||
.getOne();
|
||||
if (tokenGame && tokenGame.isSecondUserAcceptedRequest === true)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import { initAudio } from './client/audio';
|
||||
import { pong, gc} from './client/global'
|
||||
import Header from '../../pieces/Header.svelte';
|
||||
|
||||
import { push } from "svelte-spa-router";
|
||||
|
||||
let user;
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
let showWaitPage = false;
|
||||
|
||||
let waitingMessage = "Please wait..."
|
||||
let errorMessageWhenAttemptingToGetATicket;
|
||||
let errorMessageWhenAttemptingToGetATicket = "";
|
||||
|
||||
let token = ""
|
||||
let responseToCheckIfOtherUserHasAnswered;
|
||||
@@ -98,29 +98,53 @@
|
||||
waitingMessage = `Waiting for ${playerTwoUsername}'s answer !`
|
||||
let intervalId = setInterval(checkIfOtherUserIsReady , 1000 * 1);
|
||||
let timeOutId = setTimeout(()=> {
|
||||
showError = true;
|
||||
console.log("FIN DU TIMEOUT")
|
||||
errorMessageWhenAttemptingToGetATicket = "The second player took too much time to answer"
|
||||
showWaitPage = false
|
||||
optionsAreNotSet = true
|
||||
showError = true;
|
||||
isSecondPlayerAnsweredYes = false
|
||||
playerTwoUsername = "";
|
||||
matchOption = 0;
|
||||
token = ""
|
||||
clearInterval(intervalId)
|
||||
isSomethingWentWrong = true
|
||||
}, 1000 * 60 * 3)
|
||||
}, 1000 * 5)
|
||||
console.log("EN DESSOUS DE TIMEOUT")
|
||||
if (isSecondPlayerAnsweredYes === true)
|
||||
{
|
||||
clearTimeout(timeOutId)
|
||||
clearInterval(intervalId)
|
||||
isSomethingWentWrong = false;
|
||||
}
|
||||
else if (isSecondPlayerRefused === true)
|
||||
if (isSecondPlayerRefused === true)
|
||||
{
|
||||
clearTimeout(timeOutId)
|
||||
clearInterval(intervalId)
|
||||
}
|
||||
}
|
||||
if (isSomethingWentWrong === false)
|
||||
{
|
||||
const res = await fetch("http://transcendance:8080/api/v2/game/gameServer/validate", {
|
||||
method : "POST",
|
||||
headers : {'Content-Type': 'application/json'},
|
||||
body : JSON.stringify({
|
||||
playerOneUsername : user.username,
|
||||
playerTwoUsername : playerTwoUsername,
|
||||
gameOptions : matchOption,
|
||||
isGameIsWithInvitation : invite_someone,
|
||||
token : token
|
||||
})
|
||||
})
|
||||
.then(x => x.json())
|
||||
.catch(error => {
|
||||
console.log(error)
|
||||
})
|
||||
if (res.status !== 200)
|
||||
{
|
||||
showError = true;
|
||||
errorMessageWhenAttemptingToGetATicket = "Your session is not valid. Please try again."
|
||||
return ;
|
||||
}
|
||||
initAudio(sound)
|
||||
initMatchOptions(matchOption)
|
||||
initPong(new GameArea())
|
||||
@@ -132,7 +156,7 @@
|
||||
|
||||
|
||||
async function checkIfOtherUserIsReady(token : string) {
|
||||
responseToCheckIfOtherUserHasAnswered = await fetch("http://transcendance:8080/api/v2/game/pending",{
|
||||
responseToCheckIfOtherUserHasAnswered = await fetch("http://transcendance:8080/api/v2/game/requested",{
|
||||
method : "POST",
|
||||
headers : { 'Content-Type': 'application/json'},
|
||||
body : JSON.stringify({
|
||||
@@ -140,6 +164,7 @@
|
||||
})
|
||||
})
|
||||
const data = await responseToCheckIfOtherUserHasAnswered.json();
|
||||
console.log(data)
|
||||
if (data.isSecondUserAcceptedRequest === true)
|
||||
isSecondPlayerAnsweredYes = true
|
||||
if (data.status === 404 || data.status === 403)
|
||||
@@ -211,18 +236,22 @@
|
||||
<body>
|
||||
<div id="preload_font">.</div>
|
||||
{#if showError === true}
|
||||
<div id="error_notification" >
|
||||
<p>{errorMessageWhenAttemptingToGetATicket}</p>
|
||||
</div>
|
||||
<div id="div_game">
|
||||
<fieldset>
|
||||
<legend>Error</legend>
|
||||
<p>{errorMessageWhenAttemptingToGetATicket}</p>
|
||||
<button id="pong_button" on:click={() => push('/game')}>Retry</button>
|
||||
</fieldset>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if showWaitPage === true}
|
||||
<fieldset>
|
||||
<legend>Connecting to the game...</legend>
|
||||
<div id="div_game">
|
||||
<p>{waitingMessage}</p>
|
||||
</div>
|
||||
</fieldset>
|
||||
<div id="div_game">
|
||||
<fieldset>
|
||||
<legend>Connecting to the game...</legend>
|
||||
<p>{waitingMessage}</p>
|
||||
</fieldset>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if optionsAreNotSet}
|
||||
|
||||
Reference in New Issue
Block a user