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):
|
|
|
|
try:
|
|
|
|
# get usertoken data
|
|
|
|
userID = userToken.userID
|
|
|
|
|
|
|
|
# Read packet data
|
|
|
|
packetData = clientPackets.createMatch(packetData)
|
|
|
|
|
|
|
|
# Create a match object
|
|
|
|
# TODO: Player number check
|
|
|
|
matchID = glob.matches.createMatch(packetData["matchName"], packetData["matchPassword"], packetData["beatmapID"], packetData["beatmapName"], packetData["beatmapMD5"], packetData["gameMode"], userID)
|
|
|
|
|
|
|
|
# Make sure the match has been created
|
|
|
|
if matchID not in glob.matches.matches:
|
|
|
|
raise exceptions.matchCreateError
|
|
|
|
|
|
|
|
# Get match object
|
|
|
|
match = glob.matches.matches[matchID]
|
|
|
|
|
|
|
|
# Join that match
|
2016-10-04 21:43:02 +00:00
|
|
|
userToken.joinMatch(matchID)
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Give host to match creator
|
|
|
|
match.setHost(userID)
|
2016-10-08 18:47:19 +00:00
|
|
|
match.sendUpdates()
|
|
|
|
match.changePassword(packetData["matchPassword"])
|
2016-04-19 17:40:59 +00:00
|
|
|
|
|
|
|
# Console output
|
2016-06-04 10:44:54 +00:00
|
|
|
log.info("MPROOM{}: Room created!".format(matchID))
|
2016-04-19 17:40:59 +00:00
|
|
|
except exceptions.matchCreateError:
|
2016-06-04 10:44:54 +00:00
|
|
|
log.error("Error while creating match!")
|