Skip to content

Commit

Permalink
Fix Teamspeak 3 Protocol
Browse files Browse the repository at this point in the history
Resolve the issue where the protocol does not fetch all the data completely.
  • Loading branch information
BattlefieldDuck committed Jan 17, 2024
1 parent fcef01a commit 9c78743
Show file tree
Hide file tree
Showing 4 changed files with 1,111 additions and 1,006 deletions.
13 changes: 8 additions & 5 deletions opengsq/protocols/teamspeak3.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ async def __send_and_receive(self, data: bytes):
await tcpClient.recv()

tcpClient.send(data + b'\x0A')
response = await tcpClient.recv()
response = b''

while not response.endswith(b'error id=0 msg=ok\n\r'):
response += await tcpClient.recv()

# Remove last bytes b'\n\rerror id=0 msg=ok\n\r'
return response[:-21]

def __parse_rows(self, response: bytes):
Expand All @@ -47,10 +51,9 @@ def __parse_kvs(self, response: bytes):
kvs = {}

for kv in response.split(b' '):
index = kv.find(b'=')
index = len(kv) if index == -1 else index
key = str(kv[:index], encoding='utf-8', errors='ignore')
val = str(kv[index+1:], encoding='utf-8', errors='ignore')
items = kv.split(b'=', 1)
key = str(items[0], encoding='utf-8', errors='ignore')
val = str(items[1], encoding='utf-8', errors='ignore') if len(items) == 2 else ""
kvs[key] = val.replace('\\p', '|').replace('\\s', ' ').replace('\\/', '/')

return kvs
Expand Down
Loading

0 comments on commit 9c78743

Please sign in to comment.