diff --git a/ccserver/ccserver.py b/ccserver/ccserver.py index 3908b31b0d8cd0c23320633c0a84b1acc2c25731..399b34104d040b0b785490a3e1b8d7a2752c33f0 100644 --- a/ccserver/ccserver.py +++ b/ccserver/ccserver.py @@ -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. diff --git a/ccserver/client.py b/ccserver/client.py index 4eca56e27c42b9eb1220cf1b1d615c81269623e9..52ece0d0d9615af23bc60e910e54e0b2c8b5c776 100644 --- a/ccserver/client.py +++ b/ccserver/client.py @@ -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