[Protocol] Fix an instance of unwrapping in The Ship

This commit is contained in:
CosminPerRam 2023-08-17 23:08:59 +03:00
parent 7e028ce97d
commit a8fc67412c
2 changed files with 8 additions and 5 deletions

View file

@ -8,9 +8,11 @@ Protocols:
- Valve: Added the field `check_app_id` to `GatherSettings` which controls if the app id specified to the request and
reported by the server are the same, errors if not, enabled by default.
- Valve: Fixed `player`'s `score` field being `u32` when it needed to be `i32`, as specified in the protocol.
- The Ship: Fixed some instances of using `unwrap` without handling the panics.
Crate:
- Rich errors, capturing backtrace is done on `RUST_BACKTRACE=1`.
- Applied some nursery Clippy lints.
### Breaking...
Protocols:

View file

@ -4,6 +4,7 @@ use crate::{
valve::{self, get_optional_extracted_data, Server, ServerPlayer, SteamApp},
GenericResponse,
},
GDErrorKind::PacketBad,
GDResult,
};
use std::net::{IpAddr, SocketAddr};
@ -90,12 +91,12 @@ impl CommonResponse for Response {
}
impl Response {
pub fn new_from_valve_response(response: valve::Response) -> Self {
pub fn new_from_valve_response(response: valve::Response) -> GDResult<Self> {
let (port, steam_id, tv_port, tv_name, keywords) = get_optional_extracted_data(response.info.extra_data);
let the_unwrapped_ship = response.info.the_ship.unwrap(); // TODO! Err here!
let the_unwrapped_ship = response.info.the_ship.ok_or(PacketBad)?;
Self {
Ok(Self {
protocol_version: response.info.protocol_version,
name: response.info.name,
map: response.info.map,
@ -122,7 +123,7 @@ impl Response {
mode: the_unwrapped_ship.mode,
witnesses: the_unwrapped_ship.witnesses,
duration: the_unwrapped_ship.duration,
}
})
}
}
@ -140,5 +141,5 @@ pub fn query_with_timeout(
timeout_settings,
)?;
Ok(Response::new_from_valve_response(valve_response))
Response::new_from_valve_response(valve_response)
}