diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index f2fb024..aab4d94 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -759,7 +759,18 @@ def report(fro, chan, message): def multiplayer(fro, chan, message): def mpMake(): - return "Not implemented yet." + if len(message) < 2: + raise exceptions.invalidArgumentsException("Wrong syntax: !mp make ") + matchID = glob.matches.createMatch(" ".join(message[1:]), generalUtils.stringMd5(generalUtils.randomString(32)), 0, "Tournament", "", 0, -1, isTourney=True) + return "Tourney match #{} created!".format(matchID) + + def mpJoin(): + if len(message) < 2 or not message[1].isdigit(): + return exceptions.invalidArgumentsException("Wrong syntax: !mp join ") + matchID = int(message[1]) + userToken = glob.tokens.getTokenFromUsername(fro, ignoreIRC=True) + userToken.joinMatch(matchID) + return "Joined match #{}!".format(matchID) def mpClose(): myToken = glob.tokens.getTokenFromUsername(fro) @@ -771,7 +782,8 @@ def multiplayer(fro, chan, message): try: subcommands = { "make": mpMake, - "clear": mpClose + "clear": mpClose, + "join": mpJoin } requestedSubcommand = message[0].lower().strip() if requestedSubcommand not in subcommands: diff --git a/events/createMatchEvent.py b/events/createMatchEvent.py index f9992d9..886492d 100644 --- a/events/createMatchEvent.py +++ b/events/createMatchEvent.py @@ -30,8 +30,5 @@ def handle(userToken, packetData): match.setHost(userID) match.sendUpdates() match.changePassword(packetData["matchPassword"]) - - # Console output - log.info("MPROOM{}: Room created!".format(matchID)) except exceptions.matchCreateError: log.error("Error while creating match!") diff --git a/objects/match.py b/objects/match.py index 3f05b82..7f07471 100644 --- a/objects/match.py +++ b/objects/match.py @@ -25,7 +25,7 @@ class slot: self.score = 0 class match: - def __init__(self, matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID): + def __init__(self, matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID, isTourney=False): """ Create a new match object @@ -55,6 +55,7 @@ class match: self.matchModMode = matchModModes.NORMAL # default value self.seed = 0 self.matchDataCache = bytes() + self.isTourney = isTourney # Create all slots and reset them self.slots = [] @@ -67,6 +68,7 @@ class match: # Create #multiplayer channel glob.channels.addTempChannel("#multi_{}".format(self.matchID)) + log.info("MPROOM{}: {} match created!".format(self.matchID, "Tourney" if self.isTourney else "Normal")) def getMatchData(self, censored = False): """ @@ -457,7 +459,7 @@ class match: self.setSlot(slotID, slotStatuses.FREE, 0, None, 0) # Check if everyone left - if self.countUsers() == 0 and disposeMatch: + if self.countUsers() == 0 and disposeMatch and not self.isTourney: # Dispose match glob.matches.disposeMatch(self.matchID) log.info("MPROOM{}: Room disposed because all users left".format(self.matchID)) diff --git a/objects/matchList.py b/objects/matchList.py index df811e8..fc9c8f8 100644 --- a/objects/matchList.py +++ b/objects/matchList.py @@ -9,7 +9,7 @@ class matchList: self.matches = {} self.lastID = 1 - def createMatch(self, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID): + def createMatch(self, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID, isTourney=False): """ Add a new match to matches list @@ -25,7 +25,7 @@ class matchList: # Add a new match to matches list and create its stream matchID = self.lastID self.lastID+=1 - self.matches[matchID] = match.match(matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID) + self.matches[matchID] = match.match(matchID, matchName, matchPassword, beatmapID, beatmapName, beatmapMD5, gameMode, hostUserID, isTourney) return matchID def disposeMatch(self, matchID):