Beispiel #1
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)
Beispiel #2
0
    def handle_add(self, conn: Conn, packet: server_packets.BuddyAdded):
        if packet.char_id == 0:
            self.logger.warning("Buddy added or updated with char_id '0'")
            return

        buddy = conn.buddy_list.get(packet.char_id, {
            "types": [],
            "conn_id": conn.id
        })
        buddy["online"] = packet.online
        conn.buddy_list[packet.char_id] = buddy

        # verify that buddy does not exist on any other conn
        for conn_id, other_conn in self.bot.get_conns():
            if conn.id == conn_id:
                continue

            buddy = other_conn.buddy_list.get(packet.char_id, None)
            if buddy:
                # remove from other conn list
                del other_conn.buddy_list[packet.char_id]

                self.logger.warning(
                    "Removing char '%s' from conn '%s' since it already exists on another conn"
                    % (packet.char_id, conn.id))
                other_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)
Beispiel #3
0
    def remove_all_buddies_by_type(self, _type):
        buddies = filter(lambda obj: _type in obj["types"],
                         self.get_all_buddies())
        for char_id, buddy in buddies.items():
            buddy["types"].remove(_type)

            if len(buddy["types"]) == 0:
                conn = self.bot.conns[buddy["conn_id"]]
                conn.send_packet(client_packets.BuddyRemove(char_id))
 def remove_buddy(self, char_id, _type, force_remove=False):
     if char_id:
         if char_id not in self.buddy_list:
             return False
         else:
             if _type in self.buddy_list[char_id]["types"]:
                 self.buddy_list[char_id]["types"].remove(_type)
             if len(self.buddy_list[char_id]["types"]) == 0 or force_remove:
                 self.bot.send_packet(client_packets.BuddyRemove(char_id))
             return True
     else:
         return False
Beispiel #5
0
 def remove_buddy(self, char, _type):
     char_id = self.character_manager.resolve_char_to_id(char)
     if char_id:
         if char_id not in self.buddy_list:
             return False
         else:
             if _type in self.buddy_list[char_id]["types"]:
                 self.buddy_list[char_id]["types"].remove(_type)
             if len(self.buddy_list[char_id]["types"]) == 0:
                 self.bot.send_packet(client_packets.BuddyRemove(char_id))
             return True
     else:
         return False
Beispiel #6
0
    def remove_buddy(self, char_id, _type, force_remove=False):
        if char_id:
            buddy = self.get_buddy(char_id)
            if not buddy:
                return False

            if _type in buddy["types"]:
                buddy["types"].remove(_type)

            if len(buddy["types"]) == 0 or force_remove:
                if not self.is_conn_char_id(char_id):
                    conn = self.bot.conns[buddy["conn_id"]]
                    conn.send_packet(client_packets.BuddyRemove(char_id))

            return True
        else:
            return False
Beispiel #7
0
    def remove_buddy(self, char_id, _type, force_remove=False):
        if not char_id:
            return False

        for _id, conn in self.bot.get_conns():
            if char_id == conn.char_id:
                continue

            buddy = conn.buddy_list.get(char_id, None)
            if buddy:
                if _type in buddy["types"]:
                    buddy["types"].remove(_type)

                if len(buddy["types"]) == 0 or force_remove:
                    conn = self.bot.conns[buddy["conn_id"]]
                    conn.send_packet(client_packets.BuddyRemove(char_id))

        return True