- fix some bugs with mastchmaking
This commit is contained in:
Kum1ta
2024-09-27 13:05:48 +02:00
parent 6fd802a788
commit 32ae90c399
7 changed files with 47 additions and 19 deletions

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ # # By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# # # Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
# Updated: 2024/09/27 03:54:50 by tomoron ### ########.fr # # Updated: 2024/09/27 13:04:59 by edbernar ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -137,8 +137,8 @@ class Game:
self.p1 = socket self.p1 = socket
self.p1Skin = skin self.p1Skin = skin
else: else:
if(self.opponentLock != socket.id): if(self.opponentLock and dself.opponentLock != socket.id):
socket.sendError("You are not invited to this game", 9013) socket.sendError("You are not invited to this game", 9103)
return; return;
self.p2 = socket self.p2 = socket
self.p2Skin = skin self.p2Skin = skin

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ # # By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/09/25 23:28:49 by edbernar #+# #+# # # Created: 2024/09/25 23:28:49 by edbernar #+# #+# #
# Updated: 2024/09/27 03:23:10 by tomoron ### ########.fr # # Updated: 2024/09/27 10:57:55 by edbernar ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -18,21 +18,25 @@ import json
@sync_to_async @sync_to_async
def changePrivateInfo(socket, content): def changePrivateInfo(socket, content):
whatChanged = ""
try: try:
user = User.objects.get(id=socket.id) user = User.objects.get(id=socket.id)
if ("delete" in content): if ("delete" in content):
whatChanged = "Delete"
user.delete() user.delete()
socket.scope["session"].delete() socket.scope["session"].delete()
socket.sync_send(json.dumps({"type": "change_private_info", "content": "Successfully deleted."})) socket.sync_send(json.dumps({"type": "change_private_info", "content": "Successfully deleted."}))
socket.close() socket.close()
return; return;
elif ("username" in content): elif ("username" in content):
whatChanged = "Username"
if (not usernameValid(content.get("username"), socket)): if (not usernameValid(content.get("username"), socket)):
return return
user.username = content["username"] user.username = content["username"]
socket.username = content["username"] socket.username = content["username"]
socket.scope["session"]['username'] = content["username"] socket.scope["session"]['username'] = content["username"]
elif ("new_password" in content): elif ("new_password" in content):
whatChanged = "Password"
if (not passwordValid(content.get("new_password"), socket)): if (not passwordValid(content.get("new_password"), socket)):
return return
if (not content.get("old_password")): if (not content.get("old_password")):
@ -43,6 +47,7 @@ def changePrivateInfo(socket, content):
return return
user.password = hashlib.md5((user.mail + content["new_password"]).encode()).hexdigest() user.password = hashlib.md5((user.mail + content["new_password"]).encode()).hexdigest()
elif ("discord" in content): elif ("discord" in content):
whatChanged = "Discord"
if (not discordValid(content.get("discord"), socket)): if (not discordValid(content.get("discord"), socket)):
return return
if (content["discord"] == ""): if (content["discord"] == ""):
@ -54,6 +59,6 @@ def changePrivateInfo(socket, content):
return; return;
user.save() user.save()
socket.scope["session"].save() socket.scope["session"].save()
socket.sync_send(json.dumps({"type": "change_private_info", "content": "Successfully updated."})) socket.sync_send(json.dumps({"type": "change_private_info", "content": whatChanged + " successfully updated."}))
except Exception as e: except Exception as e:
socket.sendError("An unknown error occured", 9027, e) socket.sendError("An unknown error occured", 9027, e)

View File

@ -3,13 +3,15 @@
# ::: :::::::: # # ::: :::::::: #
# utils.py :+: :+: :+: # # utils.py :+: :+: :+: #
# +:+ +:+ +:+ # # +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ # # By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2024/09/27 03:36:08 by tomoron #+# #+# # # Created: 2024/09/27 03:36:08 by tomoron #+# #+# #
# Updated: 2024/09/27 03:36:42 by tomoron ### ########.fr # # Updated: 2024/09/27 11:23:51 by edbernar ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
import random
def genString(length): def genString(length):
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
return(''.join(random.choice(letters) for i in range(length))) return(''.join(random.choice(letters) for i in range(length)))

View File

@ -3,10 +3,10 @@
/* ::: :::::::: */ /* ::: :::::::: */
/* multiOnlineGamePage.js :+: :+: :+: */ /* multiOnlineGamePage.js :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */ /* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */ /* Created: 2024/08/18 00:53:53 by edbernar #+# #+# */
/* Updated: 2024/09/25 18:28:23 by hubourge ### ########.fr */ /* Updated: 2024/09/27 10:35:23 by edbernar ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -50,6 +50,8 @@ Controls :
- k : recreate et augmente le score de opponent - k : recreate et augmente le score de opponent
*/ */
const scoreMax = 5;
let scene = null; let scene = null;
let map = null; let map = null;
let ball = null; let ball = null;

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* typeChangePrivateInfo.js :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/27 10:53:20 by edbernar #+# #+# */
/* Updated: 2024/09/27 10:58:05 by edbernar ### ########.fr */
/* */
/* ************************************************************************** */
import { createNotification as CN } from "/static/javascript/notification/main.js";
function typeChangePrivateInfo(content)
{
CN.new("Information", content);
}
export { typeChangePrivateInfo };

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */ /* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/14 21:20:45 by edbernar #+# #+# */ /* Created: 2024/09/14 21:20:45 by edbernar #+# #+# */
/* Updated: 2024/09/27 00:26:12 by edbernar ### ########.fr */ /* Updated: 2024/09/27 11:26:38 by edbernar ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,9 +31,7 @@ class WaitingGamePage
{ {
document.body.children[i].style.animation = 'animShowMenuDiv 0.5s'; document.body.children[i].style.animation = 'animShowMenuDiv 0.5s';
} }
if (!opponentInfo) if (opponentInfo)
opponentInfo = {id: -1}
else
text = text.replace("other players", opponentInfo.username); text = text.replace("other players", opponentInfo.username);
intervalPoints = setInterval(() => { intervalPoints = setInterval(() => {
if (points.length < 3) if (points.length < 3)
@ -43,10 +41,10 @@ class WaitingGamePage
sentence.innerText = text + points; sentence.innerText = text + points;
}, 500); }, 500);
timeout = setTimeout(() => { timeout = setTimeout(() => {
if (!lastSelected) if (opponentInfo)
sendRequest("game", {action: 0, skinId: 0, opponent: opponentInfo.id}); sendRequest("game", {action: 0, skinId: lastSelected ? lastSelected.id : 0, opponent: opponentInfo.id});
else else
sendRequest("game", {action: 0, skinId: lastSelected.id, opponent: opponentInfo.id}); sendRequest("game", {action: 0, skinId: lastSelected ? lastSelected.id : 0});
timeout = null; timeout = null;
}, 1500); }, 1500);
returnButton.addEventListener('click', returnToLobby); returnButton.addEventListener('click', returnToLobby);

View File

@ -6,7 +6,7 @@
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */ /* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */ /* Created: 2024/07/31 22:17:24 by edbernar #+# #+# */
/* Updated: 2024/09/26 00:59:46 by edbernar ### ########.fr */ /* Updated: 2024/09/27 10:53:04 by edbernar ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -16,6 +16,7 @@ import { typeErrorInvalidPassword } from "/static/javascript/typeErrorResponse/t
import { typeErrorInvalidToken42 } from "/static/javascript/typeErrorResponse/typeErrorInvalidToken42.js"; import { typeErrorInvalidToken42 } from "/static/javascript/typeErrorResponse/typeErrorInvalidToken42.js";
import { typePrivateListMessage } from "/static/javascript/typeResponse/typePrivateListMessage.js"; import { typePrivateListMessage } from "/static/javascript/typeResponse/typePrivateListMessage.js";
import { typeNewPrivateMessage } from "/static/javascript/typeResponse/typeNewPrivateMessage.js"; import { typeNewPrivateMessage } from "/static/javascript/typeResponse/typeNewPrivateMessage.js";
import { typeChangePrivateInfo } from "/static/javascript/typeResponse/typeChangePrivateInfo.js";
import { typePrivateListUser } from "/static/javascript/typeResponse/typePrivateListUser.js"; import { typePrivateListUser } from "/static/javascript/typeResponse/typePrivateListUser.js";
import { typeCreateAccount } from "/static/javascript/typeResponse/typeCreateAccount.js"; import { typeCreateAccount } from "/static/javascript/typeResponse/typeCreateAccount.js";
import { typeAllListUser }from "/static/javascript/typeResponse/typeAllListUser.js"; import { typeAllListUser }from "/static/javascript/typeResponse/typeAllListUser.js";
@ -37,8 +38,8 @@ function launchSocket()
socket = new WebSocket('/ws'); socket = new WebSocket('/ws');
const typeResponse = ["logged_in", "login", "private_list_user", "private_list_message", "new_private_message", "all_list_user", "create_account", "game", "search_user", "user_info", "change_pfp", "private_info"]; const typeResponse = ["logged_in", "login", "private_list_user", "private_list_message", "new_private_message", "all_list_user", "create_account", "game", "search_user", "user_info", "change_pfp", "private_info", "change_private_info"];
const functionResponse = [typeLogin, typeLogin, typePrivateListUser, typePrivateListMessage, typeNewPrivateMessage, typeAllListUser, typeCreateAccount, typeGame, typeSearchUser, typeUserInfo, typeChangePfp, typePrivateInfo]; const functionResponse = [typeLogin, typeLogin, typePrivateListUser, typePrivateListMessage, typeNewPrivateMessage, typeAllListUser, typeCreateAccount, typeGame, typeSearchUser, typeUserInfo, typeChangePfp, typePrivateInfo, typeChangePrivateInfo];
const errorCode = [9007, 9010, 9011, 9013]; const errorCode = [9007, 9010, 9011, 9013];
const errorFunction = [typeErrorInvalidPassword, typeErrorInvalidToken42, typeErrorUnknown42Account, typeErrorConnectedElsewhere]; const errorFunction = [typeErrorInvalidPassword, typeErrorInvalidToken42, typeErrorUnknown42Account, typeErrorConnectedElsewhere];