#[allow(dead_code)] #[derive(Debug)] pub struct UserToken { pub uuid: String, pub token: String, pub refresh_token: String, } pub struct UserInfo { pub payload: libfj::robocraft::TokenPayload, pub extra: ExtraUserInfo, } pub enum ExtraUserInfo { Steam { id: u64, }, Username { password: String, }, Email { password: String, } } pub enum UserId { SteamId(u64), Email(String), Username(String), } pub struct UserLoginInfo { pub response: libfj::robocraft::AuthenticationResponseInfo, pub is_new: bool, } pub struct RegistrationInfo { pub display_name: String, pub password: String, pub email: Option, pub steam_id: Option, } #[async_trait::async_trait] pub trait UserProvider { async fn authenticate(&self, user: UserToken) -> Result + Send + Sync>, String>; async fn multiplayer_authenticate(&self, user: String) -> Result + Send + Sync>, String>; } #[async_trait::async_trait] pub trait UserAuthenticator { async fn login(&self, info: UserInfo) -> Result; async fn user_exists(&self, user: UserId) -> Result; async fn register(&self, info: RegistrationInfo) -> Result; } #[async_trait::async_trait] pub trait User: ChatUser + LobbyUser + MultiplayerUser { fn public_id(&self) -> &'_ str; fn is_mod(&self) -> bool; fn is_admin(&self) -> bool; fn is_dev(&self) -> bool; async fn unlocked_parts(&self) -> Vec; async fn selected_garage(&self) -> (String, u32); async fn select_garage(&self, slot: i32) -> Result<(), i16>; async fn all_slots(&self) -> UserSlots; async fn slot_by_id(&self, id: i32) -> Result, i16>; async fn save_slot(&self, vehicle: VehicleData, cpu_counter: &crate::cubes::CpuListParser) -> Result<(), i16>; async fn save_slot_order(&self, slots: Vec) -> Result<(), i16>; async fn new_slot(&self, reset_slot: Option) -> Result, i16>; async fn copy_slot(&self, slot: i32, into_slot: Option, append: &str) -> Result<(), i16>; async fn upgrade_slot(&self, increments: i32) -> Result, i16>; async fn save_slot_controls(&self, controls: ControlData) -> Result<(), i16>; async fn save_slot_customisations(&self, customs: CustomisationData) -> Result<(), i16>; async fn get_slot_customisations(&self, uuid: &str) -> Result, i16>; async fn set_slot_name(&self, slot: i32, name: String) -> Result<(), i16>; fn signup_date(&self) -> i64; async fn singleplayer_robots(&self, factory: &dyn oj_rc_factory::VehicleFactoryAdapter, weapon_order: &crate::cubes::WeaponListParser, singleplayer_config: &crate::persist::config::SingleplayerConfig, cpu_counter: &crate::cubes::CpuListParser) -> Result, i16>; async fn prepare_factory_upload(&self, vehicle: VehicleUploadData) -> Result; async fn last_seen(&self) -> Result; async fn get_avatar_info(&self) -> Result, i16>; async fn set_avatar_info(&self, info: AvatarInfo) -> Result<(), i16>; } pub struct UserSlots { pub slot_info: polariton::operation::Typed, pub slot_order: polariton::operation::Typed, } pub struct UserSlotData { pub data: polariton::operation::Typed, pub colour_data: polariton::operation::Typed, pub cube_count: polariton::operation::Typed, pub weapon_order: polariton::operation::Typed, pub movement_categories: polariton::operation::Typed, pub control_type: polariton::operation::Typed, pub control_options: polariton::operation::Typed, pub mastery_level: polariton::operation::Typed, pub robot_rank: polariton::operation::Typed, pub cpu: polariton::operation::Typed, pub cosmetic_cpu: polariton::operation::Typed, pub uuid: polariton::operation::Typed, } pub struct NewSlotData { pub name: polariton::operation::Typed, pub uuid_0: polariton::operation::Typed, pub uuid_1: polariton::operation::Typed, pub slot: polariton::operation::Typed, pub bay_cpu: polariton::operation::Typed, pub mastery_level: polariton::operation::Typed, pub slot_i: i32, } pub struct VehicleData { pub name: Option, pub slot: i32, pub robot_data: Vec, pub colour_data: Vec, pub weapon_order: Vec, pub crf_id: Option, } pub struct VehicleUploadData { pub version: String, pub slot: i32, pub name: String, pub description: String, pub thumbnail: Vec, } pub struct ControlData { pub slot: i32, pub control_ty: ControlType, pub vertical_strafing: bool, pub sideways_driving: bool, pub tracks_turn_on_spot: bool, } pub enum ControlType { Camera = 0, Keyboard = 1, Count = 2, } impl ControlType { pub fn from_i32(i: i32) -> Result { match i { 0 => Ok(Self::Camera), 1 => Ok(Self::Keyboard), 2 => Ok(Self::Count), _ => Err(crate::data::error_codes::WebServicesError::UnexpectedError as i16), } } #[inline] pub(super) fn into_db(self) -> oj_rc_database::schema::garage::ControlType { match self { Self::Camera => oj_rc_database::schema::garage::ControlType::Camera, Self::Keyboard => oj_rc_database::schema::garage::ControlType::Keyboard, Self::Count => oj_rc_database::schema::garage::ControlType::Count, } } } pub struct CustomisationData { pub uuid: String, pub bay: String, pub spawn: String, pub death: String, } pub struct GetCustomisationData { pub bay: polariton::operation::Typed, pub spawn: polariton::operation::Typed, pub death: polariton::operation::Typed, } pub struct GetAvatarInfo { pub avatar_id: polariton::operation::Typed, pub use_custom: polariton::operation::Typed, } pub struct AvatarInfo { pub avatar_id: i32, pub use_custom: bool, } #[async_trait::async_trait] pub trait ChatUser { async fn subscribed_channels(&self) -> Result, i16>; async fn subscribed_channels_strings(&self) -> Result, i16>; async fn add_subscribed_channel(&self, channel: String, channel_ty: crate::data::channel::ChatChannelType) -> Result, i16>; async fn remove_subscribed_channel(&self, channel: String, channel_ty: crate::data::channel::ChatChannelType) -> Result<(), i16>; //async fn has_pending_sanctions(&self) -> Result; async fn get_sanctions(&self, username: String) -> Result, i16>; async fn set_sanction(&self, sanction: SetSanction) -> Result<(), i16>; } pub struct SetSanction { pub is_adding: bool, // if false, it's modifying pub type_: SanctionType, pub duration: i32, pub reason: String, pub username: String, } pub enum SanctionType { Warn = 0, Mute = 1, Ban = 2, Note = 3, Kick = 4, } impl SanctionType { pub fn from_i32(i: i32) -> Result { match i { 0 => Ok(Self::Warn), 1 => Ok(Self::Mute), 2 => Ok(Self::Ban), 3 => Ok(Self::Note), 4 => Ok(Self::Kick), _ => Err(crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16), } } } #[async_trait::async_trait] pub trait LobbyUser { fn user_id(&self) -> i32; async fn player_data(&self, cpu_counter: &crate::cubes::CpuListParser) -> Result; async fn start_game(&self, game: GameDescriptor, players: Vec) -> Result<(), polariton_server::operations::SimpleOpError>; } pub struct GameDescriptor { pub guid: String, pub map: String, pub mode: crate::data::game_mode::GameMode, pub visibility: crate::data::game_mode::MapVisibility, pub auto_heal: bool, pub is_ranked: bool, pub is_custom: bool, pub is_complete: bool, } pub struct PlayerLobbyDescriptor { pub user_id: i32, pub team: i32, pub group: Option, } pub struct PlayerDescriptor { pub user_id: i32, pub player_id: u8, pub team: i32, pub group: Option, pub public_id: String, pub display_name: String, pub is_rewards_claimed: bool, } #[derive(Debug)] pub struct MultiplayerError { pub code: MultiplayerErrorCode, pub message: String, } impl core::fmt::Display for MultiplayerError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{:?}: {}", self.code, self.message) } } impl core::error::Error for MultiplayerError {} #[repr(u8)] #[derive(Debug)] pub enum MultiplayerErrorCode { HaxSpeed = 0, HaxException = 1, HaxTeleport = 2, HaxEacViolation = 6, HaxAfk = 7, HaxFirerange = 8, HaxFiredamage = 9, HaxFirerate = 10, HaxFireposition = 11, IncorrectGameGuid = 12, CustomString = 13, TimedOut = 14, GameEnded = 15, } #[async_trait::async_trait] pub trait MultiplayerUser { fn user_id(&self) -> i32; fn user_name(&self) -> &'_ str; fn display_name(&self) -> &'_ str; async fn current_game(&self) -> Result, MultiplayerError>; async fn game_players(&self, guid: &str) -> Result, MultiplayerError>; async fn complete_game(&self, guid: &str) -> Result<(), MultiplayerError>; }