Skip to content

Commit

Permalink
Update unreal2.py
Browse files Browse the repository at this point in the history
  • Loading branch information
BattlefieldDuck committed Jan 18, 2024
1 parent 224a194 commit f8e0160
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions opengsq/protocols/unreal2.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ async def get_players(self):
return players

@staticmethod
def strip_colors(text: bytes):
def strip_colors(text: str):
"""Strip color codes"""
return re.compile(b'\x1b...|[\x00-\x1a]').sub(b'', text)
return re.compile('\x1b...|[\x00-\x1a]').sub('', text)

def _read_string(self, br: BinaryReader):
length = br.read_byte()
b = br.read_bytes(length)
return Unreal2.strip_colors(b).decode('utf-8', 'ignore')

if length >= 128:
length = (length & 0x7f) * 2
encoding = 'utf-16'
else:
encoding = 'utf-8'

return Unreal2.strip_colors(br.read_bytes(length).decode(encoding, 'ignore'))


if __name__ == '__main__':
Expand All @@ -113,7 +119,7 @@ def _read_string(self, br: BinaryReader):

async def main_async():
# ut2004
unreal2 = Unreal2(host='109.230.224.189', port=6970, timeout=10.0)
unreal2 = Unreal2(host='109.230.224.189', port=6970)
details = await unreal2.get_details()
print(json.dumps(details, indent=None) + '\n')
rules = await unreal2.get_rules()
Expand Down

0 comments on commit f8e0160

Please sign in to comment.