Browse Source

Make max_pkg_size a class parameter

pull/14/head
Richard Neumann 3 years ago
parent
commit
bd865fac06
  1. 13
      rcon/client.py
  2. 2
      rcon/source/client.py

13
rcon/client.py

@ -12,8 +12,7 @@ class BaseClient:
def __init__(
self, host: str, port: int, *,
timeout: float | None = None,
passwd: str | None = None,
max_pkg_size: int | None = None
passwd: str | None = None
):
"""Initialize the base client with the SOCK_STREAM socket type."""
self._socket = socket(type=self._socket_type)
@ -21,11 +20,17 @@ class BaseClient:
self.port = port
self.timeout = timeout
self.passwd = passwd
self.max_pkg_size = max_pkg_size
def __init_subclass__(cls, *, socket_type: SocketKind | None = None):
def __init_subclass__(
cls,
*,
socket_type: SocketKind | None = None,
max_pkg_size: int | None = None
):
if socket_type is not None:
cls._socket_type = socket_type
cls._max_pkg_size = max_pkg_size
def __enter__(self):
"""Attempt an auto-login if a password is set."""

2
rcon/source/client.py

@ -25,7 +25,7 @@ class Client(BaseClient, socket_type=SOCK_STREAM):
with self._socket.makefile('rb') as file:
packet = Packet.read(file)
if self.max_pkg_size and len(packet.payload) >= self.max_pkg_size:
if self._max_pkg_size and len(packet.payload) >= self._max_pkg_size:
return packet + self.read_followup_packet()
return packet

Loading…
Cancel
Save