Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
Fixes #3 + misc changes
Browse files Browse the repository at this point in the history
added discord app media
changed presence text a bit
avoid using timer.sleep
shorter toasts
more info in readme
  • Loading branch information
Tenrys committed Mar 29, 2018
1 parent 840a335 commit a495a12
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ csgo_richpresence.spec
csgo_richpresence.exe
csgo_richpresence_installer.spec
csgo_richpresence_installer.exe
discordapp
zip.exe
Thumbs.db
desktop.ini
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ Once you feed CS:GO a specific and custom configuration file, it will start send

## Manual:

1. Place the `gamestate_integration_discordrpc.cfg` file from this repository in the `cfg` folder located in your game's installation directory. The game should now be trying to send info to the program when you restart it. (port `3000` is used by default in both the file and program)
1. Place the `gamestate_integration_discordrpc.cfg` file from this repository in the `cfg` folder located in your game's installation directory. *(Default, on Windows: `C:\Program Files (x86\Steam\steamapps\common\Counter-Strike Global Offensive\csgo\cfg`)* The game should now be trying to send info to the program when you restart it. (port `3000` is used by default in both the file and program)
2. Launch the program, **keep it open until you're done playing**.
- If you don't want to install Python and everything else, use the [latest release](https://github.com/Tenrys/csgo_richpresence/releases/latest)'s executable.

Your Discord status will now change according to what is happening in the game!

You don't need to setup your own Discord application, but I've included some the assets I've used for it if you need to.
If you're a developer you should be able to understand how to figure everything out starting from [your Discord applications page](https://discordapp.com/developers/applications/me).
The team icons are named `ct` and `t` and are considered small images. The map icons are just taken from the game's original maps folder, are considered large images and are named all lowercase based on the map's file name.

## Command line options:

### Main program:
Expand All @@ -68,3 +72,4 @@ Keep in mind this is meant to be a fun project for me to improve my Python skill

- More support for other operating systems?
- Avoid using more than one tray icon (currently win10toaster creates an extra for every notificaton)
- Figure out how to add "Ask to Join" and "Spectate" features (probably won't be allowed to just yet)
Binary file added discordapp/app_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added discordapp/csgo_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added discordapp/ct_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added discordapp/t_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 44 additions & 36 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
from http.server import BaseHTTPRequestHandler, HTTPServer
import json

want_exit = False
def exit():
print("Exiting...")
sys.exit()
def state_exit(*args, **kwargs):
global want_exit
want_exit = True



phases = {
"freezetime": "freeze time",
"live": "playing",
"over": "round over"
"over": "round over",
"warmup": "warmup"
}
modes = {
"casual": "Casual",
Expand Down Expand Up @@ -39,6 +48,9 @@ def __init__(self, *args, **kwargs):
HTTPServer.__init__(self, *args, **kwargs)

def service_actions(self):
if want_exit:
self.server_close()
exit()
running = False
for pid in psutil.pids():
try:
Expand Down Expand Up @@ -90,14 +102,14 @@ def handle_json(self, data):
team_text = "Terrorist"
else:
team_text = "Spectator" # never seen unless I add an icon
team_text += " - " + str(state["health"]) + " HP, " + str(state["armor"]) + " Armor"
# team_text += " - " + str(state["health"]) + " HP, " + str(state["armor"]) + " Armor"
team_text += " - $" + str(state["money"])

# player stats info
stats_text = str(match_stats["kills"]) + "|"
stats_text += str(match_stats["assists"]) + "|"
stats_text += str(match_stats["deaths"]) + " - "
stats_text = str(match_stats["kills"]) + "K / "
stats_text += str(match_stats["assists"]) + "A /"
stats_text += str(match_stats["deaths"]) + "D / "
stats_text += str(match_stats["mvps"]) + " MVPs"
stats_text += " - $" + str(state["money"])

# compile activity dict
activity = {
Expand Down Expand Up @@ -163,13 +175,7 @@ def do_POST(self):
def notify(msg):
print(msg)
if toaster: # silent mode only
toaster.show_toast(icon_path="icon.ico", title=our_name, msg=msg, duration=10, threaded=True)

def exit():
notify("Exiting...")
if systray: # silent mode only
systray.shutdown()
sys.exit()
toaster.show_toast(icon_path="icon.ico", title=our_name, msg=msg, duration=5, threaded=True)

parser = argparse.ArgumentParser(prog="csgo_richpresence")
parser.add_argument("-S", "--silent", action="store_true", default=False, help="hide the console window entirely, leaving the program to run in the background (Windows only)")
Expand Down Expand Up @@ -230,44 +236,46 @@ def hide_window(pid):
hide_window(our_process.parent().parent().pid) # fuck it, why not

toaster = ToastNotifier()
systray = SysTrayIcon("icon.ico", our_name, on_quit=exit)
systray = SysTrayIcon("icon.ico", our_name, on_quit=state_exit)
systray.start()

server_address = ("127.0.0.1", port)
httpd = None
next_csgo_check = 0
try:
notify("Discord Rich Presence for CS:GO is now running in the background.")
while True:
print("Looking for csgo.exe...")
found_csgo = False
for pid in psutil.pids():
try: # same as for enum_window_callback
p = psutil.Process(pid)
if p.name() == "csgo.exe":
found_csgo = True
break
except:
# print("Something could have gone wrong here while finding csgo.exe, ignore this")
pass
if found_csgo:
notify("Found csgo.exe, running server.")
if systray:
systray.update(hover_text=our_name + ": running")

httpd = CSGOGameStateServer(server_address, CSGOGameStateRequestHandler)
print("Starting httpd at {}:{}".format(server_address[0], port))
httpd.serve_forever()
time.sleep(30)
if want_exit:
exit()
if next_csgo_check < time.time():
print("Looking for csgo.exe...")
found_csgo = False
for pid in psutil.pids():
try: # same as for enum_window_callback
p = psutil.Process(pid)
if p.name() == "csgo.exe":
found_csgo = True
break
except:
# print("Something could have gone wrong here while finding csgo.exe, ignore this")
pass
if found_csgo:
notify("Found csgo.exe, running server.")
if systray:
systray.update(hover_text=our_name + ": running")

httpd = CSGOGameStateServer(server_address, CSGOGameStateRequestHandler)
print("Starting httpd at {}:{}".format(server_address[0], port))
httpd.serve_forever()
next_csgo_check = time.time() + 30
except KeyboardInterrupt:
if httpd:
print('Stopping httpd...')
httpd.server_close()

exit()
except Exception as e:
notify("Error: " + str(e))
input("Press Enter to quit.")

exit()

# so many try statements in this script jesus fuck i don't know how to code
Expand Down

0 comments on commit a495a12

Please sign in to comment.