diff --git a/CHANGELOG.md b/CHANGELOG.md index 365e5dc..3d914ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ Who knows what the future holds... [Risk of Rain 2](https://store.steampowered.com/app/632360/Risk_of_Rain_2/) support. ### Breaking: -Nothing (yet). +Valve Protocol - Rules is now a `HashMap` instead of a `Vec` (where the `ServerRule` structure had a name and value fields). # 0.0.7 - 03/01/2023 ### Changes: diff --git a/src/games/ts.rs b/src/games/ts.rs index 95c4d49..9684a41 100644 --- a/src/games/ts.rs +++ b/src/games/ts.rs @@ -1,6 +1,7 @@ +use std::collections::HashMap; use crate::GDResult; use crate::protocols::valve; -use crate::protocols::valve::{Server, ServerRule, ServerPlayer, get_optional_extracted_data, SteamID}; +use crate::protocols::valve::{Server, ServerPlayer, get_optional_extracted_data, SteamID}; #[derive(Debug)] pub struct TheShipPlayer { @@ -42,7 +43,7 @@ pub struct Response { pub tv_port: Option, pub tv_name: Option, pub keywords: Option, - pub rules: Vec, + pub rules: HashMap, pub mode: u8, pub witnesses: u8, pub duration: u8 diff --git a/src/protocols/valve/protocol.rs b/src/protocols/valve/protocol.rs index 649016f..d81f338 100644 --- a/src/protocols/valve/protocol.rs +++ b/src/protocols/valve/protocol.rs @@ -1,9 +1,10 @@ +use std::collections::HashMap; use bzip2_rs::decoder::Decoder; use crate::{GDError, GDResult}; use crate::bufferer::{Bufferer, Endianess}; use crate::protocols::types::TimeoutSettings; use crate::protocols::valve::{App, ModData, SteamID}; -use crate::protocols::valve::types::{Environment, ExtraData, GatheringSettings, Request, Response, Server, ServerInfo, ServerPlayer, ServerRule, TheShip}; +use crate::protocols::valve::types::{Environment, ExtraData, GatheringSettings, Request, Response, Server, ServerInfo, ServerPlayer, TheShip}; use crate::socket::{Socket, UdpSocket}; use crate::utils::u8_lower_upper; @@ -384,17 +385,17 @@ impl ValveProtocol { } /// Get the server's rules. - fn get_server_rules(&mut self, app: &App, protocol: u8) -> GDResult> { + fn get_server_rules(&mut self, app: &App, protocol: u8) -> GDResult> { let mut buffer = self.get_request_data(&app, protocol, Request::RULES)?; let count = buffer.get_u16()? as usize; - let mut rules: Vec = Vec::with_capacity(count); + let mut rules: HashMap = HashMap::with_capacity(count); for _ in 0..count { - rules.push(ServerRule { - name: buffer.get_string_utf8()?, - value: buffer.get_string_utf8()? - }) + let name = buffer.get_string_utf8()?; + let value = buffer.get_string_utf8()?; + + rules.insert(name, value); } Ok(rules) diff --git a/src/protocols/valve/types.rs b/src/protocols/valve/types.rs index 1e54a0e..d0697a1 100644 --- a/src/protocols/valve/types.rs +++ b/src/protocols/valve/types.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; /// The type of the server. #[derive(Debug)] @@ -20,7 +21,7 @@ pub enum Environment { pub struct Response { pub info: ServerInfo, pub players: Option>, - pub rules: Option> + pub rules: Option> } /// General server information's. @@ -79,13 +80,6 @@ pub struct ServerPlayer { pub money: Option, //the_ship } -/// A server rule. -#[derive(Debug)] -pub struct ServerRule { - pub name: String, - pub value: String -} - /// Only present for [the ship](https://developer.valvesoftware.com/wiki/The_Ship). #[derive(Debug)] pub struct TheShip { @@ -244,8 +238,9 @@ impl Default for GatheringSettings { /// Generic response types that are used by many games, they are the protocol ones, but without the /// unnecessary bits (example: the **The Ship**-only fields). pub mod game { + use std::collections::HashMap; use crate::protocols::valve::types::get_optional_extracted_data; - use super::{Server, ServerRule, ServerPlayer}; + use super::{Server, ServerPlayer}; #[derive(Debug)] pub struct Player { @@ -283,7 +278,7 @@ pub mod game { pub tv_port: Option, pub tv_name: Option, pub keywords: Option, - pub rules: Vec + pub rules: HashMap } impl Response { @@ -308,9 +303,8 @@ pub mod game { tv_port, tv_name, keywords, - rules: response.rules.unwrap_or(vec![]) + rules: response.rules.unwrap_or(HashMap::new()) } } } } -