Added query d

This commit is contained in:
Emily 2018-09-26 10:05:54 +02:00
parent 4f43e2933b
commit 4b3fbf2be3

View File

@ -20,7 +20,7 @@ def query_i():
packet = struct.pack(b"<?HHI%dsI%dsI%ds" % (len_hostname, len_mode, len_language), packet = struct.pack(b"<?HHI%dsI%dsI%ds" % (len_hostname, len_mode, len_language),
False, False,
get_online_players(), len(get_online_players()),
glob.config["server"]["max_players"], glob.config["server"]["max_players"],
len_hostname, len_hostname,
glob.config["server"]["hostname"].encode(), glob.config["server"]["hostname"].encode(),
@ -71,17 +71,42 @@ def query_c():
return packet return packet
def get_online_players(): #TODO def query_d():
return 0 packet_data = []
players = get_online_players()
packet_data.append(len(players))
for player in players:
packet_data.append([
player["id"],
len(player["nick"]), player["nick"],
player["score"],
player["ping"]
])
flat_packet_data = dataHelper.flatten(packet_data)
packet = struct.pack(b"<H" + b"cc%dsII" * flat_packet_data[0]
% [len(player["nick"]) for player in players],
*flat_packet_data)
return packet
def get_online_players(): #TODO: Get data from server's client objects
return [
{"nick": "Sunpy", "score": 64, "ping": 8} + {"id": 1} # replace id with function to get player's id
]
def get_rules(): #TODO def get_rules(): #TODO
return {"Rule name sample": "Rule value"} return {"Rule name sample": "Rule value"}
def get_players_scores(): def get_players_scores(): #TODO
return {"Sunpy": 64, "username": 123} return {"Sunpy": 64, "username": 123}
RESPONSE = { #TODO: c, d & p (https://wiki.sa-mp.com/wiki/Query_Mechanism) RESPONSE = { #TODO: c, d & p (https://wiki.sa-mp.com/wiki/Query_Mechanism)
b"i": query_i, b"i": query_i,
b"r": query_r, b"r": query_r,
b"c": query_c b"c": query_c,
b"d": query_d
} }