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;
|
const player = clientsMap.get(this.id) as ClientPlayer;
|
||||||
player.matchOptions = announce.matchOptions;
|
player.matchOptions = announce.matchOptions;
|
||||||
player.token = announce.token;
|
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.EventAssignId(this.id) )); // unused
|
||||||
this.send(JSON.stringify( new ev.ServerEvent(en.EventTypes.matchmakingInProgress) ));
|
this.send(JSON.stringify( new ev.ServerEvent(en.EventTypes.matchmakingInProgress) ));
|
||||||
if (announce.privateMatch) {
|
if (announce.privateMatch) {
|
||||||
@@ -173,7 +172,7 @@ function privateMatchmaking(player: ClientPlayer)
|
|||||||
const compatiblePlayers: ClientPlayer[] = [];
|
const compatiblePlayers: ClientPlayer[] = [];
|
||||||
for (const [id, client] of privateMatchmakingMap)
|
for (const [id, client] of privateMatchmakingMap)
|
||||||
{
|
{
|
||||||
if (client.token === token && client.username !== player.username)
|
if (client.token === token)
|
||||||
{
|
{
|
||||||
compatiblePlayers.push(client);
|
compatiblePlayers.push(client);
|
||||||
if (compatiblePlayers.length === maxPlayersNumber) {
|
if (compatiblePlayers.length === maxPlayersNumber) {
|
||||||
@@ -189,11 +188,20 @@ function privateMatchmaking(player: ClientPlayer)
|
|||||||
createGameSession(compatiblePlayers, matchOptions);
|
createGameSession(compatiblePlayers, matchOptions);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
setTimeout(function abortMatch() {
|
setTimeout(async function abortMatch() {
|
||||||
if (!player.gameSession)
|
if (!player.gameSession)
|
||||||
{
|
{
|
||||||
// TODO: informe le back de l'invalidité du token d'invitation
|
// TODO: informe le back de l'invalidité du token d'invitation
|
||||||
player.socket.send(JSON.stringify( new ev.EventMatchAbort() ));
|
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);
|
clientTerminate(player);
|
||||||
}
|
}
|
||||||
}, 60000);
|
}, 60000);
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class EventMatchEnd extends ServerEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class EventMatchAbort extends ServerEvent {
|
export class EventMatchAbort extends ServerEvent {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(en.EventTypes.matchAbort);
|
super(en.EventTypes.matchAbort);
|
||||||
}
|
}
|
||||||
@@ -102,12 +102,16 @@ export class ClientAnnouncePlayer extends ClientAnnounce {
|
|||||||
username: string;
|
username: string;
|
||||||
privateMatch: boolean;
|
privateMatch: boolean;
|
||||||
playerTwoUsername?: string;
|
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);
|
super(en.ClientRole.player);
|
||||||
this.matchOptions = matchOptions;
|
this.matchOptions = matchOptions;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.privateMatch = privateMatch;
|
this.privateMatch = privateMatch;
|
||||||
|
if (isInvitedPerson) {
|
||||||
|
this.isInvitedPerson = isInvitedPerson;
|
||||||
|
}
|
||||||
if (playerTwoUsername) {
|
if (playerTwoUsername) {
|
||||||
this.playerTwoUsername = playerTwoUsername;
|
this.playerTwoUsername = playerTwoUsername;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,6 +102,11 @@ export class GameController {
|
|||||||
return this.gameService.updateGame(updateGameDto);
|
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)
|
async declineInvitation(user : User, token : string)
|
||||||
{
|
{
|
||||||
// if (user.status === "In Game")
|
if (user.status === "In Game")
|
||||||
// return new HttpException("You must finish your game before decline.", HttpStatus.FORBIDDEN)
|
return new HttpException("You must finish your game before decline.", HttpStatus.FORBIDDEN)
|
||||||
console.log("On décline l'invitation")
|
console.log("On décline l'invitation")
|
||||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame')
|
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokengame')
|
||||||
.andWhere('tokengame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
|
.andWhere('tokengame.playerTwoUsername = :playerTwoUsername', {playerTwoUsername : user.username})
|
||||||
@@ -178,6 +178,17 @@ export class GameService {
|
|||||||
return new HttpException("Invitation not found !", HttpStatus.NOT_FOUND)
|
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)
|
async acceptInvitation(user : User, token : string)
|
||||||
{
|
{
|
||||||
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
const tokenGame = await this.tokenGameRepository.createQueryBuilder('tokenGame')
|
||||||
@@ -194,8 +205,8 @@ export class GameService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async requestIfAnotherUserHasRespondToquestForGame(user : User, token : string) {
|
async requestIfAnotherUserHasRespondToquestForGame(user : User, token : string) {
|
||||||
// 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')
|
||||||
.where('tokenGame.token = :token', {token : token})
|
.where('tokenGame.token = :token', {token : token})
|
||||||
.andWhere('tokenGame.isSecondUserAcceptedRequest = :isSecondUserAcceptedRequest', {isSecondUserAcceptedRequest : true})
|
.andWhere('tokenGame.isSecondUserAcceptedRequest = :isSecondUserAcceptedRequest', {isSecondUserAcceptedRequest : true})
|
||||||
@@ -211,6 +222,9 @@ export class GameService {
|
|||||||
|
|
||||||
async createGame(creategameDto : CreateGameDto)
|
async createGame(creategameDto : CreateGameDto)
|
||||||
{
|
{
|
||||||
|
if (creategameDto.playerOneUsername === "" || creategameDto.playerTwoUsername === ""
|
||||||
|
|| creategameDto.playerOneUsername === creategameDto.playerTwoUsername)
|
||||||
|
return HttpStatus.INTERNAL_SERVER_ERROR
|
||||||
const game = this.gameRepository.create(creategameDto)
|
const game = this.gameRepository.create(creategameDto)
|
||||||
game.isMatchIsFinished = false;
|
game.isMatchIsFinished = false;
|
||||||
this.gameRepository.save(game);
|
this.gameRepository.save(game);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
//Game's stuff
|
//Game's stuff
|
||||||
let optionsAreNotSet = true;
|
let optionsAreNotSet = true;
|
||||||
const options = new pong.InitOptions();
|
const options = new pong.InitOptions();
|
||||||
|
|
||||||
//Game's stuff client side only
|
//Game's stuff client side only
|
||||||
const gameAreaId = "game_area";
|
const gameAreaId = "game_area";
|
||||||
|
|
||||||
@@ -88,6 +88,7 @@
|
|||||||
}
|
}
|
||||||
else if (token)
|
else if (token)
|
||||||
{
|
{
|
||||||
|
options.isInvitedPerson = false
|
||||||
pong.init(options, gameAreaId, token);
|
pong.init(options, gameAreaId, token);
|
||||||
hiddenGame = false;
|
hiddenGame = false;
|
||||||
}
|
}
|
||||||
@@ -105,6 +106,7 @@
|
|||||||
options.playerOneUsername = invitation.playerOneUsername;
|
options.playerOneUsername = invitation.playerOneUsername;
|
||||||
options.playerTwoUsername = invitation.playerTwoUsername;
|
options.playerTwoUsername = invitation.playerTwoUsername;
|
||||||
options.isSomeoneIsInvited = true;
|
options.isSomeoneIsInvited = true;
|
||||||
|
options.isInvitedPerson = true
|
||||||
pong.init(options, gameAreaId, invitation.token);
|
pong.init(options, gameAreaId, invitation.token);
|
||||||
showWaitPage = false
|
showWaitPage = false
|
||||||
hiddenGame = false;
|
hiddenGame = false;
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class InitOptions {
|
|||||||
multi_balls = false;
|
multi_balls = false;
|
||||||
moving_walls = false;
|
moving_walls = false;
|
||||||
isSomeoneIsInvited = false;
|
isSomeoneIsInvited = false;
|
||||||
|
isInvitedPerson = false;
|
||||||
playerOneUsername = "";
|
playerOneUsername = "";
|
||||||
playerTwoUsername = "";
|
playerTwoUsername = "";
|
||||||
}
|
}
|
||||||
@@ -43,7 +44,7 @@ export function init(options: InitOptions, gameAreaId: string, token: string)
|
|||||||
initStartFunction(start);
|
initStartFunction(start);
|
||||||
|
|
||||||
if (options.isSomeoneIsInvited) {
|
if (options.isSomeoneIsInvited) {
|
||||||
initWebSocket(matchOptions, token, options.playerOneUsername, true, options.playerTwoUsername);
|
initWebSocket(matchOptions, token, options.playerOneUsername, true, options.playerTwoUsername, options.isInvitedPerson);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
initWebSocket(matchOptions, token, options.playerOneUsername);
|
initWebSocket(matchOptions, token, options.playerOneUsername);
|
||||||
|
|||||||
@@ -34,14 +34,14 @@ export const clientInfo = new ClientInfo();
|
|||||||
export const clientInfoSpectator = new ClientInfoSpectator(); // WIP, could refactor this
|
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");
|
socket = new WebSocket(wsUrl, "json");
|
||||||
console.log("Infos from ws.ts : options => " + options + " token => " + token + " username => " + username + " priavte match => " + privateMatch
|
console.log("Infos from ws.ts : options => " + options + " token => " + token + " username => " + username + " priavte match => " + privateMatch
|
||||||
+ " player two => " + playerTwoUsername)
|
+ " player two => " + playerTwoUsername)
|
||||||
socket.addEventListener("open", (event) => {
|
socket.addEventListener("open", (event) => {
|
||||||
if (privateMatch) {
|
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 {
|
else {
|
||||||
socket.send(JSON.stringify( new ev.ClientAnnouncePlayer(options, token, username) ));
|
socket.send(JSON.stringify( new ev.ClientAnnouncePlayer(options, token, username) ));
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export class EventMatchEnd extends ServerEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class EventMatchAbort extends ServerEvent {
|
export class EventMatchAbort extends ServerEvent {
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super(en.EventTypes.matchAbort);
|
super(en.EventTypes.matchAbort);
|
||||||
}
|
}
|
||||||
@@ -102,12 +102,16 @@ export class ClientAnnouncePlayer extends ClientAnnounce {
|
|||||||
username: string;
|
username: string;
|
||||||
privateMatch: boolean;
|
privateMatch: boolean;
|
||||||
playerTwoUsername?: string;
|
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);
|
super(en.ClientRole.player);
|
||||||
this.matchOptions = matchOptions;
|
this.matchOptions = matchOptions;
|
||||||
this.token = token;
|
this.token = token;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.privateMatch = privateMatch;
|
this.privateMatch = privateMatch;
|
||||||
|
if (isInvitedPerson) {
|
||||||
|
this.isInvitedPerson = isInvitedPerson;
|
||||||
|
}
|
||||||
if (playerTwoUsername) {
|
if (playerTwoUsername) {
|
||||||
this.playerTwoUsername = playerTwoUsername;
|
this.playerTwoUsername = playerTwoUsername;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user