def move_ship(self, location): """Move your ship to another player or specific coordinates. Syntax: /move_ship [player_name] OR /move_ship [from player] [to player]""" try: first_name, rest = extract_name(location) if rest is None: self.move_own_ship_to_player(first_name) else: self.move_player_ship_to_other(first_name, extract_name(rest)[0]) except ValueError: self.protocol.send_chat_message(self.move_ship.__doc__)
def nick_set(self, data): """ Changes player nickname. Syntax: /nick_set (name) (new name) """ if data: self.protocol.send_chat_message(self.nick_set.__doc__) return try: first_name, rest = extract_name(data) # Replace problematic chars in client name for regex in self.regexes: first_name = re.sub(regex, "", first_name) except ValueError: self.protocol.send_chat_message("Name not recognized. If it has spaces, " "please surround it by quotes!") return if not rest: self.protocol.send_chat_message(self.nick_set.__doc__) else: try: second_name = extract_name(rest)[0] # Replace problematic chars in client name for regex in self.regexes: second_name = re.sub(regex, "", second_name) except ValueError: self.protocol.send_chat_message( "New name not recognized. If it has spaces, " "please surround it by quotes!" ) return player = self.player_manager.get_by_name(str(first_name)) player2 = self.player_manager.get_by_name(str(second_name)) org_player = self.player_manager.get_by_org_name(str(first_name)) org_player2 = self.player_manager.get_by_org_name(str(second_name)) if player: first_uuid = player.uuid elif org_player: first_uuid = org_player.uuid if player2: second_uuid = player2.uuid elif org_player2: second_uuid = org_player2.uuid if player or org_player: if (player2 or org_player2) and first_uuid != second_uuid: self.protocol.send_chat_message("There's already a player by that name.") else: old_name = player.colored_name(self.config.colors) player.name = second_name self.factory.broadcast( "{}^green;'s name has been changed to {}".format(old_name, player.colored_name(self.config.colors)) )
def move_ship(self, location): """Move your ship to another player or specific coordinates. Syntax: /move_ship [player_name] OR /move_ship [from player] [to player]""" try: first_name, rest = extract_name(location) if not rest: self.move_own_ship_to_player(first_name) else: self.move_player_ship_to_other(first_name, extract_name(rest)[0]) except ValueError as e: self.protocol.send_chat_message(str(e)) self.protocol.send_chat_message(self.move_ship.__doc__) except AttributeError: self.protocol.send_chat_message("Couldn't find one or both of the users you specified.")
def teleport_to_own_ship(self, data): """ Teleports a player to their own ship. If no source player is provided, we assume you mean yourself. Syntax: /teleport home [source player] """ usage = 'Syntax: /teleport home [source player]' if not data: source = self.protocol.player.name else: source, rest = extract_name(data) if not self._validate_player(source): self.protocol.send_chat_message(usage) return source = source.lower() source_player = self.player_manager.get_logged_in_by_name(source) if source_player is None: self.logger.debug('Error: Player %s is not logged in.', source) self.protocol.send_chat_message( 'Error: Player {} is not logged in.'.format(source) ) return source_protocol = self.factory.protocols[source_player.protocol] teleport_packet = build_packet( Packets.PLAYER_WARP, player_warp_toalias_write(alias=2) ) source_protocol.client_protocol.transport.write(teleport_packet)
def whois(self, data): """ Displays client data about the specified user. Syntax: /whois (player) """ if not data: self.protocol.send_chat_message(self.whois.__doc__) return name, garbage = extract_name(data) info = self.player_manager.whois(name) if info and self.protocol.player.access_level >= UserLevels.ADMIN: self.protocol.send_chat_message( 'Name: {} ^green;: ^gray;{}\nUserlevel: ^yellow;{}^green; ' '(^gray;{}^green;)\nUUID: ^yellow;{}^green;\nIP address: ' '^cyan;{}^green;\nCurrent planet: ^yellow;{}^green;'.format( info.colored_name(self.config.colors), info.org_name, UserLevels(info.access_level), info.last_seen.strftime('%c'), info.uuid, info.ip, info.planet)) elif info: self.protocol.send_chat_message( 'Name: {} ^green;: ^gray;{}\nUserlevel: ^yellow;{}^green;\n' 'Last seen: ^gray;{}'.format( info.colored_name(self.config.colors), info.org_name, UserLevels(info.access_level), info.last_seen.strftime('%c'))) else: self.protocol.send_chat_message('Player not found!') return False
def kick(self, data): """ Kicks a user from the server. Syntax: /kick (player) [reason] """ if not data: self.protocol.send_chat_message(self.kick.__doc__) return name, reason = extract_name(data) if not reason: reason = ['no reason given'] else: reason = ' '.join(reason) info = self.player_manager.whois(name) if info and info.logged_in: self.factory.broadcast( '{}^green; kicked {} ^green;' '(reason: ^yellow;{}^green;)'.format( self.protocol.player.colored_name(self.config.colors), info.colored_name(self.config.colors), ''.join(reason))) self.logger.info('%s kicked %s (reason: %s)', self.protocol.player.name, info.name, ''.join(reason)) tp = self.factory.protocols[info.protocol] tp.die() else: self.protocol.send_chat_message( 'Couldn\'t find a user by the name ^yellow;{}^green;.'.format( name)) return False
def kick(self, data): """Kicks a user from the server.\nSyntax: /kick (player) [reason]""" if len(data) == 0: self.protocol.send_chat_message(self.kick.__doc__) return name, reason = extract_name(data) if not reason: reason = ["no reason given"] else: reason = " ".join(reason) info = self.player_manager.whois(name) if info and info.logged_in: self.factory.broadcast( "%s^green; kicked %s ^green;(reason: ^yellow;%s^green;)" % (self.protocol.player.colored_name(self.config.colors), info.colored_name(self.config.colors), "".join(reason))) self.logger.info("%s kicked %s (reason: %s)", self.protocol.player.name, info.name, "".join(reason)) tp = self.factory.protocols[info.protocol] tp.die() else: self.protocol.send_chat_message( "Couldn't find a user by the name ^yellow;%s^green;." % name) return False
def give_item(self, data): """Gives an item to a player. Syntax: /give [target player] [item name] [optional: item count]""" if len(data) >= 2: name, item = extract_name(data) target_player = self.player_manager.get_logged_in_by_name(name) target_protocol = self.protocol.factory.protocols[target_player.protocol] if target_player is not None: if len(item) > 0: item_name = item[0] if len(item) > 1: item_count = item[1] else: item_count = 1 give_item_to_player(target_protocol, item_name, item_count) target_protocol.send_chat_message( "%s has given you: %s (count: %s)" % ( self.protocol.player.name, item_name, item_count)) self.protocol.send_chat_message("Sent the item(s).") self.logger.info("%s gave %s %s (count: %s)", self.protocol.player.name, name, item_name, item_count) else: self.protocol.send_chat_message("You have to give an item name.") else: self.protocol.send_chat_message("Couldn't find name: %s" % name) return False else: self.protocol.send_chat_message(self.give_item.__doc__)
def unprotect(self, data): """Removes the protection from the current planet, or removes a registered player.\nSyntax: /unprotect [player]""" planet = self.protocol.player.planet on_ship = self.protocol.player.on_ship if len(data) == 0: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name(self.config.colors) else: addplayer, rest = extract_name(data) first_name_color = addplayer first_name = str(addplayer) if on_ship: self.protocol.send_chat_message("Can't protect ships (at the moment)") return if len(data) == 0: if planet in self.protected_planets: del self.player_planets[planet] self.protected_planets.remove(planet) self.protocol.send_chat_message("Planet successfully unprotected.") self.logger.info("Unprotected planet %s", planet) else: self.protocol.send_chat_message("Planet is not protected!") else: if first_name in self.player_planets[planet]: self.player_planets[planet].remove(first_name) self.protocol.send_chat_message("Removed ^yellow;" + first_name_color + "^green; from planet list") else: self.protocol.send_chat_message( "Cannot remove ^yellow;" + first_name_color + "^green; from planet list (not in list)") self.save()
def teleport_to_own_ship(self, data): """ Teleports a player to their own ship. If no source player is provided, we assume you mean yourself. Syntax: /teleport home [source player] """ usage = 'Syntax: /teleport home [source player]' if not data: source = self.protocol.player.name else: source, rest = extract_name(data) if not self._validate_player(source): self.protocol.send_chat_message(usage) return source = source.lower() source_player = self.player_manager.get_logged_in_by_name(source) if source_player is None: self.logger.debug('Error: Player %s is not logged in.', source) self.protocol.send_chat_message( 'Error: Player {} is not logged in.'.format(source)) return source_protocol = self.factory.protocols[source_player.protocol] teleport_packet = build_packet(Packets.PLAYER_WARP, player_warp_toalias_write(alias=2)) source_protocol.client_protocol.transport.write(teleport_packet)
def teleport_to_player(self, data): """Teleports a player to another player's location. If no source player is provided, we assume you mean yourself.\nSyntax: /teleport [player] (destination player) [source player]""" usage = 'Syntax: /teleport [player] (destination player) [source player]' if not data: self.protocol.send_chat_message(self.teleport_to_player.__doc__) return destination, rest = extract_name(data) if not self._validate_player(destination): self.protocol.send_chat_message(usage) return destination = destination.lower() if not rest: source = self.protocol.player.name source = source.lower() else: source, rest = extract_name(rest) if not self._validate_player(source): self.protocol.send_chat_message(usage) return source = source.lower() if source == destination: self.logger.debug("Error: player is teleporting to self.") self.protocol.send_chat_message("Why are you trying to teleport to yourself? That seems illogical, captain.") return destination_player = self.player_manager.get_logged_in_by_name(destination) if destination_player is None: self.logger.debug("Error: Player %s is not logged in.", destination) self.protocol.send_chat_message("Error: Player %s is not logged in." % (destination, )) return source_player = self.player_manager.get_logged_in_by_name(source) if source_player is None: self.logger.debug("Error: Player %s is not logged in.", source) self.protocol.send_chat_message("Error: Player %s is not logged in." % (source, )) return source_protocol = self.factory.protocols[source_player.protocol] teleport_packet = build_packet(Packets.PLAYER_WARP, player_warp_toplayer_write(uuid=destination_player.uuid)) source_protocol.client_protocol.transport.write(teleport_packet) self.logger.debug("Teleport command called by %s. Teleporting %s to %s", self.protocol.player.name, source, destination) self.protocol.send_chat_message("Teleported ^yellow;%s^green; to ^yellow;%s^green;." % (source, destination))
def unclaim(self, data): """Removes claimed planet, or removes a registered player.\nSyntax: /unclaim [player]""" try: my_storage = self.protocol.player.storage except AttributeError: return if not 'claims' in my_storage or int(my_storage['claims']) <= 0: my_storage['claims'] = 0 self.protocol.player.storage = my_storage self.protocol.send_chat_message("You have no claimed planets!") else: planet = self.protocol.player.planet on_ship = self.protocol.player.on_ship #print(self.player_planets[planet].first()) #player_name = self.protocol.player.name if len(data) == 0: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name(self.config.colors) else: addplayer, rest = extract_name(data) first_name_color = addplayer first_name = str(addplayer) orgplayer = self.protocol.player.org_name if on_ship: self.protocol.send_chat_message("Can't claim ships (at the moment)") return try: count = 1 for name in self.player_planets[planet]: #print(first_name, str(name)) if name != str(orgplayer) and count == 1: self.protocol.send_chat_message("You can only unclaim planets you've claimed!") return if len(data) != 0 and first_name == str(orgplayer): self.protocol.send_chat_message("Use only /unclaim if you wish to remove protection!") return count += 1 except: pass if len(data) == 0: if planet in self.protected_planets: del self.player_planets[planet] self.protected_planets.remove(planet) self.protocol.send_chat_message("Planet successfully unclaimed.") self.logger.info("Unprotected planet %s", planet) my_storage['claims'] = int(my_storage['claims']) - 1 self.protocol.player.storage = my_storage else: self.protocol.send_chat_message("Planet has not been claimed!") else: if first_name in self.player_planets[planet]: self.player_planets[planet].remove(first_name) self.protocol.send_chat_message("Removed ^yellow;" + first_name_color + "^green; from planet list") else: self.protocol.send_chat_message( "Cannot remove ^yellow;" + first_name_color + "^green; from planet list (not in list)") self.save()
def unban_by_name(self, data): name, reason = extract_name(data) info = self.player_manager.get_by_name(name) if info: self.player_manager.unban(info.name) self.protocol.send_chat_message("Unbanned: %s" % info.colored_name(self.config.colors)) self.logger.warning("%s unbanned: %s", self.protocol.player.name, info.name) else: self.protocol.send_chat_message("Couldn't find a user by the name ^yellow;%s^green;." % name) return False
def unban_by_name(self, data): name, reason = extract_name(data) info = self.player_manager.get_by_name(name) if info: self.player_manager.unban(info.org_name) self.protocol.send_chat_message("Unbanned: %s" % info.colored_name(self.config.colors)) self.logger.warning("%s unbanned: %s", self.protocol.player.org_name, info.org_name) else: self.protocol.send_chat_message("Couldn't find a user by the name ^yellow;%s^green;." % name) return False
def move_ship(self, location): """Move a player ship to another player.\nSyntax: /move_ship <to player> OR /move_ship <from player> <to player>""" if len(location) == 0: self.protocol.send_chat_message(self.move_ship.__doc__) return try: first_name, rest = extract_name(location) except ValueError as e: self.protocol.send_chat_message(str(e)) return if rest is None or len(rest) == 0: self.move_own_ship_to_player(first_name) else: try: second_name = extract_name(rest)[0] except ValueError as e: self.protocol.send_chat_message(str(e)) return self.move_player_ship_to_other(first_name, second_name)
def warp_ship(self, location): """Warps a player ship to another players ship.\nSyntax: /warp_ship [player] (to player)""" if len(location) == 0: self.protocol.send_chat_message(self.warp_ship.__doc__) return try: first_name, rest = extract_name(location) except ValueError as e: self.protocol.send_chat_message(str(e)) return if rest is None or len(rest) == 0: self.move_own_ship_to_player(first_name) else: try: second_name = extract_name(rest)[0] except ValueError as e: self.protocol.send_chat_message(str(e)) return self.move_player_ship_to_other(first_name, second_name)
def warp(self, name): """Warps you to a player's ship (or player to player).\nSyntax: /warp [player] (to player)""" if len(name) == 0: self.protocol.send_chat_message(self.warp.__doc__) return try: first_name, rest = extract_name(name) except ValueError as e: self.protocol.send_chat_message(str(e)) return if rest is None or len(rest) == 0: self.warp_self_to_player([first_name]) else: try: second_name = extract_name(rest)[0] except ValueError as e: self.protocol.send_chat_message(str(e)) return self.warp_player_to_player(first_name, second_name)
def nick_set(self, data): """Changes player nickname.\nSyntax: /nick_set (name) (new name)""" if len(data) <= 1: self.protocol.send_chat_message(self.nick_set.__doc__) return try: first_name, rest = extract_name(data) for regex in self.regexes: # Replace problematic chars in client name first_name = re.sub(regex, "", first_name) except ValueError: self.protocol.send_chat_message("Name not recognized. If it has spaces, please surround it by quotes!") return if rest is None or len(rest) == 0: self.protocol.send_chat_message(self.nick_set.__doc__) else: try: second_name = extract_name(rest)[0] for regex in self.regexes: # Replace problematic chars in client name second_name = re.sub(regex, "", second_name) except ValueError: self.protocol.send_chat_message( "New name not recognized. If it has spaces, please surround it by quotes!") return player = self.player_manager.get_by_name(str(first_name)) player2 = self.player_manager.get_by_name(str(second_name)) org_player = self.player_manager.get_by_org_name(str(first_name)) org_player2 = self.player_manager.get_by_org_name(str(second_name)) if player: first_uuid = player.uuid elif org_player: first_uuid = org_player.uuid if player2: second_uuid = player2.uuid elif org_player2: second_uuid = org_player2.uuid if player or org_player: if (player2 or org_player2) and first_uuid != second_uuid: self.protocol.send_chat_message("There's already a player by that name.") else: old_name = player.colored_name(self.config.colors) player.name = second_name self.factory.broadcast("%s^green;'s name has been changed to %s" % ( old_name, player.colored_name(self.config.colors)))
def warp(self, name): """Warps you to a player's ship, or a player to another player's ship. Syntax: /warp [player name] OR /warp [player 1] [player 2]""" if len(name) == 0: self.protocol.send_chat_message(self.warp.__doc__) return try: first_name, rest = extract_name(name) except ValueError as e: self.protocol.send_chat_message(str(e)) return if rest is None or len(rest) == 0: self.warp_self_to_player([first_name]) else: try: second_name = extract_name(rest)[0] except ValueError as e: self.protocol.send_chat_message(str(e)) return self.warp_player_to_player(first_name, second_name)
def warp(self, name): """Warps you to a player's ship, or a player to another player's ship. Syntax: /warp [player name] OR /warp [player 1] [player 2]""" if len(name) == 0: self.protocol.send_chat_message(self.warp.__doc__) return try: first_name, rest = extract_name(name) except ValueError: self.protocol.send_chat_message(self.warp.__doc__) return if rest is None or len(rest)==0: self.warp_self_to_player([first_name]) else: try: second_name = extract_name(rest)[0] except ValueError: self.protocol.send_chat_message(self.warp.__doc__) return self.warp_player_to_player(first_name, second_name)
def outpost(self, name): """Warps you (or another player) to the outpost.\nSyntax: /outpost [player]""" if len(name) == 0: self.warp_player_to_outpost(self.protocol.player.name) else: try: player_name, rest = extract_name(name) except ValueError as e: self.protocol.send_chat_message(str(e)) return self.warp_player_to_outpost(player_name)
def protect(self, data): """Protects the current planet. Only administrators and allowed players can build on protected planets.\nSyntax: /protect [player]""" planet = self.protocol.player.planet on_ship = self.protocol.player.on_ship if len(data) == 0: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name(self.config.colors) else: self.logger.info("stream: %s" % data) addplayer = data[0] try: addplayer, rest = extract_name(data) self.logger.info("name: %s" % str(addplayer)) addplayer = self.player_manager.get_by_name(addplayer).org_name first_name_color = self.player_manager.get_by_org_name(addplayer).colored_name(self.config.colors) except: self.protocol.send_chat_message("There's no player named: ^yellow;%s" % str(addplayer)) return first_name = str(addplayer) try: if first_name in self.player_planets[self.protocol.player.planet]: self.protocol.send_chat_message( "Player ^yellow;%s^green; is already in planet protect list." % first_name_color) return except: pass planet = self.protocol.player.planet # reset planet back to current planet if on_ship: self.protocol.send_chat_message("Can't protect ships (at the moment)") return if planet not in self.protected_planets: self.protected_planets.append(planet) self.protocol.send_chat_message("Planet successfully protected.") self.logger.info("Protected planet %s", planet) if len(first_name) > 0: if planet not in self.player_planets: self.player_planets[planet] = [first_name] else: self.player_planets[planet] = self.player_planets[planet] + [first_name] self.protocol.send_chat_message("Adding ^yellow;%s^green; to planet list" % first_name_color) else: if len(first_name) == 0: self.protocol.send_chat_message("Planet is already protected!") else: if planet not in self.player_planets: self.player_planets[planet] = [first_name] else: self.player_planets[planet] = self.player_planets[planet] + [first_name] self.protocol.send_chat_message("Adding ^yellow;%s^green; to planet list" % first_name_color) self.save()
def unmute(self, data): """Unmute a currently muted player.\nSyntax: /unmute (player)""" name, garbage = extract_name(data) player = self.player_manager.get_logged_in_by_name(name) if player is None: self.protocol.send_chat_message("Couldn't find a user by the name ^yellow;%s^green;" % name) return target_protocol = self.factory.protocols[player.protocol] player.muted = False target_protocol.send_chat_message("You have been ^yellow;unmuted^green;.") self.protocol.send_chat_message( "%s^green; has been ^yellow;unmuted^green;." % target_protocol.player.colored_name(self.config.colors))
def item(self, data): """ Gives an item to a player. Syntax: /item (player) (item) [count] """ if len(data) >= 2: try: name, item = extract_name(data) except ValueError as e: self.protocol.send_chat_message( 'Please check your syntax. {}'.format(e)) return except AttributeError: self.protocol.send_chat_message( 'Please check that the username you are referencing ' 'exists. If it has spaces, please surround it by quotes.') return except Exception as e: self.protocol.send_chat_message( 'An unknown error occured. {}'.format(e)) target_player = self.player_manager.get_logged_in_by_name(name) target_protocol = self.factory.protocols[target_player.protocol] if target_player is not None: if len(item) > 0: item_name = item[0] if len(item) > 1: item_count = item[1] else: item_count = 1 given = give_item_to_player(target_protocol, item_name, item_count) target_protocol.send_chat_message( '{}^green; has given you: ^yellow;{}^green; ' '(count: ^cyan;{}^green;)'.format( self.protocol.player.colored_name( self.config.colors), item_name, given)) self.protocol.send_chat_message( 'Sent ^yellow;{}^green; ' '(count: ^cyan;{}^green;) to {}'.format( item_name, given, target_player.colored_name(self.config.colors))) self.logger.info('%s gave %s %s (count: %s)', self.protocol.player.name, name, item_name, given) else: self.protocol.send_chat_message( 'You have to give an item name.') else: self.protocol.send_chat_message( 'Couldn\'t find name: ^yellow;{}^green;'.format(name)) return False else: self.protocol.send_chat_message(self.item.__doc__)
def warp(self, name): """ Warps you to a player's ship (or player to player). Syntax: /warp [player] (to player) """ if name: self.protocol.send_chat_message(self.warp.__doc__) return try: first_name, rest = extract_name(name) except ValueError as e: self.protocol.send_chat_message(str(e)) return if not rest: self.warp_self_to_player([first_name]) else: try: second_name = extract_name(rest)[0] except ValueError as e: self.protocol.send_chat_message(str(e)) return self.warp_player_to_player(first_name, second_name)
def mute(self, data): """Mute a player.\nSyntax: /mute (player)""" name, garbage = extract_name(data) player = self.player_manager.get_logged_in_by_name(name) if player is None: self.protocol.send_chat_message( "Couldn't find a user by the name ^yellow;%s^green;" % name) return target_protocol = self.factory.protocols[player.protocol] player.muted = True target_protocol.send_chat_message("You have been ^red;muted^green;.") self.protocol.send_chat_message( "%s^green; has been ^red;muted^green;." % target_protocol.player.colored_name(self.config.colors))
def backup_drop(self, data): """Remove a planet from backups completely. Syntax: /backup drop (player name) (planet name) """ usage = 'Syntax: /backup drop (player name) (planet name)' if not data: self.protocol.send_chat_message(self.backup_drop.__doc__) return player_name, planet_name = extract_name(data) if not self._validate_player(player_name): self.protocol.send_chat_message(usage) return player_name = player_name.lower() if not planet_name: self.protocol.send_chat_message( 'A planet nickname must be provided.' ) self.protocol.send_chat_message(usage) return planet_name = planet_name[0] sql = ( 'SELECT planet_coord FROM backups ' 'WHERE owner = ? AND planet_name = ?' ) result = self.db.select(sql, (player_name, planet_name)) if not result: self.protocol.send_chat_message( 'No planet available based on provided input.' ) return planet_coord = result[0] sql = 'DELETE FROM backups WHERE PLANET_COORD = ?' self.db.execute(sql, (planet_coord[0], )) dst_path = os.path.join('.', 'backups', player_name, planet_name) self._drop_tree(dst_path) self.protocol.send_chat_message( 'The planet has been removed from backups.' ) self.logger.info( '%s removed planet %s from backups for %s.', self.protocol.player.name, planet_name, player_name )
def ban_by_name(self, data): name, reason = extract_name(data) info = self.player_manager.get_by_name(name) if info: self.player_manager.ban(info.org_name) self.protocol.send_chat_message('Banned: {}'.format( info.colored_name(self.config.colors))) self.logger.warning('%s banned player: %s', self.protocol.player.org_name, info.org_name) else: self.protocol.send_chat_message( 'Couldn\'t find a user by the name ^yellow;{}^green;.'.format( name)) return False
def unprotect(self, data): """ Removes the protection from the current planet, or removes a registered player. Syntax: /unprotect [player] """ planet = self.protocol.player.planet on_ship = self.protocol.player.on_ship if not data: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name( self.config.colors ) else: addplayer, rest = extract_name(data) first_name_color = addplayer first_name = str(addplayer) if on_ship: self.protocol.send_chat_message( 'Can\'t protect ships (at the moment)' ) return if not data: if planet in self.protected_planets: del self.player_planets[planet] self.protected_planets.remove(planet) self.protocol.send_chat_message( 'Planet successfully unprotected.' ) self.logger.info('Unprotected planet %s', planet) else: self.protocol.send_chat_message('Planet is not protected!') else: if first_name in self.player_planets[planet]: self.player_planets[planet].remove(first_name) self.protocol.send_chat_message( 'Removed ^yellow;{}^green; from planet list'.format( first_name_color ) ) else: self.protocol.send_chat_message( 'Cannot remove ^yellow;{}^green; from planet list ' '(not in list)'.format(first_name_color) ) self.save()
def kick(self, data): """Kicks a user from the server. Usage: /kick [username] [reason]""" name, reason = extract_name(data) if reason is None: reason = "no reason given" info = self.player_manager.whois(name) if info and info.logged_in: tp = self.protocol.factory.protocols[info.protocol] tp.die() self.protocol.factory.broadcast("%s kicked %s (reason: %s)" % (self.protocol.player.name, info.name, " ".join(reason))) self.logger.info("%s kicked %s (reason: %s", self.protocol.player.name, info.name, " ".join(reason)) return False
def backup_list(self, data): """ List all planets currently being backed up, and their owners. Syntax: /backup list [player] """ usage = 'Syntax: /backup list [player]' if not data: player_name = self.protocol.player.name showall = True else: player_name, garbage = extract_name(data) if not self._validate_player(player_name): self.protocol.send_chat_message(usage) return showall = False player_name = player_name.lower() if showall and self.protocol.player.access_level >= UserLevels.ADMIN: sql = 'SELECT * FROM backups' backup_list = self.db.select(sql, None) else: sql = 'SELECT * FROM backups WHERE owner = ?' backup_list = self.db.select(sql, (player_name, )) self.logger.debug(backup_list) if not backup_list: self.protocol.send_chat_message( 'No planets currently being backed up.' ) return owners = set(zip(*backup_list)[2]) self.logger.debug(owners) for owner in owners: self.protocol.send_chat_message('%s:' % owner) for planet in backup_list: if owner == planet[2]: self.protocol.send_chat_message( '%s: %s (%s)' % ( planet[0], planet[1], 'active' if planet[3] else 'disabled' ) )
def item(self, data): """Gives an item to a player.\nSyntax: /item (player) (item) [count]""" if len(data) >= 2: try: name, item = extract_name(data) except ValueError as e: self.protocol.send_chat_message( "Please check your syntax. %s" % str(e)) return except AttributeError: self.protocol.send_chat_message( "Please check that the username you are referencing exists. If it has spaces, please surround it by quotes." ) return except: self.protocol.send_chat_message( "An unknown error occured. %s" % str(e)) target_player = self.player_manager.get_logged_in_by_name(name) target_protocol = self.factory.protocols[target_player.protocol] if target_player is not None: if len(item) > 0: item_name = item[0] if len(item) > 1: item_count = item[1] else: item_count = 1 give_item_to_player(target_protocol, item_name, item_count) target_protocol.send_chat_message( "%s^green; has given you: ^yellow;%s^green; (count: ^cyan;%s^green;)" % (self.protocol.player.colored_name( self.config.colors), item_name, item_count)) self.protocol.send_chat_message( "Sent ^yellow;%s^green; (count: ^cyan;%s^green;) to %s" % (item_name, item_count, target_player.colored_name(self.config.colors))) self.logger.info("%s gave %s %s (count: %s)", self.protocol.player.name, name, item_name, item_count) else: self.protocol.send_chat_message( "You have to give an item name.") else: self.protocol.send_chat_message( "Couldn't find name: ^yellow;%s^green;" % name) return False else: self.protocol.send_chat_message(self.item.__doc__)
def backup_disable(self, data): """ Stop a planet from backing up (but keep it's history around). Syntax: /backup disable [planet name] """ usage = 'Syntax: /backup disable (player name) (planet name)' if not data: self.protocol.send_chat_message(self.backup_disable.__doc__) return player_name, planet_name = extract_name(data) if not self._validate_player(player_name): self.protocol.send_chat_message(usage) return player_name = player_name.lower() if not planet_name: self.protocol.send_chat_message( 'A planet nickname must be provided.' ) self.protocol.send_chat_message(usage) return planet_name = planet_name[0] sql = ( 'SELECT planet_coord, active FROM backups ' 'WHERE owner = ? AND planet_name = ?' ) result = self.db.select(sql, (player_name, planet_name)) if not result: self.protocol.send_chat_message( 'No planet available based on provided input.' ) return planet_coord, active = result[0] if not active: self.protocol.send_chat_message( 'Planet backups are already disabled.' ) return sql = 'UPDATE backups set active = 0 WHERE planet_coord = ?' _ = self.db.execute(sql, (planet_coord, )) self.protocol.send_chat_message('Planet backups have been disabled.')
def whisper(self, data): """Sends a message to target player. Syntax: /whisper [player name] [msg]""" if len(data) == 0: self.protocol.send_chat_message(self.whisper.__doc__) return try: targetName, message = extract_name(data) if not message: self.protocol.send_chat_message("Invalid message!") self.protocol.send_chat_message(self.whisper.__doc__) return self.logger.info("Message to %s from %s: %s" % (targetName, self.protocol.player.name, " ".join(message))) self.sendWhisper(targetName, " ".join(message)) except ValueError as e: self.protocol.send_chat_message(self.whisper.__doc__) except TypeError as e: self.protocol.send_chat_message(self.whisper.__doc__)
def kick(self, data): """Kicks a user from the server. Usage: /kick [username] [reason]""" name, reason = extract_name(data) if reason is None: reason = "no reason given" info = self.player_manager.whois(name) if info and info.logged_in: tp = self.factory.protocols[info.protocol] tp.die() self.factory.broadcast("%s kicked %s (reason: %s)" % (self.protocol.player.name, info.name, " ".join(reason))) self.logger.info("%s kicked %s (reason: %s", self.protocol.player.name, info.name, " ".join(reason)) else: self.protocol.send_chat_message("Couldn't find a user by the name %s." % name) return False
def unban_by_name(self, data): name, reason = extract_name(data) info = self.player_manager.get_by_name(name) if info: self.player_manager.unban(info.org_name) self.protocol.send_chat_message( 'Unbanned: {}'.format(info.colored_name(self.config.colors)) ) self.logger.warning( '%s unbanned: %s', self.protocol.player.org_name, info.org_name ) else: self.protocol.send_chat_message( 'Couldn\'t find a user by the name ^yellow;%s^green;.'.format( name ) ) return False
def backup_drop(self, data): """Remove a planet from backups completely. Syntax: /backup drop (player name) (planet name) """ usage = 'Syntax: /backup drop (player name) (planet name)' if not data: self.protocol.send_chat_message(self.backup_drop.__doc__) return player_name, planet_name = extract_name(data) if not self._validate_player(player_name): self.protocol.send_chat_message(usage) return player_name = player_name.lower() if not planet_name: self.protocol.send_chat_message( 'A planet nickname must be provided.') self.protocol.send_chat_message(usage) return planet_name = planet_name[0] sql = ('SELECT planet_coord FROM backups ' 'WHERE owner = ? AND planet_name = ?') result = self.db.select(sql, (player_name, planet_name)) if not result: self.protocol.send_chat_message( 'No planet available based on provided input.') return planet_coord = result[0] sql = 'DELETE FROM backups WHERE PLANET_COORD = ?' self.db.execute(sql, (planet_coord[0], )) dst_path = os.path.join('.', 'backups', player_name, planet_name) self._drop_tree(dst_path) self.protocol.send_chat_message( 'The planet has been removed from backups.') self.logger.info('%s removed planet %s from backups for %s.', self.protocol.player.name, planet_name, player_name)
def backup_list(self, data): """ List all planets currently being backed up, and their owners. Syntax: /backup list [player] """ usage = 'Syntax: /backup list [player]' if not data: player_name = self.protocol.player.name showall = True else: player_name, garbage = extract_name(data) if not self._validate_player(player_name): self.protocol.send_chat_message(usage) return showall = False player_name = player_name.lower() if showall and self.protocol.player.access_level >= UserLevels.ADMIN: sql = 'SELECT * FROM backups' backup_list = self.db.select(sql, None) else: sql = 'SELECT * FROM backups WHERE owner = ?' backup_list = self.db.select(sql, (player_name, )) self.logger.debug(backup_list) if not backup_list: self.protocol.send_chat_message( 'No planets currently being backed up.') return owners = set(zip(*backup_list)[2]) self.logger.debug(owners) for owner in owners: self.protocol.send_chat_message('%s:' % owner) for planet in backup_list: if owner == planet[2]: self.protocol.send_chat_message( '%s: %s (%s)' % (planet[0], planet[1], 'active' if planet[3] else 'disabled'))
def unmute(self, data): """ Unmute a currently muted player. Syntax: /unmute (player) """ name, garbage = extract_name(data) player = self.player_manager.get_logged_in_by_name(name) if player is None: self.protocol.send_chat_message( 'Couldn\'t find a user by the name ^yellow;%s^green;'.format( name)) return target_protocol = self.factory.protocols[player.protocol] player.muted = False target_protocol.send_chat_message( 'You have been ^yellow;unmuted^green;.') self.protocol.send_chat_message( '{}^green; has been ^yellow;unmuted^green;.'.format( target_protocol.player.colored_name(self.config.colors)))
def whisper(self, data): """Sends a message to target player. Syntax: /whisper [player name] [msg]""" if len(data) == 0: self.protocol.send_chat_message(self.whisper.__doc__) return try: targetName, message = extract_name(data) if not message: self.protocol.send_chat_message("Invalid message!") self.protocol.send_chat_message(self.whisper.__doc__) return self.logger.info( "Message to %s from %s: %s" % (targetName, self.protocol.player.name, " ".join(message))) self.sendWhisper(targetName, " ".join(message)) except ValueError as e: self.protocol.send_chat_message(self.whisper.__doc__) except TypeError as e: self.protocol.send_chat_message(self.whisper.__doc__)
def backup_disable(self, data): """ Stop a planet from backing up (but keep it's history around). Syntax: /backup disable [planet name] """ usage = 'Syntax: /backup disable (player name) (planet name)' if not data: self.protocol.send_chat_message(self.backup_disable.__doc__) return player_name, planet_name = extract_name(data) if not self._validate_player(player_name): self.protocol.send_chat_message(usage) return player_name = player_name.lower() if not planet_name: self.protocol.send_chat_message( 'A planet nickname must be provided.') self.protocol.send_chat_message(usage) return planet_name = planet_name[0] sql = ('SELECT planet_coord, active FROM backups ' 'WHERE owner = ? AND planet_name = ?') result = self.db.select(sql, (player_name, planet_name)) if not result: self.protocol.send_chat_message( 'No planet available based on provided input.') return planet_coord, active = result[0] if not active: self.protocol.send_chat_message( 'Planet backups are already disabled.') return sql = 'UPDATE backups set active = 0 WHERE planet_coord = ?' _ = self.db.execute(sql, (planet_coord, )) self.protocol.send_chat_message('Planet backups have been disabled.')
def whisper(self, data): """ Sends a message to target player. Syntax: /whisper (player) (msg) """ if not data: self.protocol.send_chat_message(self.whisper.__doc__) return try: targetName, message = extract_name(data) if not message: self.protocol.send_chat_message('Invalid message!') self.protocol.send_chat_message(self.whisper.__doc__) return self.logger.info( 'Message to %s from %s: %s', targetName, self.protocol.player.name, ' '.join(message) ) self.sendWhisper(targetName, ' '.join(message)) except (ValueError, TypeError): self.protocol.send_chat_message(self.whisper.__doc__)
def whois(self, data): """Displays client data about the specified user.\nSyntax: /whois (player)""" if len(data) == 0: self.protocol.send_chat_message(self.whois.__doc__) return name, garbage = extract_name(data) info = self.player_manager.whois(name) if info and self.protocol.player.access_level >= UserLevels.ADMIN: self.protocol.send_chat_message( "Name: %s ^green;: ^gray;%s\nUserlevel: ^yellow;%s^green; (^gray;%s^green;)\nUUID: ^yellow;%s^green;\nIP address: ^cyan;%s^green;\nCurrent planet: ^yellow;%s^green;" % ( info.colored_name(self.config.colors), info.org_name, UserLevels(info.access_level), info.last_seen.strftime("%c"), info.uuid, info.ip, info.planet)) elif info: self.protocol.send_chat_message( "Name: %s ^green;: ^gray;%s\nUserlevel: ^yellow;%s^green;\nLast seen: ^gray;%s" % ( info.colored_name(self.config.colors), info.org_name, UserLevels(info.access_level), info.last_seen.strftime("%c"))) else: self.protocol.send_chat_message("Player not found!") return False
def whisper(self, data): """ Sends a message to target player. Syntax: /whisper (player) (msg) """ if not data: self.protocol.send_chat_message(self.whisper.__doc__) return try: targetName, message = extract_name(data) if not message: self.protocol.send_chat_message('Invalid message!') self.protocol.send_chat_message(self.whisper.__doc__) return self.logger.info( 'Message to %s from %s: %s', (targetName, self.protocol.player.name, ' '.join(message))) self.sendWhisper(targetName, ' '.join(message)) except (ValueError, TypeError): self.protocol.send_chat_message(self.whisper.__doc__)
def kick(self, data): """Kicks a user from the server. Usage: /kick (player) [reason]""" if len(data) == 0: self.protocol.send_chat_message(self.kick.__doc__) return name, reason = extract_name(data) if not reason: reason = [ "no reason given" ] info = self.player_manager.whois(name) if info and info.logged_in: self.factory.broadcast("%s^green; kicked %s ^green;(reason: ^yellow;%s^green;)" % (self.protocol.player.colored_name(self.config.colors), info.colored_name(self.config.colors), " ".join(reason))) self.logger.info("%s kicked %s (reason: %s)", self.protocol.player.name, info.name, " ".join(reason)) tp = self.factory.protocols[info.protocol] tp.die() else: self.protocol.send_chat_message("Couldn't find a user by the name ^yellow;%s^green;." % name) return False
def mute(self, data): """ Mute a player. Syntax: /mute (player) """ name, garbage = extract_name(data) player = self.player_manager.get_logged_in_by_name(name) if player is None: self.protocol.send_chat_message( 'Couldn\'t find a user by the name ^yellow;%s^green;'.format( name ) ) return target_protocol = self.factory.protocols[player.protocol] player.muted = True target_protocol.send_chat_message('You have been ^red;muted^green;.') self.protocol.send_chat_message( '{}^green; has been ^red;muted^green;.'.format( target_protocol.player.colored_name(self.config.colors) ) )
def whisper(self, data): """Sends a message to target player. Syntax: /whisper [player name] [msg]""" now = datetime.now() if self.config.chattimestamps: timestamp = "^orange;<" + now.strftime("%H:%M") + "> " else: timestamp = "" if len(data) == 0: self.protocol.send_chat_message(self.whisper.__doc__) return try: targetName, message = extract_name(data) if not message: self.protocol.send_chat_message("Invalid message!") self.protocol.send_chat_message(self.whisper.__doc__) return self.logger.info("Message to %s from %s: %s" % (targetName, self.protocol.player.name, " ".join(message))) self.sendWhisper(targetName, " ".join(message)) except ValueError as e: self.protocol.send_chat_message(self.whisper.__doc__) except TypeError as e: self.protocol.send_chat_message(self.whisper.__doc__)
def whisper(self, data): """Sends a message to target player.\nSyntax: /whisper (player) (msg)""" now = datetime.now() if self.config.chattimestamps: timestamp = "^orange;<" + now.strftime("%H:%M") + "> " else: timestamp = "" if len(data) == 0: self.protocol.send_chat_message(self.whisper.__doc__) return try: targetName, message = extract_name(data) if not message: self.protocol.send_chat_message("Invalid message!") self.protocol.send_chat_message(self.whisper.__doc__) return self.logger.info("Message to %s from %s: %s" % (targetName, self.protocol.player.name, " ".join(message))) self.sendWhisper(targetName, " ".join(message)) except ValueError as e: self.protocol.send_chat_message(self.whisper.__doc__) except TypeError as e: self.protocol.send_chat_message(self.whisper.__doc__)
def item(self, data): """Gives an item to a player.\nSyntax: /item (player) (item) [count]""" if len(data) >= 2: try: name, item = extract_name(data) except ValueError as e: self.protocol.send_chat_message("Please check your syntax. %s" % str(e)) return except AttributeError: self.protocol.send_chat_message( "Please check that the username you are referencing exists. If it has spaces, please surround it by quotes.") return except: self.protocol.send_chat_message("An unknown error occured. %s" % str(e)) target_player = self.player_manager.get_logged_in_by_name(name) target_protocol = self.factory.protocols[target_player.protocol] if target_player is not None: if len(item) > 0: item_name = item[0] if len(item) > 1: item_count = item[1] else: item_count = 1 give_item_to_player(target_protocol, item_name, item_count) target_protocol.send_chat_message( "%s^green; has given you: ^yellow;%s^green; (count: ^cyan;%s^green;)" % ( self.protocol.player.colored_name(self.config.colors), item_name, item_count)) self.protocol.send_chat_message("Sent ^yellow;%s^green; (count: ^cyan;%s^green;) to %s" % ( item_name, item_count, target_player.colored_name(self.config.colors))) self.logger.info("%s gave %s %s (count: %s)", self.protocol.player.name, name, item_name, item_count) else: self.protocol.send_chat_message("You have to give an item name.") else: self.protocol.send_chat_message("Couldn't find name: ^yellow;%s^green;" % name) return False else: self.protocol.send_chat_message(self.item.__doc__)
def kick(self, data): """ Kicks a user from the server. Syntax: /kick (player) [reason] """ if not data: self.protocol.send_chat_message(self.kick.__doc__) return name, reason = extract_name(data) if not reason: reason = ['no reason given'] else: reason = ' '.join(reason) info = self.player_manager.whois(name) if info and info.logged_in: self.factory.broadcast( '{}^green; kicked {} ^green;' '(reason: ^yellow;{}^green;)'.format( self.protocol.player.colored_name(self.config.colors), info.colored_name(self.config.colors), ''.join(reason) ) ) self.logger.info( '%s kicked %s (reason: %s)', self.protocol.player.name, info.name, ''.join(reason) ) tp = self.factory.protocols[info.protocol] tp.die() else: self.protocol.send_chat_message( 'Couldn\'t find a user by the name ^yellow;{}^green;.'.format( name ) ) return False
def whois(self, data): """Displays client data about the specified user.\nSyntax: /whois (player)""" if len(data) == 0: self.protocol.send_chat_message(self.whois.__doc__) return name, garbage = extract_name(data) info = self.player_manager.whois(name) if info and self.protocol.player.access_level >= UserLevels.ADMIN: self.protocol.send_chat_message( "Name: %s ^green;: ^gray;%s\nUserlevel: ^yellow;%s^green; (^gray;%s^green;)\nUUID: ^yellow;%s^green;\nIP address: ^cyan;%s^green;\nCurrent planet: ^yellow;%s^green;" % (info.colored_name(self.config.colors), info.org_name, UserLevels(info.access_level), info.last_seen.strftime("%c"), info.uuid, info.ip, info.planet)) elif info: self.protocol.send_chat_message( "Name: %s ^green;: ^gray;%s\nUserlevel: ^yellow;%s^green;\nLast seen: ^gray;%s" % (info.colored_name(self.config.colors), info.org_name, UserLevels(info.access_level), info.last_seen.strftime("%c"))) else: self.protocol.send_chat_message("Player not found!") return False
def unprotect(self, data): """Removes the protection from the current planet, or removes a registered player.\nSyntax: /unprotect [player]""" planet = self.protocol.player.planet on_ship = self.protocol.player.on_ship if len(data) == 0: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name( self.config.colors) else: addplayer, rest = extract_name(data) first_name_color = addplayer first_name = str(addplayer) if on_ship: self.protocol.send_chat_message( "Can't protect ships (at the moment)") return if len(data) == 0: if planet in self.protected_planets: del self.player_planets[planet] self.protected_planets.remove(planet) self.protocol.send_chat_message( "Planet successfully unprotected.") self.logger.info("Unprotected planet %s", planet) else: self.protocol.send_chat_message("Planet is not protected!") else: if first_name in self.player_planets[planet]: self.player_planets[planet].remove(first_name) self.protocol.send_chat_message("Removed ^yellow;" + first_name_color + "^green; from planet list") else: self.protocol.send_chat_message( "Cannot remove ^yellow;" + first_name_color + "^green; from planet list (not in list)") self.save()
def teleport_to_player(self, data): """ Teleports a player to another player's location. If no source player is provided, we assume you mean yourself. Syntax: /teleport [player] (destination player) [source player] """ usage = ( 'Syntax: /teleport [player] (destination player) [source player]' ) if not data: self.protocol.send_chat_message(self.teleport_to_player.__doc__) return destination, rest = extract_name(data) if not self._validate_player(destination): self.protocol.send_chat_message(usage) return destination = destination.lower() if not rest: source = self.protocol.player.name source = source.lower() else: source, rest = extract_name(rest) if not self._validate_player(source): self.protocol.send_chat_message(usage) return source = source.lower() if source == destination: self.logger.debug('Error: player is teleporting to self.') self.protocol.send_chat_message( 'Why are you trying to teleport to yourself? ' 'That seems illogical, captain.' ) return destination_player = self.player_manager.get_logged_in_by_name( destination ) if destination_player is None: self.logger.debug( 'Error: Player %s is not logged in.', destination ) self.protocol.send_chat_message( 'Error: Player {} is not logged in.'.format(destination) ) return source_player = self.player_manager.get_logged_in_by_name(source) if source_player is None: self.logger.debug('Error: Player %s is not logged in.', source) self.protocol.send_chat_message( 'Error: Player {} is not logged in.'.format(source) ) return source_protocol = self.factory.protocols[source_player.protocol] teleport_packet = build_packet( Packets.PLAYER_WARP, player_warp_toplayer_write(uuid=destination_player.uuid) ) source_protocol.client_protocol.transport.write(teleport_packet) self.logger.debug( 'Teleport command called by %s. Teleporting %s to %s', self.protocol.player.name, source, destination ) self.protocol.send_chat_message( 'Teleported ^yellow;{}^green; to ^yellow;{}^green;.'.format( source, destination ) )
def unclaim(self, data): """Removes claimed planet, or removes a registered player.\nSyntax: /unclaim [player]""" try: my_storage = self.protocol.player.storage except AttributeError: return if not 'claims' in my_storage or int(my_storage['claims']) <= 0: my_storage['claims'] = 0 self.protocol.player.storage = my_storage self.protocol.send_chat_message("You have no claimed planets!") else: planet = self.protocol.player.planet on_ship = self.protocol.player.on_ship #print(self.player_planets[planet].first()) #player_name = self.protocol.player.name if len(data) == 0: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name( self.config.colors) else: addplayer, rest = extract_name(data) first_name_color = addplayer first_name = str(addplayer) orgplayer = self.protocol.player.org_name if on_ship: self.protocol.send_chat_message( "Can't claim ships (at the moment)") return try: count = 1 for name in self.player_planets[planet]: #print(first_name, str(name)) if name != str(orgplayer) and count == 1: self.protocol.send_chat_message( "You can only unclaim planets you've claimed!") return if len(data) != 0 and first_name == str(orgplayer): self.protocol.send_chat_message( "Use only /unclaim if you wish to remove protection!" ) return count += 1 except: pass if len(data) == 0: if planet in self.protected_planets: del self.player_planets[planet] self.protected_planets.remove(planet) self.protocol.send_chat_message( "Planet successfully unclaimed.") self.logger.info("Unprotected planet %s", planet) my_storage['claims'] = int(my_storage['claims']) - 1 self.protocol.player.storage = my_storage else: self.protocol.send_chat_message( "Planet has not been claimed!") else: if first_name in self.player_planets[planet]: self.player_planets[planet].remove(first_name) self.protocol.send_chat_message("Removed ^yellow;" + first_name_color + "^green; from planet list") else: self.protocol.send_chat_message( "Cannot remove ^yellow;" + first_name_color + "^green; from planet list (not in list)") self.save()
def claim(self, data): """Claims the current planet. Only administrators and allowed players can build on claimed planets.\nSyntax: /claim [player]""" if self.protocol.player.planet in self.unclaimable_planets: self.protocol.send_chat_message( "This planet ^red;cannot^green; be claimed!") return try: my_storage = self.protocol.player.storage except AttributeError: return # set storage to 0 if player never used any of the claim commands if not 'claims' in my_storage: my_storage['claims'] = 0 self.protocol.player.storage = my_storage # check if max claim limit has been reached if int(my_storage['claims']) >= self.max_claims: my_storage['claims'] = self.max_claims self.protocol.player.storage = my_storage self.protocol.send_chat_message( "You already have max (^red;%s^green;) claimed planets!" % str(self.max_claims)) # assuming player is eligible to claim elif 0 <= int(my_storage['claims']) <= self.max_claims: planet = self.protocol.player.planet on_ship = self.protocol.player.on_ship if len(data) == 0: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name( self.config.colors) else: addplayer = data[0] try: addplayer, rest = extract_name(data) addplayer = self.player_manager.get_by_name( addplayer).org_name first_name_color = self.player_manager.get_by_org_name( addplayer).colored_name(self.config.colors) except: self.protocol.send_chat_message( "There's no player named: ^yellow;%s" % str(addplayer)) return first_name = str(addplayer) orgplayer = self.protocol.player.org_name try: count = 1 for name in self.player_planets[planet]: if name != str(orgplayer) and count == 1: self.protocol.send_chat_message( "You can only claim free planets!") return count += 1 except: if first_name != orgplayer: self.protocol.send_chat_message( "Use only /claim if you wish to claim a planet!") return try: for planet in self.player_planets: if first_name in self.player_planets[ self.protocol.player.planet]: self.protocol.send_chat_message( "Player ^yellow;%s^green; is already in planet protect list." % first_name_color) return except: planet = self.protocol.player.planet # reset planet back to current planet planet = self.protocol.player.planet # reset planet back to current planet if on_ship and not ("force" in " ".join(data).lower()): self.protocol.send_chat_message( "Can't claim ships (at the moment)") return if planet not in self.protected_planets: self.protected_planets.append(planet) self.protocol.send_chat_message("Planet successfully claimed.") self.logger.info("Protected planet %s", planet) my_storage['claims'] = int(my_storage['claims']) + 1 self.protocol.player.storage = my_storage if len(first_name) > 0: if planet not in self.player_planets: self.player_planets[planet] = [first_name] else: self.player_planets[planet] = self.player_planets[ planet] + [first_name] self.protocol.send_chat_message( "Adding ^yellow;%s^green; to planet list" % first_name_color) else: if len(first_name) == 0: self.protocol.send_chat_message( "Planet is already claimed!") else: if planet not in self.player_planets: self.player_planets[planet] = [first_name] else: self.player_planets[planet] = self.player_planets[ planet] + [first_name] self.protocol.send_chat_message( "Adding ^yellow;%s^green; to planet list" % first_name_color) self.save()
def protect(self, data): """ Protects the current planet. Only administrators and allowed players can build on protected planets. Syntax: /protect [player] """ on_ship = self.protocol.player.on_ship if not data: addplayer = self.protocol.player.org_name first_name_color = self.protocol.player.colored_name( self.config.colors) else: self.logger.info('stream: %s', data) addplayer = data[0] try: addplayer, rest = extract_name(data) self.logger.info('name: %s', str(addplayer)) addplayer = self.player_manager.get_by_name(addplayer).org_name first_name_color = self.player_manager.get_by_org_name( addplayer).colored_name(self.config.colors) except: self.protocol.send_chat_message( 'There\'s no player named: ^yellow;{}'.format(addplayer)) return first_name = str(addplayer) try: if first_name in self.player_planets[self.protocol.player.planet]: self.protocol.send_chat_message( 'Player ^yellow;{}^green; is already in planet protect' ' list.'.format(first_name_color)) return except: pass # reset planet back to current planet planet = self.protocol.player.planet if on_ship: self.protocol.send_chat_message( 'Can\'t protect ships (at the moment)') return if planet not in self.protected_planets: self.protected_planets.append(planet) self.protocol.send_chat_message('Planet successfully protected.') self.logger.info('Protected planet %s', planet) if first_name: if planet not in self.player_planets: self.player_planets[planet] = [first_name] else: self.player_planets[planet] = ( self.player_planets[planet] + [first_name]) self.protocol.send_chat_message( 'Adding ^yellow;%s^green; to planet list'.format( first_name_color)) else: if first_name: self.protocol.send_chat_message('Planet is already protected!') else: if planet not in self.player_planets: self.player_planets[planet] = [first_name] else: self.player_planets[planet] = ( self.player_planets[planet] + [first_name]) self.protocol.send_chat_message( 'Adding ^yellow;%s^green; to planet list'.format( first_name_color)) self.save()