rush_sync_server/server/
mod.rs

1// =====================================================
2// FILE: src/server/mod.rs - ACTIX-WEB SERVER MODULE
3// =====================================================
4
5pub mod config;
6pub mod instance;
7pub mod manager;
8pub mod middleware;
9pub mod routes;
10
11use chrono::{DateTime, Utc};
12pub use config::{ServerConfig, ServerMode};
13pub use instance::ServerInstance;
14pub use manager::ServerManager;
15use sha2::{Digest, Sha256};
16use uuid::Uuid;
17
18/// Server-Status für Tracking
19#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
20pub enum ServerStatus {
21    Stopped,
22    Starting,
23    Running,
24    Stopping,
25    Error(String),
26}
27
28/// Server-Information für Verwaltung
29#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
30pub struct ServerInfo {
31    pub id: String,
32    pub hash: String,
33    pub port: u16,
34    pub mode: ServerMode,
35    pub status: ServerStatus,
36    pub working_dir: std::path::PathBuf,
37    pub created_at: DateTime<Utc>,
38    pub last_modified: Option<DateTime<Utc>>,
39}
40
41impl ServerInfo {
42    /// Erstellt neue Server-Info mit eindeutiger ID
43    pub fn new(port: u16, mode: ServerMode) -> Self {
44        let id = Uuid::new_v4().to_string();
45        let hash = format!("{:x}", Sha256::digest(id.as_bytes()))[..8].to_string();
46
47        // working_dir VOR dem Struct bauen (nutzt nur &hash, kein Move)
48        let working_dir = std::path::PathBuf::from(format!("servers/server_{hash}"));
49
50        Self {
51            id,   // id kann direkt moved werden
52            hash, // hash wird hier genau einmal moved
53            port,
54            mode,
55            status: ServerStatus::Stopped,
56            working_dir, // bereits gebaut, eigener Move
57            created_at: Utc::now(),
58            last_modified: None,
59        }
60    }
61
62    /// Debug-Info für CLI-Ausgabe
63    pub fn debug_info(&self) -> String {
64        format!(
65            "🖥️  Server {} ({})\n   Port: {}\n   Mode: {:?}\n   Status: {:?}\n   Dir: {}",
66            self.id[..8].to_uppercase(),
67            self.hash,
68            self.port,
69            self.mode,
70            self.status,
71            self.working_dir.display()
72        )
73    }
74}