def _emote_local(self, data, connection): """ Command to provide in-game text emotes for local chat. :param data: The packet containing the command. :param connection: The connection which sent the command. :return: Null. """ if not data: emotes = ", ".join(sorted(self.set_emotes)) send_message(connection, "Available emotes are:\n {}".format(emotes)) send_message(connection, "...or, just type your own: `/me can do anything`") return False else: if self.plugins['chat_manager'].mute_check(connection.player): send_message(connection, "You are muted and cannot emote.") return False emote = " ".join(data) try: emote = self.set_emotes[emote] except KeyError: pass finally: message = "^orange;{} {}".format(connection.player.alias, emote) try: yield from (self._send_to_server(message, ChatSendMode.LOCAL, connection)) except (KeyError, AttributeError): self.logger.debug("using fallback broadcast") broadcast(connection, message)
def _emote(self, data, connection): """ Command to provide in-game text emotes. :param data: The packet containing the command. :param connection: The connection which sent the command. :return: Null. """ if not data: emotes = ", ".join(sorted(self.set_emotes)) send_message(connection, "Available emotes are:\n {}".format(emotes)) send_message(connection, "...or, just type your own: `/me can do anything`") return False else: if self._mute_check(connection.player): send_message(connection, "You are muted and cannot emote.") return False emote = " ".join(data) try: emote = self.set_emotes[emote] except KeyError: pass finally: broadcast(connection, "^orange;{} {}".format( connection.player.name, emote))
def _nick(self, data, connection): """ Change your name as it is displayed in the chat window. :param data: The packet containing the command. :param connection: The connection from which the packet came. :return: Null. """ if len(data) > 1 and connection.player.perm_check( "general_commands.nick_others"): target = self.plugins.player_manager.find_player(data[0]) alias = " ".join(data[1:]) else: alias = " ".join(data) target = connection.player if len(data) == 0: alias = connection.player.name conflict = self.plugins.player_manager.get_player_by_alias(alias) if conflict and target != conflict: raise ValueError("There's already a user by that name.") else: clean_alias = self.plugins['player_manager'].clean_name(alias) if clean_alias is None: send_message(connection, "Nickname contains no valid characters.") return old_alias = target.alias target.alias = clean_alias broadcast(connection, "{}'s name has been changed to {}".format( old_alias, clean_alias))
def _emote(self, data, connection): """ Command to provide in-game text emotes. :param data: The packet containing the command. :param connection: The connection which sent the command. :return: Null. """ if not data: emotes = ", ".join(sorted(self.set_emotes)) send_message(connection, "Available emotes are:\n {}".format(emotes)) send_message(connection, "...or, just type your own: `/me can do anything`") return False else: if self.plugins['chat_manager'].mute_check(connection.player): send_message(connection, "You are muted and cannot emote.") return False emote = " ".join(data) try: emote = self.set_emotes[emote] except KeyError: pass finally: try: asyncio.ensure_future( self.plugins["irc_bot"].bot_write(" -*- {} {}".format( connection.player.alias, emote))) except KeyError: pass broadcast(connection, "^orange;{} {}".format( connection.player.alias, emote))
def nick(self, data, protocol): name = " ".join(data) if self.plugins.player_manager.get_player_by_name(name): raise ValueError("There's already a user by that name.") else: old_name = protocol.player.name protocol.player.name = name broadcast(self.factory, "%s's name has been changed to %s" % (old_name, name))
def _maintenance(self, data, connection): if self.maintenance: self.maintenance = False broadcast(self, "^red;NOTICE: Maintence mode disabled. " "^reset;New connections are allowed.") else: self.maintenance = True broadcast(self, "^red;NOTICE: The server is now in maintenance " "mode. ^reset;No additional clients can connect.")
def _broadcast(self, data, connection): """ Broadcast a message to everyone on the server. Currently, this is actually redundant, as sending a message regularly is already a broadcast. :param data: The packet containing the command. :param connection: The connection from which the packet came. :return: Null. """ if data: message = self.broadcast_prefix + " ".join(data) broadcast(self, message)
def _kick(self, data, connection): """ Kick a play off the server. You must specify a name. You may also specify an optional reason. :param data: The packet containing the command. :param connection: The connection from which the packet came. :return: Null. """ # FIXME: Kick is currently broken. Kicking someone will cause their # starbound client to crash (overkill). try: alias = data[0] except IndexError: raise SyntaxWarning("No target provided.") try: reason = " ".join(data[1:]) except IndexError: reason = "No reason given." p = self.get_player_by_alias(alias) if p is None: send_message(connection, "Couldn't find a player with name {}".format(alias)) if not p.logged_in: send_message(connection, "Player {} is not currently logged in.".format(alias)) if p.client_id == -1 or p.connection is None: p.connection = None p.logged_in = False p.location = None self.players_online.remove(p.uuid) return kick_string = "You were kicked.\n Reason: {}".format(reason) kick_packet = build_packet( packets["server_disconnect"], ServerDisconnect.build(dict(reason=kick_string))) yield from p.connection.raw_write(kick_packet) p.connection = None p.logged_in = False p.location = None self.players_online.remove(p.uuid) broadcast( self, "^red;{} has been kicked for reason: " "{}^reset;".format(alias, reason))
def _kick(self, data, connection): """ Kick a play off the server. You must specify a name. You may also specify an optional reason. :param data: The packet containing the command. :param connection: The connection from which the packet came. :return: Null. """ # FIXME: Kick is currently broken. Kicking someone will cause their # starbound client to crash (overkill). try: alias = data[0] except IndexError: raise SyntaxWarning("No target provided.") try: reason = " ".join(data[1:]) except IndexError: reason = "No reason given." p = self.get_player_by_alias(alias) if not p.logged_in: send_message(connection, "Player {} is not currently logged in.".format(alias)) return False if p is not None: if p.client_id == -1 or p.connection is None: p.connection = None p.logged_in = False p.location = None return kick_string = "You were kicked.\n Reason: {}".format(reason) kick_packet = build_packet(packets["server_disconnect"], ServerDisconnect.build( dict(reason=kick_string))) yield from p.connection.raw_write(kick_packet) p.connection = None p.logged_in = False p.location = None broadcast(self, "^red;{} has been kicked for reason: " "{}^reset;".format(alias, reason)) else: send_message(connection, "Couldn't find a player with name {}".format(alias))
def _emote(self, data, connection): """ Command to provide in-game text emotes. :param data: The packet containing the command. :param connection: The connection which sent the command. :return: Null. """ if not data: emotes = ", ".join(sorted(self.set_emotes)) send_message(connection, "Available emotes are:\n {}".format(emotes)) send_message(connection, "...or, just type your own: `/me can do anything`") return False else: if self.plugins['chat_manager'].mute_check(connection.player): send_message(connection, "You are muted and cannot emote.") return False emote = " ".join(data) try: emote = self.set_emotes[emote] except KeyError: pass finally: if self.irc_active: asyncio.ensure_future( self.plugins["irc_bot"].bot_write(" -*- {} {}".format( connection.player.alias, emote))) if self.discord_active: asyncio.ensure_future(self.plugins["discord_bot"] .bot_write(" -*- {} {}".format( connection.player.alias, emote))) message = "^orange;{} {}".format(connection.player.alias, emote) try: yield from ( self._send_to_server(message, ChatSendMode.UNIVERSE, connection)) except (KeyError, AttributeError): self.logger.debug("using fallback broadcast") broadcast(connection, message)
def on_chat_sent(self, data, protocol): message = data['parsed']['message'] if message[ 0] == self.plugins.command_dispatcher.plugin_config.command_prefix: return True if self.mute_check(protocol.player): send_message(protocol, "You are muted and cannot chat.") return False if data['parsed']['channel'] == 1: self.plugins.player_manager.planetary_broadcast(protocol.player, message) return False elif data['parsed']['channel'] == 0: broadcast(self.factory, data['parsed']['message'], name=protocol.player.name, channel=1) return False return True
def kick(self, data, protocol): name = data[0] try: reason = " ".join(data[1:]) except IndexError: reason = "No reason given." p = self.get_player_by_name(" ".join(data)) if p is not None: kill_packet = build_packet(packets.packets['server_disconnect'], StarString.build("You were kicked.")) yield from p.protocol.raw_write(kill_packet) broadcast( self.factory, "%s has kicked %s. Reason: %s" % (protocol.player.name, p.name, reason)) else: send_message(protocol, "Couldn't find a player with name %s" % name)
def kick(self, data, protocol): name = data[0] try: reason = " ".join(data[1:]) except IndexError: reason = "No reason given." p = self.get_player_by_name(" ".join(data)) if p is not None: kill_packet = build_packet(packets.packets['server_disconnect'], StarString.build("You were kicked.")) yield from p.protocol.raw_write(kill_packet) broadcast(self.factory, "%s has kicked %s. Reason: %s" % (protocol.player.name, p.name, reason)) else: send_message(protocol, "Couldn't find a player with name %s" % name)
def _nick(self, data, connection): """ Change your name as it is displayed in the chat window. :param data: The packet containing the command. :param connection: The connection from which the packet came. :return: Null. """ alias = " ".join(data) if self.plugins.player_manager.get_player_by_alias(alias): raise ValueError("There's already a user by that name.") else: clean_alias = self.plugins['player_manager'].clean_name(alias) if clean_alias is None: send_message(connection, "Nickname contains no valid characters.") return old_alias = connection.player.alias connection.player.alias = clean_alias broadcast(self.factory, "{}'s name has been changed to {}".format(old_alias, clean_alias))
def _shutdown(self, data, connection): """ Shutdown the StarryPy server, disconnecting everyone. :param data: The packet containing the command. :param connection: The connection from which the packet came. :return: Null. """ self.logger.warning("{} has called for a shutdown.".format( connection.player.alias)) shutdown_time = 5 if data: if data[0].isdigit(): shutdown_time = int(data[0]) broadcast(self, "^red;(ADMIN) The server is shutting down in {} " "seconds.^reset;".format(shutdown_time)) yield from asyncio.sleep(shutdown_time) # this is a noisy shutdown (makes a bit of errors in the logs). Not # sure how to make it better... self.logger.warning("Shutting down server now.") self.plugins.player_manager.sync() sys.exit()
def send_announce(self, protocol, message): broadcast(self.factory, "%s %s" % (protocol.player.name, message))
def send_message(self, data, nick): message = data broadcast(self.factory, "IRC: <%s> %s" % (nick, message))
def send_announce(self, connection, message): yield from broadcast(self.factory, "{} {}".format(connection.player.name, message))