Esempio n. 1
0
    def handle_private_channel_message(
            self, conn: Conn, packet: server_packets.PrivateChannelMessage):
        if not conn.is_main:
            return

        if not self.setting_service.get("arelay_enabled").get_value():
            return

        # ignore packets from the bot's own private channel and from the bot itself
        if packet.private_channel_id == conn.get_char_id(
        ) or packet.char_id == conn.get_char_id():
            return

        message = packet.message.lstrip()
        command_prefix = self.setting_service.get(
            "arelay_command_prefix").get_value()
        if not message.startswith(command_prefix + " "):
            return

        message = message[len(command_prefix) + 1:]
        formatted_message = self.setting_service.get(
            "arelay_color").format_text(message)

        # sender is not the bot that sent it, but rather the original char that sent the message
        # given the format of !agcr messages, it could be possible to parse the sender for the message
        # but currently this is not done
        sender = None

        self.message_hub_service.send_message(self.MESSAGE_SOURCE, sender,
                                              None, formatted_message)
Esempio n. 2
0
    def add(self, conn: Conn, packet: server_packets.PublicChannelJoined):
        if not conn.is_main:
            return

        conn.channels[packet.channel_id] = packet
        if not conn.org_id and self.is_org_channel_id(packet.channel_id):
            conn.org_channel_id = packet.channel_id
            conn.org_id = 0x00ffffffff & packet.channel_id

            row = self.db.query_single(
                "SELECT name FROM org_name_cache WHERE org_id = ?",
                [conn.org_id])

            if packet.name != "Clan (name unknown)":
                source = "chat_server"
                if not row:
                    self.db.exec(
                        "INSERT INTO org_name_cache (org_id, name) VALUES (?, ?)",
                        [conn.org_id, packet.name])
                elif packet.name != row.name:
                    self.db.exec(
                        "UPDATE org_name_cache SET name = ? WHERE org_id = ?",
                        [packet.name, conn.org_id])
                conn.org_name = packet.name
            elif row:
                source = "cache"
                conn.org_name = row.name
            else:
                source = "none"

            self.logger.info(
                f"Org info for '{conn.id}': {conn.org_name} ({conn.org_id}); source: '{source}'"
            )
Esempio n. 3
0
    def handle_add(self, conn: Conn, packet):
        buddy = self.buddy_list[conn.id].get(packet.char_id, {
            "types": [],
            "conn_id": conn.id
        })
        buddy["online"] = packet.online
        self.buddy_list[conn.id][packet.char_id] = buddy

        # verify that buddy does not exist on any other conn
        for conn_id, conn_buddy_list in self.buddy_list.items():
            if conn.id != conn_id:
                buddy = conn_buddy_list.get(packet.char_id, None)
                if buddy:
                    if buddy["online"] is None:
                        # remove from other conn list
                        del conn_buddy_list[packet.char_id]
                    else:
                        # remove from this conn
                        self.logger.warning(
                            "Removing char '%s' from conn '%s' since it already exists on another conn"
                            % (packet.char_id, conn.id))
                        conn.send_packet(
                            client_packets.BuddyRemove(packet.char_id))

        if packet.online == 1:
            self.event_service.fire_event(self.BUDDY_LOGON_EVENT, packet)
        else:
            self.event_service.fire_event(self.BUDDY_LOGOFF_EVENT, packet)
Esempio n. 4
0
    def handle_private_channel_invite(self, conn: Conn, packet: server_packets.PrivateChannelInvited):
        if not conn.is_main:
            return

        channel_name = self.character_service.get_char_name(packet.private_channel_id)
        if self.ban_service.get_ban(packet.private_channel_id):
            self.logger.info("ignore private channel invite from banned char '%s'" % channel_name)
        else:
            self.private_channels.add(packet.private_channel_id)
            conn.send_packet(client_packets.PrivateChannelJoin(packet.private_channel_id))
            self.logger.info("Joined private channel %s" % channel_name)
Esempio n. 5
0
    def handle_private_channel_invite(self, conn: Conn, packet: server_packets.PrivateChannelInvited):
        if not conn.is_main:
            pass

        if self.setting_service.get_value("dark_relay") == "0":
            return

        if "Darknet" == self.character_service.get_char_name(packet.private_channel_id):
            channel_name = self.character_service.get_char_name(packet.private_channel_id)
            conn.send_packet(client_packets.PrivateChannelJoin(packet.private_channel_id))
            self.logger.info("Joined private channel {channel}".format(channel=channel_name))
            self.relay_channel_id = packet.private_channel_id
            self.relay_name = channel_name
Esempio n. 6
0
    def create_conn(self, _id):
        if _id in self.conns:
            raise Exception(f"A connection with id {_id} already exists")

        conn = Conn(_id, self.disconnect)
        self.conns[_id] = conn
        return conn
Esempio n. 7
0
    def handle_private_channel_invite(
            self, conn: Conn, packet: server_packets.PrivateChannelInvited):
        if not conn.is_main:
            return

        if not self.setting_service.get("arelay_enabled").get_value():
            return

        channel_name = self.character_service.get_char_name(
            packet.private_channel_id)
        if self.setting_service.get_value(
                "arelay_bot").lower() == channel_name.lower():
            conn.send_packet(
                client_packets.PrivateChannelJoin(packet.private_channel_id))
            self.logger.info("Joined private channel {channel}".format(
                channel=channel_name))
            self.relay_channel_id = packet.private_channel_id
Esempio n. 8
0
    def create_conn(self, _id):
        if _id in self.conns:
            raise Exception(f"A connection with id {_id} already exists")

        def failure_callback():
            self.status = BotStatus.ERROR

        conn = Conn(_id, failure_callback)
        self.conns[_id] = conn
        return conn
Esempio n. 9
0
    def format_message_old(self, msg, conn: Conn):
        for t in [
                "</header>", "</header2>", "</highlight>", "</notice>",
                "</black>", "</white>", "</yellow>", "</blue>", "</green>",
                "</red>", "</orange>", "</grey>", "</cyan>", "</violet>",
                "</neutral>", "</omni>", "</clan>", "</unknown>"
        ]:
            msg = msg.replace(t, "</font>")

        return msg \
            .replace("<header>", self.setting_service.get("header_color").get_font_color()) \
            .replace("<header2>", self.setting_service.get("header2_color").get_font_color()) \
            .replace("<highlight>", self.setting_service.get("highlight_color").get_font_color()) \
            .replace("<notice>", self.setting_service.get("notice_color").get_font_color()) \
            \
            .replace("<black>", "<font color='#000000'>") \
            .replace("<white>", "<font color='#FFFFFF'>") \
            .replace("<yellow>", "<font color='#FFFF00'>") \
            .replace("<blue>", "<font color='#8CB5FF'>") \
            .replace("<green>", "<font color='#00DE42'>") \
            .replace("<red>", "<font color='#FF0000'>") \
            .replace("<orange>", "<font color='#FCA712'>") \
            .replace("<grey>", "<font color='#C3C3C3'>") \
            .replace("<cyan>", "<font color='#00FFFF'>") \
            .replace("<violet>", "<font color='#8F00FF'>") \
            \
            .replace("<neutral>", self.setting_service.get("neutral_color").get_font_color()) \
            .replace("<omni>", self.setting_service.get("omni_color").get_font_color()) \
            .replace("<clan>", self.setting_service.get("clan_color").get_font_color()) \
            .replace("<unknown>", self.setting_service.get("unknown_color").get_font_color()) \
            \
            .replace("<myname>", conn.get_char_name()) \
            .replace("<myorg>", conn.get_org_name() or "Unknown Org") \
            .replace("<tab>", "    ") \
            .replace("<end>", "</font>") \
            .replace("<symbol>", self.setting_service.get("symbol").get_value()) \
            .replace("<br>", "\n")
Esempio n. 10
0
    def handle_private_channel_message(self, conn: Conn, packet: server_packets.PrivateChannelMessage):
        if not conn.is_main:
            return

        if packet.private_channel_id == conn.get_char_id():
            return

        channel_name = self.character_service.get_char_name(packet.private_channel_id)
        char_name = self.character_service.get_char_name(packet.char_id)
        self.logger.log_chat(conn, "Private Channel(%s)" % channel_name, char_name, packet.message)

        if len(packet.message) < 2:
            return

        # ignore leading space
        message = packet.message.lstrip()

        if message.startswith(self.setting_service.get("symbol").get_value()):
            self.command_service.process_command(
                self.command_service.trim_command_symbol(message),
                self.command_service.PRIVATE_CHANNEL,
                packet.char_id,
                lambda msg: self.bot.send_private_channel_message(msg, private_channel_id=packet.private_channel_id, conn=conn),
                conn)
Esempio n. 11
0
    def handle_private_channel_command(self, conn: Conn, packet: server_packets.PrivateChannelMessage):
        if not self.setting_service.get("accept_commands_from_slave_bots").get_value() and not conn.is_main:
            return False

        # since the command symbol is required in the private channel,
        # the command_str must have length of at least 2 in order to be valid,
        # otherwise it is ignored
        if len(packet.message) < 2:
            return False

        # ignore leading space
        message = packet.message.lstrip()

        def reply(msg):
            self.bot.send_private_channel_message(msg, private_channel_id=conn.char_id, conn=conn)
            self.event_service.fire_event(self.PRIVATE_CHANNEL_COMMAND_EVENT,
                                          DictObject({"char_id": None, "name": None, "message": msg, "conn": conn}))

        if message.startswith(self.setting_service.get("symbol").get_value()) and packet.private_channel_id == conn.get_char_id():
            char_name = self.character_service.get_char_name(packet.char_id)
            self.event_service.fire_event(self.PRIVATE_CHANNEL_COMMAND_EVENT,
                                          DictObject({"char_id": packet.char_id, "name": char_name, "message": packet.message, "conn": conn}))

            self.command_service.process_command(
                self.command_service.trim_command_symbol(message),
                self.PRIVATE_CHANNEL_COMMAND,
                packet.char_id,
                reply,
                conn)
            return True
        else:
            return False
Esempio n. 12
0
 def kickall(self, conn: Conn):
     conn.send_packet(client_packets.PrivateChannelKickAll())
Esempio n. 13
0
 def kick(self, char_id, conn: Conn):
     if char_id != conn.char_id:
         conn.send_packet(client_packets.PrivateChannelKick(char_id))
Esempio n. 14
0
 def invite(self, char_id, conn: Conn):
     if char_id != conn.char_id and conn.is_main:
         conn.send_packet(client_packets.PrivateChannelInvite(char_id))
Esempio n. 15
0
    def create_conn(self, _id):
        def failure_callback():
            self.status = BotStatus.ERROR

        conn = Conn(_id, failure_callback)
        return conn