[Games] Programmatic games by storing information as data (#45)

* Define games as structs

* Create table of response types

* Ensure serde is always included

* Remove server_ prefix in GenericResponse

* Make players online/max non-optional in generic response

* Use already existing minecraft server enum

* Implement ExtraResponses to prevent cloning when creating generic

* Add game definitions

* Add doc comments to generic types

* Include players in gamespy extra responses

* Add custom response types for TheShip and FFOW

* Cargo format differing files

* Final cleanup
This commit is contained in:
Tom 2023-06-13 18:49:58 +00:00 committed by GitHub
parent 26ad1f5d19
commit d853189e06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 806 additions and 102 deletions

View file

@ -1,3 +1,6 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub mod one;
pub mod three;
pub mod two;
@ -7,3 +10,11 @@ pub mod types;
pub use types::*;
mod client;
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq)]
pub enum QuakeVersion {
One,
Two,
Three,
}

View file

@ -2,6 +2,8 @@
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::protocols::{types::SpecificResponse, GenericResponse};
/// General server information's.
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq)]
@ -21,3 +23,30 @@ pub struct Response<P> {
/// Other server entries that weren't used.
pub unused_entries: HashMap<String, String>,
}
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ExtraResponse {
/// Other server entries that weren't used.
pub unused_entries: HashMap<String, String>,
}
impl<T> From<Response<T>> for GenericResponse {
fn from(r: Response<T>) -> Self {
Self {
name: Some(r.name),
description: None,
game: None,
game_version: Some(r.version),
map: Some(r.map),
players_maximum: r.players_maximum.into(),
players_online: r.players_online.into(),
players_bots: None,
has_password: None,
inner: SpecificResponse::Quake(ExtraResponse {
// TODO: Players
unused_entries: r.unused_entries,
}),
}
}
}