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)
|
2016-10-04 21:43:02 +00:00
|
|
|
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:
|
2016-10-04 21:43:02 +00:00
|
|
|
return
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2016-09-02 10:41:19 +00:00
|
|
|
# Hash password if needed
|
2017-12-21 17:58:56 +00:00
|
|
|
# if password != "":
|
2016-10-08 18:24:16 +00:00
|
|
|
# password = generalUtils.stringMd5(password)
|
2016-09-02 10:41:19 +00:00
|
|
|
|
2016-04-19 17:40:59 +00:00
|
|
|
# Check password
|
2017-12-21 17:58:56 +00:00
|
|
|
with glob.matches.matches[matchID] as match:
|
|
|
|
if match.matchPassword != "" and match.matchPassword != password:
|
|
|
|
raise exceptions.matchWrongPasswordException()
|
2016-04-19 17:40:59 +00:00
|
|
|
|
2017-12-21 17:58:56 +00:00
|
|
|
# Password is correct, join match
|
|
|
|
userToken.joinMatch(matchID)
|
2016-04-19 17:40:59 +00:00
|
|
|
except exceptions.matchWrongPasswordException:
|
|
|
|
userToken.enqueue(serverPackets.matchJoinFail())
|
2016-10-04 21:43:02 +00:00
|
|
|
log.warning("{} has tried to join a mp room, but he typed the wrong password".format(userToken.username))
|