pep.py/events/createMatchEvent.py

44 lines
1.3 KiB
Python
Raw Normal View History

2016-10-02 20:48:14 +00:00
from common.log import logUtils as log
2018-03-23 20:28:13 +00:00
from constants import clientPackets, serverPackets
2016-05-18 17:12:46 +00:00
from constants import exceptions
2016-10-02 20:48:14 +00:00
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)
2018-03-23 20:28:13 +00:00
# Make sure the name is valid
matchName = packetData["matchName"].strip()
if not matchName:
raise exceptions.matchCreateError()
2016-04-19 17:40:59 +00:00
# Create a match object
2018-09-10 21:35:59 +00:00
# TODO: Player number check (Dirty hack below)
2018-03-23 20:28:13 +00:00
matchID = glob.matches.createMatch(matchName, packetData["matchPassword"].strip(), packetData["beatmapID"], packetData["beatmapName"], packetData["beatmapMD5"], packetData["gameMode"], userID)
2016-04-19 17:40:59 +00:00
# Make sure the match has been created
if matchID not in glob.matches.matches:
raise exceptions.matchCreateError()
2016-04-19 17:40:59 +00:00
with glob.matches.matches[matchID] as match:
# Join that match
userToken.joinMatch(matchID)
2018-09-10 21:35:59 +00:00
# Disable slots (Dirty)
for i in range(0,16):
if match.slots[i].status is not 4:
match.slots[i].status = packetData["slot{}Status".format(i)]
# Give host to match creator
match.setHost(userID)
match.sendUpdates()
match.changePassword(packetData["matchPassword"])
2016-04-19 17:40:59 +00:00
except exceptions.matchCreateError:
log.error("Error while creating match!")
2018-03-23 20:28:13 +00:00
userToken.enqueue(serverPackets.matchJoinFail())