File tree Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Expand file tree Collapse file tree 2 files changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -108,15 +108,17 @@ impl Instance {
108
108
}
109
109
}
110
110
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 )
116
113
}
117
114
118
115
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
+ }
120
122
}
121
123
122
124
pub fn is_succeeded ( & self ) -> bool {
@@ -205,7 +207,7 @@ impl VectorOfInstance for Vec<Instance> {
205
207
let mut number = 0 ;
206
208
207
209
for instance in self {
208
- number += instance. get_online_count ( ) . await
210
+ number += instance. get_online_count ( ) . await . unwrap_or ( 0 )
209
211
}
210
212
211
213
Ok ( number)
Original file line number Diff line number Diff line change @@ -94,12 +94,14 @@ impl Task for HubTask {
94
94
let mut hub_option = None ;
95
95
96
96
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
+ } ;
103
105
}
104
106
105
107
if let Some ( hub) = hub_option {
You can’t perform that action at this time.
0 commit comments