Пример #1
0
    def datagramReceived(self, data, host):
        self.server.ping = (time.time() - self.sent_time) * 1000
        p = BSReader(data)
        p.read_char(10)
        self.server.num_players = p.read_int()

        attrs = p.read_int(p.read_int())
        self.server.protocol, self.server.game_mode, self.server.mins_left, self.server.max_players, self.server.master_mode = attrs

        self.server.map_name = p.read_string()
        self.server.description = p.read_string()
        self.d.callback(self.server)
 def datagramReceived(self, data, host):
     p = BSReader(data)
     if p.read_char(6) != [0, 1, -1, -1, 104, 0]:
         self.d.errback(ValueError('Invalid packet received.'))
         return
     v = p.read_char()
     if v == -10:
         self.n_players = len(data) - p.position
     elif v == -11:
         f = Player(self.server)
         f.client_num, f.ping = p.read_int(2)
         f.name, f.team = p.read_string(2)
         f.frags, f.score, f.deaths, f.tks, f.accuracy = p.read_int(5)
         f.health, f.armor, f.weapon, f.priv, f.state = p.read_int(5)
         f._ip = p.read_uchar(3)
         self.server.players.append(f)
     if len(self.server.players) == self.n_players:
         self.d.callback(self.server.players)