discord-ghost icon indicating copy to clipboard operation
discord-ghost copied to clipboard

I fixed #31 for you (for the most part) (edit - for PC players)

Open ghost opened this issue 5 years ago • 9 comments

for reference: #31

I felt like this should be fixed so I found a way to fix it. It's fixed under the assumption that you're running discord, destiny, and this script on the same computer. I say for the most part because there isn't anything you can do when someone is starting up the game. The script sees the game running so it goes to the API to get their status (which is wrong). If they shut down the game or start the script before they launch destiny, it does not claim they are on destiny.

Changes:

  • New utility method called isRunning. It checks if a process is running. It's copy/paste from the example in the stack overflow post in #31, but it has the types defined so the noImplicitAny in your tsconfig can stay enabled. I don't know what the types for this line are so i just put them as any:

exec(cmd, function(err: any, stdout: any, stderr: any)

  • New discordRPC method called clearActivity. That clears the D2 activity in discord for us.
  • The Client's start method now calls isRunning to see if the game is running. If it is, then it does what you had before. If it isn't, it calls the new clearActivity method.

Example output:

C:\code\gitbase\discord-ghost>npm start

> @brakacai/[email protected] start C:\code\gitbase\discord-ghost
> node ./dist/index.js

Config file found
Starting service
Destiny2 is not running.
cleared rpc.
Destiny2 is not running.
cleared rpc.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
D2 is running! Lets do this.
Destiny2 is not running.
cleared rpc.
Destiny2 is not running.
cleared rpc.

Code is here: https://apx.gg/files/discord-ghost-src.zip

disclaimer - i'm a very experienced c# dev who has only dabbled in node.js. i do not know what i am doing, but i can make things work.

ghost avatar Jul 04 '19 23:07 ghost

Hey ! I'm quite interested, would you mind opening a PR so I can review that properly?

louis-bompart avatar Jul 05 '19 00:07 louis-bompart

I haven't used github since college so I might be doing this wrong, but it looks like I need write access to upload the new branch.

ghost avatar Jul 05 '19 02:07 ghost

nvm, figured it out. I made the pull request #49

It looks like visual studio's auto formatting messed with the spacing on the lines though so it isnt as easy to compare.

ghost avatar Jul 05 '19 02:07 ghost

i tried to make it easier to compare. i'm really just messing around at this point

https://github.com/Akumati1435/discord-ghost/compare/master...Akumati1435:master-with-VS-line-formatting?expand=1

that should show you the oppose of the changes. red is green and green is red

edit: nvm, this comparison thing broke.

ghost avatar Jul 05 '19 03:07 ghost

I forked your branch and I'm taking time to thinks this over properly. This change, semantically speaking, is a breaking change (change in behavior). So I want to fix this once and for all, for everyone.

My current idea is the following: Poke the API with an incremental delay (15s,30s,1m,2m,5m,15m,30m,1h,2h). If activity is detected then reset the delay. If no activity is detected after reaching the max delay, then start a final countdown of 24hrs. In the mean time, keep poking the API every MAX_DELAY (2hrs I'd say) If the player is playing on PC (membershipType===4), on destiny 2 exe launch(and only on launch, i.e. first detection), reset the final countdown and the delay. If the player quit the app (process not detected anymore), I'll certainly try to bust the cache (sorry Bungie!), now that I know it's possible. Thus allowing us to return to the routine (poke the api, increment timer and monitor process)

louis-bompart avatar Jul 05 '19 18:07 louis-bompart

Update, this one is almost next on my hit list. Sorry for the long wait, security and privacy were my upmost priorities

louis-bompart avatar Jul 17 '19 03:07 louis-bompart

It looks like everyone is doing a great job but I need to know what is happening?

Robinhubbard31 avatar Jul 18 '19 05:07 Robinhubbard31

Yes good job

sirloveshatambaya avatar Jul 18 '19 08:07 sirloveshatambaya

I'm not sure to understand your question @Robinhubbard31

louis-bompart avatar Jul 18 '19 12:07 louis-bompart