Server code

This commit is contained in:
Bottersnike 2022-02-04 01:09:08 +00:00
parent e8ccee4a10
commit c84d8f35f6
7 changed files with 31 additions and 2 deletions

View File

@ -149,3 +149,10 @@ class Type(enum.Enum):
if i.value.id == value & ARRAY_MASK:
return i
raise ValueError(f"Unknown node type {value}")
class ServicesMode(enum.Enum):
Operation = "operation"
Debug = "debug"
Test = "test"
Factory = "factory"

View File

@ -34,8 +34,8 @@ def validate_key(info):
return seconds, rng
def get_key():
return f"1-{int(time.time()):08x}-{(next(prng) & 0xffff):04x}"
def get_key(prng_=None):
return f"1-{int(time.time()):08x}-{(next(prng_ or prng) & 0xffff):04x}"
def ea_symmetric_crypt(data, info):

View File

@ -186,6 +186,12 @@ class Decoder:
return walk(tree)
def unpack(self):
try:
return self._unpack()
except struct.error as e:
raise DecodeError(e)
def _unpack(self):
if self.is_xml_string:
return self._read_xml_string()

View File

@ -124,6 +124,12 @@ class Encoder:
self.stream.write(struct.pack(">BBBB", 0xA0, contents, self.encoding, enc_comp))
def pack(self, node):
try:
return self._pack(node)
except struct.error as e:
return EncodeError(e)
def _pack(self, node):
self._compressed = node.can_compress # Opportunically compress if we can
self._write_magic()

View File

@ -68,6 +68,14 @@ class XMLNode:
for i in self.children:
yield i
def get(self, name, default=None):
try:
return self[name]
except IndexError:
return default
except KeyError:
return default
def __getitem__(self, name):
if isinstance(name, int):
return self.children[name]

1
eaapi/server Submodule

@ -0,0 +1 @@
Subproject commit 4b0e64341fa7c7aa2db4b57b53283308997fede7

View File

@ -3,4 +3,5 @@ from distutils.core import setup
setup(
name="eaapi",
packages=["eaapi"],
install_requires=open("requirements.txt").read().split("\n"),
)