diff --git a/assets/robocraft/default.png b/assets/robocraft/default.png new file mode 100644 index 0000000..5eb849c Binary files /dev/null and b/assets/robocraft/default.png differ diff --git a/rc_chat_room/src/events/chat_message.rs b/rc_chat_room/src/events/chat_message.rs index 44c9d86..42daa58 100644 --- a/rc_chat_room/src/events/chat_message.rs +++ b/rc_chat_room/src/events/chat_message.rs @@ -10,6 +10,8 @@ pub struct PublicMessage { } impl PublicMessage { + pub const CODE: u8 = 1; + pub fn as_event_params(&self) -> polariton::operation::ParameterTable { let mut params = std::collections::HashMap::with_capacity(8); params.insert(5, polariton::operation::Typed::Str(self.sender_name.clone().into())); @@ -24,6 +26,32 @@ impl PublicMessage { } } +impl polariton_server::events::IntoEvent for PublicMessage { + const CHANNEL: u8 = 0; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: Self::CODE, + params: self.as_event_params().into(), + } + } +} + +impl polariton_server::events::IntoEvent for &PublicMessage { + const CHANNEL: u8 = 0; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: PublicMessage::CODE, + params: self.as_event_params().into(), + } + } +} + pub struct PrivateMessage { pub sender_name: String, pub sender_display_name: String, @@ -34,6 +62,8 @@ pub struct PrivateMessage { } impl PrivateMessage { + pub const CODE: u8 = 2; + pub fn as_event_params(&self) -> polariton::operation::ParameterTable { let mut params = std::collections::HashMap::with_capacity(6); params.insert(5, polariton::operation::Typed::Str(self.sender_name.clone().into())); @@ -45,3 +75,29 @@ impl PrivateMessage { params.into() } } + +impl polariton_server::events::IntoEvent for PrivateMessage { + const CHANNEL: u8 = 0; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: Self::CODE, + params: self.as_event_params().into(), + } + } +} + +impl polariton_server::events::IntoEvent for &PrivateMessage { + const CHANNEL: u8 = 0; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: PrivateMessage::CODE, + params: self.as_event_params().into(), + } + } +} diff --git a/rc_chat_room/src/events/mod.rs b/rc_chat_room/src/events/mod.rs index 8fc12b7..1005ca6 100644 --- a/rc_chat_room/src/events/mod.rs +++ b/rc_chat_room/src/events/mod.rs @@ -1 +1,3 @@ pub mod chat_message; +pub mod player_update; +pub mod room_join; diff --git a/rc_chat_room/src/events/player_update.rs b/rc_chat_room/src/events/player_update.rs new file mode 100644 index 0000000..3660cd6 --- /dev/null +++ b/rc_chat_room/src/events/player_update.rs @@ -0,0 +1,44 @@ +pub struct PlayerUpdated { + pub channel_name: String, + pub player_name: String, + pub player_state: oj_rc_core::data::channel::ChatPlayerState, +} + +impl PlayerUpdated { + pub const CODE: u8 = 6; + pub const CHANNEL: u8 = 0; + + pub fn as_event_params(&self) -> polariton::operation::ParameterTable { + let mut params = std::collections::HashMap::with_capacity(3); + params.insert(3, polariton::operation::Typed::Str(self.channel_name.clone().into())); + params.insert(22, polariton::operation::Typed::Str(self.player_name.clone().into())); + params.insert(23, polariton::operation::Typed::Int(self.player_state as _)); + params.into() + } +} + +impl polariton_server::events::IntoEvent for PlayerUpdated { + const CHANNEL: u8 = Self::CHANNEL; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: Self::CODE, + params: self.as_event_params().into(), + } + } +} + +impl polariton_server::events::IntoEvent for &PlayerUpdated { + const CHANNEL: u8 = PlayerUpdated::CHANNEL; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: PlayerUpdated::CODE, + params: self.as_event_params().into(), + } + } +} diff --git a/rc_chat_room/src/events/room_join.rs b/rc_chat_room/src/events/room_join.rs new file mode 100644 index 0000000..0e89821 --- /dev/null +++ b/rc_chat_room/src/events/room_join.rs @@ -0,0 +1,53 @@ +pub struct RoomJoined { + pub channel_name: String, + pub player_name: String, + pub player_state: oj_rc_core::data::channel::ChatPlayerState, + pub use_custom_avatar: bool, + pub custom_avatar: Vec, + pub avatar_id: i32, +} + +impl RoomJoined { + pub const CODE: u8 = 4; + pub const CHANNEL: u8 = 0; + + pub fn as_event_params(&self) -> polariton::operation::ParameterTable { + let mut params = std::collections::HashMap::with_capacity(8); + params.insert(3, polariton::operation::Typed::Str(self.channel_name.clone().into())); + params.insert(22, polariton::operation::Typed::Str(self.player_name.clone().into())); + params.insert(23, polariton::operation::Typed::Int(self.player_state as _)); + params.insert(24, polariton::operation::Typed::Bool(self.use_custom_avatar)); + if self.use_custom_avatar { + params.insert(26, polariton::operation::Typed::Bytes(self.custom_avatar.clone().into())); + } else { + params.insert(25, polariton::operation::Typed::Int(self.avatar_id)); + } + params.into() + } +} + +impl polariton_server::events::IntoEvent for RoomJoined { + const CHANNEL: u8 = Self::CHANNEL; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: Self::CODE, + params: self.as_event_params().into(), + } + } +} + +impl polariton_server::events::IntoEvent for &RoomJoined { + const CHANNEL: u8 = RoomJoined::CHANNEL; + const ENCRYPT: bool = true; + const RELIABLE: bool = true; + + fn into_event(self) -> polariton::operation::Event { + polariton::operation::Event { + code: RoomJoined::CODE, + params: self.as_event_params().into(), + } + } +} diff --git a/rc_chat_room/src/operations/all_joined_channels.rs b/rc_chat_room/src/operations/all_joined_channels.rs index 1a35d0c..434cbf9 100644 --- a/rc_chat_room/src/operations/all_joined_channels.rs +++ b/rc_chat_room/src/operations/all_joined_channels.rs @@ -1,25 +1,32 @@ //use oj_rc_core::persist::user::ChatUser; use polariton::operation::{ParameterTable, OperationResponse}; -const CODE: u8 = 11; +const CODE: u8 = 11; // subscribe all const PARAM_KEY: u8 = 18; -async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result { +async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, chat_system: &crate::state::chat::ChatImpl) -> Result { + log::info!("Adding joined user to channels"); let mut params = params.to_dict(); let user_info = user.user()?; + let name = user_info.public_id().to_owned(); + let channels = user_info.subscribed_channels_strings().await?; + let event_tx = user.event_chann(); + chat_system.system_mut().connect_user(name, channels, event_tx); params.insert(PARAM_KEY, user_info.subscribed_channels().await?); Ok(params.into()) } -pub struct JoinedChannelsProvider; +pub struct JoinedChannelsProvider { + chat_system: crate::state::chat::ChatImpl, +} #[async_trait::async_trait] impl polariton_server::operations::Operation<()> for JoinedChannelsProvider { type User = crate::UserTy; async fn handle_async(&self, params: ParameterTable<()>, user: &Self::User) -> OperationResponse<()> { - polariton_server::operations::result_to_op_resp::(do_handling(params, user).await) + polariton_server::operations::result_to_op_resp::(do_handling(params, user, &self.chat_system).await) } } @@ -30,6 +37,8 @@ impl polariton_server::operations::OperationCode for JoinedChannelsProvider { } -pub(super) fn all_channels_provider() -> JoinedChannelsProvider { - JoinedChannelsProvider +pub(super) fn all_channels_provider(chat_system: crate::state::chat::ChatImpl) -> JoinedChannelsProvider { + JoinedChannelsProvider { + chat_system, + } } diff --git a/rc_chat_room/src/operations/mod.rs b/rc_chat_room/src/operations/mod.rs index 16c371a..b61f223 100644 --- a/rc_chat_room/src/operations/mod.rs +++ b/rc_chat_room/src/operations/mod.rs @@ -15,10 +15,10 @@ use polariton_server::operations::OperationsHandler; pub fn handler(chat_system: crate::state::chat::ChatImpl, conf: &oj_rc_core::persist::config::ConfigImpl) -> OperationsHandler { OperationsHandler::new() .modify(oj_rc_core::polariton::RcOpModifier) - .add(more_auth::MoreLobbyAuth::new(chat_system.clone())) + .add(more_auth::MoreLobbyAuth::new()) .add(chat_ignores::ignores_provider()) .add(pending_sanctions::pending_sanctions_checker()) - .add(all_joined_channels::all_channels_provider()) + .add(all_joined_channels::all_channels_provider(chat_system.clone())) //.add(polariton_server::operations::Ack::<12, _>::default()) .add(send_message::send_public_message_handler(chat_system.clone())) .add(public_channels::public_channels_provider(conf)) diff --git a/rc_chat_room/src/operations/more_auth.rs b/rc_chat_room/src/operations/more_auth.rs index 5f563f3..2077f7f 100644 --- a/rc_chat_room/src/operations/more_auth.rs +++ b/rc_chat_room/src/operations/more_auth.rs @@ -4,17 +4,14 @@ use polariton_server::operations::{Operation, OperationCode}; //use crate::persist::chat_user::{ChatUser, ChatUserImpl}; //use oj_rc_core::persist::user::ChatUser; -pub struct MoreLobbyAuth { - chat_system: crate::state::chat::ChatImpl, -} +pub struct MoreLobbyAuth; impl MoreLobbyAuth { const AUTH_PAYLOAD_KEY: u8 = 245; - pub fn new(chat_system: crate::state::chat::ChatImpl) -> Self { - Self { - chat_system, - } + #[inline] + pub fn new() -> Self { + Self } /*fn build_ext_map(&self, token: &oj_rc_core::persist::user::UserToken) -> Option>> { @@ -33,12 +30,12 @@ impl MoreLobbyAuth { async fn do_auth(&self, params: std::collections::HashMap>, user: &crate::UserTy) -> Result, i16> { if let Some(Typed::Str(auth_payload)) = params.get(&Self::AUTH_PAYLOAD_KEY) { if user.update_with_auth(&auth_payload.string).await { - let user_impl = user.user()?; - let name = user_impl.public_id().to_owned(); + //let user_impl = user.user()?; + //let name = user_impl.public_id().to_owned(); //let chat_user = super::get_chat_user(user_impl.as_ref().as_ref()); - let channels = user_impl.subscribed_channels_strings().await?; - let event_tx = user.event_chann(); - self.chat_system.system_mut().connect_user(name, channels, event_tx); + //let channels = user_impl.subscribed_channels_strings().await?; + //let event_tx = user.event_chann(); + //self.chat_system.system_mut().connect_user(name, channels, event_tx); let mut resp_params = std::collections::HashMap::new(); resp_params.insert(Self::AUTH_PAYLOAD_KEY, polariton::operation::Typed::Byte(0)); return Ok(resp_params.into()); diff --git a/rc_chat_room/src/operations/subscribed_channels.rs b/rc_chat_room/src/operations/subscribed_channels.rs index 9e18683..12df639 100644 --- a/rc_chat_room/src/operations/subscribed_channels.rs +++ b/rc_chat_room/src/operations/subscribed_channels.rs @@ -1,11 +1,12 @@ //use oj_rc_core::persist::user::ChatUser; use polariton::operation::{ParameterTable, OperationResponse}; -const CODE: u8 = 12; +const CODE: u8 = 12; // get all subscribed const PARAM_KEY: u8 = 18; async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy) -> Result { + log::info!("Getting subscribed user's channels"); let mut params = params.to_dict(); let user_info = user.user()?; params.insert(PARAM_KEY, user_info.subscribed_channels().await?); diff --git a/rc_chat_room/src/state/chat/chat.rs b/rc_chat_room/src/state/chat/chat.rs index 874ab46..79c2b38 100644 --- a/rc_chat_room/src/state/chat/chat.rs +++ b/rc_chat_room/src/state/chat/chat.rs @@ -91,7 +91,7 @@ impl ChatSystem { } else if let Some(room) = self.chats.get(&channel) { let event_params = crate::events::chat_message::PublicMessage { sender_name: user.public_id().to_owned(), - sender_display_name: user.public_id().to_owned(), + sender_display_name: user.display_name().to_owned(), text, is_dev: user.is_dev(), is_mod: user.is_mod(), diff --git a/rc_chat_room/src/state/chat/room.rs b/rc_chat_room/src/state/chat/room.rs index 101dad8..f72ba99 100644 --- a/rc_chat_room/src/state/chat/room.rs +++ b/rc_chat_room/src/state/chat/room.rs @@ -1,5 +1,6 @@ pub struct ChatRoom { name: String, + #[allow(dead_code)] channel: crate::data::channel::ChatChannelType, online_users: Vec, } @@ -35,11 +36,13 @@ impl ChatRoom { } pub fn send_public_message(&self, message: crate::events::chat_message::PublicMessage) { + let user_id = &message.sender_display_name; let event = polariton::operation::Event { code: 1, params: message.as_event_params(), }; for user in self.online_users.iter() { + if user.name() == user_id { continue; } user.send(polariton_server::ToSend::Data { data: polariton::packet::Data::Event(event.clone()), encrypt: true, @@ -60,22 +63,20 @@ impl ChatRoom { pub fn connect_user(&mut self, handle: super::UserHandle) { self.cleanup(); let event = polariton::operation::Event { - code: 1, - params: crate::events::chat_message::PublicMessage { - sender_name: "system".to_owned(), - sender_display_name: "system".to_owned(), + code: crate::events::room_join::RoomJoined::CODE, + params: crate::events::room_join::RoomJoined { channel_name: self.name.clone(), - channel_ty: self.channel, - text: "joined".to_owned(), - is_dev: false, - is_mod: false, - is_admin: false, + player_name: handle.name().to_owned(), + player_state: oj_rc_core::data::channel::ChatPlayerState::Idk0, + use_custom_avatar: false, + custom_avatar: Vec::default(), + avatar_id: 0, }.as_event_params(), }; handle.send(polariton_server::ToSend::Data { data: polariton::packet::Data::Event(event), encrypt: true, - channel: 0, + channel: crate::events::room_join::RoomJoined::CHANNEL, reliable: true, }); self.online_users.push(handle); diff --git a/rc_chat_room/src/state/chat/user.rs b/rc_chat_room/src/state/chat/user.rs index 9524761..b0502b1 100644 --- a/rc_chat_room/src/state/chat/user.rs +++ b/rc_chat_room/src/state/chat/user.rs @@ -24,6 +24,17 @@ impl UserHandle { } } + /*pub fn send_later(&self, to_send: polariton_server::ToSend, wait: std::time::Duration) { + tokio::spawn(Self::send_after(self.event_tx.clone(), to_send, wait)); + } + + async fn send_after(event_tx: tokio::sync::mpsc::WeakUnboundedSender, to_send: polariton_server::ToSend, wait: std::time::Duration) { + tokio::time::sleep(wait).await; + if let Some(event_tx) = event_tx.upgrade() { + event_tx.send(to_send).unwrap_or_default(); + } + }*/ + pub fn send_private_message(&self, message: crate::events::chat_message::PrivateMessage) { let event = polariton::operation::Event { code: 2, diff --git a/rc_core/src/persist/chat.rs b/rc_core/src/persist/chat.rs index 0226bb7..ddd8396 100644 --- a/rc_core/src/persist/chat.rs +++ b/rc_core/src/persist/chat.rs @@ -7,6 +7,10 @@ pub struct ChatConfig { #[serde(default = "default_command_chann")] pub command_channel: String, pub commands: Vec, + #[serde(default = "default_selected_chann")] + pub default_channel: String, + #[serde(default = "default_true")] + pub can_create_channels: bool, } #[derive(Serialize, Deserialize, Clone, Debug)] @@ -36,7 +40,7 @@ fn default_pub_channs() -> Vec { vec![ "main".to_owned(), "sys".to_owned(), - "openjam_worship".to_owned(), + "jam_club".to_owned(), ] } @@ -44,3 +48,11 @@ fn default_pub_channs() -> Vec { fn default_command_chann() -> String { "sys".to_owned() } + +fn default_selected_chann() -> String { + "jam_club".to_owned() +} + +fn default_true() -> bool { + true +} diff --git a/rc_core/src/persist/config/cubes_json.rs b/rc_core/src/persist/config/cubes_json.rs index 42025f7..0fb0baf 100644 --- a/rc_core/src/persist/config/cubes_json.rs +++ b/rc_core/src/persist/config/cubes_json.rs @@ -288,6 +288,8 @@ impl super::ConfigProvider for CubeConfig { super::ChatSystemConfig { command_channel: self.chat.command_channel.clone(), commands: self.chat.commands.clone(), + default_channel: self.chat.default_channel.clone(), + can_create_channels: self.chat.can_create_channels, } } @@ -408,4 +410,12 @@ impl super::ConfigProvider for CubeConfig { (map.into_conf(), map_conf) }).collect() } + + fn url_links(&self) -> super::LinksConfig { + super::LinksConfig { + feedback_url: self.settings.server.feedback_url.clone(), + support_url: self.settings.server.support_url.clone(), + wiki_url: self.settings.server.wiki_url.clone(), + } + } } diff --git a/rc_core/src/persist/config/mod.rs b/rc_core/src/persist/config/mod.rs index a04f80f..17dcbd0 100644 --- a/rc_core/src/persist/config/mod.rs +++ b/rc_core/src/persist/config/mod.rs @@ -2,7 +2,7 @@ mod cubes_json; pub use cubes_json::CubeConfig; mod traits; -pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig}; +pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig}; pub type ConfigImpl = CubeConfig; diff --git a/rc_core/src/persist/config/traits.rs b/rc_core/src/persist/config/traits.rs index 11f64e0..44bc0ac 100644 --- a/rc_core/src/persist/config/traits.rs +++ b/rc_core/src/persist/config/traits.rs @@ -32,6 +32,7 @@ pub trait ConfigProvider { // FIXME don't use serializable types in traits fn network_config(&self) -> crate::persist::NetworkConf; fn maps(&self) -> std::collections::HashMap; + fn url_links(&self) -> LinksConfig; } pub struct CompleteCampaignProvider { @@ -153,6 +154,8 @@ impl GarageUpgrades { pub struct ChatSystemConfig { pub command_channel: String, pub commands: Vec, + pub default_channel: String, + pub can_create_channels: bool, } #[derive(Clone, Debug)] @@ -355,3 +358,10 @@ pub struct MapConfig { pub spawns: std::collections::HashMap>, // team -> points pub bases: std::collections::HashMap, // team -> base } + +#[derive(Clone, Debug)] +pub struct LinksConfig { + pub feedback_url: String, + pub support_url: String, + pub wiki_url: String, +} diff --git a/rc_core/src/persist/settings.rs b/rc_core/src/persist/settings.rs index dabe163..9f0595c 100644 --- a/rc_core/src/persist/settings.rs +++ b/rc_core/src/persist/settings.rs @@ -22,7 +22,7 @@ fn default_gameplay_settings() -> super::GameplaySettings { shield_hps: 2_000, request_review_level: 10_000, critical_ratio: 5.0, - cross_promo_image: "https://git.ngram.ca/OpenJam/servers/raw/branch/main/assets/robocraft/favicon.jpg".to_owned(), + cross_promo_image: "https://git.ngram.ca/OpenJam/servers/raw/branch/main/assets/robocraft/default.png".to_owned(), cross_promo_link: "https://git.ngram.ca/OpenJam/servers".to_owned(), } } @@ -78,6 +78,12 @@ pub struct ServerSettings { pub queue_mode: QueueMode, #[serde(default = "default_cdn_root_url")] pub cdn_url: String, + #[serde(default = "default_feedback_url")] + pub feedback_url: String, + #[serde(default = "default_support_url")] + pub support_url: String, + #[serde(default = "default_wiki_url")] + pub wiki_url: String, } #[derive(Serialize, Deserialize, Clone, Debug, Default)] @@ -98,9 +104,24 @@ fn default_server_conf() -> ServerSettings { auto_signup: false, queue_mode: QueueMode::Notify, cdn_url: default_cdn_root_url(), + feedback_url: default_feedback_url(), + support_url: default_support_url(), + wiki_url: default_wiki_url(), } } fn default_cdn_root_url() -> String { "http://127.0.0.1:8010".to_owned() } + +fn default_feedback_url() -> String { + "https://mstdn.ca/@ngram".to_owned() +} + +fn default_support_url() -> String { + "https://rvlt.gg/jtVE0pD5".to_owned() +} + +fn default_wiki_url() -> String { + "https://git.ngram.ca/OpenJam/servers/wiki".to_owned() +} diff --git a/rc_core/src/persist/user/account_json.rs b/rc_core/src/persist/user/account_json.rs index edbe0aa..a476d30 100644 --- a/rc_core/src/persist/user/account_json.rs +++ b/rc_core/src/persist/user/account_json.rs @@ -1142,11 +1142,20 @@ impl super::GameEventSetter for GameEventSetterImpl { impl super::ChatUser for UserData { async fn subscribed_channels(&self) -> Result, i16> { let channels = self.subscribed_channels_strings().await?; + log::info!("User is subscribed to channels {:?}", channels); Ok(polariton::operation::Typed::Arr(polariton::operation::Arr { ty: polariton::serdes::TypePrefix::HashMap, // hashtable - items: channels.iter().map(|name| crate::data::channel::ChatChannelInfo { - channel_name: name.to_owned(), - members: Vec::default(), + items: channels.into_iter().map(|name| crate::data::channel::ChatChannelInfo { + channel_name: name, + members: vec![ + crate::data::channel::ChatChannelMember { + name: self.account.display_name.clone(), + use_custom_avatar: false, + state: crate::data::channel::ChatPlayerState::Idk0, + custom_avatar: Vec::default(), + avatar_id: 0, + }, + ], channel_ty: crate::data::channel::ChatChannelType::Public, }.as_transmissible()).collect() })) diff --git a/rc_services_room/src/operations/mod.rs b/rc_services_room/src/operations/mod.rs index a64c280..c67981d 100644 --- a/rc_services_room/src/operations/mod.rs +++ b/rc_services_room/src/operations/mod.rs @@ -113,7 +113,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler .add(polariton_server::operations::Ack::<132, _>::default()) // verify user level .add(load_analytics::NoAnalytics) .add(polariton_server::operations::Ack::<131, _>::default()) // analytics updated notification - .add(platform_config::platform_config_provider()) + .add(platform_config::platform_config_provider(&init_ctx.cubes)) .add(tier_banding::tiers_banding_provider()) .add(cube_list::cube_list_provider(&init_ctx.cubes)) .add(special_items::special_item_list_provider()) diff --git a/rc_services_room/src/operations/platform_config.rs b/rc_services_room/src/operations/platform_config.rs index a0b6763..851b03e 100644 --- a/rc_services_room/src/operations/platform_config.rs +++ b/rc_services_room/src/operations/platform_config.rs @@ -1,29 +1,54 @@ -use polariton_server::operations::SimpleFunc; +use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl}; use polariton::{operation::{Dict, ParameterTable, Typed}, serdes::TypePrefix}; +const CODE: u8 = 165; + const PLATFORM_CONFIG_KEY: u8 = 197; -pub(super) fn platform_config_provider() -> SimpleFunc<165, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { - SimpleFunc::new(|params, _| { +pub(super) fn platform_config_provider(conf: &oj_rc_core::ConfigImpl) -> SimpleOpImpl { + SimpleOpImpl::new(PlatformConfigProvider { + chat_config: >::chat_system_config(conf), + links: >::url_links(conf), + }) +} + +pub(super) struct PlatformConfigProvider { + chat_config: oj_rc_core::persist::config::ChatSystemConfig, + links: oj_rc_core::persist::config::LinksConfig, +} + +#[async_trait::async_trait] +impl SimpleOperation for PlatformConfigProvider { + type User = crate::UserTy; + const CODE: u8 = CODE; + + async fn handle(&self, params: ParameterTable, user: &Self::User) -> Result, SimpleOpError> { + let user = user.user()?; + let mut connected_channels = user.subscribed_channels_strings().await?; + let client_selected_channel = if connected_channels.is_empty() || connected_channels.contains(&self.chat_config.default_channel) { + self.chat_config.default_channel.clone() + } else { + connected_channels.remove(0) + }; let mut params = params.to_dict(); params.insert(PLATFORM_CONFIG_KEY, Typed::Dict(Dict { key_ty: TypePrefix::Any, // obj val_ty: TypePrefix::Any, // obj items: vec![ - (Typed::Str("BuyPremiumAvailable".into()), Typed::Bool(false.into())), - (Typed::Str("MainShopButtonAvailable".into()), Typed::Bool(false.into())), - (Typed::Str("RoboPassButtonAvailable".into()), Typed::Bool(false.into())), - (Typed::Str("LanguageSelectionAvailable".into()), Typed::Bool(false.into())), - (Typed::Str("AutoJoinPublicChatRoom".into()), Typed::Bool(true.into())), // TODO maybe? - (Typed::Str("CanCreateChatRooms".into()), Typed::Bool(true.into())), // TODO - (Typed::Str("CurseVoiceEnabled".into()), Typed::Bool(false.into())), - (Typed::Str("DeltaDNAEnabled".into()), Typed::Bool(false.into())), - (Typed::Str("UseDecimalSystem".into()), Typed::Bool(true.into())), - (Typed::Str("FeedbackURL".into()), Typed::Str("https://mstdn.ca/@ngram".into())), - (Typed::Str("SupportURL".into()), Typed::Str("https://git.ngni.us/OpenJam/servers".into())), - (Typed::Str("WikiURL".into()), Typed::Str("https://git.ngram.ca/OpenJam/servers/wiki".into())), + (Typed::Str("BuyPremiumAvailable".into()), Typed::Bool(false)), + (Typed::Str("MainShopButtonAvailable".into()), Typed::Bool(false)), + (Typed::Str("RoboPassButtonAvailable".into()), Typed::Bool(false)), + (Typed::Str("LanguageSelectionAvailable".into()), Typed::Bool(false)), + (Typed::Str("AutoJoinPublicChatRoom".into()), Typed::Str(client_selected_channel.into())), + (Typed::Str("CanCreateChatRooms".into()), Typed::Bool(self.chat_config.can_create_channels)), + (Typed::Str("CurseVoiceEnabled".into()), Typed::Bool(false)), + (Typed::Str("DeltaDNAEnabled".into()), Typed::Bool(false)), + (Typed::Str("UseDecimalSystem".into()), Typed::Bool(true)), + (Typed::Str("FeedbackURL".into()), Typed::Str(self.links.feedback_url.clone().into())), + (Typed::Str("SupportURL".into()), Typed::Str(self.links.support_url.clone().into())), + (Typed::Str("WikiURL".into()), Typed::Str(self.links.wiki_url.clone().into())), ].into(), })); Ok(params.into()) - }) + } }