mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
[Protocol] Standardize fields (#84)
* [Protocol] Standardize The Ship fields * [Protocol] Standardize FFOW fields * [Protocol] Rename Valve's protocol field to protocol_version * [Protocol] Rename Minecraft's version_protocol field to protocol_version * [Protocol] Rename Valve's version field to game_version * [Protocol] Rename Minecraft java version_name to game_version * [Crate] Reformat RESPONSES.md * [Protocol] Renamed Minecraft Java players_sample to players * [Protocol] Rename Quake (1,2,3) version field to game_version * [Protocol] Rename quake (1 and 2) game_type field to game_mode * [Protocol] Rename Valve, FFOW, TS game field to game_mode * [Generics] Rename game field/function to game_mode * [Protocol] Change players_minimum, _maximum and _bots from those who werent u8 or u32 to u32 * [Protocol] Change instances of player score field type from u32 to i32 * [Crate] Nicer gramar in CHANGELOG * [Protocol] Apply clippy fixes
This commit is contained in:
parent
65c56dc196
commit
9d8fb1ba94
25 changed files with 249 additions and 200 deletions
|
|
@ -211,7 +211,7 @@ impl ValveProtocol {
|
|||
let name = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let map = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let folder = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let game = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let game_mode = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let players = buffer.read()?;
|
||||
let max_players = buffer.read()?;
|
||||
let protocol = buffer.read()?;
|
||||
|
|
@ -245,11 +245,11 @@ impl ValveProtocol {
|
|||
let bots = buffer.read::<u8>()?;
|
||||
|
||||
Ok(ServerInfo {
|
||||
protocol,
|
||||
protocol_version: protocol,
|
||||
name,
|
||||
map,
|
||||
folder,
|
||||
game,
|
||||
game_mode,
|
||||
appid: 0, // not present in the obsolete response
|
||||
players_online: players,
|
||||
players_maximum: max_players,
|
||||
|
|
@ -259,7 +259,7 @@ impl ValveProtocol {
|
|||
has_password,
|
||||
vac_secured,
|
||||
the_ship: None,
|
||||
version: "".to_string(), // a version field only for the mod
|
||||
game_version: "".to_string(), // a version field only for the mod
|
||||
extra_data: None,
|
||||
is_mod,
|
||||
mod_data,
|
||||
|
|
@ -281,7 +281,7 @@ impl ValveProtocol {
|
|||
let name = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let map = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let folder = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let game = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let game_mode = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let mut appid = buffer.read::<u16>()? as u32;
|
||||
let players = buffer.read()?;
|
||||
let max_players = buffer.read()?;
|
||||
|
|
@ -300,7 +300,7 @@ impl ValveProtocol {
|
|||
})
|
||||
}
|
||||
};
|
||||
let version = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let game_version = buffer.read_string::<Utf8Decoder>(None)?;
|
||||
let extra_data = match buffer.read::<u8>() {
|
||||
Err(_) => None,
|
||||
Ok(value) => {
|
||||
|
|
@ -339,11 +339,11 @@ impl ValveProtocol {
|
|||
};
|
||||
|
||||
Ok(ServerInfo {
|
||||
protocol,
|
||||
protocol_version: protocol,
|
||||
name,
|
||||
map,
|
||||
folder,
|
||||
game,
|
||||
game_mode,
|
||||
appid,
|
||||
players_online: players,
|
||||
players_maximum: max_players,
|
||||
|
|
@ -353,7 +353,7 @@ impl ValveProtocol {
|
|||
has_password,
|
||||
vac_secured,
|
||||
the_ship,
|
||||
version,
|
||||
game_version,
|
||||
extra_data,
|
||||
is_mod: false,
|
||||
mod_data: None,
|
||||
|
|
@ -436,7 +436,6 @@ fn get_response(
|
|||
let mut client = ValveProtocol::new(address, timeout_settings)?;
|
||||
|
||||
let info = client.get_server_info(&engine)?;
|
||||
let protocol = info.protocol;
|
||||
|
||||
if let Engine::Source(Some(appids)) = &engine {
|
||||
let mut is_specified_id = false;
|
||||
|
|
@ -454,6 +453,8 @@ fn get_response(
|
|||
}
|
||||
}
|
||||
|
||||
let protocol = info.protocol_version;
|
||||
|
||||
Ok(Response {
|
||||
info,
|
||||
players: match gather_settings.players {
|
||||
|
|
|
|||
|
|
@ -61,12 +61,12 @@ impl CommonResponse for Response {
|
|||
fn as_original(&self) -> GenericResponse { GenericResponse::Valve(self) }
|
||||
|
||||
fn name(&self) -> Option<&str> { Some(&self.info.name) }
|
||||
fn game(&self) -> Option<&str> { Some(&self.info.game) }
|
||||
fn game_version(&self) -> Option<&str> { Some(&self.info.version) }
|
||||
fn game_mode(&self) -> Option<&str> { Some(&self.info.game_mode) }
|
||||
fn game_version(&self) -> Option<&str> { Some(&self.info.game_version) }
|
||||
fn map(&self) -> Option<&str> { Some(&self.info.map) }
|
||||
fn players_maximum(&self) -> u64 { self.info.players_maximum.into() }
|
||||
fn players_online(&self) -> u64 { self.info.players_online.into() }
|
||||
fn players_bots(&self) -> Option<u64> { Some(self.info.players_bots.into()) }
|
||||
fn players_maximum(&self) -> u32 { self.info.players_maximum.into() }
|
||||
fn players_online(&self) -> u32 { self.info.players_online.into() }
|
||||
fn players_bots(&self) -> Option<u32> { Some(self.info.players_bots.into()) }
|
||||
fn has_password(&self) -> Option<bool> { Some(self.info.has_password) }
|
||||
|
||||
fn players(&self) -> Option<Vec<&dyn CommonPlayer>> {
|
||||
|
|
@ -81,15 +81,15 @@ impl CommonResponse for Response {
|
|||
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||
pub struct ServerInfo {
|
||||
/// Protocol used by the server.
|
||||
pub protocol: u8,
|
||||
pub protocol_version: u8,
|
||||
/// Name of the server.
|
||||
pub name: String,
|
||||
/// Map name.
|
||||
pub map: String,
|
||||
/// Name of the folder containing the game files.
|
||||
pub folder: String,
|
||||
/// The name of the game.
|
||||
pub game: String,
|
||||
/// The server-declared name of the game/game mode.
|
||||
pub game_mode: String,
|
||||
/// [Steam Application ID](https://developer.valvesoftware.com/wiki/Steam_Application_ID) of game.
|
||||
pub appid: u32,
|
||||
/// Number of players on the server.
|
||||
|
|
@ -109,7 +109,7 @@ pub struct ServerInfo {
|
|||
/// [The ship](https://developer.valvesoftware.com/wiki/The_Ship) extra data
|
||||
pub the_ship: Option<TheShip>,
|
||||
/// Version of the game installed on the server.
|
||||
pub version: String,
|
||||
pub game_version: String,
|
||||
/// Some extra data that the server might provide or not.
|
||||
pub extra_data: Option<ExtraData>,
|
||||
/// GoldSrc only: Indicates whether the hosted game is a mod.
|
||||
|
|
@ -125,7 +125,7 @@ pub struct ServerPlayer {
|
|||
/// Player's name.
|
||||
pub name: String,
|
||||
/// General score.
|
||||
pub score: u32,
|
||||
pub score: i32,
|
||||
/// How long a player has been in the server (seconds).
|
||||
pub duration: f32,
|
||||
/// Only for [the ship](https://developer.valvesoftware.com/wiki/The_Ship): deaths count
|
||||
|
|
@ -137,7 +137,7 @@ pub struct ServerPlayer {
|
|||
impl CommonPlayer for ServerPlayer {
|
||||
fn as_original(&self) -> GenericPlayer { GenericPlayer::Valve(self) }
|
||||
fn name(&self) -> &str { &self.name }
|
||||
fn score(&self) -> Option<u32> { Some(self.score) }
|
||||
fn score(&self) -> Option<i32> { Some(self.score) }
|
||||
}
|
||||
|
||||
/// Only present for [the ship](https://developer.valvesoftware.com/wiki/The_Ship).
|
||||
|
|
@ -447,7 +447,7 @@ pub mod game {
|
|||
/// Player's name.
|
||||
pub name: String,
|
||||
/// Player's score.
|
||||
pub score: u32,
|
||||
pub score: i32,
|
||||
/// How long a player has been in the server (seconds).
|
||||
pub duration: f32,
|
||||
}
|
||||
|
|
@ -511,10 +511,10 @@ pub mod game {
|
|||
let (port, steam_id, tv_port, tv_name, keywords) = get_optional_extracted_data(response.info.extra_data);
|
||||
|
||||
Self {
|
||||
protocol: response.info.protocol,
|
||||
protocol: response.info.protocol_version,
|
||||
name: response.info.name,
|
||||
map: response.info.map,
|
||||
game: response.info.game,
|
||||
game: response.info.game_mode,
|
||||
appid: response.info.appid,
|
||||
players_online: response.info.players_online,
|
||||
players_details: response
|
||||
|
|
@ -528,7 +528,7 @@ pub mod game {
|
|||
server_type: response.info.server_type,
|
||||
has_password: response.info.has_password,
|
||||
vac_secured: response.info.vac_secured,
|
||||
version: response.info.version,
|
||||
version: response.info.game_version,
|
||||
port,
|
||||
steam_id,
|
||||
tv_port,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue