Merge branch 'main' of github.com:Kum1ta/PTME_Transcendence

This commit is contained in:
Kum1ta
2024-09-16 14:04:37 +02:00
4 changed files with 38 additions and 5 deletions

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
# Updated: 2024/09/15 14:44:14 by edbernar ### ########.fr #
# Updated: 2024/09/16 14:03:03 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -91,6 +91,10 @@ class Game:
self.p1.sync_send(data_raw)
self.p2.sync_send(data_raw)
def move(self, socket, pos, up):
opponent = p1 if socket != p1 else p2
opponent.sync_send({"type":"game","content":{"action":3, "pos":pos, "up":up}})
async def gameLoop(self):
self.started = True
self.sendPlayers({"action":2})

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/08/09 08:08:00 by edbernar #+# #+# #
# Updated: 2024/09/14 18:55:01 by tomoron ### ########.fr #
# Updated: 2024/09/16 13:39:22 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -24,6 +24,7 @@ import hashlib
mail_pattern = "^((?!\\.)[\\w\\-_.]*[^.])(@\\w+)(\\.\\w+(\\.\\w+)?[^.\\W])$"
password_pattern = "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$"
allowed_char_username = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
URLMAIL = SERVER_URL + "/verify?token="
@sync_to_async
@ -45,7 +46,7 @@ def createAccount(socket, content):
if (len(content["username"]) > 20):
socket.sendError("Username must be at most 20 characters long", 9017)
return
if (content["username"].isalnum() == False):
if (not all(c in allowed_char_username for c in content["username"])):
socket.sendError("Username must contain only letters and numbers", 9018)
return
if (len(content["password"]) < 8):

View File

@ -0,0 +1,18 @@
# **************************************************************************** #
# #
# ::: :::::::: #
# move.py :+: :+: :+: #
# +:+ +:+ +:+ #
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/16 13:54:55 by tomoron #+# #+# #
# Updated: 2024/09/16 14:03:09 by tomoron ### ########.fr #
# #
# **************************************************************************** #
def move(socket, content):
up = content.get("up", False)
pos = content.get("pos", None)
if(pos == None):
return;
socket.game.move(socket, up, pos)

View File

@ -6,13 +6,14 @@
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/09 16:10:26 by tomoron #+# #+# #
# Updated: 2024/09/15 13:38:55 by tomoron ### ########.fr #
# Updated: 2024/09/16 13:59:24 by tomoron ### ########.fr #
# #
# **************************************************************************** #
from .gameActions.start import start
from .gameActions.ready import ready
from .gameActions.leave import leave
from .gameActions.move import move
# game request format : {"type":"game", "content":{"action": 1, ...}}
@ -24,6 +25,11 @@ from .gameActions.leave import leave
# - username
#
# 2 : go : the game started
#
# 3 : move : when the oponnent moves or the client did an illegal move
# - is_opponent
# - pos
# - up
#client actions (actions sent by the client) :
# 0 : start : starts a game
@ -32,8 +38,12 @@ from .gameActions.leave import leave
# 1 : ready : tell the server the game is ready to start
#
# 2 : leave : leave the game (or waiting screen)
#
# 3 : move : when the client moves
# - pos :
# - up : True/False(default : False) is the player up
action_list = [start, ready, leave]
action_list = [start, ready, leave, move]
async def gameRequest(socket, content):
action = content["action"]
if(action < 0 or action > len(action_list)):