follow the pattern
This commit is contained in:
parent
0c021c70f0
commit
cc332c63ae
4 changed files with 14 additions and 7 deletions
|
@ -361,5 +361,5 @@ pub struct AppState {
|
|||
pub offline_users: RwLock<HashMap<String, Arc<RwLock<User>>>>,
|
||||
pub packs: CardPacks,
|
||||
pub packs_meta: CardPacksMeta,
|
||||
pub games: RwLock<Vec<Game>>,
|
||||
pub games: RwLock<HashMap<String, RwLock<Game>>>,
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ async fn main() -> Result<()> {
|
|||
let online_users = RwLock::new(HashMap::<SocketAddr, Arc<RwLock<User>>>::new());
|
||||
let offline_users = RwLock::new(HashMap::<String, Arc<RwLock<User>>>::new());
|
||||
let (packs, packs_meta) = load_cards_from_json("data/cah-cards-full.json")?;
|
||||
let games = RwLock::new(vec![]);
|
||||
let games = RwLock::new(HashMap::new());
|
||||
|
||||
let app_state = Arc::new(AppState {
|
||||
tx,
|
||||
|
|
|
@ -15,7 +15,10 @@ use axum::{
|
|||
use futures::{SinkExt, StreamExt};
|
||||
use lib::*;
|
||||
use serde_json::{from_str, to_string};
|
||||
use std::{net::SocketAddr, sync::Arc};
|
||||
use std::{
|
||||
net::SocketAddr,
|
||||
sync::{Arc, RwLock},
|
||||
};
|
||||
use tokio::sync::broadcast::Sender;
|
||||
pub mod meta;
|
||||
pub mod user;
|
||||
|
@ -131,7 +134,11 @@ fn game_handle_new_game(
|
|||
|
||||
// create game
|
||||
if let Ok(new_game_object) = Game::new(manifest) {
|
||||
state.games.write().unwrap().push(new_game_object);
|
||||
state
|
||||
.games
|
||||
.write()
|
||||
.unwrap()
|
||||
.insert(new_game_object.name.clone(), RwLock::new(new_game_object));
|
||||
tx.send(meta_games_browser_update(state))?;
|
||||
tx.send(meta_server_summary_update(state))?;
|
||||
}
|
||||
|
|
|
@ -49,11 +49,11 @@ pub fn meta_games_browser_update(state: &Arc<AppState>) -> String {
|
|||
// this may get expensive if there are many games
|
||||
let mut names = vec![];
|
||||
|
||||
for game in state.games.read().unwrap().iter() {
|
||||
for game in state.games.read().unwrap().values() {
|
||||
names.push(format!(
|
||||
"Name: {} Host: {}",
|
||||
game.name,
|
||||
game.host.read().unwrap().name
|
||||
game.read().unwrap().name,
|
||||
game.read().unwrap().host.read().unwrap().name
|
||||
));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue