This commit is contained in:
2025-03-07 19:13:44 +01:00
parent 460a18638f
commit d005e8fec9

View File

@@ -1,5 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::marker;
use std::collections::HashMap;
use std::time::Instant;
use std::{io::Cursor, net::SocketAddr, str::FromStr, sync::Arc, time::Duration};
@@ -25,8 +24,7 @@ struct Client {
username: Option<String>,
realname: Option<String>,
modes: HashSet<u8>, // [byte per mode](https://www.unrealircd.org/docs/User_modes)
// modes: HashSet<u8>, // [byte per mode](https://www.unrealircd.org/docs/User_modes)
last_pong: Instant,
c2s_tx: Option<Sender<Message>>,
@@ -46,7 +44,7 @@ impl Client {
username: None,
realname: None,
modes: HashSet::new(),
// modes: HashSet::new(),
last_pong: Instant::now(),
c2s_tx: Some(c2s_tx),
@@ -63,7 +61,7 @@ impl Client {
}
#[derive(Default, Debug)]
struct AppState {
pub struct AppState {
clients: RwLock<HashMap<SocketAddr, Client>>,
}
@@ -96,7 +94,7 @@ impl AppState {
&self,
peer_addr: SocketAddr,
username: &str,
mode: u16,
// mode: u16,
realname: Option<&str>,
) {
if let Some(client) = self.clients.write().await.get_mut(&peer_addr) {
@@ -191,7 +189,7 @@ async fn main() -> Result<()> {
let acceptor = TlsAcceptor::from(Arc::new(config));
let listener = TcpListener::bind("0.0.0.0:6697").await?;
// which means, this goes into yet another thread
// Connection loop
let state: Arc<AppState> = app_state.clone();
tokio::spawn(async move {
loop {
@@ -217,7 +215,7 @@ async fn main() -> Result<()> {
}
});
// todo: the "processing" loop goes here...
// Processing loop
let state: Arc<AppState> = app_state.clone();
tokio::spawn(async move {
loop {
@@ -304,11 +302,11 @@ async fn handle(
"USER" => {
let mut params = msg.params()?;
let username = params.next().unwrap_or_default(); // aviinl
let mode = params.next().unwrap_or_default().parse::<u16>()?; // mode
params.next().unwrap_or_default(); // unused
// let mode = params.next().unwrap_or_default().parse::<u16>()?; // mode
// params.next().unwrap_or_default(); // unused
let realname = msg.trailing()?; // realname
state.user(peer_addr, username, mode, realname).await;
state.user(peer_addr, username, /*mode,*/ realname).await;
let nick = state.nick(peer_addr).await.unwrap_or(username.to_string());
state