init pong refactoring for spectator mode
+ pongSpectator.ts should be good + EventError wip, not tested
This commit is contained in:
@@ -88,7 +88,7 @@ async function clientAnnounceListener(this: WebSocket, data: string)
|
||||
});
|
||||
if (!response.ok)
|
||||
{
|
||||
// send message to client ? or just gtfo ?
|
||||
this.send(JSON.stringify( new ev.EventError((await response.json()).message)));
|
||||
clientTerminate(clientsMap.get(this.id));
|
||||
return;
|
||||
}
|
||||
@@ -111,7 +111,7 @@ async function clientAnnounceListener(this: WebSocket, data: string)
|
||||
const announce: ev.ClientAnnounceSpectator = <ev.ClientAnnounceSpectator>msg;
|
||||
const gameSession = gameSessionsMap.get(announce.gameSessionId);
|
||||
if (!gameSession) {
|
||||
// WIP: send "invalid game session"
|
||||
this.send(JSON.stringify( new ev.EventError("invalid gameSessionId")));
|
||||
clientTerminate(clientsMap.get(this.id));
|
||||
return;
|
||||
}
|
||||
@@ -187,13 +187,15 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
});
|
||||
createGameSession(compatiblePlayers, matchOptions);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
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",{
|
||||
if (player.socket.OPEN) {
|
||||
player.socket.send(JSON.stringify( new ev.EventMatchAbort() ));
|
||||
}
|
||||
const response = await fetch(c.addressBackEnd + "/game/gameserver/destroysession",{
|
||||
method: "POST",
|
||||
headers : {"Content-Type": "application/json"},
|
||||
body : JSON.stringify({
|
||||
@@ -201,7 +203,7 @@ function privateMatchmaking(player: ClientPlayer)
|
||||
})
|
||||
})
|
||||
.then(x => x.json())
|
||||
.catch(error => console.log("ERROR : " + error))
|
||||
.catch(error => console.log("ERROR : " + error));
|
||||
clientTerminate(player);
|
||||
}
|
||||
}, 60000);
|
||||
|
||||
@@ -72,12 +72,19 @@ export class EventMatchEnd extends ServerEvent {
|
||||
}
|
||||
|
||||
export class EventMatchAbort extends ServerEvent {
|
||||
|
||||
constructor() {
|
||||
super(en.EventTypes.matchAbort);
|
||||
}
|
||||
}
|
||||
|
||||
export class EventError extends ServerEvent {
|
||||
message: string;
|
||||
constructor(message: string) {
|
||||
super(en.EventTypes.error);
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* From Client */
|
||||
export class ClientEvent {
|
||||
|
||||
@@ -6,6 +6,7 @@ export enum EventTypes {
|
||||
matchEnd,
|
||||
assignId,
|
||||
matchmakingComplete,
|
||||
error,
|
||||
|
||||
// Generic
|
||||
matchmakingInProgress,
|
||||
|
||||
Reference in New Issue
Block a user