add protection, can't start a game if another is already started and can't do game actions if not in a game
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
|
||||
# Updated: 2024/09/14 21:30:54 by tomoron ### ########.fr #
|
||||
# Updated: 2024/09/15 13:33:31 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -48,6 +48,7 @@ class Game:
|
||||
self.p1 = socket
|
||||
else:
|
||||
self.p2 = socket
|
||||
print("set game to self")
|
||||
socket.game = self
|
||||
if(self.p2 != None and self.p1 != None):
|
||||
data = json.dumps({"type":"game", "content":{
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/09/14 15:37:49 by tomoron #+# #+# #
|
||||
# Updated: 2024/09/14 21:20:32 by tomoron ### ########.fr #
|
||||
# Updated: 2024/09/15 13:39:02 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
@ -6,13 +6,9 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/09/13 23:41:12 by tomoron #+# #+# #
|
||||
# Updated: 2024/09/14 19:27:51 by tomoron ### ########.fr #
|
||||
# Updated: 2024/09/15 13:37:23 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
async def ready(socket, content):
|
||||
print("ready request")
|
||||
if(socket.game == None):
|
||||
socket.sendError("No game started", 9101)
|
||||
return;
|
||||
await socket.game.setReady(socket)
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/09/11 17:07:08 by tomoron #+# #+# #
|
||||
# Updated: 2024/09/14 19:28:30 by tomoron ### ########.fr #
|
||||
# Updated: 2024/09/15 13:33:53 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -15,5 +15,6 @@ from ...Game import Game
|
||||
async def start(socket, content):
|
||||
if(socket.game != None):
|
||||
socket.sendError("Game already started", 9102)
|
||||
return;
|
||||
Game(socket, content.get("with_bot", False))
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
# By: tomoron <tomoron@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2024/09/09 16:10:26 by tomoron #+# #+# #
|
||||
# Updated: 2024/09/14 19:22:52 by tomoron ### ########.fr #
|
||||
# Updated: 2024/09/15 13:38:55 by tomoron ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
@ -39,5 +39,8 @@ async def gameRequest(socket, content):
|
||||
if(action < 0 or action > len(action_list)):
|
||||
socket.sendError("Action out of range", 9100)
|
||||
return;
|
||||
if(action != 0 and socket.game == None):
|
||||
socket.sendError("No game started",9101)
|
||||
return ;
|
||||
await action_list[action](socket,content)
|
||||
|
||||
|
Reference in New Issue
Block a user