Django
- fix some bugs with mastchmaking
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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.p1Skin = skin
|
||||
else:
|
||||
if(self.opponentLock != socket.id):
|
||||
socket.sendError("You are not invited to this game", 9013)
|
||||
if(self.opponentLock and dself.opponentLock != socket.id):
|
||||
socket.sendError("You are not invited to this game", 9103)
|
||||
return;
|
||||
self.p2 = socket
|
||||
self.p2Skin = skin
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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
|
||||
def changePrivateInfo(socket, content):
|
||||
whatChanged = ""
|
||||
try:
|
||||
user = User.objects.get(id=socket.id)
|
||||
if ("delete" in content):
|
||||
whatChanged = "Delete"
|
||||
user.delete()
|
||||
socket.scope["session"].delete()
|
||||
socket.sync_send(json.dumps({"type": "change_private_info", "content": "Successfully deleted."}))
|
||||
socket.close()
|
||||
return;
|
||||
elif ("username" in content):
|
||||
whatChanged = "Username"
|
||||
if (not usernameValid(content.get("username"), socket)):
|
||||
return
|
||||
user.username = content["username"]
|
||||
socket.username = content["username"]
|
||||
socket.scope["session"]['username'] = content["username"]
|
||||
elif ("new_password" in content):
|
||||
whatChanged = "Password"
|
||||
if (not passwordValid(content.get("new_password"), socket)):
|
||||
return
|
||||
if (not content.get("old_password")):
|
||||
@ -43,6 +47,7 @@ def changePrivateInfo(socket, content):
|
||||
return
|
||||
user.password = hashlib.md5((user.mail + content["new_password"]).encode()).hexdigest()
|
||||
elif ("discord" in content):
|
||||
whatChanged = "Discord"
|
||||
if (not discordValid(content.get("discord"), socket)):
|
||||
return
|
||||
if (content["discord"] == ""):
|
||||
@ -54,6 +59,6 @@ def changePrivateInfo(socket, content):
|
||||
return;
|
||||
user.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:
|
||||
socket.sendError("An unknown error occured", 9027, e)
|
||||
|
@ -3,13 +3,15 @@
|
||||
# ::: :::::::: #
|
||||
# utils.py :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# 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):
|
||||
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
return(''.join(random.choice(letters) for i in range(length)))
|
||||
|
@ -3,10 +3,10 @@
|
||||
/* ::: :::::::: */
|
||||
/* multiOnlineGamePage.js :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hubourge <hubourge@student.42.fr> +#+ +:+ +#+ */
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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
|
||||
*/
|
||||
|
||||
const scoreMax = 5;
|
||||
|
||||
let scene = null;
|
||||
let map = null;
|
||||
let ball = null;
|
||||
|
@ -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 };
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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';
|
||||
}
|
||||
if (!opponentInfo)
|
||||
opponentInfo = {id: -1}
|
||||
else
|
||||
if (opponentInfo)
|
||||
text = text.replace("other players", opponentInfo.username);
|
||||
intervalPoints = setInterval(() => {
|
||||
if (points.length < 3)
|
||||
@ -43,10 +41,10 @@ class WaitingGamePage
|
||||
sentence.innerText = text + points;
|
||||
}, 500);
|
||||
timeout = setTimeout(() => {
|
||||
if (!lastSelected)
|
||||
sendRequest("game", {action: 0, skinId: 0, opponent: opponentInfo.id});
|
||||
if (opponentInfo)
|
||||
sendRequest("game", {action: 0, skinId: lastSelected ? lastSelected.id : 0, opponent: opponentInfo.id});
|
||||
else
|
||||
sendRequest("game", {action: 0, skinId: lastSelected.id, opponent: opponentInfo.id});
|
||||
sendRequest("game", {action: 0, skinId: lastSelected ? lastSelected.id : 0});
|
||||
timeout = null;
|
||||
}, 1500);
|
||||
returnButton.addEventListener('click', returnToLobby);
|
||||
|
@ -6,7 +6,7 @@
|
||||
/* By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 { typePrivateListMessage } from "/static/javascript/typeResponse/typePrivateListMessage.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 { typeCreateAccount } from "/static/javascript/typeResponse/typeCreateAccount.js";
|
||||
import { typeAllListUser }from "/static/javascript/typeResponse/typeAllListUser.js";
|
||||
@ -37,8 +38,8 @@ function launchSocket()
|
||||
|
||||
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 functionResponse = [typeLogin, typeLogin, typePrivateListUser, typePrivateListMessage, typeNewPrivateMessage, typeAllListUser, typeCreateAccount, typeGame, typeSearchUser, typeUserInfo, typeChangePfp, typePrivateInfo];
|
||||
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, typeChangePrivateInfo];
|
||||
|
||||
const errorCode = [9007, 9010, 9011, 9013];
|
||||
const errorFunction = [typeErrorInvalidPassword, typeErrorInvalidToken42, typeErrorUnknown42Account, typeErrorConnectedElsewhere];
|
||||
|
Reference in New Issue
Block a user