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