pep.py/events/createMatchEvent.py

45 lines
1.4 KiB
Python
Raw Normal View History

2016-05-18 17:12:46 +00:00
from constants import serverPackets
from constants import clientPackets
from objects import glob
from helpers import consoleHelper
from constants import bcolors
2016-05-18 17:12:46 +00:00
from events import joinMatchEvent
from constants import exceptions
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
joinMatchEvent.joinMatch(userToken, matchID, packetData["matchPassword"])
# Give host to match creator
match.setHost(userID)
# Send match create packet to everyone in lobby
for i in glob.matches.usersInLobby:
# Make sure this user is still connected
token = glob.tokens.getTokenFromUserID(i)
if token != None:
token.enqueue(serverPackets.createMatch(matchID))
# Console output
consoleHelper.printColored("> MPROOM{}: Room created!".format(matchID), bcolors.BLUE)
except exceptions.matchCreateError:
consoleHelper.printColored("[!] Error while creating match!", bcolors.RED)