Skip to content

Commit

Permalink
Rename classes
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 15, 2024
1 parent 029f240 commit 1ad02d3
Show file tree
Hide file tree
Showing 17 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions opengsq/protocol_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def error_received(self, exc):
pass


class UDPClient(Socket):
class UdpClient(Socket):
@staticmethod
async def communicate(protocol: ProtocolBase, data: bytes):
with UDPClient() as udpClient:
with UdpClient() as udpClient:
udpClient.settimeout(protocol._timeout)
await udpClient.connect((protocol._host, protocol._port))
udpClient.send(data)
Expand All @@ -113,10 +113,10 @@ def __init__(self):
super().__init__(SocketKind.SOCK_DGRAM)


class TCPClient(Socket):
class TcpClient(Socket):
@staticmethod
async def communicate(protocol: ProtocolBase, data: bytes):
with TCPClient() as tcpClient:
with TcpClient() as tcpClient:
tcpClient.settimeout(protocol._timeout)
await tcpClient.connect((protocol._host, protocol._port))
tcpClient.send(data)
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/ase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class ASE(ProtocolBase):
Expand All @@ -12,7 +12,7 @@ class ASE(ProtocolBase):
_response = b'EYE1'

async def get_status(self) -> dict:
response = await UDPClient.communicate(self, self._request)
response = await UdpClient.communicate(self, self._request)
header = response[:4]

if header != self._response:
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/battlefield.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from opengsq.binary_reader import BinaryReader
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import TCPClient
from opengsq.protocol_socket import TcpClient


class Battlefield(ProtocolBase):
Expand Down Expand Up @@ -72,7 +72,7 @@ async def get_players(self) -> list:
return players

async def __get_data(self, request: bytes):
response = await TCPClient.communicate(self, request)
response = await TcpClient.communicate(self, request)
return self.__decode(response)

def __decode(self, response: bytes):
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/doom3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class Doom3(ProtocolBase):
Expand All @@ -18,7 +18,7 @@ class Doom3(ProtocolBase):

async def get_info(self, strip_color=True):
request = b'\xFF\xFFgetInfo\x00ogsq\x00'
response = await UDPClient.communicate(self, request)
response = await UdpClient.communicate(self, request)

# Remove the first two 0xFF
br = BinaryReader(response[2:])
Expand Down
6 changes: 3 additions & 3 deletions opengsq/protocols/gamespy1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from opengsq.binary_reader import BinaryReader
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class GameSpy1(ProtocolBase):
Expand Down Expand Up @@ -74,7 +74,7 @@ async def get_teams(self) -> list:
return self.__parse_as_object(await self.__connect_and_send(self.__Request.TEAMS))

# Receive packets and sort it
async def __get_packets_response(self, udpClient: UDPClient):
async def __get_packets_response(self, udpClient: UdpClient):
payloads = {}
packet_count = -1

Expand Down Expand Up @@ -104,7 +104,7 @@ async def __get_packets_response(self, udpClient: UDPClient):

async def __connect_and_send(self, data) -> BinaryReader:
# Connect to remote host
with UDPClient() as udpClient:
with UdpClient() as udpClient:
udpClient.settimeout(self._timeout)
await udpClient.connect((self._host, self._port))

Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/gamespy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from opengsq.binary_reader import BinaryReader
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class GameSpy2(ProtocolBase):
Expand All @@ -17,7 +17,7 @@ class Request(Flag):
async def get_status(self, request: Request = Request.INFO | Request.PLAYERS | Request.TEAMS) -> dict:
"""Retrieves information about the server including, Info, Players, and Teams."""
data = b'\xFE\xFD\x00\x04\x05\x06\x07' + self.__get_request_bytes(request)
response = await UDPClient.communicate(self, data)
response = await UdpClient.communicate(self, data)

# Remove the first 5 bytes { 0x00, 0x04, 0x05, 0x06, 0x07 }
br = BinaryReader(response[5:])
Expand Down
6 changes: 3 additions & 3 deletions opengsq/protocols/gamespy3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class GameSpy3(ProtocolBase):
Expand All @@ -14,7 +14,7 @@ class GameSpy3(ProtocolBase):
async def get_status(self):
"""Retrieves information about the server including, Info, Players, and Teams."""
# Connect to remote host
with UDPClient() as udpClient:
with UdpClient() as udpClient:
udpClient.settimeout(self._timeout)
await udpClient.connect((self._host, self._port))

Expand Down Expand Up @@ -76,7 +76,7 @@ async def get_status(self):

return result

async def __read(self, udpClient: UDPClient) -> bytes:
async def __read(self, udpClient: UdpClient) -> bytes:
packet_count = -1
payloads = {}

Expand Down
6 changes: 3 additions & 3 deletions opengsq/protocols/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import TCPClient
from opengsq.protocol_socket import TcpClient


class Minecraft(ProtocolBase):
Expand All @@ -29,7 +29,7 @@ async def get_status(self, version=47, strip_color=True) -> dict:
request = b'\x00' + protocol + self._pack_varint(len(address)) + address + struct.pack('H', self._port) + b'\x01'
request = self._pack_varint(len(request)) + request + b'\x01\x00'

with TCPClient() as tcpClient:
with TcpClient() as tcpClient:
tcpClient.settimeout(self._timeout)
await tcpClient.connect((self._host, self._port))
tcpClient.send(request)
Expand Down Expand Up @@ -71,7 +71,7 @@ async def get_status(self, version=47, strip_color=True) -> dict:

async def get_status_pre17(self, strip_color=True) -> dict:
"""Get ping info from a server that uses a version older than Minecraft 1.7"""
response = await TCPClient.communicate(self, b'\xFE\x01')
response = await TcpClient.communicate(self, b'\xFE\x01')

br = BinaryReader(response)
header = br.read_byte()
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/quake1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from opengsq.binary_reader import BinaryReader
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class Quake1(ProtocolBase):
Expand Down Expand Up @@ -89,7 +89,7 @@ def _get_player_match_collections(self, br: BinaryReader):

async def _connect_and_send(self, data):
header = b'\xFF\xFF\xFF\xFF'
response_data = await UDPClient.communicate(self, header + data + b'\x00')
response_data = await UdpClient.communicate(self, header + data + b'\x00')

# Remove the last 0x00 if exists (Only if Quake1)
if response_data[-1] == 0:
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/raknet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class Raknet(ProtocolBase):
Expand All @@ -16,7 +16,7 @@ class Raknet(ProtocolBase):

async def get_status(self) -> dict:
request = self.__ID_UNCONNECTED_PING + self.__TIMESTAMP + self.__OFFLINE_MESSAGE_DATA_ID + self.__CLIENT_GUID
response = await UDPClient.communicate(self, request)
response = await UdpClient.communicate(self, request)

br = BinaryReader(response)
header = br.read_bytes(1)
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/samp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import Socket, UDPClient
from opengsq.protocol_socket import Socket, UdpClient


class Samp(ProtocolBase):
Expand Down Expand Up @@ -55,7 +55,7 @@ async def __send_and_receive(self, data: bytes):
request = self._request_header + packet_header

# Validate the response
response = await UDPClient.communicate(self, request)
response = await UdpClient.communicate(self, request)
header = response[:len(self._response_header)]

if header != self._response_header:
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/satisfactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class Satisfactory(ProtocolBase):
Expand All @@ -19,7 +19,7 @@ async def get_status(self) -> dict:

# Send message id, protocol version
request = struct.pack('2b', 0, 0) + 'opengsq'.encode()
response = await UDPClient.communicate(self, request)
response = await UdpClient.communicate(self, request)
br = BinaryReader(response)
header = br.read_byte()

Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/scum.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import ServerNotFoundException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import Socket, TCPClient
from opengsq.protocol_socket import Socket, TcpClient


class Scum(ProtocolBase):
Expand Down Expand Up @@ -41,7 +41,7 @@ async def query_master_servers() -> list:

for host, port in Scum._master_servers:
try:
with TCPClient() as tcpClient:
with TcpClient() as tcpClient:
tcpClient.settimeout(5)
await tcpClient.connect((host, port))
tcpClient.send(b'\x04\x03\x00\x00')
Expand Down
10 changes: 5 additions & 5 deletions opengsq/protocols/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import AuthenticationException, InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import TCPClient, UDPClient
from opengsq.protocol_socket import TcpClient, UdpClient


class Source(ProtocolBase):
Expand Down Expand Up @@ -187,7 +187,7 @@ async def get_rules(self) -> dict:

async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:
# Connect to remote host
with UDPClient() as udpClient:
with UdpClient() as udpClient:
udpClient.settimeout(self._timeout)
await udpClient.connect((self._host, self._port))

Expand Down Expand Up @@ -217,7 +217,7 @@ async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:

return response_data

async def __receive(self, udpClient: UDPClient) -> bytes:
async def __receive(self, udpClient: UdpClient) -> bytes:
total_packets = -1
payloads = dict()
packets = list()
Expand Down Expand Up @@ -285,7 +285,7 @@ def __is_gold_source_split(self, br: BinaryReader):
# Check is it Gold Source packet split format
return number == 0 and br.read().startswith(b'\xFF\xFF\xFF\xFF')

async def __parse_gold_source_packet(self, udpClient: UDPClient, packets: list):
async def __parse_gold_source_packet(self, udpClient: UdpClient, packets: list):
total_packets = -1
payloads = dict()

Expand Down Expand Up @@ -346,7 +346,7 @@ async def authenticate(self, password: str):
"""Authenticate the connection"""

# Connect
self._tcpClient = TCPClient()
self._tcpClient = TcpClient()
self._tcpClient.settimeout(self._timeout)
await self._tcpClient.connect((self._host, self._port))

Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/teamspeak3.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import TCPClient
from opengsq.protocol_socket import TcpClient


class Teamspeak3(ProtocolBase):
Expand All @@ -23,7 +23,7 @@ async def get_channels(self):
return self.__parse_rows(response)

async def __send_and_receive(self, data: bytes):
with TCPClient() as tcpClient:
with TcpClient() as tcpClient:
tcpClient.settimeout(self._timeout)
await tcpClient.connect((self._host, self._port))

Expand Down
8 changes: 4 additions & 4 deletions opengsq/protocols/unreal2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import UDPClient
from opengsq.protocol_socket import UdpClient


class Unreal2(ProtocolBase):
Expand All @@ -15,7 +15,7 @@ class Unreal2(ProtocolBase):
_PLAYERS = 0x02

async def get_details(self):
response = await UDPClient.communicate(self, b'\x79\x00\x00\x00' + bytes([self._DETAILS]))
response = await UdpClient.communicate(self, b'\x79\x00\x00\x00' + bytes([self._DETAILS]))

# Remove the first 4 bytes \x80\x00\x00\x00
br = BinaryReader(response[4:])
Expand Down Expand Up @@ -56,7 +56,7 @@ async def get_details(self):
return details

async def get_rules(self):
response = await UDPClient.communicate(self, b'\x79\x00\x00\x00' + bytes([self._RULES]))
response = await UdpClient.communicate(self, b'\x79\x00\x00\x00' + bytes([self._RULES]))

# Remove the first 4 bytes \x80\x00\x00\x00
br = BinaryReader(response[4:])
Expand All @@ -83,7 +83,7 @@ async def get_rules(self):
return rules

async def get_players(self):
response = await UDPClient.communicate(self, b'\x79\x00\x00\x00' + bytes([self._PLAYERS]))
response = await UdpClient.communicate(self, b'\x79\x00\x00\x00' + bytes([self._PLAYERS]))

# Remove the first 4 bytes \x80\x00\x00\x00
br = BinaryReader(response[4:])
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/vcmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from opengsq.binary_reader import BinaryReader
from opengsq.exceptions import InvalidPacketException
from opengsq.protocol_base import ProtocolBase
from opengsq.protocol_socket import Socket, UDPClient
from opengsq.protocol_socket import Socket, UdpClient


class Vcmp(ProtocolBase):
Expand Down Expand Up @@ -46,7 +46,7 @@ async def __send_and_receive(self, data: bytes):
request = self._request_header + packet_header

# Validate the response
response = await UDPClient.communicate(self, request)
response = await UdpClient.communicate(self, request)
header = response[:len(self._response_header)]

if header != self._response_header:
Expand Down

0 comments on commit 1ad02d3

Please sign in to comment.