mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Prefix all crates with oj_ and use release version of dependencies
This commit is contained in:
@@ -1 +1 @@
|
||||
pub use rc_core::data::channel;
|
||||
pub use oj_rc_core::data::channel;
|
||||
|
||||
@@ -8,14 +8,14 @@ mod data;
|
||||
mod operations;
|
||||
mod events;
|
||||
|
||||
use polariton_auth::Handshake;
|
||||
use rc_core::ConfigProvider;
|
||||
use oj_polariton_auth::Handshake;
|
||||
use oj_rc_core::ConfigProvider;
|
||||
use tokio::net;
|
||||
|
||||
use polariton::packet::{Data, Message, Packet, StandardMessage};
|
||||
use polariton::operation::{OperationResponse, Typed};
|
||||
|
||||
pub type UserTy = rc_core::UserState;
|
||||
pub type UserTy = oj_rc_core::UserState;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
@@ -23,10 +23,10 @@ async fn main() -> std::io::Result<()> {
|
||||
let args = cli::CliArgs::get();
|
||||
log::debug!("Got cli args {:?}", args);
|
||||
|
||||
let cubes = rc_core::persist::config::ConfigImpl::load(&args.assets).expect("Bad config data");
|
||||
let users = std::sync::Arc::new(rc_core::persist::user::UserImpl::load(&args.data, &cubes).await.expect("Bad user data"));
|
||||
let cubes = oj_rc_core::persist::config::ConfigImpl::load(&args.assets).expect("Bad config data");
|
||||
let users = std::sync::Arc::new(oj_rc_core::persist::user::UserImpl::load(&args.data, &cubes).await.expect("Bad user data"));
|
||||
|
||||
let chat_system = state::chat::ChatImpl::new(<rc_core::ConfigImpl as ConfigProvider<()>>::chat_system_config(&cubes)).expect("Bad chat config data");
|
||||
let chat_system = state::chat::ChatImpl::new(<oj_rc_core::ConfigImpl as ConfigProvider<()>>::chat_system_config(&cubes)).expect("Bad chat config data");
|
||||
|
||||
let server = std::sync::Arc::new(polariton_server::Server::new(operations::handler(chat_system, &cubes), polariton_server::events::EventsHandler::new()));
|
||||
|
||||
@@ -49,7 +49,7 @@ async fn main() -> std::io::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: std::sync::Arc<polariton_server::Server<crate::UserTy>>, users: std::sync::Arc<rc_core::persist::user::UserImpl>) {
|
||||
async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAddr, server: std::sync::Arc<polariton_server::Server<crate::UserTy>>, users: std::sync::Arc<oj_rc_core::persist::user::UserImpl>) {
|
||||
log::debug!("Accepting connection from address {}", address);
|
||||
let enc = match do_connect_handshake(&mut socket).await {
|
||||
Some(x) => x,
|
||||
@@ -59,7 +59,7 @@ async fn process_socket(mut socket: net::TcpStream, address: std::net::SocketAdd
|
||||
}
|
||||
};
|
||||
let (chann_tx, chann_rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
let user_state = rc_core::UserState::<()>::new(users, chann_tx.clone());
|
||||
let user_state = oj_rc_core::UserState::<()>::new(users, chann_tx.clone());
|
||||
let (socket_r, socket_w) = socket.into_split();
|
||||
server.handle_async_with_channel(socket_r, socket_w, user_state, polariton::packet::SerdesContext::from_boxed(Default::default(), enc), chann_tx, chann_rx).await;
|
||||
log::debug!("Goodbye connection from address {}", address);
|
||||
@@ -95,7 +95,7 @@ impl AuthError {
|
||||
}
|
||||
}
|
||||
|
||||
impl polariton_auth::AuthProvider<AuthError> for AuthImpl {
|
||||
impl oj_polariton_auth::AuthProvider<AuthError> for AuthImpl {
|
||||
fn validate(&mut self, params: &std::collections::HashMap<u8, Typed>) -> Result<std::collections::HashMap<u8, Typed>, AuthError> {
|
||||
if let Some(Typed::Str(token)) = params.get(&TOKEN_KEY) {
|
||||
if let Some(Typed::Str(service)) = params.get(&SERVICE_KEY) {
|
||||
@@ -198,7 +198,7 @@ async fn do_connect_handshake(
|
||||
let to_send = match handshake.authenticate(&packet3, &ctx) {
|
||||
Ok(x) => x,
|
||||
Err(h) => match h.extra {
|
||||
polariton_auth::AuthError::Validation(e) => {
|
||||
oj_polariton_auth::AuthError::Validation(e) => {
|
||||
e.log_err();
|
||||
return None;
|
||||
},
|
||||
|
||||
@@ -24,8 +24,8 @@ impl <C: Send + 'static> SimpleOperation<C> for AddSanctionProvider {
|
||||
if let Some(Typed::Str(reason)) = params.remove(&REASON_PARAM_KEY) {
|
||||
if let Some(Typed::Str(username)) = params.remove(&USERNAME_PARAM_KEY) {
|
||||
let user_info = user.user()?;
|
||||
let sanction = rc_core::persist::user::SetSanction {
|
||||
type_: rc_core::persist::user::SanctionType::from_i32(sanction_ty)?,
|
||||
let sanction = oj_rc_core::persist::user::SetSanction {
|
||||
type_: oj_rc_core::persist::user::SanctionType::from_i32(sanction_ty)?,
|
||||
is_adding,
|
||||
duration,
|
||||
reason: reason.string,
|
||||
@@ -38,7 +38,7 @@ impl <C: Send + 'static> SimpleOperation<C> for AddSanctionProvider {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err((rc_core::data::error_codes::ChatErrorCodes::UnexpectedError as i16).into())
|
||||
Err((oj_rc_core::data::error_codes::ChatErrorCodes::UnexpectedError as i16).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//use rc_core::persist::user::ChatUser;
|
||||
//use oj_rc_core::persist::user::ChatUser;
|
||||
use polariton::operation::{ParameterTable, OperationResponse};
|
||||
|
||||
const CODE: u8 = 11;
|
||||
|
||||
@@ -21,7 +21,7 @@ impl SimpleOperation<()> for GetSanctionsProvider {
|
||||
params.insert(SANCTIONS_PARAM_KEY, sanctions);
|
||||
return Ok(params.into());
|
||||
}
|
||||
Err((rc_core::data::error_codes::ChatErrorCodes::UnexpectedError as i16).into())
|
||||
Err((oj_rc_core::data::error_codes::ChatErrorCodes::UnexpectedError as i16).into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ mod list_sanctions;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
pub fn handler(chat_system: crate::state::chat::ChatImpl, conf: &rc_core::persist::config::ConfigImpl) -> OperationsHandler<crate::UserTy> {
|
||||
pub fn handler(chat_system: crate::state::chat::ChatImpl, conf: &oj_rc_core::persist::config::ConfigImpl) -> OperationsHandler<crate::UserTy> {
|
||||
OperationsHandler::new()
|
||||
.modify(rc_core::polariton::OpIdCopy)
|
||||
.modify(oj_rc_core::polariton::OpIdCopy)
|
||||
.add(more_auth::MoreLobbyAuth::new(chat_system.clone()))
|
||||
.add(chat_ignores::ignores_provider())
|
||||
.add(pending_sanctions::pending_sanctions_checker())
|
||||
|
||||
@@ -2,7 +2,7 @@ use polariton::operation::Typed;
|
||||
use polariton_server::operations::{Operation, OperationCode};
|
||||
|
||||
//use crate::persist::chat_user::{ChatUser, ChatUserImpl};
|
||||
//use rc_core::persist::user::ChatUser;
|
||||
//use oj_rc_core::persist::user::ChatUser;
|
||||
|
||||
pub struct MoreLobbyAuth {
|
||||
chat_system: crate::state::chat::ChatImpl,
|
||||
@@ -17,8 +17,8 @@ impl MoreLobbyAuth {
|
||||
}
|
||||
}
|
||||
|
||||
/*fn build_ext_map(&self, token: &rc_core::persist::user::UserToken) -> Option<std::collections::HashMap<std::any::TypeId, Box<dyn std::any::Any + Send + Sync + 'static>>> {
|
||||
let user_dir = self.root.join(rc_core::persist::user::USERS_DIR).join(&token.uuid);
|
||||
/*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>>> {
|
||||
let user_dir = self.root.join(oj_rc_core::persist::user::USERS_DIR).join(&token.uuid);
|
||||
let data = if let Ok(data) = ChatUserImpl::load(&user_dir) {
|
||||
data
|
||||
} else {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use polariton_server::operations::Immediate;
|
||||
//use polariton::operation::{ParameterTable, Typed};
|
||||
use rc_core::ConfigProvider;
|
||||
use oj_rc_core::ConfigProvider;
|
||||
|
||||
const PARAM_KEY: u8 = 20;
|
||||
|
||||
pub(super) fn public_channels_provider(conf: &rc_core::persist::config::ConfigImpl) -> Immediate<13, crate::UserTy> {
|
||||
pub(super) fn public_channels_provider(conf: &oj_rc_core::persist::config::ConfigImpl) -> Immediate<13, crate::UserTy> {
|
||||
let pub_channs = conf.public_channels();
|
||||
Immediate::new(move || {
|
||||
let mut params = std::collections::HashMap::with_capacity(1);
|
||||
|
||||
@@ -17,7 +17,7 @@ pub fn send_public_message_handler(chat_system: crate::state::chat::ChatImpl) ->
|
||||
let user = user.user()?;
|
||||
if message_text.string.bytes().len() > MAX_MESSAGE_LEN {
|
||||
log::warn!("Rejecting too long chat message from {}", user.token().uuid);
|
||||
return Err(rc_core::data::error_codes::ChatErrorCodes::Flood as i16)
|
||||
return Err(oj_rc_core::data::error_codes::ChatErrorCodes::Flood as i16)
|
||||
}
|
||||
let chat_loc = if let Some(Typed::Str(chat_loc)) = params.remove(&CHAT_LOCATION_PARAM_KEY) {
|
||||
chat_loc.string.clone()
|
||||
@@ -44,7 +44,7 @@ pub fn send_private_message_handler(chat_system: crate::state::chat::ChatImpl) -
|
||||
let user = user.user()?;
|
||||
if message_text.string.bytes().len() > MAX_MESSAGE_LEN {
|
||||
log::warn!("Rejecting too long chat message from {}", user.token().uuid);
|
||||
return Err(rc_core::data::error_codes::ChatErrorCodes::Flood as i16)
|
||||
return Err(oj_rc_core::data::error_codes::ChatErrorCodes::Flood as i16)
|
||||
}
|
||||
let chat_loc = if let Some(Typed::Str(chat_loc)) = params.remove(&CHAT_LOCATION_PARAM_KEY) {
|
||||
chat_loc.string.clone()
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//use rc_core::persist::user::ChatUser;
|
||||
//use oj_rc_core::persist::user::ChatUser;
|
||||
use polariton::operation::{ParameterTable, OperationResponse};
|
||||
|
||||
const CODE: u8 = 12;
|
||||
|
||||
@@ -30,7 +30,7 @@ pub(super) fn is_online_provider(chat_system: crate::state::ChatImpl) -> SimpleC
|
||||
Ok(params.into())
|
||||
}
|
||||
} else {
|
||||
Err(rc_core::data::error_codes::ChatErrorCodes::UnexpectedError as _)
|
||||
Err(oj_rc_core::data::error_codes::ChatErrorCodes::UnexpectedError as _)
|
||||
}
|
||||
}, chat_system)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ pub struct ChatProvider {
|
||||
}
|
||||
|
||||
impl ChatProvider {
|
||||
pub fn new(conf: rc_core::persist::config::ChatSystemConfig) -> std::io::Result<Self> {
|
||||
pub fn new(conf: oj_rc_core::persist::config::ChatSystemConfig) -> std::io::Result<Self> {
|
||||
Ok(Self {
|
||||
chat_system: std::sync::Arc::new(std::sync::RwLock::new(crate::state::chat::ChatSystem::new(conf)?)),
|
||||
})
|
||||
@@ -83,7 +83,7 @@ impl ChatSystem {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_public_message(&self, user: &dyn rc_core::persist::user::User<()>, text: String, channel: String, channel_ty: crate::data::channel::ChatChannelType) {
|
||||
pub fn handle_public_message(&self, user: &dyn oj_rc_core::persist::user::User<()>, text: String, channel: String, channel_ty: crate::data::channel::ChatChannelType) {
|
||||
if self.config.is_command_channel(&channel) {
|
||||
if let Some(user_handle) = self.online_users.get(&user.token().uuid) {
|
||||
self.handle_public_command(user, text, user_handle, channel, channel_ty);
|
||||
@@ -103,7 +103,7 @@ impl ChatSystem {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_public_command(&self, user: &dyn rc_core::persist::user::User<()>, text: String, handle: &super::UserHandle, channel: String, channel_ty: crate::data::channel::ChatChannelType) {
|
||||
fn handle_public_command(&self, user: &dyn oj_rc_core::persist::user::User<()>, text: String, handle: &super::UserHandle, channel: String, channel_ty: crate::data::channel::ChatChannelType) {
|
||||
let event_params = crate::events::chat_message::PublicMessage {
|
||||
sender_name: self.config.command_username().to_owned(),
|
||||
sender_display_name: self.config.command_username().to_owned(),
|
||||
@@ -126,7 +126,7 @@ impl ChatSystem {
|
||||
handle.send(polariton_server::ToSend::Data { data: polariton::packet::Data::Event(event), encrypt: true, channel: 0, reliable: true });
|
||||
}
|
||||
|
||||
pub fn handle_private_message(&self, user: &dyn rc_core::persist::user::User<()>, text: String, recipient: String) {
|
||||
pub fn handle_private_message(&self, user: &dyn oj_rc_core::persist::user::User<()>, text: String, recipient: String) {
|
||||
if self.config.is_command_user(&recipient) {
|
||||
if let Some(user_handle) = self.online_users.get(&user.token().uuid) {
|
||||
self.handle_private_command(user, text, user_handle);
|
||||
@@ -144,7 +144,7 @@ impl ChatSystem {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_private_command(&self, user: &dyn rc_core::persist::user::User<()>, text: String, handle: &super::UserHandle) {
|
||||
fn handle_private_command(&self, user: &dyn oj_rc_core::persist::user::User<()>, text: String, handle: &super::UserHandle) {
|
||||
let event_params = crate::events::chat_message::PrivateMessage {
|
||||
sender_name: self.config.command_username().to_owned(),
|
||||
sender_display_name: self.config.command_username().to_owned(),
|
||||
@@ -161,7 +161,7 @@ impl ChatSystem {
|
||||
handle.send_private_message(response);
|
||||
}
|
||||
|
||||
pub fn new(config: rc_core::persist::config::ChatSystemConfig) -> std::io::Result<Self> {
|
||||
pub fn new(config: oj_rc_core::persist::config::ChatSystemConfig) -> std::io::Result<Self> {
|
||||
Ok(Self {
|
||||
chats: HashMap::new(),
|
||||
online_users: HashMap::new(),
|
||||
|
||||
@@ -7,11 +7,11 @@ pub struct ChatSystemConfig {
|
||||
#[derive(Clone, Copy)]
|
||||
struct CommandContext<'a, 'b> {
|
||||
chat_system: &'a super::ChatSystem,
|
||||
user: &'b dyn rc_core::persist::user::User<()>,
|
||||
user: &'b dyn oj_rc_core::persist::user::User<()>,
|
||||
}
|
||||
|
||||
impl ChatSystemConfig {
|
||||
pub fn from_persist(config: rc_core::persist::config::ChatSystemConfig) -> std::io::Result<Self> {
|
||||
pub fn from_persist(config: oj_rc_core::persist::config::ChatSystemConfig) -> std::io::Result<Self> {
|
||||
let mut compiled_commands = Vec::with_capacity(config.commands.len());
|
||||
for (i, cmd) in config.commands.into_iter().enumerate() {
|
||||
let compiled_command = ChatCommand::compile_command(cmd).map_err(|e| {
|
||||
@@ -26,7 +26,7 @@ impl ChatSystemConfig {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn perform_command(&self, text: &str, chat_system: &super::ChatSystem, user: &dyn rc_core::persist::user::User<()>,) -> String {
|
||||
pub fn perform_command(&self, text: &str, chat_system: &super::ChatSystem, user: &dyn oj_rc_core::persist::user::User<()>,) -> String {
|
||||
let ctx = CommandContext {
|
||||
chat_system,
|
||||
user,
|
||||
@@ -58,7 +58,7 @@ pub struct ChatCommand {
|
||||
}
|
||||
|
||||
impl ChatCommand {
|
||||
fn compile_command(command: rc_core::persist::ChatCommand) -> Result<Self, regex::Error> {
|
||||
fn compile_command(command: oj_rc_core::persist::ChatCommand) -> Result<Self, regex::Error> {
|
||||
Ok(Self {
|
||||
regex: regex::RegexBuilder::new(&command.regex).build()?,
|
||||
op: ChatOperation::from_persist(command.op)
|
||||
@@ -81,11 +81,11 @@ enum ChatOperation {
|
||||
}
|
||||
|
||||
impl ChatOperation {
|
||||
fn from_persist(op: rc_core::persist::ChatOperation) -> Self {
|
||||
fn from_persist(op: oj_rc_core::persist::ChatOperation) -> Self {
|
||||
match op {
|
||||
rc_core::persist::ChatOperation::BuiltIn(b_in) => Self::BuiltIn(BuiltIn::from_persist(b_in)),
|
||||
rc_core::persist::ChatOperation::Custom => Self::Custom,
|
||||
rc_core::persist::ChatOperation::Nop => Self::Nop,
|
||||
oj_rc_core::persist::ChatOperation::BuiltIn(b_in) => Self::BuiltIn(BuiltIn::from_persist(b_in)),
|
||||
oj_rc_core::persist::ChatOperation::Custom => Self::Custom,
|
||||
oj_rc_core::persist::ChatOperation::Nop => Self::Nop,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,10 +104,10 @@ enum BuiltIn {
|
||||
}
|
||||
|
||||
impl BuiltIn {
|
||||
fn from_persist(b_in: rc_core::persist::BuiltInChatOperation) -> Self {
|
||||
fn from_persist(b_in: oj_rc_core::persist::BuiltInChatOperation) -> Self {
|
||||
match b_in {
|
||||
rc_core::persist::BuiltInChatOperation::OnlineUsers => Self::OnlineUsers,
|
||||
rc_core::persist::BuiltInChatOperation::TotalUsers => Self::TotalUsers,
|
||||
oj_rc_core::persist::BuiltInChatOperation::OnlineUsers => Self::OnlineUsers,
|
||||
oj_rc_core::persist::BuiltInChatOperation::TotalUsers => Self::TotalUsers,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user