Alex Nørgaard
2 years ago
No known key found for this signature in database
GPG Key ID: 94D54F6A3604E97
4 changed files with
41 additions and
3 deletions
-
a2s/a2s_async.py
-
a2s/a2s_fragment.py
-
a2s/a2s_sync.py
-
a2s/byteio.py
|
|
@ -148,6 +148,14 @@ async def request_async_impl( |
|
|
|
|
|
|
|
|
|
|
|
class A2SProtocol(asyncio.DatagramProtocol): |
|
|
|
__slots__ = ( |
|
|
|
"recv_queue", |
|
|
|
"error_event", |
|
|
|
"error", |
|
|
|
"fragment_buf", |
|
|
|
"transport", |
|
|
|
) |
|
|
|
|
|
|
|
def __init__(self): |
|
|
|
self.recv_queue: asyncio.Queue[bytes] = asyncio.Queue() |
|
|
|
self.error_event: asyncio.Event = asyncio.Event() |
|
|
@ -192,6 +200,12 @@ class A2SProtocol(asyncio.DatagramProtocol): |
|
|
|
|
|
|
|
|
|
|
|
class A2SStreamAsync: |
|
|
|
__slots__ = ( |
|
|
|
"transport", |
|
|
|
"protocol", |
|
|
|
"timeout", |
|
|
|
) |
|
|
|
|
|
|
|
def __init__(self, transport: asyncio.DatagramTransport, protocol: A2SProtocol, timeout: float) -> None: |
|
|
|
self.transport = transport |
|
|
|
self.protocol = protocol |
|
|
|
|
|
@ -29,6 +29,16 @@ from a2s.byteio import ByteReader |
|
|
|
|
|
|
|
|
|
|
|
class A2SFragment: |
|
|
|
__slots__ = ( |
|
|
|
"message_id", |
|
|
|
"fragment_count", |
|
|
|
"fragment_id", |
|
|
|
"mtu", |
|
|
|
"decompressed_size", |
|
|
|
"crc", |
|
|
|
"payload", |
|
|
|
) |
|
|
|
|
|
|
|
def __init__( |
|
|
|
self, |
|
|
|
message_id: int, |
|
|
|
|
|
@ -48,8 +48,6 @@ logger: logging.Logger = logging.getLogger("a2s") |
|
|
|
|
|
|
|
T = TypeVar("T", InfoProtocol, RulesProtocol, PlayersProtocol) |
|
|
|
|
|
|
|
__all__ = ("A2SStream",) |
|
|
|
|
|
|
|
|
|
|
|
@overload |
|
|
|
def request_sync( |
|
|
@ -139,6 +137,11 @@ def request_sync_impl( |
|
|
|
|
|
|
|
|
|
|
|
class A2SStream: |
|
|
|
__slots__ = ( |
|
|
|
"address", |
|
|
|
"_socket", |
|
|
|
) |
|
|
|
|
|
|
|
def __init__(self, address: Tuple[str, int], timeout: float) -> None: |
|
|
|
self.address: Tuple[str, int] = address |
|
|
|
self._socket: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
|
|
|
|
|
@ -32,7 +32,6 @@ from a2s.exceptions import BufferExhaustedError |
|
|
|
|
|
|
|
from .defaults import DEFAULT_ENCODING |
|
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING: |
|
|
|
from typing_extensions import Literal |
|
|
|
|
|
|
@ -42,6 +41,12 @@ STRUCT_OPTIONS = Literal[ |
|
|
|
|
|
|
|
|
|
|
|
class ByteReader: |
|
|
|
__slots__ = ( |
|
|
|
"stream", |
|
|
|
"endian", |
|
|
|
"encoding", |
|
|
|
) |
|
|
|
|
|
|
|
def __init__(self, stream: io.BytesIO, endian: str = "=", encoding: Optional[str] = None) -> None: |
|
|
|
self.stream: io.BytesIO = stream |
|
|
|
self.endian: str = endian |
|
|
@ -126,6 +131,12 @@ class ByteReader: |
|
|
|
|
|
|
|
|
|
|
|
class ByteWriter: |
|
|
|
__slots__ = ( |
|
|
|
"stream", |
|
|
|
"endian", |
|
|
|
"encoding", |
|
|
|
) |
|
|
|
|
|
|
|
def __init__(self, stream: io.BytesIO, endian: str = "=", encoding: Optional[str] = None) -> None: |
|
|
|
self.stream: io.BytesIO = stream |
|
|
|
self.endian: str = endian |
|
|
|