pep.py/events/joinMatchEvent.py

35 lines
1.0 KiB
Python

from common.log import logUtils as log
from constants import clientPackets
from constants import exceptions
from constants import serverPackets
from objects import glob
def handle(userToken, packetData):
# read packet data
packetData = clientPackets.joinMatch(packetData)
matchID = packetData["matchID"]
password = packetData["password"]
# Get match from ID
try:
# Make sure the match exists
if matchID not in glob.matches.matches:
return
# Match exists, get object
match = glob.matches.matches[matchID]
# Hash password if needed
#if password != "":
# password = generalUtils.stringMd5(password)
# Check password
if match.matchPassword != "" and match.matchPassword != password:
raise exceptions.matchWrongPasswordException()
# Password is correct, join match
userToken.joinMatch(matchID)
except exceptions.matchWrongPasswordException:
userToken.enqueue(serverPackets.matchJoinFail())
log.warning("{} has tried to join a mp room, but he typed the wrong password".format(userToken.username))