Be sure the right number of connection is used
authorGreg Burri <greg.burri@gmail.com>
Mon, 22 Mar 2021 21:42:54 +0000 (22:42 +0100)
committerGreg Burri <greg.burri@gmail.com>
Mon, 22 Mar 2021 21:42:54 +0000 (22:42 +0100)
backend/src/valheim_controller.rs

index 29f30f1..8c04e23 100644 (file)
@@ -85,7 +85,7 @@ fn get_active_players() -> Vec<String> {
 \r
     journal.seek_tail().unwrap();\r
 \r
-    let mut number_of_connections = 0;\r
+    let mut number_of_connections = -1i32;\r
     let mut players : Vec<String> = Vec::new();\r
 \r
     loop {\r
@@ -99,7 +99,7 @@ fn get_active_players() -> Vec<String> {
                                 let player_name = String::from(character_str.get(0..pos_end).unwrap());\r
                                 if !players.contains(&player_name) {\r
                                     players.push(player_name);\r
-                                    if players.len() == number_of_connections {\r
+                                    if players.len() as i32 == number_of_connections {\r
                                         return players;\r
                                     }\r
                                 }\r
@@ -109,11 +109,12 @@ fn get_active_players() -> Vec<String> {
                             let nb_of_connections_str = mess.get(pos+STRING_BEFORE_NB_OF_CONNECTIONS.len()+1..).unwrap();\r
                             if let Some(pos_end) = nb_of_connections_str.find(' ') {\r
                                 if let Ok(n) = nb_of_connections_str.get(0..pos_end).unwrap().parse() {\r
-                                    if n > number_of_connections {\r
-                                        number_of_connections = n;\r
-                                    }\r
-                                    if players.len() >= number_of_connections {\r
-                                        return players;\r
+                                    if number_of_connections == -1 {\r
+                                        number_of_connections = n as i32\r
+\r
+                                        if players.len() as i32 >= number_of_connections {\r
+                                            return players;\r
+                                        }\r
                                     }\r
                                 }\r
                             }\r