Skip to content

Commit

Permalink
fix the array of match
Browse files Browse the repository at this point in the history
  • Loading branch information
a-boring-man committed Apr 19, 2023
1 parent f693d9f commit 16313d5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion back/nest_project/src/game_engine/game_engine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export class GameEngineService {
if (this.pl1_ready && this.pl2_ready && this.ongoing_match === false) {
let thiss = this;
this.ongoing_match = true;
thiss.server.emit("Match_Update", this.ms);
//thiss.server.emit("Match_Update", this.ms);
//console.log();
this.loop = setInterval(function() {
if (thiss.game_must_stop) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IsBoolean, IsNotEmpty, IsString } from "class-validator";
import { IsBoolean, IsNotEmpty, IsString, MaxLength } from "class-validator";

/**
* DTO use for private matchmaking request
*/
export class PrivateGameRequestDTO {
@IsString() @IsNotEmpty() target: string;
@IsString() @IsNotEmpty() @MaxLength(64) target: string;
@IsBoolean() @IsNotEmpty() super_game_mode: boolean;
}

Expand All @@ -19,9 +19,9 @@ export class PublicGameRequestDTO {
* DTO use for sending input
*/
export class GameInputDTO {
@IsString() @IsNotEmpty() input: string;
@IsString() @IsNotEmpty() @MaxLength(64) input: string;
}

export class SpectatorRequestDTO {
@IsString() @IsNotEmpty() player1_login: string;
@IsString() @IsNotEmpty() @MaxLength(64) player1_login: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ export class GameUpdateCenterGateway implements OnGatewayInit, OnGatewayConnecti
// check if undefined is it is then set the value to 0 instead
nbr_of_socket = nbr_of_socket ?? 0;
this.login_to_nbr_of_active_socket.set(user_entity.login, ++nbr_of_socket);
this.transfer_all_match(client);
console.log("in handle connection nbr_of socket vaut : ", nbr_of_socket);
this.logger.debug("client Connected---------------- socket id : " + client.id + " client login" + user_entity.login);
}

transfer_all_match(@ConnectedSocket() client: Socket) {
console.log("in transfert there is : ", this.all_the_match.length);
for (let index = 0; index < this.all_the_match.length; index++) {
const match = this.all_the_match[index];
this.server.to(client.id).emit("Match_Update", match);
Expand Down
6 changes: 3 additions & 3 deletions back/nest_project/src/pong_engine/pong_engine.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export class PongEngineService {
let thiss = this;
this.ongoing_match = true;
// console.log("room to emit", thiss.server);
thiss.server.emit("Match_Update", this.ms);
//thiss.server.emit("Match_Update", this.ms);
console.log(thiss.pl1.rooms, thiss.pl2.rooms);
this.loop = setInterval(function() {
if (thiss.game_must_stop) {
Expand Down Expand Up @@ -235,8 +235,8 @@ export class PongEngineService {
}
this.server.emit("Match_End", this.match_end_state);
await this.matchservice.createMatch(match);
//let result = await this.matchservice.findMatch();
//console.log("the score should be save and the match history is :", result);
// let result = await this.matchservice.findMatch();
// console.log("the score should be save and the match history is :", result);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion front/react_project/src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import React, { useContext, useState } from "react"
import { NavLink, Link } from "react-router-dom"
import { useNavigate } from "react-router-dom";
import { accountService } from "../services/account.service";
import SocketContext from './context';

const NavBar: React.FC = () => {
let navigate = useNavigate();
const [burgerList, setBurgerList] = useState<boolean>(false)
const [burgerList, setBurgerList] = useState<boolean>(false);
const {disconnect, disconnectGame} = useContext(SocketContext);

const logout = () => {
disconnect();
disconnectGame();
accountService.logout();
navigate("/login");
}
Expand Down

0 comments on commit 16313d5

Please sign in to comment.