gamedig / rust-gamedig

Game Server Query Library.
https://crates.io/crates/gamedig
MIT License
38 stars 11 forks source link

Programmatic games by storing information as data #45

Closed Douile closed 1 year ago

Douile commented 1 year ago

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

CosminPerRam commented 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.

Douile commented 1 year ago

I like this idea, didn't think of that.

Douile commented 1 year ago

I created a table of all the response types: https://github.com/Douile/rust-gamedig/blob/dev-programmatic-games-2/RESPONSES.md

Douile commented 1 year ago

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:

Douile commented 1 year ago

Let me know if you want me to rebase this to make commits neater, if you're just going to squash its fine.

CosminPerRam commented 1 year ago

I'll squash it.

CosminPerRam commented 1 year ago

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!

Douile commented 1 year ago

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.