Skip to content

Commit

Permalink
Add support for retrieving PS3 player stats
Browse files Browse the repository at this point in the history
  • Loading branch information
cetteup committed Oct 28, 2021
1 parent 6eef94d commit deffe8f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pybfbc2stats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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']
12 changes: 7 additions & 5 deletions pybfbc2stats/asyncio_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 10 additions & 7 deletions pybfbc2stats/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 20 additions & 0 deletions pybfbc2stats/constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum


class Step(int, Enum):
hello = 1
memcheck = 2
Expand All @@ -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',
Expand Down

0 comments on commit deffe8f

Please sign in to comment.