Add !mp size

This commit is contained in:
Giuseppe Guerra 2017-08-03 23:47:34 +02:00
parent 9f647d5f9e
commit 310bc1d3b3
3 changed files with 19 additions and 5 deletions

View File

@ -9,7 +9,7 @@ from common import generalUtils
from common.constants import mods from common.constants import mods
from common.log import logUtils as log from common.log import logUtils as log
from common.ripple import userUtils from common.ripple import userUtils
from constants import exceptions from constants import exceptions, slotStatuses
from common.constants import gameModes from common.constants import gameModes
from common.constants import privileges from common.constants import privileges
from constants import serverPackets from constants import serverPackets
@ -777,7 +777,7 @@ def multiplayer(fro, chan, message):
def mpJoin(): def mpJoin():
if len(message) < 2 or not message[1].isdigit(): if len(message) < 2 or not message[1].isdigit():
return exceptions.invalidArgumentsException("Wrong syntax: !mp join <id>") raise exceptions.invalidArgumentsException("Wrong syntax: !mp join <id>")
matchID = int(message[1]) matchID = int(message[1])
userToken = glob.tokens.getTokenFromUsername(fro, ignoreIRC=True) userToken = glob.tokens.getTokenFromUsername(fro, ignoreIRC=True)
userToken.joinMatch(matchID) userToken.joinMatch(matchID)
@ -800,13 +800,27 @@ def multiplayer(fro, chan, message):
glob.matches.matches[matchID].isLocked = False glob.matches.matches[matchID].isLocked = False
return "This match has been unlocked" return "This match has been unlocked"
def mpSize():
if len(message) < 2 or not message[1].isdigit() or int(message[1]) < 1 or int(message[1]) > 16:
raise exceptions.invalidArgumentsException("Wrong syntax: !mp size <slots(1-16)>")
matchSize = int(message[1])
_match = glob.matches.matches[getMatchIDFromChannel(chan)]
for i in range(0, matchSize):
if _match.slots[i].status == slotStatuses.LOCKED:
_match.toggleSlotLocked(i)
for i in range(matchSize, 16):
if _match.slots[i].status != slotStatuses.LOCKED:
_match.toggleSlotLocked(i)
return "Match size changed to {}".format(matchSize)
try: try:
subcommands = { subcommands = {
"make": mpMake, "make": mpMake,
"clear": mpClose, "clear": mpClose,
"join": mpJoin, "join": mpJoin,
"lock": mpLock, "lock": mpLock,
"unlock": mpUnlock "unlock": mpUnlock,
"size": mpSize,
} }
requestedSubcommand = message[0].lower().strip() requestedSubcommand = message[0].lower().strip()
if requestedSubcommand not in subcommands: if requestedSubcommand not in subcommands:

View File

@ -24,4 +24,4 @@ def handle(userToken, packetData):
return return
# Lock/Unlock slot # Lock/Unlock slot
match.toggleSlotLock(packetData["slotID"]) match.toggleSlotLocked(packetData["slotID"])

View File

@ -215,7 +215,7 @@ class match:
self.sendUpdates() self.sendUpdates()
log.info("MPROOM{}: Slot{} changed ready status to {}".format(self.matchID, slotID, self.slots[slotID].status)) log.info("MPROOM{}: Slot{} changed ready status to {}".format(self.matchID, slotID, self.slots[slotID].status))
def toggleSlotLock(self, slotID): def toggleSlotLocked(self, slotID):
""" """
Lock a slot Lock a slot
Same as calling setSlot and then sendUpdate Same as calling setSlot and then sendUpdate