Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: Make An Announcement Web Request When Launching A Game #41

Open
v1605 opened this issue Aug 25, 2023 · 8 comments
Open

Request: Make An Announcement Web Request When Launching A Game #41

v1605 opened this issue Aug 25, 2023 · 8 comments

Comments

@v1605
Copy link

v1605 commented Aug 25, 2023

The idea for this feature is that when launching a game, the Mister could send a post request to a specific url(s) containing the core and game name being launched. This would allow users to integrate external services and sync them to Mister activity. For example, you could change smart lighting based on the games,or track games played in an external database.

@wizzomafizzo
Copy link
Owner

I like this idea a lot! It's definitely doable

This is the current payload for the /games/playing API endpoint. Would it be suitable for what you're imagining?

{
  "core": "PSX",
  "system": "PSX",
  "systemName": "Playstation",
  "game": "PSX/Crash Bandicoot.mgl",
  "gameName": "Crash Bandicoot"
}

I guess I can put an option in the remote.ini file to specify a url to post to

@v1605
Copy link
Author

v1605 commented Aug 26, 2023

Exactly the sort of request I was thinking of. I would maybe add two more fields "platform: mister" and possibly hostname. That way if this type of standard more prevalent, you can differentiate between different platforms and help if users have multi Mister setups.

@v1605
Copy link
Author

v1605 commented Aug 27, 2023

I also realized this could potentially be used in the Retrotink 4k via pico (depending on the cli). Per core and per game profiles for the Mister could be huge (and a fun project for me lol).

@wizzomafizzo
Copy link
Owner

Give this a try! Just replace your current remote.sh in the Script folder and it will auto-update later with the real release.

Create a file in the Scripts folder called remote.ini like this:

[remote]
announce_game_url=http://10.0.0.193:8080/

And then restart mister or do restart remote service from the settings page.

From then on it will send the POST payload to that address every time the game/core state changes. Below is the example data consumed by a dummy python server

image
remote.zip

@wizzomafizzo
Copy link
Owner

Oh and you must have the recents option enabled in the mister ini or else the game won't be detected only the core

@v1605
Copy link
Author

v1605 commented Aug 27, 2023

Thanks for getting a this up and running so fast! I was able to get a webhook up and running in home assistant to start looking at different automatons. I did notice some strange behavior when switching cores. For example

  1. Load up core: works perfectly
    {"platform":"MiSTer","hostname":"MiSTer","core":"SNES","system":"SNESMusic","systemName":"SNES Music","gamePath":"","gameFilename":".","gameName":""}

  2. Launch game: works perfectly
    {"platform":"MiSTer","hostname":"MiSTer","core":"SNES","system":"SNESMusic","systemName":"SNES Music","gamePath":"/media/fat/games/SNES/1 US - S/Super Mario World (USA).sfc","gameFilename":"Super Mario World (USA).sfc","gameName":"Super Mario World (USA)"}

  3. Switch to a different core: it sends two request, a duplicate of the one above and then one with the new core but old game
    {"platform":"MiSTer","hostname":"MiSTer","core":"SNES","system":"SNESMusic","systemName":"SNES Music","gamePath":"/media/fat/games/SNES/1 US - S/Super Mario World (USA).sfc","gameFilename":"Super Mario World (USA).sfc","gameName":"Super Mario World (USA)"} {"platform":"MiSTer","hostname":"MiSTer","core":"PSX","system":"PSX","systemName":"Playstation","gamePath":"/media/fat/games/SNES/1 US - S/Super Mario World (USA).sfc","gameFilename":"Super Mario World (USA).sfc","gameName":"Super Mario World (USA)"}

  4. Launch game on new core: again two requests with the first blanking out the name and the second with the new game
    {"platform":"MiSTer","hostname":"MiSTer","core":"PSX","system":"PSX","systemName":"Playstation","gamePath":"","gameFilename":".","gameName":""} {"platform":"MiSTer","hostname":"MiSTer","core":"PSX","system":"PSX","systemName":"Playstation","gamePath":"/media/fat/games/PSX/bin/Ape Escape (USA)/Ape Escape (USA)/Ape Escape (USA).cue","gameFilename":"Ape Escape (USA).cue","gameName":"Ape Escape (USA)"}

@wizzomafizzo
Copy link
Owner

Unfortunately, that is just how it works. MiSTer's own reporting of launched games and cores are wildly out of sync with each other

I could come up with some sort of buffering for it to make them look in sync, but it's not a 10 minute job like this was. I would say give it a shot how it is, and then let me know what features you want to see added that are stopping automations from working

One thing missing from this payload is the intention of the event that triggered it. For other apps they normally also know this event is because a core was stopped/started or a game was stopped/started

@v1605
Copy link
Author

v1605 commented Aug 27, 2023

Understood. Nothing should block any automation, just adding a debounce to the home assistant side should be enough to filter out the double requests and as long as I keep track of the current game, everything should work fine. The intent would be a neat addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants