Skip to content

Commit

Permalink
Update protocols
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 16, 2024
1 parent 71f46f7 commit dca8223
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions opengsq/binary_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def __init__(self, data: bytes):
self.__data = data
self.stream_position = 0

def length(self) -> int:
def remaining_bytes(self) -> int:
return len(self.__data) - self.stream_position

def is_end(self) -> int:
return self.stream_position >= len(self.__data) - 1
return self.stream_position >= len(self.__data)

def prepend_bytes(self, data):
self.__data = data + self.__data
Expand Down Expand Up @@ -58,7 +58,7 @@ def read_float(self) -> float:
def read_string(self, delimiters=[b'\x00'], encoding='utf-8', errors='ignore') -> str:
bytes_string = b''

while self.length() > 0:
while self.remaining_bytes() > 0:
stream_byte = bytes([self.read_byte()])

if stream_byte in delimiters:
Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/doom3.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ async def get_info(self, strip_color=True):
info['version'] = f'{major}.{minor}'

# Read packet size
if br.read_long() != br.length():
if br.read_long() != br.remaining_bytes():
br.stream_position -= 4

# Key / value pairs, delimited by an empty pair
while br.length() > 0:
while br.remaining_bytes() > 0:
key = br.read_string().strip()
val = br.read_string().strip()

Expand Down
4 changes: 2 additions & 2 deletions opengsq/protocols/gamespy1.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __parse_as_key_values(self, br: BinaryReader, is_status=False):
kv = {}

# Bind key value
while br.length() > 0:
while br.remaining_bytes() > 0:
key = br.read_string(b'\\').lower()

# Check is the end of key_values
Expand All @@ -137,7 +137,7 @@ def __parse_as_key_values(self, br: BinaryReader, is_status=False):
def __parse_as_object(self, br: BinaryReader, is_player=False):
items, keyhashes, filters = {}, [], []

while br.length() > 0:
while br.remaining_bytes() > 0:
# Get the key, for example player_1, frags_1, ping_1, etc...
key = br.read_string(b'\\').lower()

Expand Down
6 changes: 3 additions & 3 deletions opengsq/protocols/gamespy2.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __get_info(self, br: BinaryReader) -> dict:
info = {}

# Read all key values
while br.length() > 0:
while br.remaining_bytes() > 0:
key = br.read_string()

if key == '':
Expand All @@ -71,7 +71,7 @@ def __get_players(self, br: BinaryReader) -> list:
# Get all keys
keys = []

while br.length() > 0:
while br.remaining_bytes() > 0:
key = br.read_string()

if key == '':
Expand All @@ -97,7 +97,7 @@ def __get_teams(self, br: BinaryReader) -> list:
# Get all keys
keys = []

while br.length() > 0:
while br.remaining_bytes() > 0:
key = br.read_string()

if key == '':
Expand Down
2 changes: 1 addition & 1 deletion opengsq/protocols/quake1.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _parse_info(self, br: BinaryReader) -> dict:
info = {}

# Read all key values until meet \n
while br.length() > 0:
while br.remaining_bytes() > 0:
key = br.read_string(self._delimiter1)

if key == '':
Expand Down
2 changes: 1 addition & 1 deletion opengsq/protocols/scum.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def query_master_servers() -> list:
total = br.read_short()

# server bytes length always 127
while br.length() >= 127:
while br.remaining_bytes() >= 127:
server = {}
server['ip'] = '.'.join(map(str, reversed([br.read_byte(), br.read_byte(), br.read_byte(), br.read_byte()])))
server['port'] = br.read_short()
Expand Down
2 changes: 1 addition & 1 deletion opengsq/protocols/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async def get_players(self) -> list:
player['Duration'] = br.read_float()
players.append(player)

if br.length() > 0:
if br.remaining_bytes() > 0:
for i in range(player_count):
players[i]['Deaths'] = br.read_long()
players[i]['Money'] = br.read_long()
Expand Down
2 changes: 1 addition & 1 deletion opengsq/protocols/unreal2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async def get_details(self):
details['NumPlayers'] = br.read_long()
details['MaxPlayers'] = br.read_long()

if br.length() > 12:
if br.remaining_bytes() > 12:
try:
# Killing Floor
stream_position = br.stream_position
Expand Down

0 comments on commit dca8223

Please sign in to comment.