From d70acd840aec24a72855d3daa8321f4bd1177f3c Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Thu, 19 Oct 2023 10:40:56 +0200 Subject: simplify server fetching logic --- south_browser/rpc.py | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/south_browser/rpc.py b/south_browser/rpc.py index fe76829..db87d35 100644 --- a/south_browser/rpc.py +++ b/south_browser/rpc.py @@ -49,21 +49,19 @@ def NSGetServerCount(repeat: bool = True): def NSGetGameServers(): # work around Squirrel closure bullshit server_count = NSGetServerCount() + if not server_count: + return [] - for i in range(server_count): + primret = [] + for c in range(server_count): + primret.append(f"[s[{c}].index, s[{c}].id, s[{c}].name, s[{c}].description, s[{c}].map, s[{c}].playlist, s[{c}].playerCount, s[{c}].maxPlayerCount, s[{c}].requiresPassword, s[{c}].region]") - primret = [] + ret = "[" + ",".join(primret) + "]" - for c in range(server_count): - primret.append(f"[s[{c}].index, s[{c}].id, s[{c}].name, s[{c}].description, s[{c}].map, s[{c}].playlist, s[{c}].playerCount, s[{c}].maxPlayerCount, s[{c}].requiresPassword, s[{c}].region]") - - ret = "[" + ",".join(primret) + "]" - - return cmd("execute_squirrel", { - "code": f"array s = NSGetGameServers()\nreturn {ret}" - })["result"] + return cmd("execute_squirrel", { + "code": f"array s = NSGetGameServers()\nreturn {ret}" + })["result"] - return [] def NSTryAuthWithServer(index: int, password: str = None): if password is None: -- cgit v1.2.3