Files
osirose-new/packet-service/src/connection_state.rs
raven 9fcd1741de Updated chat handler to use the MessageType enum values instead of numbers
Added local_id tracking for the packet service
Added mob spawning packet in response to game logic events (only for a NearbyUpdate event right now)
2025-07-22 00:23:56 -04:00

54 lines
1.7 KiB
Rust

use std::collections::HashMap;
use std::sync::Arc;
use std::fmt;
use tokio::net::TcpStream;
use tokio::io::{WriteHalf};
use crate::handlers::chat_client::ChatClientHandler;
#[derive(Clone)]
pub struct ConnectionState {
pub user_id: Option<String>,
pub session_id: Option<String>,
pub character_id: Option<i8>,
pub character_name: Option<String>,
pub character_list: Option<Vec<u32>>,
pub additional_data: HashMap<String, String>,
pub client_id: u16,
pub local_id: u16, // Local connection ID for packet routing
pub chat_handler: Option<Arc<ChatClientHandler>>,
pub writer: Option<Arc<tokio::sync::Mutex<WriteHalf<TcpStream>>>>,
}
impl ConnectionState {
pub fn new() -> Self {
Self {
user_id: None,
session_id: None,
character_id: None,
character_name: None,
character_list: None,
additional_data: HashMap::new(),
client_id: 0,
local_id: 0,
chat_handler: None,
writer: None,
}
}
}
impl fmt::Debug for ConnectionState {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("ConnectionState")
.field("user_id", &self.user_id)
.field("session_id", &self.session_id)
.field("character_id", &self.character_id)
.field("character_name", &self.character_name)
.field("character_list", &self.character_list)
.field("additional_data", &self.additional_data)
.field("client_id", &self.client_id)
.field("chat_handler", &self.chat_handler.as_ref().map(|_| "<chat handler>"))
.field("writer", &self.writer.as_ref().map(|_| "<writer>"))
.finish()
}
}