Add !mp host and !mp clearhost

This commit is contained in:
Giuseppe Guerra 2017-08-04 00:24:01 +02:00
parent baa8ae4cc2
commit 3309f2f8fd
2 changed files with 41 additions and 7 deletions

View File

@ -819,9 +819,30 @@ def multiplayer(fro, chan, message):
username = message[1] username = message[1]
newSlotID = int(message[2]) newSlotID = int(message[2])
userID = userUtils.getIDSafe(username) userID = userUtils.getIDSafe(username)
if userID is None:
raise exceptions.userNotFoundException("No such user")
_match = glob.matches.matches[getMatchIDFromChannel(chan)] _match = glob.matches.matches[getMatchIDFromChannel(chan)]
_match.userChangeSlot(userID, newSlotID) success = _match.userChangeSlot(userID, newSlotID)
return "Player {} moved to slot {}".format(username, newSlotID) if success:
result = "Player {} moved to slot {}".format(username, newSlotID)
else:
result = "You can't use that slot: it's either already occupied by someone else or locked"
return result
def mpHost():
if len(message) < 2:
raise exceptions.invalidArgumentsException("Wrong syntax: !mp host <username>")
username = message[1]
userID = userUtils.getIDSafe(username)
if userID is None:
raise exceptions.userNotFoundException("No such user")
_match = glob.matches.matches[getMatchIDFromChannel(chan)]
success = _match.setHost(userID)
return "{} is now the host".format(username) if success else "Couldn't give host to {}".format(username)
def mpClearHost():
matchID = getMatchIDFromChannel(chan)
glob.matches.matches[matchID].removeHost()
try: try:
subcommands = { subcommands = {
@ -832,6 +853,8 @@ def multiplayer(fro, chan, message):
"unlock": mpUnlock, "unlock": mpUnlock,
"size": mpSize, "size": mpSize,
"move": mpMove, "move": mpMove,
"host": mpHost,
"clearhost": mpClearHost,
} }
requestedSubcommand = message[0].lower().strip() requestedSubcommand = message[0].lower().strip()
if requestedSubcommand not in subcommands: if requestedSubcommand not in subcommands:

View File

@ -140,12 +140,22 @@ class match:
""" """
slotID = self.getUserSlotID(newHost) slotID = self.getUserSlotID(newHost)
if slotID is None or self.slots[slotID].user not in glob.tokens.tokens: if slotID is None or self.slots[slotID].user not in glob.tokens.tokens:
return return False
token = glob.tokens.tokens[self.slots[slotID].user] token = glob.tokens.tokens[self.slots[slotID].user]
self.hostUserID = newHost self.hostUserID = newHost
token.enqueue(serverPackets.matchTransferHost()) token.enqueue(serverPackets.matchTransferHost())
self.sendUpdates() self.sendUpdates()
log.info("MPROOM{}: {} is now the host".format(self.matchID, token.username)) log.info("MPROOM{}: {} is now the host".format(self.matchID, token.username))
return True
def removeHost(self):
"""
Removes the host (for tourney matches)
:return:
"""
self.hostUserID = -1
self.sendUpdates()
log.info("MPROOM{}: Removed host".format(self.matchID))
def setSlot(self, slotID, status = None, team = None, user = "", mods = None, loaded = None, skip = None, complete = None): def setSlot(self, slotID, status = None, team = None, user = "", mods = None, loaded = None, skip = None, complete = None):
""" """
@ -490,16 +500,16 @@ class match:
""" """
# Make sure the match is not locked # Make sure the match is not locked
if self.isLocked: if self.isLocked:
return return False
# Make sure the user is in room # Make sure the user is in room
oldSlotID = self.getUserSlotID(userID) oldSlotID = self.getUserSlotID(userID)
if oldSlotID is None: if oldSlotID is None:
return return False
# Make sure there is no one inside new slot # Make sure there is no one inside new slot
if self.slots[newSlotID].user is not None or self.slots[newSlotID].status != slotStatuses.FREE: if self.slots[newSlotID].user is not None or self.slots[newSlotID].status != slotStatuses.FREE:
return return False
# Get old slot data # Get old slot data
#oldData = dill.copy(self.slots[oldSlotID]) #oldData = dill.copy(self.slots[oldSlotID])
@ -516,6 +526,7 @@ class match:
# Console output # Console output
log.info("MPROOM{}: {} moved to slot {}".format(self.matchID, userID, newSlotID)) log.info("MPROOM{}: {} moved to slot {}".format(self.matchID, userID, newSlotID))
return True
def changePassword(self, newPassword): def changePassword(self, newPassword):
""" """
@ -581,7 +592,7 @@ class match:
self.setHost(glob.tokens.tokens[self.slots[slotID].user].userID) self.setHost(glob.tokens.tokens[self.slots[slotID].user].userID)
# Send updates # Send updates
self.sendUpdates() # self.sendUpdates()
def playerFailed(self, userID): def playerFailed(self, userID):
""" """