Beispiel #1
0
 def get_server_clients_detailed(self):
     response = self.send_request(OPCODE_CLIENTS_DETAILED)
     result = []
     if response is None:
         # SA-MP server will return null if there's a lot of players
         # We'll handle this by returning an empty list instead to avoid type error.
         return result
     num_clients = decode_int(response[:2])
     offset = 2
     for n in range(num_clients):
         player_id = decode_int(response[offset:offset])
         offset += 1
         name = decode_string(response, offset, len_bytes=1)
         offset += 1 + len(name)
         score = decode_int(response[offset:offset + 4])
         offset += 4
         ping = decode_int(response[offset:offset + 4])
         offset += 4
         detail = ClientDetail(
             id=player_id,
             name=name,
             score=score,
             ping=ping,
         )
         result.append(detail)
     return result
Beispiel #2
0
 def get_server_clients(self):
     response = self.send_request(OPCODE_CLIENTS)
     num_clients = decode_int(response[:2])
     offset = 2
     result = []
     for n in range(num_clients):
         name = decode_string(response, offset, len_bytes=1)
         offset += 1 + len(name)
         score = decode_int(response[offset:offset + 4])
         offset += 4
         client = Client(
             name=name,
             score=score,
         )
         result.append(client)
     return result
Beispiel #3
0
    def get_server_info(self):
        response = self.send_request(OPCODE_INFO)

        offset = 0
        hostname = decode_string(response, 5, 4)
        offset += len(hostname)
        gamemode = decode_string(response, offset + 9, 4)
        offset += len(gamemode)
        language = decode_string(response, offset + 13, 4)

        return ServerInfo(
            password=bool(response[0]),
            players=decode_int(response[1:3]),
            max_players=decode_int(response[3:5]),
            hostname=hostname,
            gamemode=gamemode,
            language=language,
        )
Beispiel #4
0
 def get_server_clients(self):
     response = self.send_request(OPCODE_CLIENTS)
     result = []
     if response is None:
         # SA-MP server will return null if there's a lot of players
         # We'll handle this by returning an empty list instead to avoid type error.
         return result
     num_clients = decode_int(response[:2])
     offset = 2
     for n in range(num_clients):
         name = decode_string(response, offset, len_bytes=1)
         offset += 1 + len(name)
         score = decode_int(response[offset:offset + 4])
         offset += 4
         client = Client(
             name=name,
             score=score,
         )
         result.append(client)
     return result
Beispiel #5
0
 def get_server_clients_detailed(self):
     response = self.send_request(OPCODE_CLIENTS_DETAILED)
     num_clients = decode_int(response[:2])
     offset = 2
     result = []
     for n in range(num_clients):
         player_id = decode_int(response[offset:offset])
         offset += 1
         name = decode_string(response, offset, len_bytes=1)
         offset += 1 + len(name)
         score = decode_int(response[offset:offset + 4])
         offset += 4
         ping = decode_int(response[offset:offset + 4])
         offset += 4
         detail = ClientDetail(
             id=player_id,
             name=name,
             score=score,
             ping=ping,
         )
         result.append(detail)
     return result
Beispiel #6
0
 def get_server_rules(self):
     response = self.send_request(OPCODE_RULES)
     num_rules = decode_int(response[:2])
     offset = 2
     result = []
     for n in range(num_rules):
         name = decode_string(response, offset, len_bytes=1)
         offset += 1 + len(name)
         value = decode_string(response, offset, len_bytes=1)
         offset += 1 + len(value)
         rule = Rule(
             name=str(name),
             value=value,
         )
         result.append(rule)
     return result
 def test_decode_int_4(self):
     self.assertEqual(7989, utils.decode_int(b'5\x1f\x00\x00'))
 def test_decode_int_1(self):
     self.assertEqual(0, utils.decode_int(chr(0)))
     self.assertEqual(16, utils.decode_int(chr(16)))
     self.assertEqual(200, utils.decode_int(chr(200)))
Beispiel #9
0
 def test_decode_int_1(self):
     self.assertEqual(0, utils.decode_int(chr(0).encode('latin-1')))
     self.assertEqual(16, utils.decode_int(chr(16).encode('latin-1')))
     self.assertEqual(200, utils.decode_int(chr(200).encode('latin-1')))