Skip to content

Commit fa08d5e

Browse files
Better parameter naming
1 parent aac9ce4 commit fa08d5e

37 files changed

+76
-76
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import asyncio
5757
from opengsq.protocols import Source
5858

5959
async def main():
60-
source = Source(address='45.147.5.5', query_port=27015)
60+
source = Source(host='45.147.5.5', port=27015)
6161
info = await source.get_info()
6262
print(info)
6363

@@ -91,7 +91,7 @@ which makes it easy to query game servers from your terminal. Run
9191

9292
```sh
9393
# query server using source protocol
94-
opengsq source --address 123.123.123.123 --query_port 27015 --function get_info
94+
opengsq source --host 123.123.123.123 --port 27015 --function get_info
9595
```
9696

9797
## Tests and Results

opengsq/protocol_base.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class ProtocolBase(abc.ABC):
77
def full_name(self):
88
pass
99

10-
def __init__(self, address: str, query_port: int, timeout: float = 5.0):
11-
self._address = address
12-
self._query_port = query_port
10+
def __init__(self, host: str, port: int, timeout: float = 5.0):
11+
self._host = host
12+
self._port = port
1313
self._timeout = timeout

opengsq/protocols/ase.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ASE(ProtocolBase):
1414
async def get_status(self) -> dict:
1515
with SocketAsync() as sock:
1616
sock.settimeout(self._timeout)
17-
await sock.connect((self._address, self._query_port))
17+
await sock.connect((self._host, self._port))
1818

1919
# Send Request
2020
sock.send(self._request)
@@ -87,7 +87,7 @@ def __read_string(self, br: BinaryReader):
8787

8888
async def main_async():
8989
# mtasa
90-
ase = ASE(address='79.137.97.3', query_port=22126, timeout=10.0)
90+
ase = ASE(host='79.137.97.3', port=22126, timeout=10.0)
9191
status = await ase.get_status()
9292
print(json.dumps(status, indent=None) + '\n')
9393

opengsq/protocols/battlefield.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def get_players(self) -> list:
7373

7474
async def __get_data(self, request: bytes):
7575
kind = SocketKind.SOCK_STREAM
76-
response = await SocketAsync.send_and_receive(self._address, self._query_port, self._timeout, request, kind)
76+
response = await SocketAsync.send_and_receive(self._host, self._port, self._timeout, request, kind)
7777
return self.__decode(response)
7878

7979
def __decode(self, response: bytes):

opengsq/protocols/doom3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Doom3(ProtocolBase):
1818

1919
async def get_info(self, strip_color=True):
2020
request = b'\xFF\xFFgetInfo\x00ogsq\x00'
21-
response = await SocketAsync.send_and_receive(self._address, self._query_port, self._timeout, request)
21+
response = await SocketAsync.send_and_receive(self._host, self._port, self._timeout, request)
2222

2323
# Remove the first two 0xFF
2424
br = BinaryReader(response[2:])
@@ -104,17 +104,17 @@ def strip_colors(text: str):
104104

105105
async def main_async():
106106
# doom3
107-
doom3 = Doom3(address='66.85.14.240', query_port=27666, timeout=5.0)
107+
doom3 = Doom3(host='66.85.14.240', port=27666, timeout=5.0)
108108
info = await doom3.get_info()
109109
print(json.dumps(info, indent=None) + '\n')
110110

111111
# etqw
112-
doom3 = Doom3(address='178.162.135.83', query_port=27735, timeout=5.0)
112+
doom3 = Doom3(host='178.162.135.83', port=27735, timeout=5.0)
113113
info = await doom3.get_info()
114114
print(json.dumps(info, indent=None) + '\n')
115115

116116
# quake4
117-
doom3 = Doom3(address='88.99.0.7', query_port=28007, timeout=5.0)
117+
doom3 = Doom3(host='88.99.0.7', port=28007, timeout=5.0)
118118
info = await doom3.get_info()
119119
print(json.dumps(info, indent=None) + '\n')
120120

opengsq/protocols/gamespy1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ async def __connect_and_send(self, data) -> BinaryReader:
106106
# Connect to remote host
107107
with SocketAsync() as sock:
108108
sock.settimeout(self._timeout)
109-
await sock.connect((self._address, self._query_port))
109+
await sock.connect((self._host, self._port))
110110

111111
sock.send(data)
112112
br = BinaryReader(await self.__get_packets_response(sock))
@@ -179,10 +179,10 @@ def __parse_as_object(self, br: BinaryReader, is_player=False):
179179
import json
180180

181181
async def main_async():
182-
gs1 = GameSpy1(address='51.81.48.224', query_port=23000, timeout=5.0) # bfield1942
182+
gs1 = GameSpy1(host='51.81.48.224', port=23000, timeout=5.0) # bfield1942
183183
#gs1 = GameSpy1(address='139.162.235.20', query_port=7778, timeout=5.0) # ut
184184
#gs1 = GameSpy1(address='192.223.24.6', query_port=7778, timeout=5.0) # ut
185-
gs1 = GameSpy1(address='141.94.205.35', query_port=12300, timeout=5.0) # mohaa
185+
gs1 = GameSpy1(host='141.94.205.35', port=12300, timeout=5.0) # mohaa
186186
status = await gs1.get_status()
187187
print(json.dumps(status, indent=None) + '\n')
188188

opengsq/protocols/gamespy2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def get_status(self, request: Request = Request.INFO | Request.PLAYERS | R
1919
# Connect to remote host
2020
with SocketAsync() as sock:
2121
sock.settimeout(self._timeout)
22-
await sock.connect((self._address, self._query_port))
22+
await sock.connect((self._host, self._port))
2323

2424
# Send Request
2525
sock.send(b'\xFE\xFD\x00\x04\x05\x06\x07' + self.__get_request_bytes(request))
@@ -125,7 +125,7 @@ def __get_teams(self, br: BinaryReader) -> list:
125125
import json
126126

127127
async def main_async():
128-
gs2 = GameSpy2(address='158.69.118.94', query_port=23000, timeout=5.0)
128+
gs2 = GameSpy2(host='158.69.118.94', port=23000, timeout=5.0)
129129
status = await gs2.get_status()
130130
print(json.dumps(status, indent=None) + '\n')
131131

opengsq/protocols/gamespy3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async def get_status(self):
1616
# Connect to remote host
1717
with SocketAsync() as sock:
1818
sock.settimeout(self._timeout)
19-
await sock.connect((self._address, self._query_port))
19+
await sock.connect((self._host, self._port))
2020

2121
request_h = b'\xFE\xFD'
2222
timestamp = b'\x04\x05\x06\x07'
@@ -139,7 +139,7 @@ async def __read(self, sock) -> bytes:
139139
import json
140140

141141
async def main_async():
142-
gs3 = GameSpy3(address='185.107.96.59', query_port=29900, timeout=5.0)
142+
gs3 = GameSpy3(host='185.107.96.59', port=29900, timeout=5.0)
143143
server = await gs3.get_status()
144144
print(json.dumps(server, indent=None))
145145

opengsq/protocols/gamespy4.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class GameSpy4(GameSpy3):
1212
import json
1313

1414
async def main_async():
15-
gs4 = GameSpy4(address='188.18.10.72', query_port=19133, timeout=5.0)
15+
gs4 = GameSpy4(host='188.18.10.72', port=19133, timeout=5.0)
1616
server = await gs4.get_status()
1717
print(json.dumps(server, indent=None))
1818

opengsq/protocols/minecraft.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ async def get_status(self, version=47, strip_color=True) -> dict:
2424
"""
2525

2626
# Prepare the request
27-
address = self._address.encode('utf8')
27+
address = self._host.encode('utf8')
2828
protocol = self._pack_varint(version)
29-
request = b'\x00' + protocol + self._pack_varint(len(address)) + address + struct.pack('H', self._query_port) + b'\x01'
29+
request = b'\x00' + protocol + self._pack_varint(len(address)) + address + struct.pack('H', self._port) + b'\x01'
3030
request = self._pack_varint(len(request)) + request + b'\x01\x00'
3131

3232
with SocketAsync(SocketKind.SOCK_STREAM) as sock:
3333
sock.settimeout(self._timeout)
34-
await sock.connect((self._address, self._query_port))
34+
await sock.connect((self._host, self._port))
3535
sock.send(request)
3636

3737
response = await sock.recv()
@@ -72,7 +72,7 @@ async def get_status_pre17(self, strip_color=True) -> dict:
7272
"""Get ping info from a server that uses a version older than Minecraft 1.7"""
7373
with SocketAsync(SocketKind.SOCK_STREAM) as sock:
7474
sock.settimeout(self._timeout)
75-
await sock.connect((self._address, self._query_port))
75+
await sock.connect((self._host, self._port))
7676
sock.send(b'\xFE\x01')
7777
response = await sock.recv()
7878

@@ -141,7 +141,7 @@ def _unpack_varint(self, br: BinaryReader):
141141
import asyncio
142142

143143
async def main_async():
144-
minecraft = Minecraft(address='51.83.219.117', query_port=25565, timeout=5.0)
144+
minecraft = Minecraft(host='51.83.219.117', port=25565, timeout=5.0)
145145
status = await minecraft.get_status(47, strip_color=True)
146146
print(json.dumps(status, indent=None, ensure_ascii=False) + '\n')
147147
status = await minecraft.get_status_pre17()

opengsq/protocols/quake1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ class Quake1(ProtocolBase):
99
"""Quake1 Protocol"""
1010
full_name = 'Quake1 Protocol'
1111

12-
def __init__(self, address: str, query_port: int, timeout: float = 5.0):
12+
def __init__(self, host: str, port: int, timeout: float = 5.0):
1313
"""Quake1 Query Protocol"""
14-
super().__init__(address, query_port, timeout)
14+
super().__init__(host, port, timeout)
1515
self._delimiter1 = b'\\'
1616
self._delimiter2 = b'\n'
1717
self._request_header = b'status'
@@ -91,7 +91,7 @@ async def _connect_and_send(self, data):
9191
# Connect to remote host
9292
with SocketAsync() as sock:
9393
sock.settimeout(self._timeout)
94-
await sock.connect((self._address, self._query_port))
94+
await sock.connect((self._host, self._port))
9595

9696
header = b'\xFF\xFF\xFF\xFF'
9797

@@ -118,7 +118,7 @@ async def _connect_and_send(self, data):
118118
import json
119119

120120
async def main_async():
121-
quake1 = Quake1(address='35.185.44.174', query_port=27500, timeout=5.0)
121+
quake1 = Quake1(host='35.185.44.174', port=27500, timeout=5.0)
122122
status = await quake1.get_status()
123123
print(json.dumps(status, indent=None) + '\n')
124124

opengsq/protocols/quake2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class Quake2(Quake1):
88
"""Quake2 Protocol"""
99
full_name = 'Quake2 Protocol'
1010

11-
def __init__(self, address: str, query_port: int, timeout: float = 5.0):
11+
def __init__(self, host: str, port: int, timeout: float = 5.0):
1212
"""Quake2 Query Protocol"""
13-
super().__init__(address, query_port, timeout)
13+
super().__init__(host, port, timeout)
1414
self._response_header = 'print\n'
1515

1616
def _parse_players(self, br: BinaryReader) -> list:
@@ -40,7 +40,7 @@ def _parse_players(self, br: BinaryReader) -> list:
4040
import json
4141

4242
async def main_async():
43-
quake2 = Quake2(address='46.165.236.118', query_port=27910, timeout=5.0)
43+
quake2 = Quake2(host='46.165.236.118', port=27910, timeout=5.0)
4444
status = await quake2.get_status()
4545
print(json.dumps(status, indent=None) + '\n')
4646

opengsq/protocols/quake3.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ class Quake3(Quake2):
88
"""Quake3 Protocol"""
99
full_name = 'Quake3 Protocol'
1010

11-
def __init__(self, address: str, query_port: int, timeout: float = 5.0):
11+
def __init__(self, host: str, port: int, timeout: float = 5.0):
1212
"""Quake3 Query Protocol"""
13-
super().__init__(address, query_port, timeout)
13+
super().__init__(host, port, timeout)
1414
self._request_header = b'getstatus'
1515
self._response_header = 'statusResponse\n'
1616

@@ -67,7 +67,7 @@ def strip_colors(text: str):
6767
import json
6868

6969
async def main_async():
70-
quake3 = Quake3(address='85.10.197.106', query_port=27960, timeout=5.0)
70+
quake3 = Quake3(host='85.10.197.106', port=27960, timeout=5.0)
7171
info = await quake3.get_info()
7272
status = await quake3.get_status()
7373
print(json.dumps(info, indent=None) + '\n')

opengsq/protocols/raknet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Raknet(ProtocolBase):
1616

1717
async def get_status(self) -> dict:
1818
request = self.__ID_UNCONNECTED_PING + self.__TIMESTAMP + self.__OFFLINE_MESSAGE_DATA_ID + self.__CLIENT_GUID
19-
response = await SocketAsync.send_and_receive(self._address, self._query_port, self._timeout, request)
19+
response = await SocketAsync.send_and_receive(self._host, self._port, self._timeout, request)
2020

2121
br = BinaryReader(response)
2222
header = br.read_bytes(1)
@@ -66,7 +66,7 @@ async def get_status(self) -> dict:
6666
import json
6767

6868
async def main_async():
69-
raknet = Raknet(address='193.70.94.83', query_port=19132, timeout=5.0)
69+
raknet = Raknet(host='193.70.94.83', port=19132, timeout=5.0)
7070
status = await raknet.get_status()
7171
print(json.dumps(status, indent=None) + '\n')
7272

opengsq/protocols/samp.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ async def get_rules(self):
5050

5151
async def __send_and_receive(self, data: bytes):
5252
# Format the address
53-
host = SocketAsync.gethostbyname(self._address)
54-
packet_header = struct.pack('BBBBH', *map(int, host.split('.') + [self._query_port])) + data
53+
host = SocketAsync.gethostbyname(self._host)
54+
packet_header = struct.pack('BBBBH', *map(int, host.split('.') + [self._port])) + data
5555
request = self._request_header + packet_header
5656

5757
# Validate the response
58-
response = await SocketAsync.send_and_receive(self._address, self._query_port, self._timeout, request)
58+
response = await SocketAsync.send_and_receive(self._host, self._port, self._timeout, request)
5959
header = response[:len(self._response_header)]
6060

6161
if header != self._response_header:
@@ -73,7 +73,7 @@ def __read_string(self, br: BinaryReader, read_offset=1):
7373
import json
7474

7575
async def main_async():
76-
samp = Samp(address='51.254.178.238', query_port=7777, timeout=5.0)
76+
samp = Samp(host='51.254.178.238', port=7777, timeout=5.0)
7777
status = await samp.get_status()
7878
print(json.dumps(status, indent=None) + '\n')
7979
players = await samp.get_players()

opengsq/protocols/satisfactory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ async def get_status(self) -> dict:
1919

2020
# Send message id, protocol version
2121
request = struct.pack('2b', 0, 0) + 'opengsq'.encode()
22-
response = await SocketAsync.send_and_receive(self._address, self._query_port, self._timeout, request)
22+
response = await SocketAsync.send_and_receive(self._host, self._port, self._timeout, request)
2323
br = BinaryReader(response)
2424
header = br.read_byte()
2525

@@ -42,7 +42,7 @@ async def get_status(self) -> dict:
4242
import json
4343

4444
async def main_async():
45-
satisfactory = Satisfactory(address='delta3.ptse.host', query_port=15777, timeout=5.0)
45+
satisfactory = Satisfactory(host='delta3.ptse.host', port=15777, timeout=5.0)
4646
status = await satisfactory.get_status()
4747
print(json.dumps(status, indent=None) + '\n')
4848

opengsq/protocols/source.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ async def __connect_and_send_challenge(self, header: __RequestHeader) -> bytes:
189189
# Connect to remote host
190190
with SocketAsync() as sock:
191191
sock.settimeout(self._timeout)
192-
await sock.connect((self._address, self._query_port))
192+
await sock.connect((self._host, self._port))
193193

194194
# Send and receive
195195
request_base = b'\xFF\xFF\xFF\xFF' + header
@@ -348,7 +348,7 @@ async def authenticate(self, password: str):
348348
# Connect
349349
self._sock = SocketAsync(SocketKind.SOCK_STREAM)
350350
self._sock.settimeout(self._timeout)
351-
await self._sock.connect((self._address, self._query_port))
351+
await self._sock.connect((self._host, self._port))
352352

353353
# Send password
354354
id = random.randrange(4096)
@@ -459,7 +459,7 @@ def get_bytes(self):
459459
import json
460460

461461
async def main_async():
462-
source = Source(address='209.205.114.187', query_port=27015, timeout=5.0)
462+
source = Source(host='209.205.114.187', port=27015, timeout=5.0)
463463
info = await source.get_info()
464464
print(json.dumps(info, indent=None, ensure_ascii=False) + '\n')
465465
players = await source.get_players()

opengsq/protocols/teamspeak3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class Teamspeak3(ProtocolBase):
66
"""Teamspeak 3 Protocol"""
77
full_name = 'Teamspeak 3 Protocol'
88

9-
def __init__(self, address: str, query_port: int, voice_port: int, timeout: float = 5):
10-
super().__init__(address, query_port, timeout)
9+
def __init__(self, host: str, port: int, voice_port: int, timeout: float = 5):
10+
super().__init__(host, port, timeout)
1111
self._voice_port = voice_port
1212

1313
async def get_info(self):
@@ -25,7 +25,7 @@ async def get_channels(self):
2525
async def __send_and_receive(self, data: bytes):
2626
with SocketAsync(SocketKind.SOCK_STREAM) as sock:
2727
sock.settimeout(self._timeout)
28-
await sock.connect((self._address, self._query_port))
28+
await sock.connect((self._host, self._port))
2929

3030
# b'TS3\n\rWelcome to the TeamSpeak 3 ServerQuery interface,
3131
# type "help" for a list of commands and "help <command>" for information on a specific command.\n\r'
@@ -61,7 +61,7 @@ def __parse_kvs(self, response: bytes):
6161
import json
6262

6363
async def main_async():
64-
teamspeak3 = Teamspeak3(address='145.239.200.2', query_port=10011, voice_port=9987, timeout=5.0)
64+
teamspeak3 = Teamspeak3(host='145.239.200.2', port=10011, voice_port=9987, timeout=5.0)
6565
info = await teamspeak3.get_info()
6666
print(json.dumps(info, indent=None) + '\n')
6767
clients = await teamspeak3.get_clients()

0 commit comments

Comments
 (0)