fix invite double channel when add friend fix invite, history power up time limited wall

This commit is contained in:
Alexandre POMMIER 2023-06-25 00:30:30 +02:00
parent 2f777480a0
commit 9098c29287
7 changed files with 66 additions and 37 deletions

6
.env
View File

@ -12,9 +12,15 @@
#URL
NGINX_ENVSUBST_TEMPLATE_SUFFIX=".conf"
# BASE_URL=http://localhost
# SOCKET_URL=localhost:8080
BASE_URL=localhost:8080
REACT_APP_BASE_URL=localhost:8080
REDIRECT_URI=http://localhost:8080/api/auth/login
#postgres var
# POSTGRES_HOST=127.0.0.1
# DB_TYPE=postgres
POSTGRES_HOST=postgresql
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/17 01:00:00 by apommier #+# #+# */
/* Updated: 2023/06/24 20:00:09 by apommier ### ########.fr */
/* Updated: 2023/06/25 00:10:18 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -96,6 +96,12 @@ export class AppController {
const user = await this.userService.findOne(req.user.username)
if (!user)
return (0);
if (user.friends.find(item => item === data.username))
{
user.friendRequest = user.friendRequest.filter((item) => item !== data.username);
this.userService.save(user);
return (1);
}
//create personnal conv for user
//await this.userService.addFriend(user, data.username);
@ -115,13 +121,13 @@ export class AppController {
messages: null,
group: false,
private: false,
};
conv.members.push(req.user.username);
conv.members.push(data.username);
await this.chatService.createConv(conv);
return await this.userService.addFriend(user, data.username);
}
@UseGuards(JwtAuthGuard)

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/17 01:00:07 by apommier #+# #+# */
/* Updated: 2023/06/24 19:29:33 by apommier ### ########.fr */
/* Updated: 2023/06/24 23:30:52 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -75,6 +75,7 @@ export class UsersService {
user.friendRequest = user.friendRequest || [];
if (user.friendRequest.find(item => item === username))
return (1);
user.friends = user.friends || [];
if (user.friends.find(item => item === username))
return (1);
user.friendRequest.push(username);
@ -104,17 +105,16 @@ export class UsersService {
if (user)
{
// const ret = await this.matchRepository.query("SELECT * FROM \"MatchLog\"");
// 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);
console.log("user id=0 ", user.id);
// const matchLog = await this.userRepository.query("SELECT * FROM \"MatchLog\" WHERE \"parentId\" = ANY ($1);", [[user.id]]);
return await this.userRepository.query("SELECT * FROM \"MatchLog\" WHERE \"parentId\" = ANY ($1);", [[user.id]]);
// console.log("all match2= ", matchLog);
}
// 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) {

View File

@ -6,7 +6,7 @@
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/19 15:18:38 by apommier #+# #+# */
/* Updated: 2023/06/24 17:20:24 by apommier ### ########.fr */
/* Updated: 2023/06/24 23:37:39 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -282,13 +282,13 @@ addPrivateParty(client: Socket, payload: any): void {
@SubscribeMessage('pong:forced')
forcedMessage(client: Socket, payload: any): void
{
console.log(`from: ${client.id}`);
console.log(payload);
// console.log(`from: ${client.id}`);
// console.log(payload);
const game = this.games.get(payload.gameId);
const playersIds = game.map(socket => socket.id);
console.log(`id of 0= ${playersIds[0]}`);
// console.log(`id of 0= ${playersIds[0]}`);
if (playersIds[0] === payload.id)
{
@ -298,19 +298,19 @@ addPrivateParty(client: Socket, payload: any): void {
{
this.clients[playersIds[0]].emit('pong:info', payload);
}
console.log("END OF HANDLE");
// console.log("END OF HANDLE");
}
@SubscribeMessage('pong:paddle')
handlePaddle(client: Socket, payload: any): void
{
console.log(`from: ${client.id}`);
console.log(payload);
// console.log(`from: ${client.id}`);
// console.log(payload);
const game = this.games.get(payload.gameId);
const playersIds = game.map(socket => socket.id);
console.log(`id of 0= ${playersIds[0]}`);
// console.log(`id of 0= ${playersIds[0]}`);
if (playersIds[0] === payload.id)
{
@ -320,7 +320,7 @@ addPrivateParty(client: Socket, payload: any): void {
{
this.clients[playersIds[0]].emit('pong:paddle', payload);
}
console.log("END OF HANDLE");
// console.log("END OF HANDLE");
}
@SubscribeMessage('pong:point')
@ -363,9 +363,7 @@ addPrivateParty(client: Socket, payload: any): void {
{
const game = this.games.get(payload.gameId);
const playersIds = game.map(socket => socket.id);
console.log(`name of client= ${payload.name}`);
if (playersIds[0] === payload.id)
{
this.clients[playersIds[1]].emit('pong:name', payload);

View File

@ -62,8 +62,20 @@ function WinLoss() {
const getUser = async ()=>{
try{
// const tmpUser = await api.get("/profile")
const tmpUser = await api.post("/user", {username: username})
const tmpHistory = await api.post("/history", {username: username})
console.log("username win loss=", username)
let tmpUser;
let tmpHistory;
if (username)
{
tmpUser = await api.post("/user", {username: username});
tmpHistory = await api.post("/history", {username: username})
}
else
{
tmpUser = await api.get("/profile");
tmpHistory = await api.post("/history", {username: tmpUser.data.username})
}
setHistory(tmpHistory.data);
setUser(tmpUser.data);
setIsLoading(false)

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* Home.tsx :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sadjigui <sadjigui@student.42.fr> +#+ +:+ +#+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/06/09 08:19:04 by apommier #+# #+# */
/* Updated: 2023/06/23 22:11:28 by apommier ### ########.fr */
/* Updated: 2023/06/24 23:26:45 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
@ -224,7 +224,12 @@ function Home () {
):("")}
</div>
<div className="home">
<motion.div animate={{x: move ? -200: 120}}
<motion.div
// style={{
// backdropFilter: move ? "blur(10px)" : "none",
// WebkitBackdropFilter: move ? "blur(10px)" : "none"
// }}
animate={{x: move ? '-50%' : '30%'}}
transition={{type: "tween", duration: 0.5}}>
<Profile/>
</motion.div>

View File

@ -124,6 +124,8 @@ function DrawCanvas(option: number, gameParam: GameProps) {
const maxScore = 5;
let lastUpdateTime = performance.now();
let lastPower = 0;
const maxAngle = 50;
let maxBounceAngle = (maxAngle * Math.PI) / 180;
@ -182,7 +184,7 @@ socket.on('pong:gameId', async (data) => {
opRank = response.data
console.log(`rank= ${opRank}`);
console.log(`myname= ${myName}`);
const info = {
id: myId,
name: myName,
@ -491,7 +493,7 @@ socket.on('pong:hisPoint', (data) => {
// id: myId,
// option: option,
// };
// await api.post("status", {status: 1});
await api.post("deleteInvite", {username: gameParam.username})
}
catch (err){
@ -759,6 +761,10 @@ async function draw(timestamp: number)
}
else if (event.code === "KeyW")
{
let date = new Date();
console.log("last time =", date.getTime() - lastPower)
if (date.getTime() - lastPower < 15000)//10000 + 5000
return ;
if (!superpowerModifier)
return ;
paddleY = 0;
@ -770,13 +776,9 @@ 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);
date = new Date();
lastPower = date.getTime();
// console.log("date= ", date.getTime())
}
});