diff --git a/constants/fokabotCommands.py b/constants/fokabotCommands.py index 8c5f187..775d120 100644 --- a/constants/fokabotCommands.py +++ b/constants/fokabotCommands.py @@ -936,6 +936,11 @@ def multiplayer(fro, chan, message): _match.sendUpdates() return "Match settings have been updated!" + def mpAbort(): + _match = glob.matches.matches[getMatchIDFromChannel(chan)] + _match.abort() + return "Match aborted!" + try: subcommands = { "make": mpMake, @@ -951,6 +956,7 @@ def multiplayer(fro, chan, message): "invite": mpInvite, "map": mpMap, "set": mpSet, + "abort": mpAbort, } requestedSubcommand = message[0].lower().strip() if requestedSubcommand not in subcommands: diff --git a/constants/packetIDs.py b/constants/packetIDs.py index 19721b7..06c62ca 100644 --- a/constants/packetIDs.py +++ b/constants/packetIDs.py @@ -77,7 +77,8 @@ server_silenceEnd = 92 server_userSilenced = 94 server_userPresenceBundle = 96 client_userPanelRequest = 97 -client_tournamentMatchInfoRequest = 93 +client_tournamentMatchInfoRequest = 937 +server_matchAbort = 106 server_switchServer = 107 client_tournamentJoinMatchChannel = 108 client_tournamentLeaveMatchChannel = 109 \ No newline at end of file diff --git a/constants/serverPackets.py b/constants/serverPackets.py index bf5a1f5..e945d51 100644 --- a/constants/serverPackets.py +++ b/constants/serverPackets.py @@ -264,6 +264,9 @@ def playerFailed(slotID): def matchTransferHost(): return packetHelper.buildPacket(packetIDs.server_matchTransferHost) +def matchAbort(): + return packetHelper.buildPacket(packetIDs.server_matchAbort) + def switchServer(address): return packetHelper.buildPacket(packetIDs.server_switchServer, [[address, dataTypes.STRING]]) diff --git a/objects/match.py b/objects/match.py index 2d3193b..1b98c9a 100644 --- a/objects/match.py +++ b/objects/match.py @@ -396,13 +396,7 @@ class match: self.inProgress = False # Reset slots - for i in range(0,16): - if self.slots[i].user is not None and self.slots[i].status == slotStatuses.PLAYING: - self.slots[i].status = slotStatuses.NOT_READY - self.slots[i].loaded = False - self.slots[i].skip = False - self.slots[i].complete = False - self.slots[i].score = 0 + self.resetSlotsReady() # Send match update self.sendUpdates() @@ -417,6 +411,15 @@ class match: # Console output log.info("MPROOM{}: Match completed".format(self.matchID)) + def resetSlotsReady(self): + for i in range(0,16): + if self.slots[i].user is not None and self.slots[i].status == slotStatuses.PLAYING: + self.slots[i].status = slotStatuses.NOT_READY + self.slots[i].loaded = False + self.slots[i].skip = False + self.slots[i].complete = False + self.slots[i].score = 0 + def getUserSlotID(self, userID): """ Get slot ID occupied by userID @@ -726,7 +729,7 @@ class match: glob.streams.add(self.playingStreamName) # Change inProgress value - match.inProgress = True + self.inProgress = True # Set playing to ready players and set load, skip and complete to False # Make clients join playing stream @@ -752,3 +755,16 @@ class match: for i in range(matchSize, 16): if self.slots[i].status != slotStatuses.LOCKED: self.toggleSlotLocked(i) + + def abort(self): + if not self.inProgress: + log.warning("MPROOM{}: Match is not in progress!".format(self.matchID)) + return + self.inProgress = False + self.isStarting = False + self.resetSlotsReady() + self.sendUpdates() + glob.streams.broadcast(self.playingStreamName, serverPackets.matchAbort()) + glob.streams.dispose(self.playingStreamName) + glob.streams.remove(self.playingStreamName) + log.info("MPROOM{}: Match aborted".format(self.matchID))