Beispiel #1
0
    def _handleUpdateServers(self, line):
        if self._remainingServers is None:
            self._remainingServers = int(line)
        elif not self._currentServer:
            host, port = line.split(' - Port: ', 1)
            self._currentServer = Server(host, int(port))
        elif self._remainingNets is None:
            self._remainingNets = int(line)
        elif self._currentNet is None:
            self._currentNet = Net(line)
        elif self._remainingClients is None:
            self._remainingClients = int(line)
        else:
            client = Client.from_dict(parse_dict(line))
            self._currentNet.clients.append(client)
            self._remainingClients -= 1

        if self._currentNet and self._remainingClients == 0:
            self._currentServer.nets.append(self._currentNet)
            self._currentNet = None
            self._remainingClients = None
            self._remainingNets -= 1

        if self._currentServer and self._remainingNets == 0:
            self._servers.append(self._currentServer)
            self._currentServer = None
            self._remainingNets = None
            self._remainingServers -= 1

        if self._remainingServers == 0:
            self.serversUpdated(self._servers)
            return False
        return True  # expect more data
Beispiel #2
0
 def handleRegister(self, args):
     client = Client.from_dict(args)
     try:
         self.backend.register(client)
         self.sendLine('OK')
     except RegistrationFailed as ex:
         self.sendLine(ex.message or 'NU')
Beispiel #3
0
 def handleClientConnect(self, args):
     client = Client.from_dict(args)
     network = args.get('NT')
     try:
         id = self.backend.client_connect(self.server, network, client)
         self.sendLine(id)
     except InvalidCredentials:
         self.sendLine('WRONG')
     except AccessDenied:
         self.sendLine('BLOCK')