forked from lavina/lavina
1
0
Fork 0
This commit is contained in:
Nikita Vilunov 2024-05-10 15:47:43 +02:00
parent 40b9ffe46a
commit 361946bc35
4 changed files with 6 additions and 13 deletions

View File

@ -23,8 +23,7 @@ addresses = [
[cluster.metadata] [cluster.metadata]
node_id = 0 node_id = 0
main_owner = 0 main_owner = 0
test_owner = 1 rooms = { aaaaa = 1, test = 0 }
test2_owner = 0
[tracing] [tracing]
endpoint = "http://localhost:4317" endpoint = "http://localhost:4317"

View File

@ -23,8 +23,7 @@ addresses = [
[cluster.metadata] [cluster.metadata]
node_id = 1 node_id = 1
main_owner = 0 main_owner = 0
test_owner = 1 rooms = { aaaaa = 1, test = 0 }
test2_owner = 0
[tracing] [tracing]
endpoint = "http://localhost:4317" endpoint = "http://localhost:4317"

View File

@ -3,6 +3,7 @@ use reqwest::Client;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware}; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_tracing::{DefaultSpanBackend, TracingMiddleware}; use reqwest_tracing::{DefaultSpanBackend, TracingMiddleware};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::sync::Arc; use std::sync::Arc;
@ -22,10 +23,7 @@ pub struct ClusterMetadata {
pub node_id: u32, pub node_id: u32,
/// Owns all rooms and players in the cluster. /// Owns all rooms and players in the cluster.
pub main_owner: u32, pub main_owner: u32,
/// Owns the room `test`. pub rooms: HashMap<String, u32>,
pub test_owner: u32,
/// Owns the room `test2`.
pub test2_owner: u32,
} }
#[derive(Clone)] #[derive(Clone)]

View File

@ -446,11 +446,8 @@ impl Player {
} }
fn room_location(&self, room_id: &RoomId) -> Option<u32> { fn room_location(&self, room_id: &RoomId) -> Option<u32> {
let node = match &**room_id.as_inner() { let res = self.cluster_metadata.rooms.get(room_id.as_inner().as_ref()).copied();
"aaaaa" => self.cluster_metadata.test_owner, let node = res.unwrap_or(self.cluster_metadata.main_owner);
"test" => self.cluster_metadata.test2_owner,
_ => self.cluster_metadata.main_owner,
};
if node == self.cluster_metadata.node_id { if node == self.cluster_metadata.node_id {
None None
} else { } else {