diff --git a/.env b/.env index e5812e20..53fa4ec5 100644 --- a/.env +++ b/.env @@ -12,15 +12,9 @@ #URL NGINX_ENVSUBST_TEMPLATE_SUFFIX=".conf" - -# BASE_URL=http://localhost -# SOCKET_URL=bess-f2r2s16:8080 BASE_URL=bess-f2r2s16:8080 REACT_APP_BASE_URL=bess-f2r2s16:8080 REDIRECT_URI=http://bess-f2r2s16:8080/api/auth/login -#postgres var -# POSTGRES_HOST=127.0.0.1 -# DB_TYPE=postgres POSTGRES_HOST=postgresql POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres diff --git a/.gitignore b/.gitignore index ace7e3a2..d9d0b8f9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -#.env +.env +containers/react/.env backend/node_modules/ containers/backend/dist/ diff --git a/conf/.nfs000000000358102100000482 b/conf/.nfs000000000358102100000482 deleted file mode 100644 index b3bdd0df..00000000 --- a/conf/.nfs000000000358102100000482 +++ /dev/null @@ -1,23 +0,0 @@ -server { - # listen 443 ssl; - # listen 80 ssl; - # listen 443 ssl; - # listen ${NGINX_PORT}; - listen 8080; - - location /{ - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://react_app:8081; - } - - location /api { - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://api:3000/api; - } -} \ No newline at end of file diff --git a/containers/api/src/chat/chat.service.ts b/containers/api/src/chat/chat.service.ts index 05415e63..d69bad68 100644 --- a/containers/api/src/chat/chat.service.ts +++ b/containers/api/src/chat/chat.service.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:25 by apommier #+# #+# */ -/* Updated: 2023/06/23 19:37:41 by apommier ### ########.fr */ +/* Updated: 2023/06/24 18:47:59 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/containers/api/src/model/user.entity.ts b/containers/api/src/model/user.entity.ts index 5fd7c12b..55d93f59 100644 --- a/containers/api/src/model/user.entity.ts +++ b/containers/api/src/model/user.entity.ts @@ -82,7 +82,7 @@ export class User { } -@Entity() +@Entity({name: 'MatchLog' }) export class MatchLog { @PrimaryGeneratedColumn() id: number; diff --git a/containers/api/src/users/users.service.ts b/containers/api/src/users/users.service.ts index 0ce83a87..796a7535 100644 --- a/containers/api/src/users/users.service.ts +++ b/containers/api/src/users/users.service.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/17 01:00:07 by apommier #+# #+# */ -/* Updated: 2023/06/23 22:27:16 by apommier ### ########.fr */ +/* Updated: 2023/06/24 19:29:33 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,8 +75,10 @@ export class UsersService { user.friendRequest = user.friendRequest || []; if (user.friendRequest.find(item => item === username)) return (1); + if (user.friends.find(item => item === username)) + return (1); user.friendRequest.push(username); - this.save(user); + this.save(user); return (1); } @@ -99,13 +101,20 @@ export class UsersService { async getHistory(username: string) { const user = await this.findOne(username); - - if (user) { - const children = user.children; - console.log(user); - console.log(user.children); // or perform any operations with the children - return children; + + if (user) + { + + // const ret = await this.matchRepository.query("SELECT * FROM \"MatchLog\" WHERE id = ($1);", [user.id]); + const ret = await this.matchRepository.query("SELECT * FROM \"MatchLog\""); + console.log("all match= ", ret); } + // const children = user.children; + // console.log(user); + // console.log(user.children); // or perform any operations with the children + // return children; + + // } } async addFriend(user: User, username: string) { @@ -122,6 +131,7 @@ export class UsersService { } user.friends.push(username); user.friendRequest = user.friendRequest.filter((item) => item !== username); + user2.friends = user2.friends || []; user2.friends.push(user.username); this.save(user2); this.save(user); diff --git a/containers/pong/src/pong/pong.gateway.ts b/containers/pong/src/pong/pong.gateway.ts index c72da145..7ce72768 100644 --- a/containers/pong/src/pong/pong.gateway.ts +++ b/containers/pong/src/pong/pong.gateway.ts @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/19 15:18:38 by apommier #+# #+# */ -/* Updated: 2023/06/24 00:43:19 by apommier ### ########.fr */ +/* Updated: 2023/06/24 17:20:24 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -167,8 +167,9 @@ addMatchmaking(client: Socket, payload: any): void { player.join(gameId); console.log(`Player ${player.id} joined game ${gameId}`); }); + payload.gameId = gameId; players.forEach((player) => { - player.emit('pong:gameId', gameId); + player.emit('pong:gameId', payload); }); } @@ -202,8 +203,8 @@ joinPrivateParty(client: Socket, payload: any): void { { game.push(client); const playersIds = game.map(socket => socket.id); - this.clients[playersIds[0]].emit('pong:gameId', payload.gameId); - this.clients[playersIds[1]].emit('pong:gameId', payload.gameId); + this.clients[playersIds[0]].emit('pong:gameId', payload); + this.clients[playersIds[1]].emit('pong:gameId', payload); } else { @@ -367,11 +368,11 @@ addPrivateParty(client: Socket, payload: any): void { if (playersIds[0] === payload.id) { - this.clients[playersIds[1]].emit('pong:name', payload.name); + this.clients[playersIds[1]].emit('pong:name', payload); } if (playersIds[1] === payload.id) { - this.clients[playersIds[0]].emit('pong:name', payload.name); + this.clients[playersIds[0]].emit('pong:name', payload); } } diff --git a/containers/react/src/components/Game/Ranking.tsx b/containers/react/src/components/Game/Ranking.tsx index 94f417ed..9410f119 100644 --- a/containers/react/src/components/Game/Ranking.tsx +++ b/containers/react/src/components/Game/Ranking.tsx @@ -21,18 +21,15 @@ function Ranking(){ // setFriends(tmpFriends.data); // return tmpUser; // console.log(`user= ${tmpUser.data.username}`); - setIsLoading(false) - + setIsLoading(false); } catch(err){ console.log(err); } }; getRanking(); - - }, []) - - console.log(`ranking after= ${ranking}`) + }, []); + console.log(`ranking after= ${ranking}`); return (
diff --git a/containers/react/src/components/Messages/Message.tsx b/containers/react/src/components/Messages/Message.tsx index f62562f6..38814ba3 100644 --- a/containers/react/src/components/Messages/Message.tsx +++ b/containers/react/src/components/Messages/Message.tsx @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* Message.tsx :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: sadjigui +#+ +:+ +#+ */ +/* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/06/01 18:24:46 by apommier #+# #+# */ -/* Updated: 2023/06/24 15:10:21 by sadjigui ### ########.fr */ +/* Updated: 2023/06/24 16:00:48 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/containers/react/src/pages/canvas.tsx b/containers/react/src/pages/canvas.tsx index e316a6ba..5bcfdb45 100644 --- a/containers/react/src/pages/canvas.tsx +++ b/containers/react/src/pages/canvas.tsx @@ -170,7 +170,9 @@ socket.on('pong:privateId', async (data) => { socket.on('pong:gameId', async (data) => { console.log("gameId received"); - gameId = data; + gameId = data.gameId; + console.log("gameid = ", gameId); + console.log("data gameid = ", data); try { let response = await api.get('/profile'); @@ -190,6 +192,16 @@ socket.on('pong:gameId', async (data) => { console.log("emit to name"); socket.emit('pong:name', info); + if (data.id === myId) + { + console.log("myId= true") + vX = 0.0001; + } + else + { + console.log("myId= false") + vX = -0.0001; + } } catch (error) { console.log(error); // Handle error here @@ -198,7 +210,11 @@ socket.on('pong:gameId', async (data) => { }); socket.on('pong:name', (data) => { - opName = data; + opName = data.name; + // if (data.myId === myId) + // vX = 0.0001; + // else + // vX = -0.0001; console.log(`opponent Name= ${opName}`) }); @@ -222,7 +238,6 @@ socket.on('pong:info', (data) => { vY = data.vY; }); - socket.on('pong:paddle', (data) => { console.log("paddle info receive") oPaddleY = (data.paddleY / data.height) * canvas.height @@ -251,7 +266,7 @@ socket.on('pong:point', (data) => { // console.log("up point"); myScore = data.point; // } - vX = 0.0001; + vX = -0.0001; vY = 0; ballX = canvas.width / 2; ballY = canvas.height / 2; @@ -265,7 +280,7 @@ socket.on('pong:hisPoint', (data) => { // console.log("up point"); hisScore = data.point; // } - vX = 0.0001; + vX = -0.0001; vY = 0; ballX = canvas.width / 2; ballY = canvas.height / 2; @@ -338,6 +353,7 @@ socket.on('pong:hisPoint', (data) => { point: hisScore, } socket.emit('pong:point', info); + vX = 0.0001; } function send_my_point() @@ -740,9 +756,8 @@ async function draw(timestamp: number) vX -= 0.0001; } send_forced_info(); - // console.log(`vx = ${vX}`); } - else if (event.code === "KeyR") + else if (event.code === "KeyW") { if (!superpowerModifier) return ; @@ -755,6 +770,13 @@ async function draw(timestamp: number) paddleY = canvas.height / 2 - paddleHeight / 2; console.log('Cinq secondes se sont écoulées.'); }, 5000); + + // setTimeout(() => { + // // code à exécuter après 5 secondes + // paddleHeight = canvas.height * 0.25; + // paddleY = canvas.height / 2 - paddleHeight / 2; + // console.log('Cinq secondes se sont écoulées.'); + // }, 5000); } }); diff --git a/containers/react/src/styles/Game.css b/containers/react/src/styles/Game.css index 7b2adb2a..f2a2f498 100644 --- a/containers/react/src/styles/Game.css +++ b/containers/react/src/styles/Game.css @@ -23,6 +23,8 @@ } .profilePic{ + margin-left: 10px; + /* margin-top: 10px; */ height: 30px; width: 30px; border-radius: 50%; diff --git a/docker-compose.yml b/docker-compose.yml index e88a66b0..d15b89f4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,4 +1,4 @@ -version: "3.3" +version: "3.3" services: @@ -24,7 +24,7 @@ services: # depends_on: # - nginx ports: - - 8081:8081 + - 8001:8001 volumes: - ./containers/react:/app # - ./containers/react:/app @@ -115,4 +115,4 @@ volumes: # o: 'bind' # device: '/backend' db: - driver: local + driver: local \ No newline at end of file