More work.
Added chat service Updated packet service to pass the tcp stream around in a Arc type. Updated character position data to not require multiplying the coords Added more debug logs Added an interceptor for gRPC comms with the chat server Updated build and push script for the chat server changes
This commit is contained in:
22
chat-service/src/chat_channels/guild_chat.rs
Normal file
22
chat-service/src/chat_channels/guild_chat.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use crate::chat_channels::ChatChannel;
|
||||
use crate::chat_service::Clients;
|
||||
use crate::chat_service::chat::ChatMessage;
|
||||
|
||||
/// A dedicated module for guild chat.
|
||||
#[derive(Debug)]
|
||||
pub struct GuildChat;
|
||||
|
||||
impl ChatChannel for GuildChat {
|
||||
fn handle_message(&self, message: ChatMessage, sender_id: &str, clients: &Clients) {
|
||||
// This is a placeholder. In a real implementation, verify
|
||||
// guild membership by consulting your Character or Guild service.
|
||||
let clients_lock = clients.lock().unwrap();
|
||||
for (id, tx) in clients_lock.iter() {
|
||||
// For demonstration, send only to clients whose IDs contain
|
||||
// "guild". Replace this logic with your actual membership check.
|
||||
if id != sender_id && id.contains("guild") {
|
||||
let _ = tx.try_send(message.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
chat-service/src/chat_channels/local_chat.rs
Normal file
22
chat-service/src/chat_channels/local_chat.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use tracing::debug;
|
||||
use crate::chat_channels::ChatChannel;
|
||||
use crate::chat_service::Clients;
|
||||
use crate::chat_service::chat::ChatMessage;
|
||||
|
||||
/// A dedicated module for local chat.
|
||||
#[derive(Debug)]
|
||||
pub struct LocalChat;
|
||||
|
||||
impl ChatChannel for LocalChat {
|
||||
fn handle_message(&self, message: ChatMessage, sender_id: &str, clients: &Clients) {
|
||||
// In a full implementation, you might query for nearby clients.
|
||||
// For demo purposes, we simply broadcast to all clients except the sender.
|
||||
debug!("LocalChat::handle_message: {:?}", message);
|
||||
let clients_lock = clients.lock().unwrap();
|
||||
for (id, tx) in clients_lock.iter() {
|
||||
// if id != sender_id {
|
||||
let _ = tx.try_send(message.clone());
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
12
chat-service/src/chat_channels/mod.rs
Normal file
12
chat-service/src/chat_channels/mod.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
pub mod local_chat;
|
||||
pub mod shout_chat;
|
||||
pub mod guild_chat;
|
||||
|
||||
/// Define a common trait for all dedicated chat channels.
|
||||
use crate::chat_service::Clients;
|
||||
use crate::chat_service::chat::ChatMessage;
|
||||
|
||||
pub trait ChatChannel: Send + Sync {
|
||||
/// Process and route the chat message.
|
||||
fn handle_message(&self, message: ChatMessage, sender_id: &str, clients: &Clients);
|
||||
}
|
||||
20
chat-service/src/chat_channels/shout_chat.rs
Normal file
20
chat-service/src/chat_channels/shout_chat.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use crate::chat_channels::ChatChannel;
|
||||
use crate::chat_service::Clients;
|
||||
use crate::chat_service::chat::ChatMessage;
|
||||
|
||||
/// A dedicated module for shout chat.
|
||||
#[derive(Debug)]
|
||||
pub struct ShoutChat;
|
||||
|
||||
impl ChatChannel for ShoutChat {
|
||||
fn handle_message(&self, message: ChatMessage, sender_id: &str, clients: &Clients) {
|
||||
// For demo purposes, we simply broadcast to all clients except the sender.
|
||||
// TODO: make sure the clients are on the same map
|
||||
let clients_lock = clients.lock().unwrap();
|
||||
for (id, tx) in clients_lock.iter() {
|
||||
if id != sender_id {
|
||||
let _ = tx.try_send(message.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user