diff --git a/events/matchReadyEvent.py b/events/matchReadyEvent.py index eb24ced..91f9e3f 100644 --- a/events/matchReadyEvent.py +++ b/events/matchReadyEvent.py @@ -14,3 +14,8 @@ def handle(userToken, _): slotID = match.getUserSlotID(userID) if slotID is not None: match.toggleSlotReady(slotID) + + # If this is a tournament match, we should send the current status of ready + # players. + if match.isTourney: + match.sendReadyStatus(match) diff --git a/objects/match.py b/objects/match.py index 3de20ba..29bd2f5 100644 --- a/objects/match.py +++ b/objects/match.py @@ -814,4 +814,37 @@ class match: def resetReady(self): for _slot in self.slots: if _slot.status == slotStatuses.READY: - _slot.status = slotStatuses.NOT_READY \ No newline at end of file + _slot.status = slotStatuses.NOT_READY + + def sendReadyStatus(self): + chanName = "#multi_{}".format(self.matchID) + + # Make sure match exists before attempting to do anything else + if chanName not in glob.channels.channels: + return + + totalUsers = 0 + readyUsers = 0 + + for slot in match.slots: + # Make sure there is a user in this slot + if slot.user is None: + continue + + # In this slot there is a user, so we increase the amount of total users + # in this multi room. + totalUsers += 1 + + if slot.status == slotStatuses.READY: + readyUsers += 1 + + message = "{} users ready out of {}.".format(readyUsers, totalUsers) + + if totalUsers == readyUsers: + message += " All users ready!" + + # Check whether there is anyone left in this match. + if totalUsers == 0: + message = "The match is now empty." + + chat.sendMessage("FokaBot", chanName, message) diff --git a/objects/osuToken.py b/objects/osuToken.py index 9135edf..0ecb052 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -321,9 +321,12 @@ class token: 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: + # 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(match) def leaveMatch(self): """ @@ -354,10 +357,15 @@ class token: # Set slot to free match.userLeft(self) + if match.isTourney: + # If an user leaves, then the ready status of the match changes and + # maybe all users are ready. Or maybe nobody is in the match anymore + match.sendReadyStatus(match) + def kick(self, message="You have been kicked from the server. Please login again.", reason="kick"): """ Kick this user from the server - + :param message: Notification message to send to this user. Default: "You have been kicked from the server. Please login again." :param reason: Kick reason, used in logs. Default: "kick"