feat(protocols): Add more control over gathering additional information (#180)

* protocols: Add more control over gathering additional information

Adds GatherToggle which allows choosing the behaviour for how the query
handles fetching additional information. The choices are:
- DontGather - Don't attempt to fetch information
- AttemptGather - Try to fetch the information but ignore errors
- Required - Try to fetch information and fail if it errors

A handy macro was also added to utils to dispatch additional queries
based on a GatherToggle value.

* Add/Update badge

* protocols: Improve GatherToggle enum names

Co-Authored-By: Cain <75994858+cainthebest@users.noreply.github.com>
Co-Authored-By: CosminPerRam <cosmin.p@live.com>

* Add/Update badge

---------

Co-authored-by: GitHub Action <action@github.com>
Co-authored-by: Cain <75994858+cainthebest@users.noreply.github.com>
Co-authored-by: CosminPerRam <cosmin.p@live.com>
This commit is contained in:
Tom 2024-01-22 11:36:17 +00:00 committed by GitHub
parent 6d0c25d6ea
commit 89ed19f089
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 195 additions and 64 deletions

View file

@ -19,7 +19,7 @@ use crate::{
},
},
socket::{Socket, UdpSocket},
utils::{retry_on_timeout, u8_lower_upper},
utils::{maybe_gather, retry_on_timeout, u8_lower_upper},
GDErrorKind::{BadGame, Decompress, UnknownEnumCast},
GDResult,
};
@ -470,13 +470,13 @@ fn get_response(
Ok(Response {
info,
players: match gather_settings.players {
false => None,
true => Some(client.get_server_players(&engine, protocol)?),
},
rules: match gather_settings.rules {
false => None,
true => Some(client.get_server_rules(&engine, protocol)?),
},
players: maybe_gather!(
gather_settings.players,
client.get_server_players(&engine, protocol)
),
rules: maybe_gather!(
gather_settings.rules,
client.get_server_rules(&engine, protocol)
),
})
}