def handle(userToken, packetData): # read packet data packetData = clientPackets.joinMatch(packetData) matchID = packetData["matchID"] password = packetData["password"] # Get match from ID try: # Make sure the match exists if matchID not in glob.matches.matches: return # Hash password if needed # if password != "": # password = generalUtils.stringMd5(password) # Check password with glob.matches.matches[matchID] as match: if match.matchPassword != "" and match.matchPassword != password: raise exceptions.matchWrongPasswordException() # 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))
def handle(userToken, packetData): try: # get usertoken data userID = userToken.userID # Read packet data packetData = clientPackets.createMatch(packetData) # Make sure the name is valid matchName = packetData["matchName"].strip() if not matchName: raise exceptions.matchCreateError() # Create a match object # TODO: Player number check matchID = glob.matches.createMatch(matchName, packetData["matchPassword"].strip(), packetData["beatmapID"], packetData["beatmapName"], packetData["beatmapMD5"], packetData["gameMode"], userID, creatorUserID=userID) # Make sure the match has been created if matchID not in glob.matches.matches: raise exceptions.matchCreateError() with glob.matches.matches[matchID] as match: # Join that match userToken.joinMatch(matchID) # Multiplayer Room Patch 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"]) except exceptions.matchCreateError: log.error("Error while creating match!") userToken.enqueue(serverPackets.matchJoinFail())
def joinMatch(self, matchID): """ Set match to matchID, join match stream and channel :param matchID: new match ID :return: """ # Make sure the match exists if matchID not in glob.matches.matches: return # Match exists, get object match = glob.matches.matches[matchID] # Stop spectating self.stopSpectating() # Leave other matches if self.matchID > -1 and self.matchID != matchID: self.leaveMatch() # Try to join match joined = match.userJoin(self) if not joined: self.enqueue(serverPackets.matchJoinFail()) return # Set matchID, join stream, channel and send packet self.matchID = matchID self.joinStream(match.streamName) chat.joinChannel(token=self, channel="{}_{}".format( chatChannels.MULTIPLAYER_PREFIX, self.matchID), force=True) self.enqueue(serverPackets.matchJoinSuccess(matchID)) if match.isTourney: # Alert the user if we have just joined a tourney match self.enqueue( serverPackets.notification( "You are now in a tournament match.")) # If an user joins, then the ready status of the match changes and # maybe not all users are ready. match.sendReadyStatus()
def joinMatch(self, matchID): """ Set match to matchID, join match stream and channel :param matchID: new match ID :return: """ # Make sure the match exists if matchID not in glob.matches.matches: return # Match exists, get object match = glob.matches.matches[matchID] # Stop spectating self.stopSpectating() # Leave other matches if self.matchID > -1 and self.matchID != matchID: self.leaveMatch() # Try to join match joined = match.userJoin(self) if not joined: self.enqueue(serverPackets.matchJoinFail()) return # Set matchID, join stream, channel and send packet self.matchID = matchID self.joinStream(match.streamName) chat.joinChannel(token=self, channel="#multi_{}".format(self.matchID)) self.enqueue(serverPackets.matchJoinSuccess(matchID)) # Alert the user if we have just joined a tourney match if match.isTourney: self.enqueue( serverPackets.notification( "You are now in a tournament match."))