I dont remember what I changed... sorry

This commit is contained in:
Emily 2018-10-02 00:38:25 +02:00
parent 3d1aa21bab
commit 3bdd78b61c
5 changed files with 50 additions and 20 deletions

View File

@ -11,9 +11,6 @@ def handle(client, data):
return b"\x19\x00"
if client.state == 2:
client.state = 3
return b"\xe3\x00\x00"
if client.state == 3:
client.state = 4
return b"\xe3\x00\x00", b"\x00\x00\x42\x98\x0c\x11\x33\x45\x30\x42\x33\x33\x35\x32\x37\x34\x46\x39\x31\x43\x39\x39\x00"
return b"WUT?"

View File

@ -99,12 +99,12 @@ def get_online_players(): #TODO: Get data from server's client objects
]
def get_rules(): #TODO
return {b"Rule name sample": b"Rule value"}
return {b"Rule name sample": b"Rule value", b"weburl": b"https://git.osufx.com/Sunpy/sampy"}
def get_players_scores(): #TODO
return {b"Sunpy": 64, b"username": 123}
RESPONSE = { #TODO: c, d & p (https://wiki.sa-mp.com/wiki/Query_Mechanism)
RESPONSE = { #TODO?: p (https://wiki.sa-mp.com/wiki/Query_Mechanism) (We dont really need to do the last handler as it happens somewhat automatically)
b"i": query_i,
b"r": query_r,
b"c": query_c,

31
notes.md Normal file
View File

@ -0,0 +1,31 @@
## Packet stuff
---
### Client to server
Name|Pattern|Ids|Description
---|---|---|---
Struct ID|a2 08 {id} 27|id = data id|Following packet is part of id
First packet|Amount of seperate packets sent|Total length before end|Bit length
---|---|---|---
a2 08 8a 27|2|52 (48)|104 (96)
a2 08 c4 27|3|45 (41)|90 (82)
### Server to client
Name|Pattern|Ids|Description
---|---|---|---
Struct ID|e3 {id} 00|id = data id|Following packet is part of id
First packet|Amount of seperate packets sent|Total length before end|Bit length
---|---|---|---
e3 00 00|2|26 (23)|52 (46)
e3 01 00|2|20 (17)|40 (34)
e3 07 00|1|3|6
e3 0a 00|2|130 (127)|260 (254)
e3 0b 00|2|11 (8)|22 (16)
e3 0c 00|2|15 (12)|30 (24)
### Random notices
- 27 seem to be used a lot
- Server to client `Struct ID` seem to be incremental
-

View File

@ -1,13 +1,12 @@
from importlib import reload
import re
import socket
from handlers import serverPingHandler, mainHandler
class Client:
BUFF_SIZE = 65535
HANDLERS = {
re.compile(b"SAMP"): serverPingHandler
b"SAMP": serverPingHandler
}
def __init__(self, server, addr):
@ -19,7 +18,7 @@ class Client:
def handle_data(self, data):
found = False
for pattern, handler in self.HANDLERS.items():
if pattern.match(data):
if data.startswith(pattern):
queue = handler.handle(self, data)
if queue:
self.write_to_buffer(queue)

View File

@ -4,6 +4,9 @@ import socket
from threading import Thread
import select
def format_hex(hex_str):
return " ".join([hex_str[i:i+2] for i in range(0, len(hex_str), 2)])
class Proxy(Thread):
BUFF_SIZE = 65535
@ -48,14 +51,14 @@ class Proxy(Thread):
c_data = b"\x08\x1e\x77\xda"
"""
print("[C] -> {}".format(c_data))
with open("logs/{}-client-raw.log".format(LISTEN[1]), "a") as f:
f.write("({}) {} \r\n".format(self.prnt_id_client, c_data))
with open("logs/{}-client-raw.log".format(LISTEN[1]), "ab") as f:
f.write("({}) ".format(self.prnt_id_client).encode() + c_data + b"\r\n")
with open("logs/{}-client-hex.log".format(LISTEN[1]), "a") as f:
f.write("({}) {} \r\n".format(self.prnt_id_client, c_data.hex()))
with open("logs/{}-all-raw.log".format(LISTEN[1]), "a") as f:
f.write("[C] -> ({}) {} \r\n".format(self.prnt_id_client, c_data))
f.write("({}) {} \r\n".format(self.prnt_id_client, format_hex(c_data.hex())))
with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f:
f.write("[C] -> ({}) ".format(self.prnt_id_client).encode() + c_data + b"\r\n")
with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f:
f.write("[C] -> ({}) {} \r\n".format(self.prnt_id_client, c_data.hex()))
f.write("[C] -> ({}) {} \r\n".format(self.prnt_id_client, format_hex(c_data.hex())))
target.sendto(c_data, self.target)
self.prnt_id_client += 1
@ -66,14 +69,14 @@ class Proxy(Thread):
#print("[S] data:{}".format(s_data))
if s_data:
print("[C] <- {}".format(s_data))
with open("logs/{}-server-raw.log".format(LISTEN[1]), "a") as f:
f.write("({}) {} \r\n".format(self.prnt_id_server, s_data))
with open("logs/{}-server-raw.log".format(LISTEN[1]), "ab") as f:
f.write("({}) ".format(self.prnt_id_server).encode() + s_data + b"\r\n")
with open("logs/{}-server-hex.log".format(LISTEN[1]), "a") as f:
f.write("({}) {} \r\n".format(self.prnt_id_server, s_data.hex()))
with open("logs/{}-all-raw.log".format(LISTEN[1]), "a") as f:
f.write("[C] <- ({}) {} \r\n".format(self.prnt_id_server, s_data))
f.write("({}) {} \r\n".format(self.prnt_id_server, format_hex(s_data.hex())))
with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f:
f.write("[C] <- ({}) ".format(self.prnt_id_server).encode() + s_data + b"\r\n")
with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f:
f.write("[C] <- ({}) {} \r\n".format(self.prnt_id_server, s_data.hex()))
f.write("[C] <- ({}) {} \r\n".format(self.prnt_id_server, format_hex(s_data.hex())))
client.sendto(s_data, c_addr)
self.prnt_id_server += 1
client.close()