diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-24 14:48:12 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-24 14:48:12 +0200 |
| commit | 5d6b5049c2a34a3f8abe725d4a871ba84a0dd714 (patch) | |
| tree | 57cb03bf59b3358a96742f455d38c21f4f645396 /src/bin/server/games/registry.rs | |
| parent | stable and working, both platforms (diff) | |
| download | zagan-bet-5d6b5049c2a34a3f8abe725d4a871ba84a0dd714.tar.gz zagan-bet-5d6b5049c2a34a3f8abe725d4a871ba84a0dd714.zip | |
TLS transport and games framework on client and server
Diffstat (limited to '')
| -rw-r--r-- | src/bin/server/games/registry.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/bin/server/games/registry.rs b/src/bin/server/games/registry.rs new file mode 100644 index 0000000..e77a138 --- /dev/null +++ b/src/bin/server/games/registry.rs | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #![allow(dead_code)] | ||
| 2 | |||
| 3 | use crate::games::traits::Game; | ||
| 4 | use std::collections::HashMap; | ||
| 5 | use std::sync::{Arc, Mutex}; | ||
| 6 | |||
| 7 | pub type GameRef = Arc<dyn Game + Send + Sync>; | ||
| 8 | |||
| 9 | pub struct GameRegistry { | ||
| 10 | games: Arc<Mutex<HashMap<String, GameRef>>>, | ||
| 11 | } | ||
| 12 | |||
| 13 | impl GameRegistry { | ||
| 14 | pub fn new() -> Self { | ||
| 15 | Self { | ||
| 16 | games: Arc::new(Mutex::new(HashMap::new())), | ||
| 17 | } | ||
| 18 | } | ||
| 19 | |||
| 20 | pub fn register_game<G: Game + Send + Sync + 'static>(&self, game: G) { | ||
| 21 | let game_type = game.game_type().to_string(); | ||
| 22 | let mut games = self.games.lock().unwrap(); | ||
| 23 | games.insert(game_type, Arc::new(game)); | ||
| 24 | } | ||
| 25 | |||
| 26 | pub fn get_game(&self, game_type: &str) -> Option<GameRef> { | ||
| 27 | let games = self.games.lock().unwrap(); | ||
| 28 | games.get(game_type).cloned() | ||
| 29 | } | ||
| 30 | |||
| 31 | pub fn list_games(&self) -> Vec<String> { | ||
| 32 | let games = self.games.lock().unwrap(); | ||
| 33 | games.keys().cloned().collect() | ||
| 34 | } | ||
| 35 | |||
| 36 | pub fn game_exists(&self, game_type: &str) -> bool { | ||
| 37 | let games = self.games.lock().unwrap(); | ||
| 38 | games.contains_key(game_type) | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | // Global registry instance | ||
| 43 | use crate::games::slots::SlotsGame; | ||
| 44 | use once_cell::sync::Lazy; | ||
| 45 | |||
| 46 | static GAME_REGISTRY: Lazy<GameRegistry> = Lazy::new(|| { | ||
| 47 | let registry = GameRegistry::new(); | ||
| 48 | // Register games here | ||
| 49 | registry.register_game(SlotsGame::new()); | ||
| 50 | registry | ||
| 51 | }); | ||
| 52 | |||
| 53 | pub fn get_game_registry() -> &'static GameRegistry { | ||
| 54 | &GAME_REGISTRY | ||
| 55 | } | ||
