Пример #1
0
    def add_active_client(self, client_name, thread_handle):
        def f():
            # Add if client isn't already in dict
            if not self.get_active_client_by_name(client_name):
                # Add client
                client_obj = Client(client_name, thread_handle)
                self.active_clients[client_obj.id] = client_obj

            # Do nothing if they're already a member
            # raise DuplicateClientError(client_name)

        safe(self.active_clients_lock, partial(f))
    def remove_member(self, client):
        def f():
            message = "{0} has left this chatroom.\n".format(client.name)

            message = ("CHAT:{0}\n"
                       "CLIENT_NAME:{1}\n"
                       "MESSAGE:{2}\n").format(self.id, client.name, message)

            self.send_message_to_all_members(message)

            self.members.pop(client.id, None)

            client.remove_chat_room(self)

        safe(self.lock, partial(f))
Пример #3
0
    def remove_active_client(self, client_name):
        def f():
            client = self.get_active_client_by_name(client_name)

            # Loop through chat rooms and remove client
            for chat_room in client.chat_rooms.values():
                chat_room.remove_member(client)

            client.thread_handle.terminate_request = True

            self.active_clients.pop(client.id)

        def g():
            safe(self.chat_rooms_lock, partial(f))

        safe(self.active_clients_lock, partial(g))
    def add_member(self, client):
        def f():
            if self.members.get(client.id):
                raise DuplicateChatClientError()
            self.members[client.id] = client

            message = "{0} has joined this chatroom.\n".format(client.name)

            message = ("CHAT:{0}\n"
                       "CLIENT_NAME:{1}\n"
                       "MESSAGE:{2}\n").format(self.id, client.name, message)

            self.send_message_to_all_members(message)

            client.add_chat_room(self)

        safe(self.lock, partial(f))
    def remove_member(self, client):
        def f():
            message = "{0} has left this chatroom.\n".format(client.name)

            message = (
                "CHAT:{0}\n"
                "CLIENT_NAME:{1}\n"
                "MESSAGE:{2}\n"
            ).format(self.id, client.name, message)

            self.send_message_to_all_members(message)

            self.members.pop(client.id, None)

            client.remove_chat_room(self)

        safe(self.lock, partial(f))
Пример #6
0
    def add_chat_room(self, chat_room_name):
        def f():
            chat_room = self.get_chat_room_by_name(chat_room_name)
            if not chat_room:
                chat_room = ChatRoom(chat_room_name)
                chat_room_id = chat_room.id
                self.chat_rooms[chat_room_id] = chat_room
            return chat_room

        return safe(self.chat_rooms_lock, partial(f))
    def add_member(self, client):
        def f():
            if self.members.get(client.id):
                raise DuplicateChatClientError()
            self.members[client.id] = client

            message = "{0} has joined this chatroom.\n".format(client.name)

            message = (
                "CHAT:{0}\n"
                "CLIENT_NAME:{1}\n"
                "MESSAGE:{2}\n"
            ).format(self.id, client.name, message)

            self.send_message_to_all_members(message)

            client.add_chat_room(self)

        safe(self.lock, partial(f))
Пример #8
0
 def g():
     safe(self.chat_rooms_lock, partial(f))