Skip to main content

steamid/
enums.rs

1//! Enums and constants for SteamID components.
2
3/// Steam universe types.
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
5#[repr(u8)]
6pub enum Universe {
7    #[default]
8    Invalid = 0,
9    Public = 1,
10    Beta = 2,
11    Internal = 3,
12    Dev = 4,
13}
14
15impl Universe {
16    /// Convert a numeric value to a Universe.
17    pub fn from_u8(value: u8) -> Self {
18        match value {
19            1 => Universe::Public,
20            2 => Universe::Beta,
21            3 => Universe::Internal,
22            4 => Universe::Dev,
23            _ => Universe::Invalid,
24        }
25    }
26}
27
28/// Steam account types.
29#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
30#[repr(u8)]
31pub enum AccountType {
32    #[default]
33    Invalid = 0,
34    Individual = 1,
35    Multiseat = 2,
36    GameServer = 3,
37    AnonGameServer = 4,
38    Pending = 5,
39    ContentServer = 6,
40    Clan = 7,
41    Chat = 8,
42    P2PSuperSeeder = 9,
43    AnonUser = 10,
44}
45
46impl AccountType {
47    /// Convert a numeric value to an AccountType.
48    pub fn from_u8(value: u8) -> Self {
49        match value {
50            1 => AccountType::Individual,
51            2 => AccountType::Multiseat,
52            3 => AccountType::GameServer,
53            4 => AccountType::AnonGameServer,
54            5 => AccountType::Pending,
55            6 => AccountType::ContentServer,
56            7 => AccountType::Clan,
57            8 => AccountType::Chat,
58            9 => AccountType::P2PSuperSeeder,
59            10 => AccountType::AnonUser,
60            _ => AccountType::Invalid,
61        }
62    }
63
64    /// Get the character representation of this account type for Steam3 format.
65    pub fn to_char(self) -> char {
66        match self {
67            AccountType::Invalid => 'I',
68            AccountType::Individual => 'U',
69            AccountType::Multiseat => 'M',
70            AccountType::GameServer => 'G',
71            AccountType::AnonGameServer => 'A',
72            AccountType::Pending => 'P',
73            AccountType::ContentServer => 'C',
74            AccountType::Clan => 'g',
75            AccountType::Chat => 'T',
76            AccountType::P2PSuperSeeder => 'i', // Not typically used
77            AccountType::AnonUser => 'a',
78        }
79    }
80
81    /// Get the AccountType from a character in Steam3 format.
82    pub fn from_char(c: char) -> Self {
83        match c {
84            'I' => AccountType::Invalid,
85            'U' => AccountType::Individual,
86            'M' => AccountType::Multiseat,
87            'G' => AccountType::GameServer,
88            'A' => AccountType::AnonGameServer,
89            'P' => AccountType::Pending,
90            'C' => AccountType::ContentServer,
91            'g' => AccountType::Clan,
92            'T' => AccountType::Chat,
93            'a' => AccountType::AnonUser,
94            _ => AccountType::Invalid,
95        }
96    }
97}
98
99/// Named instance values.
100#[derive(Debug, Clone, Copy, PartialEq, Eq)]
101#[repr(u32)]
102pub enum Instance {
103    All = 0,
104    Desktop = 1,
105    Console = 2,
106    Web = 4,
107}
108
109/// Bit masks and constants for SteamID manipulation.
110pub mod masks {
111    /// Mask to extract the account ID from a 64-bit SteamID.
112    pub const ACCOUNT_ID_MASK: u64 = 0xFFFFFFFF;
113    /// Mask to extract the instance from the upper 32 bits of a 64-bit SteamID.
114    pub const ACCOUNT_INSTANCE_MASK: u32 = 0x000FFFFF;
115}
116
117/// Chat instance flags for identifying chat room types.
118pub mod chat_instance_flags {
119    use super::masks::ACCOUNT_INSTANCE_MASK;
120
121    /// Flag indicating a group chat (clan chat).
122    pub const CLAN: u32 = (ACCOUNT_INSTANCE_MASK + 1) >> 1; // 0x80000
123    /// Flag indicating a lobby.
124    pub const LOBBY: u32 = (ACCOUNT_INSTANCE_MASK + 1) >> 2; // 0x40000
125    /// Flag indicating a matchmaking lobby.
126    pub const MMS_LOBBY: u32 = (ACCOUNT_INSTANCE_MASK + 1) >> 3; // 0x20000
127}