Chérif et Luke coop, invitations fix et timeout
This commit is contained in:
5
memo.txt
5
memo.txt
@@ -2,9 +2,8 @@ DONE :
|
||||
|
||||
|
||||
TODO :
|
||||
- refactoring,
|
||||
Write independent init script like old pong.ts,
|
||||
to limit the numbers of imports and clutter in svelte script.
|
||||
- timeout in gameserver for private match (TO test)
|
||||
|
||||
- If in game, destroy game scripts stuff when changing page.
|
||||
(I need to dig deeper in svelte to know how this could work)
|
||||
- mode spectateur
|
||||
|
||||
@@ -168,12 +168,12 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
const maxPlayersNumber = 2;
|
||||
privateMatchmakingMap.set(player.id, player);
|
||||
const matchOptions = player.matchOptions;
|
||||
console.log(player)
|
||||
|
||||
const token = player.token;
|
||||
const compatiblePlayers: ClientPlayer[] = [];
|
||||
for (const [id, client] of privateMatchmakingMap)
|
||||
{
|
||||
if (client.token === token)
|
||||
if (client.token === token && client.username !== player.username)
|
||||
{
|
||||
compatiblePlayers.push(client);
|
||||
if (compatiblePlayers.length === maxPlayersNumber) {
|
||||
@@ -188,6 +188,16 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
});
|
||||
createGameSession(compatiblePlayers, matchOptions);
|
||||
}
|
||||
else {
|
||||
setTimeout(function abortMatch() {
|
||||
if (!player.gameSession)
|
||||
{
|
||||
// TODO: informe le back de l'invalidité du token d'invitation
|
||||
player.socket.send(JSON.stringify( new ev.EventMatchAbort() ));
|
||||
clientTerminate(player);
|
||||
}
|
||||
}, 60000);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -223,7 +233,7 @@ function createGameSession(playersArr: ClientPlayer[], matchOptions: en.MatchOpt
|
||||
{
|
||||
gameSessionsMap.delete(gameSession.id);
|
||||
gameSession.playersMap.forEach((client) => {
|
||||
client.socket.send(JSON.stringify( new ev.ServerEvent(en.EventTypes.matchAbort) ));
|
||||
client.socket.send(JSON.stringify( new ev.EventMatchAbort() ));
|
||||
client.gameSession = null;
|
||||
clientTerminate(client);
|
||||
});
|
||||
@@ -245,27 +255,27 @@ async function playerReadyConfirmationListener(this: WebSocket, data: string)
|
||||
{
|
||||
// WIP nest , send gameSession.id
|
||||
const gameSessionPlayersIterator = gameSession.playersMap.values();
|
||||
const body = {
|
||||
gameServerIdOfTheMatch : gameSession.id,
|
||||
gameOptions: gameSession.matchOptions,
|
||||
playerOneUsername: (<ClientPlayer>gameSessionPlayersIterator.next().value).username,
|
||||
playerTwoUsername: (<ClientPlayer>gameSessionPlayersIterator.next().value).username,
|
||||
playerOneUsernameResult : 0,
|
||||
playerTwoUsernameResult : 0
|
||||
};
|
||||
const response = await fetch(c.addressBackEnd + "/game/gameserver/creategame",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
gameServerIdOfTheMatch : gameSession.id,
|
||||
gameOptions: gameSession.matchOptions,
|
||||
playerOneUsername: (<ClientPlayer>gameSessionPlayersIterator.next().value).username,
|
||||
playerTwoUsername: (<ClientPlayer>gameSessionPlayersIterator.next().value).username,
|
||||
playerOneUsernameResult : 0,
|
||||
playerTwoUsernameResult : 0
|
||||
|
||||
})
|
||||
body: JSON.stringify(body)
|
||||
});
|
||||
if (!response.ok)
|
||||
{
|
||||
gameSessionsMap.delete(gameSession.id);
|
||||
gameSession.playersMap.forEach((client) => {
|
||||
client.socket.send(JSON.stringify( new ev.ServerEvent(en.EventTypes.matchAbort) ));
|
||||
client.socket.send(JSON.stringify( new ev.EventMatchAbort() ));
|
||||
client.gameSession = null;
|
||||
clientTerminate(client);
|
||||
});
|
||||
|
||||
@@ -71,6 +71,13 @@ export class EventMatchEnd extends ServerEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export class EventMatchAbort extends ServerEvent {
|
||||
|
||||
constructor() {
|
||||
super(en.EventTypes.matchAbort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* From Client */
|
||||
export class ClientEvent {
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import * as enumeration from './shared_js/enums';
|
||||
import * as pong from "./client/pong"
|
||||
import * as pongSpectator from "./client/pongSpectator" // TODO init spectator
|
||||
import { matchEnded, matchAbort } from "./client/ws";
|
||||
|
||||
//user's stuff
|
||||
let user;
|
||||
@@ -102,7 +103,8 @@
|
||||
if (invitation.token)
|
||||
{
|
||||
options.playerOneUsername = invitation.playerOneUsername;
|
||||
options.playerTwoUsername = user.username;
|
||||
options.playerTwoUsername = invitation.playerTwoUsername;
|
||||
options.isSomeoneIsInvited = true;
|
||||
pong.init(options, gameAreaId, invitation.token);
|
||||
showWaitPage = false
|
||||
hiddenGame = false;
|
||||
@@ -148,7 +150,7 @@
|
||||
console.log(error)
|
||||
|
||||
})
|
||||
showInvitation()
|
||||
showInvitation() // maybe useless
|
||||
initGameForPrivateParty(invitation)
|
||||
}
|
||||
</script>
|
||||
@@ -268,6 +270,9 @@
|
||||
#game_page {
|
||||
margin: 0;
|
||||
background-color: #222425;
|
||||
position: relative;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
#canvas_container {
|
||||
margin-top: 20px;
|
||||
|
||||
@@ -53,6 +53,13 @@ export function init(options: InitOptions, gameAreaId: string, token: string)
|
||||
export function destroy()
|
||||
{
|
||||
// TODO
|
||||
if (pong)
|
||||
{
|
||||
clearInterval(pong.handleInputInterval);
|
||||
clearInterval(pong.gameLoopInterval);
|
||||
clearInterval(pong.drawLoopInterval);
|
||||
initPong(null);
|
||||
}
|
||||
}
|
||||
|
||||
function start()
|
||||
|
||||
@@ -11,6 +11,7 @@ import { sleep } from "./utils.js";
|
||||
import { Vector, VectorInteger } from "../shared_js/class/Vector.js";
|
||||
|
||||
export let matchEnded = false;
|
||||
export let matchAbort = false;
|
||||
|
||||
class ClientInfo {
|
||||
id = "";
|
||||
@@ -87,6 +88,7 @@ function preMatchListener(this: WebSocket, event: MessageEvent)
|
||||
startFunction();
|
||||
break;
|
||||
case en.EventTypes.matchAbort:
|
||||
matchAbort = true;
|
||||
socket.removeEventListener("message", preMatchListener);
|
||||
msg.matchAbort();
|
||||
break;
|
||||
|
||||
@@ -71,6 +71,13 @@ export class EventMatchEnd extends ServerEvent {
|
||||
}
|
||||
}
|
||||
|
||||
export class EventMatchAbort extends ServerEvent {
|
||||
|
||||
constructor() {
|
||||
super(en.EventTypes.matchAbort);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* From Client */
|
||||
export class ClientEvent {
|
||||
|
||||
Reference in New Issue
Block a user