Add !mp host and !mp clearhost
This commit is contained in:
		| @@ -819,9 +819,30 @@ def multiplayer(fro, chan, message): | ||||
| 		username = message[1] | ||||
| 		newSlotID = int(message[2]) | ||||
| 		userID = userUtils.getIDSafe(username) | ||||
| 		if userID is None: | ||||
| 			raise exceptions.userNotFoundException("No such user") | ||||
| 		_match = glob.matches.matches[getMatchIDFromChannel(chan)] | ||||
| 		_match.userChangeSlot(userID, newSlotID) | ||||
| 		return "Player {} moved to slot {}".format(username, newSlotID) | ||||
| 		success = _match.userChangeSlot(userID, 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: | ||||
| 		subcommands = { | ||||
| @@ -832,6 +853,8 @@ def multiplayer(fro, chan, message): | ||||
| 			"unlock": mpUnlock, | ||||
| 			"size": mpSize, | ||||
| 			"move": mpMove, | ||||
| 			"host": mpHost, | ||||
| 			"clearhost": mpClearHost, | ||||
| 		} | ||||
| 		requestedSubcommand = message[0].lower().strip() | ||||
| 		if requestedSubcommand not in subcommands: | ||||
|   | ||||
| @@ -140,12 +140,22 @@ class match: | ||||
| 		""" | ||||
| 		slotID = self.getUserSlotID(newHost) | ||||
| 		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] | ||||
| 		self.hostUserID = newHost | ||||
| 		token.enqueue(serverPackets.matchTransferHost()) | ||||
| 		self.sendUpdates() | ||||
| 		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): | ||||
| 		""" | ||||
| @@ -490,16 +500,16 @@ class match: | ||||
| 		""" | ||||
| 		# Make sure the match is not locked | ||||
| 		if self.isLocked: | ||||
| 			return | ||||
| 			return False | ||||
|  | ||||
| 		# Make sure the user is in room | ||||
| 		oldSlotID = self.getUserSlotID(userID) | ||||
| 		if oldSlotID is None: | ||||
| 			return | ||||
| 			return False | ||||
|  | ||||
| 		# Make sure there is no one inside new slot | ||||
| 		if self.slots[newSlotID].user is not None or self.slots[newSlotID].status != slotStatuses.FREE: | ||||
| 			return | ||||
| 			return False | ||||
|  | ||||
| 		# Get old slot data | ||||
| 		#oldData = dill.copy(self.slots[oldSlotID]) | ||||
| @@ -516,6 +526,7 @@ class match: | ||||
|  | ||||
| 		# Console output | ||||
| 		log.info("MPROOM{}: {} moved to slot {}".format(self.matchID, userID, newSlotID)) | ||||
| 		return True | ||||
|  | ||||
| 	def changePassword(self, newPassword): | ||||
| 		""" | ||||
| @@ -581,7 +592,7 @@ class match: | ||||
| 		self.setHost(glob.tokens.tokens[self.slots[slotID].user].userID) | ||||
|  | ||||
| 		# Send updates | ||||
| 		self.sendUpdates() | ||||
| 		# self.sendUpdates() | ||||
|  | ||||
| 	def playerFailed(self, userID): | ||||
| 		""" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user