problèmes du jeu réglés en grosse partie
This commit is contained in:
@@ -96,8 +96,7 @@ async function clientAnnounceListener(this: WebSocket, data: string)
|
||||
const player = clientsMap.get(this.id) as ClientPlayer;
|
||||
player.matchOptions = announce.matchOptions;
|
||||
player.token = announce.token;
|
||||
player.username = announce.username;
|
||||
|
||||
announce.isInvitedPerson ? player.username = announce.playerTwoUsername : player.username = announce.username;
|
||||
this.send(JSON.stringify( new ev.EventAssignId(this.id) )); // unused
|
||||
this.send(JSON.stringify( new ev.ServerEvent(en.EventTypes.matchmakingInProgress) ));
|
||||
if (announce.privateMatch) {
|
||||
@@ -173,7 +172,7 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
const compatiblePlayers: ClientPlayer[] = [];
|
||||
for (const [id, client] of privateMatchmakingMap)
|
||||
{
|
||||
if (client.token === token && client.username !== player.username)
|
||||
if (client.token === token)
|
||||
{
|
||||
compatiblePlayers.push(client);
|
||||
if (compatiblePlayers.length === maxPlayersNumber) {
|
||||
@@ -189,11 +188,20 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
createGameSession(compatiblePlayers, matchOptions);
|
||||
}
|
||||
else {
|
||||
setTimeout(function abortMatch() {
|
||||
setTimeout(async function abortMatch() {
|
||||
if (!player.gameSession)
|
||||
{
|
||||
// TODO: informe le back de l'invalidité du token d'invitation
|
||||
player.socket.send(JSON.stringify( new ev.EventMatchAbort() ));
|
||||
const responseTobakc = await fetch(c.addressBackEnd + "/game/gameserver/destroysession",{
|
||||
method: "POST",
|
||||
headers : {"Content-Type": "application/json"},
|
||||
body : JSON.stringify({
|
||||
token : player.token
|
||||
})
|
||||
})
|
||||
.then(x => x.json())
|
||||
.catch(error => console.log("ERROR : " + error))
|
||||
clientTerminate(player);
|
||||
}
|
||||
}, 60000);
|
||||
|
||||
@@ -72,7 +72,7 @@ export class EventMatchEnd extends ServerEvent {
|
||||
}
|
||||
|
||||
export class EventMatchAbort extends ServerEvent {
|
||||
|
||||
|
||||
constructor() {
|
||||
super(en.EventTypes.matchAbort);
|
||||
}
|
||||
@@ -102,12 +102,16 @@ export class ClientAnnouncePlayer extends ClientAnnounce {
|
||||
username: string;
|
||||
privateMatch: boolean;
|
||||
playerTwoUsername?: string;
|
||||
constructor(matchOptions: en.MatchOptions, token: string, username: string, privateMatch: boolean = false, playerTwoUsername?: string) {
|
||||
isInvitedPerson? : boolean;
|
||||
constructor(matchOptions: en.MatchOptions, token: string, username: string, privateMatch: boolean = false, playerTwoUsername?: string, isInvitedPerson? : boolean) {
|
||||
super(en.ClientRole.player);
|
||||
this.matchOptions = matchOptions;
|
||||
this.token = token;
|
||||
this.username = username;
|
||||
this.privateMatch = privateMatch;
|
||||
if (isInvitedPerson) {
|
||||
this.isInvitedPerson = isInvitedPerson;
|
||||
}
|
||||
if (playerTwoUsername) {
|
||||
this.playerTwoUsername = playerTwoUsername;
|
||||
}
|
||||
|
||||
@@ -102,6 +102,11 @@ export class GameController {
|
||||
return this.gameService.updateGame(updateGameDto);
|
||||
}
|
||||
|
||||
@Post('gameserver/destroysession')
|
||||
async destroySession(@Body('token') token)
|
||||
{
|
||||
return this.gameService.destroySession(token);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -166,8 +166,8 @@ export class GameService {
|
||||
|
||||
async declineInvitation(user : User, token : string)
|
||||
{
|
||||
// if (user.status === "In Game")
|
||||
// return new HttpException("You must finish your game before decline.", HttpStatus.FORBIDDEN)
|
||||
if (user.status === "In Game")
|
||||
return new HttpException("You must finish your game before decline.", HttpStatus.FORBIDDEN)
|
||||
console.log("On décline l'invitation")
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame')
|
||||
.andWhere('tokengame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
|
||||
@@ -178,6 +178,17 @@ export class GameService {
|
||||
return new HttpException("Invitation not found !", HttpStatus.NOT_FOUND)
|
||||
}
|
||||
|
||||
async destroySession(token : string)
|
||||
{
|
||||
console.log("On détruit le token et la session qui va avec")
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame')
|
||||
.where('tokengame.token = :token', {token : token})
|
||||
.getOne();
|
||||
if (tokenGame)
|
||||
return this.tokenGameRepository.remove(tokenGame);
|
||||
return new HttpException("Invitation not found !", HttpStatus.NOT_FOUND)
|
||||
}
|
||||
|
||||
async acceptInvitation(user : User, token : string)
|
||||
{
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
||||
@@ -194,8 +205,8 @@ export class GameService {
|
||||
}
|
||||
|
||||
async requestIfAnotherUserHasRespondToquestForGame(user : User, token : string) {
|
||||
// if (user.status === "In Game")
|
||||
// return new HttpException("You can't do that.", HttpStatus.BAD_REQUEST)
|
||||
if (user.status === "In Game")
|
||||
return new HttpException("You can't do that.", HttpStatus.BAD_REQUEST)
|
||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
||||
.where('tokenGame.token = :token', {token : token})
|
||||
.andWhere('tokenGame.isSecondUserAcceptedRequest = :isSecondUserAcceptedRequest', {isSecondUserAcceptedRequest : true})
|
||||
@@ -211,6 +222,9 @@ export class GameService {
|
||||
|
||||
async createGame(creategameDto : CreateGameDto)
|
||||
{
|
||||
if (creategameDto.playerOneUsername === "" || creategameDto.playerTwoUsername === ""
|
||||
|| creategameDto.playerOneUsername === creategameDto.playerTwoUsername)
|
||||
return HttpStatus.INTERNAL_SERVER_ERROR
|
||||
const game = this.gameRepository.create(creategameDto)
|
||||
game.isMatchIsFinished = false;
|
||||
this.gameRepository.save(game);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
//Game's stuff
|
||||
let optionsAreNotSet = true;
|
||||
const options = new pong.InitOptions();
|
||||
|
||||
|
||||
//Game's stuff client side only
|
||||
const gameAreaId = "game_area";
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
}
|
||||
else if (token)
|
||||
{
|
||||
options.isInvitedPerson = false
|
||||
pong.init(options, gameAreaId, token);
|
||||
hiddenGame = false;
|
||||
}
|
||||
@@ -105,6 +106,7 @@
|
||||
options.playerOneUsername = invitation.playerOneUsername;
|
||||
options.playerTwoUsername = invitation.playerTwoUsername;
|
||||
options.isSomeoneIsInvited = true;
|
||||
options.isInvitedPerson = true
|
||||
pong.init(options, gameAreaId, invitation.token);
|
||||
showWaitPage = false
|
||||
hiddenGame = false;
|
||||
|
||||
@@ -21,6 +21,7 @@ export class InitOptions {
|
||||
multi_balls = false;
|
||||
moving_walls = false;
|
||||
isSomeoneIsInvited = false;
|
||||
isInvitedPerson = false;
|
||||
playerOneUsername = "";
|
||||
playerTwoUsername = "";
|
||||
}
|
||||
@@ -43,7 +44,7 @@ export function init(options: InitOptions, gameAreaId: string, token: string)
|
||||
initStartFunction(start);
|
||||
|
||||
if (options.isSomeoneIsInvited) {
|
||||
initWebSocket(matchOptions, token, options.playerOneUsername, true, options.playerTwoUsername);
|
||||
initWebSocket(matchOptions, token, options.playerOneUsername, true, options.playerTwoUsername, options.isInvitedPerson);
|
||||
}
|
||||
else {
|
||||
initWebSocket(matchOptions, token, options.playerOneUsername);
|
||||
|
||||
@@ -34,14 +34,14 @@ export const clientInfo = new ClientInfo();
|
||||
export const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this
|
||||
|
||||
|
||||
export function initWebSocket(options: en.MatchOptions, token: string, username: string, privateMatch = false, playerTwoUsername?: string)
|
||||
export function initWebSocket(options: en.MatchOptions, token: string, username: string, privateMatch = false, playerTwoUsername?: string, isInvitedPerson? : boolean)
|
||||
{
|
||||
socket = new WebSocket(wsUrl, "json");
|
||||
console.log("Infos from ws.ts : options => " + options + " token => " + token + " username => " + username + " priavte match => " + privateMatch
|
||||
+ " player two => " + playerTwoUsername)
|
||||
socket.addEventListener("open", (event) => {
|
||||
if (privateMatch) {
|
||||
socket.send(JSON.stringify( new ev.ClientAnnouncePlayer(options, token, username, privateMatch, playerTwoUsername) ));
|
||||
socket.send(JSON.stringify( new ev.ClientAnnouncePlayer(options, token, username, privateMatch, playerTwoUsername, isInvitedPerson) ));
|
||||
}
|
||||
else {
|
||||
socket.send(JSON.stringify( new ev.ClientAnnouncePlayer(options, token, username) ));
|
||||
|
||||
@@ -72,7 +72,7 @@ export class EventMatchEnd extends ServerEvent {
|
||||
}
|
||||
|
||||
export class EventMatchAbort extends ServerEvent {
|
||||
|
||||
|
||||
constructor() {
|
||||
super(en.EventTypes.matchAbort);
|
||||
}
|
||||
@@ -102,12 +102,16 @@ export class ClientAnnouncePlayer extends ClientAnnounce {
|
||||
username: string;
|
||||
privateMatch: boolean;
|
||||
playerTwoUsername?: string;
|
||||
constructor(matchOptions: en.MatchOptions, token: string, username: string, privateMatch: boolean = false, playerTwoUsername?: string) {
|
||||
isInvitedPerson? : boolean;
|
||||
constructor(matchOptions: en.MatchOptions, token: string, username: string, privateMatch: boolean = false, playerTwoUsername?: string, isInvitedPerson? : boolean) {
|
||||
super(en.ClientRole.player);
|
||||
this.matchOptions = matchOptions;
|
||||
this.token = token;
|
||||
this.username = username;
|
||||
this.privateMatch = privateMatch;
|
||||
if (isInvitedPerson) {
|
||||
this.isInvitedPerson = isInvitedPerson;
|
||||
}
|
||||
if (playerTwoUsername) {
|
||||
this.playerTwoUsername = playerTwoUsername;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user