diff --git a/rcon/exceptions.py b/rcon/exceptions.py index 4a04377..6bf6d56 100644 --- a/rcon/exceptions.py +++ b/rcon/exceptions.py @@ -2,6 +2,7 @@ __all__ = [ 'ConfigReadError', + 'EmptyResponse', 'SessionTimeout', 'UserAbort', 'WrongPassword' @@ -12,6 +13,10 @@ class ConfigReadError(Exception): """Indicates an error while reading the configuration.""" +class EmptyResponse(Exception): + """Indicates an empty response from the server.""" + + class SessionTimeout(Exception): """Indicates that the session timed out.""" diff --git a/rcon/source/proto.py b/rcon/source/proto.py index 97e3d2d..5c63284 100644 --- a/rcon/source/proto.py +++ b/rcon/source/proto.py @@ -8,6 +8,8 @@ from logging import getLogger from random import randint from typing import IO, NamedTuple +from rcon.exceptions import EmptyResponse + __all__ = ['LittleEndianSignedInt32', 'Type', 'Packet', 'random_request_id'] @@ -114,6 +116,10 @@ class Packet(NamedTuple): LOGGER.debug('Reading packet asynchronously.') size = await LittleEndianSignedInt32.aread(reader) LOGGER.debug(' => size: %i', size) + + if not size: + raise EmptyResponse() + id_ = await LittleEndianSignedInt32.aread(reader) LOGGER.debug(' => id: %i', id_) type_ = await Type.aread(reader, prefix=' ') @@ -134,6 +140,10 @@ class Packet(NamedTuple): LOGGER.debug('Reading packet.') size = LittleEndianSignedInt32.read(file) LOGGER.debug(' => size: %i', size) + + if not size: + raise EmptyResponse() + id_ = LittleEndianSignedInt32.read(file) LOGGER.debug(' => id: %i', id_) type_ = Type.read(file, prefix=' ')