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:
2025-06-06 17:52:29 -04:00
parent 85d41c0239
commit ad6ba2c8e6
32 changed files with 787 additions and 92 deletions

View 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());
}
}
}
}

View 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());
// }
}
}
}

View 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);
}

View 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());
}
}
}
}