pep.py/events/joinMatchEvent.py

36 lines
1.1 KiB
Python
Raw Normal View History

2016-10-02 20:48:14 +00:00
from common.log import logUtils as log
2016-05-18 17:12:46 +00:00
from constants import clientPackets
from constants import exceptions
2016-10-02 20:48:14 +00:00
from constants import serverPackets
from objects import glob
2016-04-19 17:40:59 +00:00
def handle(userToken, packetData):
# read packet data
packetData = clientPackets.joinMatch(packetData)
matchID = packetData["matchID"]
password = packetData["password"]
2016-04-19 17:40:59 +00:00
# Get match from ID
try:
# Make sure the match exists
if matchID not in glob.matches.matches:
return
2016-04-19 17:40:59 +00:00
# Match exists, get object
match = glob.matches.matches[matchID]
# Hash password if needed
#if password != "":
# password = generalUtils.stringMd5(password)
2016-04-19 17:40:59 +00:00
# Check password
# Always send wrong password if this is a tourney match
if (match.matchPassword != "" and match.matchPassword != password) or match.isTourney:
raise exceptions.matchWrongPasswordException
2016-04-19 17:40:59 +00:00
# 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))