Skip to content

Commit 72706d7

Browse files
committed
OnlineCount fix mistake and try to fix bug
1 parent 64e7df7 commit 72706d7

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/epsilon/server/instance.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,17 @@ impl Instance {
108108
}
109109
}
110110

111-
pub async fn get_online_count(&self) -> i32 {
112-
match self.get_info().await {
113-
Ok(status) => status.players.online as i32,
114-
Err(_) => 0,
115-
}
111+
pub async fn get_online_count(&self) -> EResult<i32> {
112+
Ok(self.get_info().await?.players.online as i32)
116113
}
117114

118115
pub async fn get_available_slots(&self) -> i32 {
119-
self.get_instance_slots() - self.get_online_count().await
116+
let online_count_result = self.get_online_count().await;
117+
118+
match online_count_result {
119+
Ok(online_count) => self.get_instance_slots() - online_count,
120+
Err(_) => 0
121+
}
120122
}
121123

122124
pub fn is_succeeded(&self) -> bool {
@@ -205,7 +207,7 @@ impl VectorOfInstance for Vec<Instance> {
205207
let mut number = 0;
206208

207209
for instance in self {
208-
number += instance.get_online_count().await
210+
number += instance.get_online_count().await.unwrap_or(0)
209211
}
210212

211213
Ok(number)

src/tasks/hub_task.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ impl Task for HubTask {
9494
let mut hub_option = None;
9595

9696
for instance in hubs_ready {
97-
let online_player = instance.get_online_count().await;
98-
99-
if instance.get_state() == EpsilonState::Running && online_player <= n {
100-
n = online_player;
101-
hub_option = Some(instance);
102-
}
97+
let online_player_result = instance.get_online_count().await;
98+
99+
if let Ok(online_player) = online_player_result {
100+
if instance.get_state() == EpsilonState::Running && online_player <= n {
101+
n = online_player;
102+
hub_option = Some(instance);
103+
}
104+
};
103105
}
104106

105107
if let Some(hub) = hub_option {

0 commit comments

Comments
 (0)