Merge branch 'master' of bitbucket.org:LuckyLaszlo/ft_transcendence
This commit is contained in:
@@ -26,7 +26,7 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./requirements/nestjs/api_back/src:/usr/app/src
|
- ./requirements/nestjs/api_back/src:/usr/app/src
|
||||||
- ./requirements/nestjs/api_back/test:/usr/app/test/
|
- ./requirements/nestjs/api_back/test:/usr/app/test/
|
||||||
- nestjs_photos_volume:/usr/app/src/uploads/avatars
|
- nestjs_photos_volume:/usr/app/uploads/avatars
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
depends_on:
|
depends_on:
|
||||||
- postgresql
|
- postgresql
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import * as ev from "../../shared_js/class/Event.js"
|
|||||||
import * as en from "../../shared_js/enums.js"
|
import * as en from "../../shared_js/enums.js"
|
||||||
|
|
||||||
export class Client {
|
export class Client {
|
||||||
|
role: en.ClientRole;
|
||||||
socket: WebSocket;
|
socket: WebSocket;
|
||||||
id: string; // same as "socket.id"
|
id: string; // same as "socket.id"
|
||||||
isAlive: boolean = true;
|
isAlive: boolean = true;
|
||||||
@@ -23,9 +24,8 @@ export class ClientPlayer extends Client {
|
|||||||
inputBuffer: ev.EventInput = new ev.EventInput();
|
inputBuffer: ev.EventInput = new ev.EventInput();
|
||||||
lastInputId: number = 0;
|
lastInputId: number = 0;
|
||||||
racket: Racket;
|
racket: Racket;
|
||||||
constructor(socket: WebSocket, id: string, racket: Racket) {
|
constructor(socket: WebSocket, id: string) {
|
||||||
super(socket, id);
|
super(socket, id);
|
||||||
this.racket = racket;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ async function clientAnnounceListener(this: WebSocket, data: string)
|
|||||||
if (msg.role === en.ClientRole.player)
|
if (msg.role === en.ClientRole.player)
|
||||||
{
|
{
|
||||||
const announce: ev.ClientAnnouncePlayer = <ev.ClientAnnouncePlayer>msg;
|
const announce: ev.ClientAnnouncePlayer = <ev.ClientAnnouncePlayer>msg;
|
||||||
|
const player = clientsMap.get(this.id) as ClientPlayer;
|
||||||
|
player.role = msg.role;
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
playerOneUsername: announce.username,
|
playerOneUsername: announce.username,
|
||||||
@@ -106,8 +108,6 @@ async function clientAnnounceListener(this: WebSocket, data: string)
|
|||||||
clientTerminate(clientsMap.get(this.id));
|
clientTerminate(clientsMap.get(this.id));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
player.username = announce.username;
|
||||||
@@ -126,13 +126,15 @@ async function clientAnnounceListener(this: WebSocket, data: string)
|
|||||||
else if (msg.role === en.ClientRole.spectator)
|
else if (msg.role === en.ClientRole.spectator)
|
||||||
{
|
{
|
||||||
const announce: ev.ClientAnnounceSpectator = <ev.ClientAnnounceSpectator>msg;
|
const announce: ev.ClientAnnounceSpectator = <ev.ClientAnnounceSpectator>msg;
|
||||||
|
const spectator = clientsMap.get(this.id) as ClientSpectator;
|
||||||
|
spectator.role = msg.role;
|
||||||
|
|
||||||
const gameSession = gameSessionsMap.get(announce.gameSessionId);
|
const gameSession = gameSessionsMap.get(announce.gameSessionId);
|
||||||
if (!gameSession) {
|
if (!gameSession) {
|
||||||
this.send(JSON.stringify( new ev.EventError("invalid gameSessionId") ));
|
this.send(JSON.stringify( new ev.EventError("invalid gameSessionId") ));
|
||||||
clientTerminate(clientsMap.get(this.id));
|
clientTerminate(clientsMap.get(this.id));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const spectator = clientsMap.get(this.id) as ClientSpectator;
|
|
||||||
spectator.gameSession = gameSession;
|
spectator.gameSession = gameSession;
|
||||||
gameSession.spectatorsMap.set(spectator.id, spectator);
|
gameSession.spectatorsMap.set(spectator.id, spectator);
|
||||||
spectator.socket.once("message", spectatorReadyConfirmationListener);
|
spectator.socket.once("message", spectatorReadyConfirmationListener);
|
||||||
@@ -419,7 +421,7 @@ const pingInterval = setInterval( () => {
|
|||||||
}, 4200);
|
}, 4200);
|
||||||
|
|
||||||
|
|
||||||
export function clientTerminate(client: Client)
|
export async function clientTerminate(client: Client)
|
||||||
{
|
{
|
||||||
client.socket.terminate();
|
client.socket.terminate();
|
||||||
if (client.gameSession)
|
if (client.gameSession)
|
||||||
@@ -439,6 +441,23 @@ export function clientTerminate(client: Client)
|
|||||||
else if (privateMatchmakingMap.has(client.id)) {
|
else if (privateMatchmakingMap.has(client.id)) {
|
||||||
privateMatchmakingMap.delete(client.id);
|
privateMatchmakingMap.delete(client.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (client.role === en.ClientRole.player)
|
||||||
|
{
|
||||||
|
const player = client as ClientPlayer;
|
||||||
|
console.log("/resetuserstatus " + player.username);
|
||||||
|
const response = await fetch(c.addressBackEnd + "/game/gameserver/resetuserstatus",
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({username: player.username})
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
console.log("/resetuserstatus " + player.username + " failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -101,4 +101,9 @@ export class GameController {
|
|||||||
{
|
{
|
||||||
return this.gameService.destroySession(token);
|
return this.gameService.destroySession(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post('gameserver/resetuserstatus')
|
||||||
|
async resetUserStatus(@Body('username') username){
|
||||||
|
this.gameService.resetStatus(username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -305,5 +305,12 @@ export class GameService {
|
|||||||
}
|
}
|
||||||
return HttpStatus.OK
|
return HttpStatus.OK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async resetStatus(username : string){
|
||||||
|
const user : User = await this.userRepository.findOneBy({username : username})
|
||||||
|
if (!user)
|
||||||
|
return HttpStatus.NOT_FOUND;
|
||||||
|
this.userService.updateStatus(user.id, STATUS.CONNECTED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user