last update before merge with Cherif
This commit is contained in:
@@ -191,7 +191,7 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
}
|
||||
|
||||
|
||||
async function createGameSession(playersArr: ClientPlayer[], matchOptions: en.MatchOptions)
|
||||
function createGameSession(playersArr: ClientPlayer[], matchOptions: en.MatchOptions)
|
||||
{
|
||||
// const id = gameSessionIdPLACEHOLDER; // Force ID, TESTING SPECTATOR
|
||||
const id = uuidv4();
|
||||
@@ -227,22 +227,10 @@ async function createGameSession(playersArr: ClientPlayer[], matchOptions: en.Ma
|
||||
});
|
||||
}
|
||||
}, 5000);
|
||||
|
||||
/* // WIP nest , send gameSession.id
|
||||
await fetch(c.addressBackEnd + "/game/newGameSession",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: id,
|
||||
})
|
||||
}); */
|
||||
}
|
||||
|
||||
|
||||
function playerReadyConfirmationListener(this: WebSocket, data: string)
|
||||
async function playerReadyConfirmationListener(this: WebSocket, data: string)
|
||||
{
|
||||
try {
|
||||
const msg : ev.ClientEvent = JSON.parse(data);
|
||||
@@ -251,7 +239,34 @@ function playerReadyConfirmationListener(this: WebSocket, data: string)
|
||||
const client = clientsMap.get(this.id);
|
||||
const gameSession = client.gameSession;
|
||||
gameSession.unreadyPlayersMap.delete(this.id);
|
||||
if (gameSession.unreadyPlayersMap.size === 0) {
|
||||
if (gameSession.unreadyPlayersMap.size === 0)
|
||||
{
|
||||
// WIP nest , send gameSession.id
|
||||
const gameSessionPlayersIterator = gameSession.playersMap.values();
|
||||
const response = await fetch(c.addressBackEnd + "/game/newGameSession",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id: gameSession.id,
|
||||
gameOptions: gameSession.matchOptions,
|
||||
playerOneUsername: (<ClientPlayer>gameSessionPlayersIterator.next().value).username,
|
||||
playerTwoUsername: (<ClientPlayer>gameSessionPlayersIterator.next().value).username,
|
||||
})
|
||||
});
|
||||
if (!response.ok)
|
||||
{
|
||||
gameSessionsMap.delete(gameSession.id);
|
||||
gameSession.playersMap.forEach((client) => {
|
||||
client.socket.send(JSON.stringify( new ev.ServerEvent(en.EventTypes.matchAbort) ));
|
||||
client.gameSession = null;
|
||||
clientTerminate(client);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
gameSession.playersMap.forEach( (client) => {
|
||||
client.socket.send(JSON.stringify( new ev.ServerEvent(en.EventTypes.matchStart) ));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user