浏览代码

fix(gsm): add kill to route

Bryan Lee 1 年之前
父节点
当前提交
b79fcc0412
共有 1 个文件被更改,包括 11 次插入16 次删除
  1. 11 16
      game-server-manager/src/game/mod.rs

+ 11 - 16
game-server-manager/src/game/mod.rs

@@ -11,9 +11,11 @@ use subprocess::Popen;
 pub fn config_service(cfg: &mut web::ServiceConfig) {
     cfg.service(get::list)
         .service(get::find_by_port)
-        .service(spawn::spawn);
+        .service(spawn::spawn)
+        .service(kill::kill);
 }
 
+#[derive(Debug)]
 pub struct GamesData {
     games: RwLock<Games>,
 }
@@ -29,12 +31,7 @@ impl GamesData {
 const BASE_PORT: u16 = 9000;
 const MAX_NUM_GAMES: usize = 250;
 
-pub struct Game {
-    process: Popen,
-    port: u16,
-    created_at: DateTime<Utc>,
-}
-
+#[derive(Debug)]
 pub struct Games([Option<Game>; MAX_NUM_GAMES]);
 
 impl Games {
@@ -79,15 +76,6 @@ impl Games {
             .collect()
     }
 
-    pub fn get_available_port(&self) -> Option<u16> {
-        let idx = self.0.iter().position(|p| p.is_none());
-        let Some(idx) = idx else {
-            return None;
-        };
-        let idx: u16 = idx.try_into().unwrap();
-        Some(idx + BASE_PORT)
-    }
-
     pub fn get_available_entry(&mut self) -> Option<(u16, &mut Option<Game>)> {
         let idx = self.0.iter().position(|p| p.is_none());
         let Some(idx) = idx else {
@@ -99,6 +87,13 @@ impl Games {
     }
 }
 
+#[derive(Debug)]
+pub struct Game {
+    process: Popen,
+    port: u16,
+    created_at: DateTime<Utc>,
+}
+
 #[derive(Debug, Clone, Serialize)]
 pub struct GameDescription {
     pub process_id: u32,