-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackets.py
More file actions
40 lines (30 loc) · 1021 Bytes
/
Copy pathPackets.py
File metadata and controls
40 lines (30 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from DataTypes import *
from collections import OrderedDict
class Packet:
form = OrderedDict()
packetId = VarInt(0)
def __init__(self):
self.data = OrderedDict()
for key, value in self.form.items():
self.data[key] = value()
def __getitem__(self, key):
return self.data[key].value
def __setitem__(self, key, value):
self.data[key].value = value
def __dir__(self):
return list(self.form.keys())
def pack(self):
output = b""
for item in self.data:
output += item.pack()
output = self.packetId.pack() + output
leng = VarInt(len(output))
output = leng.pack() + output
return output
def unpack(self, data):
for item in self.data:
item.unpack(data)
class HandShake:
form = OrderedDict([("Protocol Version", VarInt), ("Server Address", String), ("Server Port", UnsignedShort),
("Next State", VarInt)])
packetId = VarInt(0)