use serde::Deserialize;
#[derive(Deserialize)]
pub struct ServerResponse {
pub server: Server
}
#[derive(Debug, Deserialize)]
pub struct Server {
pub categories: Vec<String>,
#[serde(rename = "inheritedCategories")]
pub inherited_categories: Vec<String>,
pub purchased_icons: Vec<String>,
pub backup_slots: usize,
pub suspended: bool,
pub server_version_type: String,
pub proxy: bool,
#[serde(rename = "connectedServers")]
pub connected_servers: Vec<String>,
#[serde(rename = "_id")]
pub id: String,
pub motd: String,
pub visibility: bool,
pub server_plan: String,
pub storage_node: String,
pub owner: String,
pub name: String,
pub name_lower: String,
pub creation: usize,
pub platform: String,
pub credits_per_day: f32,
__v: isize,
pub last_online: usize,
pub active_icon: Option<String>,
pub icon: Option<String>,
pub online: bool,
#[serde(rename = "maxPlayers")]
pub max_players: usize,
#[serde(rename = "playerCount")]
pub player_count: usize,
#[serde(rename = "rawPlan")]
pub raw_plan: String,
#[serde(rename = "activeServerPlan")]
pub active_server_plan: String
}
#[derive(Debug, Deserialize)]
pub struct ServerIcon {
#[serde(rename = "_id")]
pub id: String,
pub display_name: String,
pub icon_name: String,
pub price: usize,
pub rank: String,
pub available: bool,
pub disabled: bool,
pub created: usize,
pub last_updated: usize,
__v: isize
}
#[derive(Deserialize)]
pub struct ServerListResponse {
pub servers: Vec<ServerData>
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ServerData {
pub static_info: StaticInfo,
pub name: String,
pub motd: String,
pub icon: Option<String>,
pub player_data: PlayerData,
pub connectable: Option<bool>,
pub visibility: bool
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct StaticInfo {
#[serde(rename = "_id")]
pub id: String,
pub server_plan: String,
pub service_start_date: usize,
pub platform: String,
#[serde(rename = "planMaxPlayers")]
pub max_players: usize,
pub raw_plan: String,
pub connected_servers: Vec<String>
}
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct PlayerData {
pub player_count: usize,
}
#[derive(Deserialize)]
pub struct OwnedServerRes {
pub server: OwnedServer
}
#[derive(Debug, Deserialize)]
pub struct OwnedServer {
#[serde(rename = "_id")]
pub id: String,
pub active_plugins: Vec<String>,
pub backup_slots: usize,
pub categories: Vec<String>,
#[serde(rename = "connectedServers")]
pub connected_servers: Vec<String>,
pub creation: usize,
pub credits_per_day: f32,
pub installed_content: Vec<InstalledContent>,
pub last_online: usize,
pub motd: String,
pub name: String,
pub name_lower: String,
pub owner: String,
pub platform: String,
pub proxy: bool,
pub purchased_icons: Vec<String>,
pub server_plan: String,
pub server_properties: ServerProperties,
pub server_version_type: String,
pub suspended: bool,
pub visibility: bool
}
#[derive(Debug, Deserialize)]
pub struct ServerProperties {
#[serde(rename = "allow-flight")]
pub allow_flight: bool,
#[serde(rename = "allow-nether")]
pub allow_nether: bool,
#[serde(rename = "announce-player-achievements")]
pub announce_player_achievements: bool,
pub difficulty: i8,
#[serde(rename = "enable-command-block")]
pub allow_cmd_block: bool,
#[serde(rename = "enforce-whitelist")]
pub enforce_whitelist: bool,
#[serde(rename = "force-gamemode")]
pub force_gamemode: bool,
pub gamemode: usize,
pub hardcore: bool,
#[serde(rename = "level-name")]
pub level_name: String,
#[serde(rename = "max-players")]
pub max_players: usize,
#[serde(rename = "max-tick-time")]
pub max_tick_time: usize,
#[serde(rename = "op-permission-level")]
pub permission_level: u8,
pub pvp: bool,
#[serde(rename = "spawn-mobs")]
pub spawn_mobs: bool,
#[serde(rename = "spawn-npcs")]
pub spawn_npcs: bool,
#[serde(rename = "spawn-protection")]
pub spawn_prot: usize,
#[serde(rename = "white-list")]
pub whitelist: bool
}
#[derive(Debug, Deserialize)]
pub struct InstalledContent {
#[serde(rename = "_id")]
pub id: String,
pub content_id: String,
pub content_version_id: String,
pub install_date: String,
pub last_updated: String,
pub pinned: bool
}
use crate::{Client, Error, http};
impl OwnedServer {
pub async fn start_service(&self, client: &Client) -> Result<(), Error> {
http::post(&client, &format!("server/{}/start_service", &self.id)).await
}
pub async fn destroy_service(&self, client: &Client) -> Result<(), Error> {
http::post(&client, &format!("server/{}/destroy_service", &self.id)).await
}
pub async fn start(&self, client: &Client) -> Result<(), Error> {
http::post(&client, &format!("server/{}/start", &self.id)).await
}
pub async fn shut_down(&self, client: &Client) -> Result<(), Error> {
http::post(&client, &format!("server/{}/shutdown", &self.id)).await
}
}