Added query d
This commit is contained in:
parent
4f43e2933b
commit
4b3fbf2be3
|
@ -20,7 +20,7 @@ def query_i():
|
|||
|
||||
packet = struct.pack(b"<?HHI%dsI%dsI%ds" % (len_hostname, len_mode, len_language),
|
||||
False,
|
||||
get_online_players(),
|
||||
len(get_online_players()),
|
||||
glob.config["server"]["max_players"],
|
||||
len_hostname,
|
||||
glob.config["server"]["hostname"].encode(),
|
||||
|
@ -71,17 +71,42 @@ def query_c():
|
|||
|
||||
return packet
|
||||
|
||||
def get_online_players(): #TODO
|
||||
return 0
|
||||
def query_d():
|
||||
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
|
||||
return {"Rule name sample": "Rule value"}
|
||||
|
||||
def get_players_scores():
|
||||
def get_players_scores(): #TODO
|
||||
return {"Sunpy": 64, "username": 123}
|
||||
|
||||
RESPONSE = { #TODO: c, d & p (https://wiki.sa-mp.com/wiki/Query_Mechanism)
|
||||
b"i": query_i,
|
||||
b"r": query_r,
|
||||
b"c": query_c
|
||||
b"c": query_c,
|
||||
b"d": query_d
|
||||
}
|
Reference in New Issue
Block a user