mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
[Protocol] Fix an instance of unwrapping in The Ship
This commit is contained in:
parent
7e028ce97d
commit
a8fc67412c
2 changed files with 8 additions and 5 deletions
|
|
@ -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
|
- 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.
|
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.
|
- 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:
|
Crate:
|
||||||
- Rich errors, capturing backtrace is done on `RUST_BACKTRACE=1`.
|
- Rich errors, capturing backtrace is done on `RUST_BACKTRACE=1`.
|
||||||
|
- Applied some nursery Clippy lints.
|
||||||
|
|
||||||
### Breaking...
|
### Breaking...
|
||||||
Protocols:
|
Protocols:
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ use crate::{
|
||||||
valve::{self, get_optional_extracted_data, Server, ServerPlayer, SteamApp},
|
valve::{self, get_optional_extracted_data, Server, ServerPlayer, SteamApp},
|
||||||
GenericResponse,
|
GenericResponse,
|
||||||
},
|
},
|
||||||
|
GDErrorKind::PacketBad,
|
||||||
GDResult,
|
GDResult,
|
||||||
};
|
};
|
||||||
use std::net::{IpAddr, SocketAddr};
|
use std::net::{IpAddr, SocketAddr};
|
||||||
|
|
@ -90,12 +91,12 @@ impl CommonResponse for Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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 (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,
|
protocol_version: response.info.protocol_version,
|
||||||
name: response.info.name,
|
name: response.info.name,
|
||||||
map: response.info.map,
|
map: response.info.map,
|
||||||
|
|
@ -122,7 +123,7 @@ impl Response {
|
||||||
mode: the_unwrapped_ship.mode,
|
mode: the_unwrapped_ship.mode,
|
||||||
witnesses: the_unwrapped_ship.witnesses,
|
witnesses: the_unwrapped_ship.witnesses,
|
||||||
duration: the_unwrapped_ship.duration,
|
duration: the_unwrapped_ship.duration,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,5 +141,5 @@ pub fn query_with_timeout(
|
||||||
timeout_settings,
|
timeout_settings,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Response::new_from_valve_response(valve_response))
|
Response::new_from_valve_response(valve_response)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue