Added r query for pinging

This commit is contained in:
Emily 2018-09-24 13:40:46 +02:00
parent 25c543fa3b
commit 99d00cf6a9
2 changed files with 29 additions and 2 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.pythonPath": "/usr/bin/python3"
}

View File

@ -30,9 +30,33 @@ def query_i():
return packet
def query_r():
packet_data = []
rules = get_rules()
packet_data.append(len(rules)) # len_rules
for name, value in rules.items():
packet_data.append(len(name)) # len_name
packet_data.append(name)
packet_data.append(len(value)) # len_value
packet_data.append(value)
flat_packet_data = [y for x in packet_data for y in x] # flattens the packet data arrays to one stream
packet = struct.pack(b"<H" + b"c%dsc%ds" * packet_data[0] # using len_rules
% [y for x in rules.items() for y in x], # array of only rules entries
*flat_packet_data)
return packet
def get_online_players(): #TODO
return 0
RESPONSE = { #TODO: r, c, d & p (https://wiki.sa-mp.com/wiki/Query_Mechanism)
b"i": query_i
def get_rules(): #TODO
return {"Rule name sample": "Rule value"}
RESPONSE = { #TODO: c, d & p (https://wiki.sa-mp.com/wiki/Query_Mechanism)
b"i": query_i,
b"r": query_r
}