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:
@@ -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?);
|
||||
|
||||
Reference in New Issue
Block a user