From a8fc67412c3fddf2a17f1c998a45f932769baef1 Mon Sep 17 00:00:00 2001 From: CosminPerRam Date: Thu, 17 Aug 2023 23:08:59 +0300 Subject: [PATCH] [Protocol] Fix an instance of unwrapping in The Ship --- CHANGELOG.md | 2 ++ src/games/ts.rs | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 338338d..380594c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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: diff --git a/src/games/ts.rs b/src/games/ts.rs index ab6dd23..cd0e49c 100644 --- a/src/games/ts.rs +++ b/src/games/ts.rs @@ -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 { 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) }