From ab9881a85c5776f05ad741be841c7e4e1ab2e403 Mon Sep 17 00:00:00 2001 From: Letter N <24603524+LetterN@users.noreply.github.com> Date: Mon, 25 Mar 2019 14:45:02 +0800 Subject: [PATCH 1/3] upgrades main.py --- .gitignore | 4 ++++ config.py | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee1f428 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +# Ignores vs code config +.vscode/ +# Ignores local cached file +__pycache__/ diff --git a/config.py b/config.py index 6aed05e..e473f5b 100644 --- a/config.py +++ b/config.py @@ -3,19 +3,19 @@ "Goonstation RP #1": ["Goonstation RP #1", "goonhub", "goon1.goonhub.com", 26100, "fetch"], "Yogstation 13": ["Yogstation 13", "yogstation", "game.yogstation.net", 4133, "fetch"], "BeeStation 13": ["BeeStation", "beestation", "198.58.107.171", 3333, "fetch"], - "ss13": ["Unknown Server", "ss13"], "Oracle Station | Medium RP": ["Oracle Station", "oraclestation"], #"byond.oraclestation.com", 5000 "Hippie Station": ["Hippie Station", "hippiestation", "62.210.11.24", 1337, "fetch"], - "/tg/Station Bagil": ["Station Bagil", "tgstation", "bagil.aws.tgstation13.org", 2337, "fetch"], - "/tg/Station Sybil": ["Station Sybil", "tgstation", "sybil.aws.tgstation13.org", 1337, "fetch"], - "/tg/Station Terry": ["Station Terry", "tgstation", "terry.tgstation13.org", 3337, "fetch"], + "/tg/Station Bagil": ["Bagil Station", "tgstation", "bagil.tgstation13.org", 2337, "fetch"], + "/tg/Station Sybil": ["Sybil Station", "tgstation", "sybil.tgstation13.org", 1337, "fetch"], + "/tg/Station Terry": ["Terry Station", "tgstation", "terry.tgstation13.org", 3337, "fetch"], + "TerraGov Marine Corps": ["TGMC", "tgmc", "tgmc.tgstation13.org", 5337, "fetch"], "[99% FREE LAG] Convict Conclave": ["Convict Conclave", "ss13"], "[ss13.ru] Yellow Circus": ["Yellow Circus", "ss13"], "Persistence Station 13": ["Persistence Station", "persistence"], "Apollo Gaming": ["Apollo Gaming","apollo"], "Lebensraum Alpha": ["Lebensraum Alpha", "ss13"], - "Baystation 12": ["Baystation 12", "bs12", "https://baystation12.net/status.dat", 80, "http"], - "FTL13": ["FTL13", "ftl13", "ftl13.com", 7777, "fetch"], + "Baystation 12": ["Baystation 12", "bs12", "baystation12.net/status.dat", 80, "http"], + "FTL13": ["FTL13", "ftl13", "stable.ftl13.com", 7777, "fetch"], "Tool Box Station": ["Toolbox Station", "toolbox"], "Pressurized Roleplay": ["Pressurized Roleplay", "pressure"], "StarTrek13": ["Star Trek 13", "startrek"], @@ -24,8 +24,9 @@ "Aurora Station": ["Aurora Station", "ss13"], "VOREStation": ["VOREStation", "citadel", "citadel-station.net", 44150, "fetch"], "Citadel Station 13": ["Citadel Station", "citadel", "citadel-station.net", 44130, "fetch"], - "Colonial Marines": ["Colonial Marines", "cm"] + "Colonial Marines": ["Colonial Marines", "cm"], + "ss13": ["Unknown Server", "ss13"] } - -client_id = "440289271580983308" +# formula: "Server Name": ["Big text name", "icon", "ip", port] +client_id = "440289271580983308" \ No newline at end of file From 367afe6be98f045ad5c15b2de0678bf570dece8b Mon Sep 17 00:00:00 2001 From: Letter N <24603524+LetterN@users.noreply.github.com> Date: Mon, 25 Mar 2019 14:45:52 +0800 Subject: [PATCH 2/3] adds more fancy shjhit --- main.py | 239 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 125 insertions(+), 114 deletions(-) diff --git a/main.py b/main.py index 505bee1..d4592ac 100644 --- a/main.py +++ b/main.py @@ -11,119 +11,130 @@ import webbrowser if "join" in sys.argv: - print("joining game...") - def join(ev): - ie = webbrowser.get(webbrowser.iexplore) - ie.open('google.com') - rp = pypresence.Client(client_id) - rp.start() - print(rp.read()) - rp.register_event("ACTIVITY_JOIN", join) - rp.loop.run_forever() + print("joining game...") + def join(ev): + ie = webbrowser.get(webbrowser.BackgroundBrowser) + ie.open('') #py 3.6 breaks this + rp = pypresence.Client(client_id) + rp.start() + print(rp.read()) + rp.register_event("ACTIVITY_JOIN", join) + rp.loop.run_forever() else: - - while True: - try: - rp = pypresence.Client(client_id) - rp.start() - break - except: - time.sleep(20) - - - - - - def get_hwnds_for_pid (pid): - def callback (hwnd, hwnds): - if win32gui.IsWindowVisible (hwnd) and win32gui.IsWindowEnabled (hwnd): - _, found_pid = win32process.GetWindowThreadProcessId (hwnd) - if found_pid == pid: - hwnds.append (hwnd) - return True - - hwnds = [] - win32gui.EnumWindows (callback, hwnds) - return hwnds - - - - def get_server(): - - p = [proc for proc in psutil.process_iter() if proc.name() == "dreamseeker.exe"] - - p = p[0] - - windows=get_hwnds_for_pid(p.pid) - - - windowtitles = [i for i in [str(win32gui.GetWindowText(item)) - for item in windows] if i != ""] - - - for title in windowtitles: - if not title == "Space Station 13": - for i in servers.keys(): - if title.startswith(i): - - return servers[i] - - else: - server = "ss13" - return servers[server] - - - while True: - try: - server = get_server() - activity = {"state": server[0], "large_text": server[0], "large_image":server[1]} - if len(server) == 5: - try: - if server[4] == "fetch": - status = util.fetch(server[2], server[3], "status") - elif server[4] == "http": - status = requests.get(server[2]).json() - - if server[0] in ["Baystation 12"]: - details = status["map"]+" | "+str(status["players"])+" players" - - elif server[0] in ["Goonstation #2","Goonstation RP #1", "Hippie Station", "BeeStation", "FTL13", "Station Bagil", "Station Terry", "Station Sybil", "Citadel Station", "Yogstation 13"]: - activity["details"] = status["map_name"]+" | "+str(status["players"])+" players" - - if server[0] in ["Goonstation #2","Goonstation RP #1"]: - activity["start"] = int(time.time())-int(status["elapsed"]) - - elif server[0] in ["Hippie Station", "BeeStation", "FTL13", "Station Bagil", "Station Terry", "Station Sybil", "Citadel Station", "Yogstation 13"]: - activity["start"] = int(time.time())-int(status["round_duration"]) - - except Exception as E: - pass - - - #activity["party_id"] = "234412341" - #activity["join"] = "432452421342" - #activity["party_size"] = [1,4] - #activity["match"] = "23431234" - #activity["instance"] = True - #activity["spectate"] = "53242523421" - - rp.set_activity(**activity) - - time.sleep(15) - - except Exception as e: - print(e) - time.sleep(10) - try: - rp.clear_activity() - time.sleep(5) - except Exception as e: - print(e) - while True: - try: - rp = pypresence.Client(client_id) - rp.start() - break - except: - time.sleep(20) + while True: + try: + rp = pypresence.Client(client_id) + rp.start() + break + except: + time.sleep(15) + + def get_hwnds_for_pid (pid): + def callback (hwnd, hwnds): + if win32gui.IsWindowVisible (hwnd) and win32gui.IsWindowEnabled (hwnd): + _, found_pid = win32process.GetWindowThreadProcessId (hwnd) + if found_pid == pid: + hwnds.append (hwnd) + return True + hwnds = [] + win32gui.EnumWindows (callback, hwnds) + return hwnds + + def get_server(): + p = [proc for proc in psutil.process_iter() if proc.name() == "dreamseeker.exe"] + p = p[0] + + windows=get_hwnds_for_pid(p.pid) + windowtitles = [i for i in [str(win32gui.GetWindowText(item)) + for item in windows] if i != ""] + for title in windowtitles: + if not title == "Space Station 13": + for i in servers.keys(): + if title.startswith(i): + return servers[i] + else: + server = "ss13" + return servers[server] + + while True: + try: + server = get_server() + activity = {"large_text": server[0], "large_image":server[1]} + if len(server) >= 5: + try: + if server[4] == "fetch": + status = util.fetch(server[2], server[3], "status") + print("Status (fetch): "+str(status)) + elif server[4] == "http": + status = requests.get(server[2]).json() + print("Status (http): "+str(status)) + + if server[0] in ["Bagil Station", "Terry Station", "Sybil Station", "Citadel Station", "FTL13"]: + activity["start"] = int(time.time())-int(status["round_duration"]) + activity["party_id"] = str(status["round_id"]) + " | " + status["map_name"] #apparently terry has NO revision + #activity["join"] = party id + server name + #activity["spectate"] = party id + server name + + if status["round_id"]: #check if round id is avalable + activity["details"] = "Map: "+status["map_name"]+" | Gamemode: "+status["mode"]+" | Round id: "+str(status["round_id"]) + else: + activity["details"] = "Map: "+status["map_name"]+" | Gamemode: "+status["mode"] + + if status["popcap"]: #fetch popcap + activity["party_size"] = [int(status["players"])] + [int(status["popcap"])] + + actualstatus = int(status["gamestate"]) + if actualstatus == 0: #0: init, 1:lobbywait 2:start + activity["state"] = "Initializing game" + activity["instance"] = False + elif actualstatus == 1: + activity["state"] = "Waiting on Lobby" + activity["instance"] = True + elif actualstatus == 2: + activity["state"] = "Starting" + elif actualstatus == 3: + activity["state"] = "Started" + elif actualstatus == 4: + activity["state"] = "Round ended!" + activity["instance"] = False + + if server[0] in ["Baystation 12"]: + activity["details"] = "Map: "+status["map"]+" | Players"+str(status["players"]) + elif server[0] in ["Goonstation #2","Goonstation RP #1", "Hippie Station", "BeeStation", "Yogstation 13"]: + activity["details"] = "Map: "+status["map_name"]+" | Players"+str(status["players"]) + elif server[0] in ["VOREStation"]: #apparently this fucker dosen't return map data + activity["details"] = "Gamemode: "+status["mode"]+" | Players"+status["players"] + + if server[0] in ["Goonstation #2","Goonstation RP #1"]: + activity["start"] = int(time.time())-int(status["elapsed"]) + elif server[0] in ["Hippie Station", "BeeStation", "Yogstation 13"]: + activity["start"] = int(time.time())-int(status["round_duration"]) + elif server[0] in ["VOREStation"]: #andd also it fucking returns time (in string) not in VARS! + ittimetostop = status["roundduration"] + ittimetostop = ittimetostop.split(':') + activity["start"] = int(time.time())-(int(ittimetostop[0]) + int(ittimetostop[1])) + + except Exception as E: + print(E) + pass + + rp.set_activity(**activity) + print(str(activity)) + time.sleep(15) + + except Exception as e: + print(e) + time.sleep(10) + try: + rp.clear_activity() + time.sleep(5) + except Exception as e: + print(e) + while True: + try: + rp = pypresence.Client(client_id) + rp.start() + break + except: + time.sleep(20) \ No newline at end of file From cc46d6257282d8eade4133e19ee51299aec595f6 Mon Sep 17 00:00:00 2001 From: Letter N <24603524+LetterN@users.noreply.github.com> Date: Mon, 25 Mar 2019 17:23:59 +0800 Subject: [PATCH 3/3] forgot about this --- main.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.py b/main.py index d4592ac..ada9488 100644 --- a/main.py +++ b/main.py @@ -83,6 +83,8 @@ def get_server(): if status["popcap"]: #fetch popcap activity["party_size"] = [int(status["players"])] + [int(status["popcap"])] + else: #best guess maxcap + activity["party_size"] = [int(status["players"])] + [90] actualstatus = int(status["gamestate"]) if actualstatus == 0: #0: init, 1:lobbywait 2:start