mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Fix auto-selecting chat channel, add some more config options
This commit is contained in:
BIN
assets/robocraft/default.png
Normal file
BIN
assets/robocraft/default.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 39 KiB |
@@ -10,6 +10,8 @@ pub struct PublicMessage {
|
||||
}
|
||||
|
||||
impl PublicMessage {
|
||||
pub const CODE: u8 = 1;
|
||||
|
||||
pub fn as_event_params<C>(&self) -> polariton::operation::ParameterTable<C> {
|
||||
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 <C: Send + 'static> polariton_server::events::IntoEvent<C> for PublicMessage {
|
||||
const CHANNEL: u8 = 0;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
polariton::operation::Event {
|
||||
code: Self::CODE,
|
||||
params: self.as_event_params().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <C: Send + 'static> polariton_server::events::IntoEvent<C> for &PublicMessage {
|
||||
const CHANNEL: u8 = 0;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
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<C>(&self) -> polariton::operation::ParameterTable<C> {
|
||||
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 <C: Send + 'static> polariton_server::events::IntoEvent<C> for PrivateMessage {
|
||||
const CHANNEL: u8 = 0;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
polariton::operation::Event {
|
||||
code: Self::CODE,
|
||||
params: self.as_event_params().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <C: Send + 'static> polariton_server::events::IntoEvent<C> for &PrivateMessage {
|
||||
const CHANNEL: u8 = 0;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
polariton::operation::Event {
|
||||
code: PrivateMessage::CODE,
|
||||
params: self.as_event_params().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1 +1,3 @@
|
||||
pub mod chat_message;
|
||||
pub mod player_update;
|
||||
pub mod room_join;
|
||||
|
||||
44
rc_chat_room/src/events/player_update.rs
Normal file
44
rc_chat_room/src/events/player_update.rs
Normal file
@@ -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<C>(&self) -> polariton::operation::ParameterTable<C> {
|
||||
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 <C: Send + 'static> polariton_server::events::IntoEvent<C> for PlayerUpdated {
|
||||
const CHANNEL: u8 = Self::CHANNEL;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
polariton::operation::Event {
|
||||
code: Self::CODE,
|
||||
params: self.as_event_params().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <C: Send + 'static> polariton_server::events::IntoEvent<C> for &PlayerUpdated {
|
||||
const CHANNEL: u8 = PlayerUpdated::CHANNEL;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
polariton::operation::Event {
|
||||
code: PlayerUpdated::CODE,
|
||||
params: self.as_event_params().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
53
rc_chat_room/src/events/room_join.rs
Normal file
53
rc_chat_room/src/events/room_join.rs
Normal file
@@ -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<u8>,
|
||||
pub avatar_id: i32,
|
||||
}
|
||||
|
||||
impl RoomJoined {
|
||||
pub const CODE: u8 = 4;
|
||||
pub const CHANNEL: u8 = 0;
|
||||
|
||||
pub fn as_event_params<C>(&self) -> polariton::operation::ParameterTable<C> {
|
||||
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 <C: Send + 'static> polariton_server::events::IntoEvent<C> for RoomJoined {
|
||||
const CHANNEL: u8 = Self::CHANNEL;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
polariton::operation::Event {
|
||||
code: Self::CODE,
|
||||
params: self.as_event_params().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl <C: Send + 'static> polariton_server::events::IntoEvent<C> for &RoomJoined {
|
||||
const CHANNEL: u8 = RoomJoined::CHANNEL;
|
||||
const ENCRYPT: bool = true;
|
||||
const RELIABLE: bool = true;
|
||||
|
||||
fn into_event(self) -> polariton::operation::Event<C> {
|
||||
polariton::operation::Event {
|
||||
code: RoomJoined::CODE,
|
||||
params: self.as_event_params().into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<ParameterTable, i16> {
|
||||
async fn do_handling(params: ParameterTable<()>, user: &crate::UserTy, chat_system: &crate::state::chat::ChatImpl) -> Result<ParameterTable, i16> {
|
||||
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::<CODE, ()>(do_handling(params, user).await)
|
||||
polariton_server::operations::result_to_op_resp::<CODE, ()>(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,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<crate::UserTy> {
|
||||
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))
|
||||
|
||||
@@ -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<std::collections::HashMap<std::any::TypeId, Box<dyn std::any::Any + Send + Sync + 'static>>> {
|
||||
@@ -33,12 +30,12 @@ impl MoreLobbyAuth {
|
||||
async fn do_auth<C>(&self, params: std::collections::HashMap<u8, Typed<C>>, user: &crate::UserTy) -> Result<polariton::operation::ParameterTable<C>, 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());
|
||||
|
||||
@@ -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<ParameterTable, i16> {
|
||||
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?);
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub struct ChatRoom {
|
||||
name: String,
|
||||
#[allow(dead_code)]
|
||||
channel: crate::data::channel::ChatChannelType,
|
||||
online_users: Vec<super::UserHandle>,
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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<polariton_server::ToSend>, 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,
|
||||
|
||||
@@ -7,6 +7,10 @@ pub struct ChatConfig {
|
||||
#[serde(default = "default_command_chann")]
|
||||
pub command_channel: String,
|
||||
pub commands: Vec<ChatCommand>,
|
||||
#[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<String> {
|
||||
vec![
|
||||
"main".to_owned(),
|
||||
"sys".to_owned(),
|
||||
"openjam_worship".to_owned(),
|
||||
"jam_club".to_owned(),
|
||||
]
|
||||
}
|
||||
|
||||
@@ -44,3 +48,11 @@ fn default_pub_channs() -> Vec<String> {
|
||||
fn default_command_chann() -> String {
|
||||
"sys".to_owned()
|
||||
}
|
||||
|
||||
fn default_selected_chann() -> String {
|
||||
"jam_club".to_owned()
|
||||
}
|
||||
|
||||
fn default_true() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
@@ -288,6 +288,8 @@ impl <C: Clone + Send> super::ConfigProvider<C> 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 <C: Clone + Send> super::ConfigProvider<C> 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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ pub trait ConfigProvider<C: Clone> {
|
||||
// FIXME don't use serializable types in traits
|
||||
fn network_config(&self) -> crate::persist::NetworkConf;
|
||||
fn maps(&self) -> std::collections::HashMap<GameMap, MapConfig>;
|
||||
fn url_links(&self) -> LinksConfig;
|
||||
}
|
||||
|
||||
pub struct CompleteCampaignProvider {
|
||||
@@ -153,6 +154,8 @@ impl GarageUpgrades {
|
||||
pub struct ChatSystemConfig {
|
||||
pub command_channel: String,
|
||||
pub commands: Vec<crate::persist::ChatCommand>,
|
||||
pub default_channel: String,
|
||||
pub can_create_channels: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -355,3 +358,10 @@ pub struct MapConfig {
|
||||
pub spawns: std::collections::HashMap<u8, Vec<Point>>, // team -> points
|
||||
pub bases: std::collections::HashMap<u8, (Sphere, f32)>, // team -> base
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct LinksConfig {
|
||||
pub feedback_url: String,
|
||||
pub support_url: String,
|
||||
pub wiki_url: String,
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -1142,11 +1142,20 @@ impl super::GameEventSetter for GameEventSetterImpl {
|
||||
impl super::ChatUser for UserData {
|
||||
async fn subscribed_channels(&self) -> Result<polariton::operation::Typed<()>, 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()
|
||||
}))
|
||||
|
||||
@@ -113,7 +113,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
||||
.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())
|
||||
|
||||
@@ -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<ParameterTable, i16>) + Sync + Sync> {
|
||||
SimpleFunc::new(|params, _| {
|
||||
pub(super) fn platform_config_provider<C: Send + 'static>(conf: &oj_rc_core::ConfigImpl) -> SimpleOpImpl<C, crate::UserTy, PlatformConfigProvider> {
|
||||
SimpleOpImpl::new(PlatformConfigProvider {
|
||||
chat_config: <oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::chat_system_config(conf),
|
||||
links: <oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::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 <C: Send + 'static> SimpleOperation<C> for PlatformConfigProvider {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CODE;
|
||||
|
||||
async fn handle(&self, params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, 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())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user