Example #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
Example #2
0
 def decodedLineReceived(self, line):
     parts = line.split(':', 1)
     command = parts[0]
     if len(parts) == 1:
         args = {}
     elif parts[1] and parts[1][0] == '<':
         args = parse_dict(parts[1])
     else:
         args = {'_': parts[1]}
     if command in self.commandHandlers:
         handler, allowedArgs = self.commandHandlers[command]
         if allowedArgs is False:
             handler(args)
         else:
             handler({key: args[key] for key in allowedArgs})
     else:
         raise InvalidClientRequest('Unknown command "%s".' % command)