Skip to content

Commit

Permalink
FIX: add more logability to #9 issue
Browse files Browse the repository at this point in the history
This may provide a possible fix, I still cannot reproduce the error naturally, but have an idea why it might occur.

I made some tests cases on my end to test, and now added more loggers to narrow down the problem in case it happens again.
  • Loading branch information
Bratah123 committed Feb 1, 2024
1 parent 81a6e80 commit c0f085a
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,22 @@ def online(self) -> tuple[dict[str, str], str]:
error_message = ""
# format output
if res: # "name,playeruid,steamid\n" this is the header
lines = res.split()[1:] # remove the header
lines = res.split('\n')[1:] # remove the header
for line in lines:
words = line.split(",")
if len(words) != 3:
words = line.split(",")[0:-1] # remove the last element, which is an empty string
if len(words) < 3:
log.error(f'Unable to parse player info for player: {words}')
break

ign = words[0]
steam_id = words[2]

if len(words) > 3:
log.debug(f'Ran into a player with more than 3 points of data during parsing: {words}')
# If the player name has a comma, the split will produce more than 3 words
ign = ",".join(words[0:-2])
steam_id = words[-1]

players[steam_id] = ign
else:
error_message = self.GENERIC_ERROR
Expand Down Expand Up @@ -247,5 +256,7 @@ async def force_stop(self):
return res if res else self.GENERIC_ERROR

if __name__ == "__main__":
send_command_fallback("ShowPlayers")
client = Client()
players, error = client.online()
print(players)
logger.shutdown_logger()

0 comments on commit c0f085a

Please sign in to comment.