forked from lavina/lavina
1
0
Fork 0
This commit is contained in:
Nikita Vilunov 2024-05-10 16:00:24 +02:00
parent a740dc80fe
commit baacea4b44
2 changed files with 11 additions and 2 deletions

View File

@ -20,8 +20,9 @@ pub struct ClusterConfig {
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
pub struct ClusterMetadata { pub struct ClusterMetadata {
/// The node id of the current node.
pub node_id: u32, pub node_id: u32,
/// Owns all rooms and players in the cluster. /// Owns all rooms in the cluster except the ones specified in `rooms`.
pub main_owner: u32, pub main_owner: u32,
pub rooms: HashMap<String, u32>, pub rooms: HashMap<String, u32>,
} }
@ -46,7 +47,13 @@ impl LavinaClient {
return Err(anyhow!("Unknown node")); return Err(anyhow!("Unknown node"));
}; };
match self.client.post(format!("http://{}{}", address, path)).json(&req).send().await { match self.client.post(format!("http://{}{}", address, path)).json(&req).send().await {
Ok(_) => Ok(()), Ok(res) => {
if res.status().is_server_error() || res.status().is_client_error() {
tracing::error!("Cluster request failed: {:?}", res);
return Err(anyhow!("Server error"));
}
Ok(())
}
Err(e) => Err(e.into()), Err(e) => Err(e.into()),
} }
} }

View File

@ -10,6 +10,8 @@ use lavina_core::repo::Storage;
use lavina_core::room::RoomId; use lavina_core::room::RoomId;
use lavina_core::LavinaCore; use lavina_core::LavinaCore;
// TODO move this into core
pub async fn route( pub async fn route(
core: &LavinaCore, core: &LavinaCore,
storage: &Storage, storage: &Storage,