[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:
CosminPerRam 2023-08-15 20:44:18 +03:00 committed by GitHub
parent 65c56dc196
commit 9d8fb1ba94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 249 additions and 200 deletions

View file

@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, PartialOrd)]
pub struct TheShipPlayer {
pub name: String,
pub score: u32,
pub score: i32,
pub duration: f32,
pub deaths: u32,
pub money: u32,
@ -39,24 +39,24 @@ impl CommonPlayer for TheShipPlayer {
fn as_original(&self) -> GenericPlayer { GenericPlayer::TheShip(self) }
fn name(&self) -> &str { &self.name }
fn score(&self) -> Option<u32> { Some(self.score) }
fn score(&self) -> Option<i32> { Some(self.score) }
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub struct Response {
pub protocol: u8,
pub protocol_version: u8,
pub name: String,
pub map: String,
pub game: String,
pub players: u8,
pub players_details: Vec<TheShipPlayer>,
pub max_players: u8,
pub bots: u8,
pub game_mode: String,
pub game_version: String,
pub players: Vec<TheShipPlayer>,
pub players_online: u8,
pub players_maximum: u8,
pub players_bots: u8,
pub server_type: Server,
pub has_password: bool,
pub vac_secured: bool,
pub version: String,
pub port: Option<u16>,
pub steam_id: Option<u64>,
pub tv_port: Option<u16>,
@ -73,15 +73,15 @@ impl CommonResponse for Response {
fn name(&self) -> Option<&str> { Some(&self.name) }
fn map(&self) -> Option<&str> { Some(&self.map) }
fn game(&self) -> Option<&str> { Some(&self.game) }
fn players_maximum(&self) -> u64 { self.max_players.into() }
fn players_online(&self) -> u64 { self.players.into() }
fn players_bots(&self) -> Option<u64> { Some(self.bots.into()) }
fn game_mode(&self) -> Option<&str> { Some(&self.game_mode) }
fn players_maximum(&self) -> u32 { self.players_maximum.into() }
fn players_online(&self) -> u32 { self.players_online.into() }
fn players_bots(&self) -> Option<u32> { Some(self.players_bots.into()) }
fn has_password(&self) -> Option<bool> { Some(self.has_password) }
fn players(&self) -> Option<Vec<&dyn CommonPlayer>> {
Some(
self.players_details
self.players
.iter()
.map(|p| p as &dyn CommonPlayer)
.collect(),
@ -96,23 +96,23 @@ impl Response {
let the_unwrapped_ship = response.info.the_ship.unwrap();
Self {
protocol: response.info.protocol,
protocol_version: response.info.protocol_version,
name: response.info.name,
map: response.info.map,
game: response.info.game,
players: response.info.players_online,
players_details: response
game_mode: response.info.game_mode,
game_version: response.info.game_version,
players_online: response.info.players_online,
players: response
.players
.unwrap()
.iter()
.map(TheShipPlayer::new_from_valve_player)
.collect(),
max_players: response.info.players_maximum,
bots: response.info.players_bots,
players_maximum: response.info.players_maximum,
players_bots: response.info.players_bots,
server_type: response.info.server_type,
has_password: response.info.has_password,
vac_secured: response.info.vac_secured,
version: response.info.version,
port,
steam_id,
tv_port,