1
0
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:
NG (Graham)
2025-08-13 22:17:24 -04:00
parent a8692b2839
commit 624fee6d72
20 changed files with 316 additions and 55 deletions

View File

@@ -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(),

View File

@@ -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);

View File

@@ -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,