diff --git a/pybfbc2stats/__init__.py b/pybfbc2stats/__init__.py index 3d085c8..3f72576 100644 --- a/pybfbc2stats/__init__.py +++ b/pybfbc2stats/__init__.py @@ -2,7 +2,7 @@ from .asyncio_connection import AsyncConnection from .client import Client from .connection import Connection -from .constants import Namespace +from .constants import Platform, Namespace from .exceptions import PyBfbc2StatsError, PyBfbc2StatsTimeoutError, PyBfbc2StatsParameterError, \ PyBfbc2StatsNotFoundError @@ -14,5 +14,5 @@ __version__ = '0.1.4' __author__ = 'cetteup' __credits__ = 'nemo, Luigi Auriemma' -__all__ = ['Connection', 'Client', 'AsyncConnection', 'AsyncClient', 'PyBfbc2StatsError', 'Namespace', +__all__ = ['Connection', 'Client', 'AsyncConnection', 'AsyncClient', 'PyBfbc2StatsError', 'Platform', 'Namespace', 'PyBfbc2StatsParameterError', 'PyBfbc2StatsTimeoutError', 'PyBfbc2StatsNotFoundError'] diff --git a/pybfbc2stats/asyncio_client.py b/pybfbc2stats/asyncio_client.py index fc4ed66..a76c656 100644 --- a/pybfbc2stats/asyncio_client.py +++ b/pybfbc2stats/asyncio_client.py @@ -1,17 +1,19 @@ from typing import List -from . import Client, Namespace from .asyncio_connection import AsyncConnection -from .constants import Step +from .client import Client +from .constants import Step, Namespace, FESL_DETAILS, Platform from .exceptions import PyBfbc2StatsNotFoundError class AsyncClient(Client): connection: AsyncConnection - def __init__(self, username: str, password: str, timeout: float = 2.0, track_steps: bool = True): - super().__init__(username, password, timeout, track_steps) - self.connection = AsyncConnection('bfbc2-pc-server.fesl.ea.com', 18321, timeout) + def __init__(self, username: str, password: str, platform: Platform, timeout: float = 2.0, + track_steps: bool = True): + super().__init__(username, password, platform, timeout=timeout, track_steps=track_steps) + self.connection = AsyncConnection(FESL_DETAILS[self.platform]['host'], FESL_DETAILS[self.platform]['port'], + timeout) async def __aenter__(self): return self diff --git a/pybfbc2stats/client.py b/pybfbc2stats/client.py index 96742c2..d869f53 100644 --- a/pybfbc2stats/client.py +++ b/pybfbc2stats/client.py @@ -3,24 +3,27 @@ from urllib.parse import quote_from_bytes, unquote_to_bytes from .connection import Connection -from .constants import STATS_KEYS, BUFFER_SIZE, Step, Namespace +from .constants import STATS_KEYS, BUFFER_SIZE, Step, Namespace, Platform, FESL_DETAILS from .exceptions import PyBfbc2StatsParameterError, PyBfbc2StatsError, PyBfbc2StatsNotFoundError class Client: username: bytes password: bytes + platform: Platform timeout: float track_steps: bool connection: Connection complete_steps: List[Step] = [] - def __init__(self, username: str, password: str, timeout: float = 2.0, track_steps: bool = True): + def __init__(self, username: str, password: str, platform: Platform, timeout: float = 2.0, + track_steps: bool = True): self.username = username.encode('utf8') self.password = password.encode('utf8') + self.platform = platform self.timeout = timeout self.track_steps = track_steps - self.connection = Connection('bfbc2-pc-server.fesl.ea.com', 18321, timeout) + self.connection = Connection(FESL_DETAILS[self.platform]['host'], FESL_DETAILS[self.platform]['port'], timeout) def __enter__(self): return self @@ -134,12 +137,12 @@ def build_packet(header: bytes, body: bytes): return bytes(packet) - @staticmethod - def get_hello_packet() -> bytes: + def get_hello_packet(self) -> bytes: return Client.build_packet( b'fsys\xc0\x00\x00\x01', - b'TXN=Hello\nclientString=bfbc2-pc\nsku=PC\nlocale=en_US\nclientPlatform=PC\nclientVersion=2.0\n' - b'SDKVersion=5.1.2.0.0\nprotocolVersion=2.0\nfragmentSize=8096\nclientType=server' + b'TXN=Hello\nclientString=' + FESL_DETAILS[self.platform]['clientString'] + b'\nsku=PC\nlocale=en_US\n' + b'clientPlatform=PC\nclientVersion=2.0\nSDKVersion=5.1.2.0.0\nprotocolVersion=2.0\nfragmentSize=8096\n' + b'clientType=server' ) @staticmethod diff --git a/pybfbc2stats/constants.py b/pybfbc2stats/constants.py index c26b896..f7bf83c 100644 --- a/pybfbc2stats/constants.py +++ b/pybfbc2stats/constants.py @@ -1,5 +1,6 @@ from enum import Enum + class Step(int, Enum): hello = 1 memcheck = 2 @@ -12,7 +13,26 @@ class Namespace(bytes, Enum): ps3 = b'ps3' +class Platform(int, Enum): + pc = 1 + # XBOX is not yet supported + # xbox360 = 2 + ps3 = 3 + + BUFFER_SIZE = 8144 +FESL_DETAILS = { + Platform.pc: { + 'host': 'bfbc2-pc-server.fesl.ea.com', + 'port': 18321, + 'clientString': b'bfbc2-pc' + }, + Platform.ps3: { + 'host': 'bfbc2-ps3-server.fesl.ea.com', + 'port': 18331, + 'clientString': b'bfbc2-ps3' + } +} STATS_KEYS = [b'accuracy', b'br40mmgl_00', b'br40mmgl_01', b'br40mmsg_00', b'br40mmsg_01', b'br9a91_00', b'br9a91_01', b'braek_00', b'braek_01', b'brair_00', b'brair_01', b'brak47v_00', b'brak47v_01', b'braks74u_00', b'braks74u_01', b'bran94_00', b'bran94_01', b'brarm_00', b'brarm_01', b'bratm_00', b'bratm_01',