diff --git a/steam/game_servers.py b/steam/game_servers.py index 0303f63..9c86550 100644 --- a/steam/game_servers.py +++ b/steam/game_servers.py @@ -120,7 +120,7 @@ from bz2 import decompress as _bz2_decompress from re import match as _re_match from struct import pack as _pack, unpack_from as _unpack_from from time import time as _time -from enum import IntEnum, Enum +from enum import IntEnum from steam.util.binary import StructReader @@ -161,7 +161,7 @@ def query_master(filter_text=r'\napp\500', region=MSRegion.World, master=MSServe :type region: :class:`.MSRegion` :param master: (optional) master server to query :type master: (:class:`str`, :class:`int`) - :raises: This function will raise in various situations + :raises: :class:`RuntimeError`, :class:`socket.timeout` :returns: a generator yielding (ip, port) pairs :rtype: :class:`generator` """ @@ -292,8 +292,9 @@ def a2s_info(server_addr, timeout=2, force_goldsrc=False): :type force_goldsrc: :class:`bool` :param timeout: (optional) timeout in seconds :type timeout: float + :raises: :class:`RuntimeError`, :class:`socket.timeout` :returns: a dict with information or `None` on timeout - :rtype: :class:`dict`, :class:`None` + :rtype: :class:`dict` """ ss = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) ss.connect(server_addr) @@ -306,36 +307,32 @@ def a2s_info(server_addr, timeout=2, force_goldsrc=False): # handle response(s) try: data = _handle_a2s_response(ss) - except socket.timeout: + except: ss.close() - return None + raise ping = max(0.0, _time() - start) * 1000 if force_goldsrc: if data[4:5] != b'm': ss.close() - return None + raise socket.timeout('time out') else: # we got a valid GoldSrc response, check if it is followed by Source response if data[4:5] == b'm': ss.settimeout(0.3) try: - data2 = _handle_a2s_response(ss) + data = _handle_a2s_response(ss) except socket.timeout: pass - if data2[4:5] == b'I': - data = data2 - ss.close() data = StructReader(data) - data.skip(4) # packet header - header, = data.unpack('