From 361946bc35fce3a148afee63cd307c6eb1340158 Mon Sep 17 00:00:00 2001 From: Nikita Vilunov Date: Fri, 10 May 2024 15:47:43 +0200 Subject: [PATCH] wip --- config.0.toml | 3 +-- config.1.toml | 3 +-- crates/lavina-core/src/clustering.rs | 6 ++---- crates/lavina-core/src/player.rs | 7 ++----- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/config.0.toml b/config.0.toml index 5e0340d..183a6b8 100644 --- a/config.0.toml +++ b/config.0.toml @@ -23,8 +23,7 @@ addresses = [ [cluster.metadata] node_id = 0 main_owner = 0 -test_owner = 1 -test2_owner = 0 +rooms = { aaaaa = 1, test = 0 } [tracing] endpoint = "http://localhost:4317" diff --git a/config.1.toml b/config.1.toml index b522b67..cf4a0f9 100644 --- a/config.1.toml +++ b/config.1.toml @@ -23,8 +23,7 @@ addresses = [ [cluster.metadata] node_id = 1 main_owner = 0 -test_owner = 1 -test2_owner = 0 +rooms = { aaaaa = 1, test = 0 } [tracing] endpoint = "http://localhost:4317" diff --git a/crates/lavina-core/src/clustering.rs b/crates/lavina-core/src/clustering.rs index 20ad30d..524087f 100644 --- a/crates/lavina-core/src/clustering.rs +++ b/crates/lavina-core/src/clustering.rs @@ -3,6 +3,7 @@ use reqwest::Client; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use reqwest_tracing::{DefaultSpanBackend, TracingMiddleware}; use serde::{Deserialize, Serialize}; +use std::collections::HashMap; use std::net::SocketAddr; use std::sync::Arc; @@ -22,10 +23,7 @@ pub struct ClusterMetadata { pub node_id: u32, /// Owns all rooms and players in the cluster. pub main_owner: u32, - /// Owns the room `test`. - pub test_owner: u32, - /// Owns the room `test2`. - pub test2_owner: u32, + pub rooms: HashMap, } #[derive(Clone)] diff --git a/crates/lavina-core/src/player.rs b/crates/lavina-core/src/player.rs index 1f6a2c0..872e8bc 100644 --- a/crates/lavina-core/src/player.rs +++ b/crates/lavina-core/src/player.rs @@ -446,11 +446,8 @@ impl Player { } fn room_location(&self, room_id: &RoomId) -> Option { - let node = match &**room_id.as_inner() { - "aaaaa" => self.cluster_metadata.test_owner, - "test" => self.cluster_metadata.test2_owner, - _ => self.cluster_metadata.main_owner, - }; + let res = self.cluster_metadata.rooms.get(room_id.as_inner().as_ref()).copied(); + let node = res.unwrap_or(self.cluster_metadata.main_owner); if node == self.cluster_metadata.node_id { None } else {