add skin to opponent request(1),add protection to not select skin out of range

This commit is contained in:
2024-09-27 17:40:27 +02:00
parent 07c35c20fc
commit fcf49cde52
3 changed files with 11 additions and 6 deletions

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/13 16:20:58 by tomoron #+# #+# #
# Updated: 2024/09/27 17:17:23 by tomoron ### ########.fr #
# Updated: 2024/09/27 17:36:06 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -137,7 +137,7 @@ class Game:
self.p2.sync_send({"type":"game", "content":{"action":7, "content":self.obstacles}})
self.obstaclesInvLength()
def join(self, socket, skin):
def join(self, socket, skin = 0):
try:
if(self.p1 == None):
print("game created, set as player 1")
@ -153,8 +153,8 @@ class Game:
socket.game = self
if(self.p2 != None and self.p1 != None):
print("both players here, send opponent to both players")
self.p1.sync_send({"type":"game", "content":{"action":1,"id":self.p2.id,"username":self.p2.username}})
self.p2.sync_send({"type":"game", "content":{"action":1,"id":self.p1.id,"username":self.p1.username}})
self.p1.sync_send({"type":"game", "content":{"action":1,"id":self.p2.id,"username":self.p2.username, "skin":self.p2Skin}})
self.p2.sync_send({"type":"game", "content":{"action":1,"id":self.p1.id,"username":self.p1.username, "skin":self.p1Skin}})
except Exception as e:
socket.sendError("invalid request", 9005, e)

View File

@ -6,7 +6,7 @@
# By: edbernar <edbernar@student.42angouleme. +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/11 17:07:08 by tomoron #+# #+# #
# Updated: 2024/09/27 16:33:32 by tomoron ### ########.fr #
# Updated: 2024/09/27 17:39:59 by tomoron ### ########.fr #
# #
# **************************************************************************** #
@ -20,5 +20,9 @@ async def start(socket, content):
if(opponent != None and opponent not in socket.onlinePlayers):
socket.sendError("Your opponent isn't online",9032)
return;
Game(socket, content.get("with_bot", False), content.get("skinId", 0),opponent)
skinId = content.get("skinId", 0)
if(skinId < 0 or skinId >= len(Game.skins)):
socket.sendError("Skin id out of range", 9033)
return;
Game(socket, content.get("with_bot", False),skinId ,opponent)