Commit 34c3ef80 authored by Antoine Millet's avatar Antoine Millet
Browse files

Added search_client_by_connection method on CCServer.

Also updated the CCClient class to make its attributes publics.
parent 954621fc
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -71,6 +71,21 @@ class CCServer(object):
        
        self._connected[login] = CCClient(login, role, self, connection)

    def search_client_by_connection(self, connection):
        '''
        Search a connected client by it connection. If no client is found,
        return None.

        :param connection: the connection of the client to search
        :return: the found client or None
        '''

        for client in self._connected.values():
            if client.connection is connection:
                return client
        else:
            return None

    def run(self):
        '''
        Run the server mainloop.
+7 −7
Original line number Diff line number Diff line
@@ -9,13 +9,13 @@ class CCClient(object):
    def __init__(self, login, role, server, connection):

        # The login of the client:
        self._login = login
        self.login = login

        # The role of the client:
        self._role = role
        self.role = role

        # The server binded to this client:
        self._server = server
        self.server = server

        # The connection of the client (public attribute):
        self.connection = connection
@@ -30,10 +30,10 @@ class CCClient(object):
        # Get the tags from the server
        tags = self.connection.call('get_tags', tags)
        # Add the static tags:
        tags['a'] = self._login
        tags['hv'] = self._login
        tags['role'] = self._role
        tags['a'] = self.login
        tags['hv'] = self.login
        tags['role'] = self.role
        # Update it with the locally defined tags:
        tags.update(self._server.conf.show(self._login)['tags'])
        tags.update(self.server.conf.show(self.login)['tags'])

        return tags