Skip to main content

server/domain/
available_game.rs

1use serde::{Deserialize, Serialize};
2use strum::EnumString;
3
4use crate::domain::GameId;
5
6/// How a game appears in the public lobby / matchmaking pool.
7#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, EnumString)]
8pub enum Availability {
9    /// Only joinable via direct invite or link. Does not appear in public list.
10    Private,
11
12    /// Visible and joinable by anyone in the lobby browser (other than the original host).
13    Public,
14}
15
16/// A game that is visible in the public lobby and can be joined. These only get created
17/// with respect to a given user, i.e. they are "available" to that user. Either the user
18/// is the host, or participating in the game, or they can join as a guest.
19#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
20pub struct AvailableGame {
21    id: GameId,
22    name: String,
23    availability: Availability,
24}
25
26impl AvailableGame {
27    /// Creates a new game entry for the lobby, available for a given user.
28    #[must_use]
29    pub fn new(id: GameId, name: String, availability: Availability) -> Self {
30        Self {
31            id,
32            name,
33            availability,
34        }
35    }
36
37    /// Returns the unique game identifier.
38    #[inline(always)]
39    #[must_use]
40    pub fn id(&self) -> &GameId {
41        &self.id
42    }
43
44    /// Returns the human-readable name of the game.
45    #[inline(always)]
46    #[must_use]
47    pub fn name(&self) -> &str {
48        &self.name
49    }
50
51    /// Returns the visibility setting of the game.
52    #[inline(always)]
53    #[must_use]
54    pub fn availability(&self) -> &Availability {
55        &self.availability
56    }
57}