Closed Douile closed 1 year ago
... but the downside of cloning the response as I chose to include the original response type within the generic response.
Had a quick thought of making yet another struct for each protocol, something like a "NonGenericValveResponse" that would be the original struct, but without the fields that GenericResponse
uses, this would eliminate the need of cloning but I'm not sure if it is worth doing.
I like this idea, didn't think of that.
I created a table of all the response types: https://github.com/Douile/rust-gamedig/blob/dev-programmatic-games-2/RESPONSES.md
The only real remaining problem I see is generating the list of game definitions: I'm not sure I want to write all 52 manually.
The other stuff still to be done:
Let me know if you want me to rebase this to make commits neater, if you're just going to squash its fine.
I'll squash it.
Formatting seems to fail, could you look into it to make it pass? In rest, great job on managing the generic query and programmatic games, thank you a lot. I do have some ideas to expand on it and/or to make it more maintainable, but firstly, let's merge this!
Thank you. Nice, I'm planning on making another PR to add a way to generically access a list of players via a method implementation on the GenericResponse object after this is merged so let me know what changes are planned.
This PR adds the ability to store a game as a Game struct which has all the information we need to make a request for that game: default port, protocol (and protocol settings). It also has extra metadata.
In order to use the game structs with a common function a common return type had to be defined, here I chose to create a struct them implement from on other structs to convert them into the generic type. This has the benefit of not having to pass pointers around like if I had used traits but the downside of cloning the response as I chose to include the original response type within the generic response.
This draft only includes one game for each protocol for testing purposes, if everyone is happy I will go ahead and add the rest.
This would replace #42 however we could potentially use a similar build script to generate the game data structures e.g. from node-gamedig/games.txt
EDIT: in theory this could also replace the individual query functions for each specific game however it might be nice to keep them as they provide a way to easily get the specific response types.
EDIT: closes #36