Initialisiere yourchat2 als eigenständigen Rust-Chatdienst und portiere die Kernfunktionen aus der Altanwendung.

Die Implementierung enthält modulare Command-/State-/DB-Strukturen, DB-basierte Authentifizierung inkl. Rechte- und Raumzugriffsprüfung sowie kompatible Chat- und Dice-Commands.

Made-with: Cursor
This commit is contained in:
Torsten Schulz (local)
2026-03-04 17:04:41 +01:00
commit 0b91b94ae1
10 changed files with 3453 additions and 0 deletions

89
src/types.rs Normal file
View File

@@ -0,0 +1,89 @@
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio_postgres::Client as PgClient;
pub(crate) type ClientId = u64;
#[derive(Clone)]
pub(crate) struct ClientConn {
pub(crate) user_name: String,
pub(crate) room: String,
pub(crate) color: Option<String>,
pub(crate) token: Option<String>,
pub(crate) falukant_user_id: Option<i32>,
pub(crate) chat_user_id: Option<i32>,
pub(crate) age: Option<i32>,
pub(crate) rights: HashSet<String>,
pub(crate) logged_in: bool,
pub(crate) tx: mpsc::UnboundedSender<String>,
}
#[derive(Default)]
pub(crate) struct ChatState {
pub(crate) clients: HashMap<ClientId, ClientConn>,
pub(crate) rooms: HashMap<String, HashSet<ClientId>>,
pub(crate) tokens: HashMap<String, ClientId>,
pub(crate) logged_in_names: HashSet<String>,
pub(crate) dice_games: HashMap<String, DiceGame>,
pub(crate) room_meta: HashMap<String, RoomMeta>,
}
#[derive(Clone, Default)]
pub(crate) struct ServerConfig {
pub(crate) allowed_users: Option<HashSet<String>>,
pub(crate) db_client: Option<Arc<PgClient>>,
}
#[derive(Debug)]
pub(crate) struct UserProfile {
pub(crate) display_name: String,
pub(crate) color: Option<String>,
pub(crate) falukant_user_id: Option<i32>,
pub(crate) chat_user_id: Option<i32>,
pub(crate) age: Option<i32>,
pub(crate) rights: HashSet<String>,
}
#[derive(Debug, Deserialize)]
pub(crate) struct Command {
#[serde(rename = "type")]
pub(crate) cmd_type: Value,
pub(crate) token: Option<String>,
pub(crate) name: Option<String>,
pub(crate) room: Option<String>,
pub(crate) message: Option<String>,
pub(crate) value: Option<Value>,
pub(crate) password: Option<String>,
pub(crate) rounds: Option<i32>,
pub(crate) to: Option<String>,
#[serde(rename = "userName")]
pub(crate) user_name: Option<String>,
}
#[derive(Debug, Serialize)]
pub(crate) struct RoomInfo {
pub(crate) name: String,
pub(crate) users: usize,
}
#[derive(Clone, Default)]
pub(crate) struct DiceGame {
pub(crate) running: bool,
pub(crate) current_round: i32,
pub(crate) total_rounds: i32,
pub(crate) rolled_this_round: HashMap<ClientId, i32>,
pub(crate) total_scores: HashMap<ClientId, i32>,
}
#[derive(Clone, Debug, Default)]
pub(crate) struct RoomMeta {
pub(crate) name: String,
pub(crate) password: Option<String>,
pub(crate) min_age: Option<i32>,
pub(crate) max_age: Option<i32>,
pub(crate) is_public: bool,
pub(crate) owner_id: Option<i32>,
}