rust/hedgewars-server/src/core/client.rs
author S.D.
Tue, 27 Sep 2022 14:59:03 +0300
changeset 15900 fc3cb23fd26f
parent 15591 4b2f3228f13b
child 15960 ab57c0d81748
permissions -rw-r--r--
Allow to see rooms of incompatible versions in the lobby For the new clients the room version is shown in a separate column. There is also a hack for previous versions clients: the room vesion specifier is prepended to the room names for rooms of incompatible versions, and the server shows 'incompatible version' error if the client tries to join them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15095
c5a6e8566425 shuffle server files
alfadur
parents: 14812
diff changeset
     1
use super::types::ClientId;
13810
0463a4221327 cleanup crate imports
alfadur
parents: 13771
diff changeset
     2
use bitflags::*;
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
     3
14478
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
     4
bitflags! {
15554
f1205f33bf5b complete checker login handling
alfadur <mail@none>
parents: 15096
diff changeset
     5
    pub struct ClientFlags: u8 {
13493
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
     6
        const IS_ADMIN = 0b0000_0001;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
     7
        const IS_MASTER = 0b0000_0010;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
     8
        const IS_READY = 0b0000_0100;
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
     9
        const IS_IN_GAME = 0b0000_1000;
15591
4b2f3228f13b fix editing teams while a game is in progress
alfadur
parents: 15554
diff changeset
    10
        const IS_CONTRIBUTOR = 0b0001_0000;
4b2f3228f13b fix editing teams while a game is in progress
alfadur
parents: 15554
diff changeset
    11
        const HAS_SUPER_POWER = 0b0010_0000;
4b2f3228f13b fix editing teams while a game is in progress
alfadur
parents: 15554
diff changeset
    12
        const IS_REGISTERED = 0b0100_0000;
13529
662f7df89d06 Implement room config export
alfadur
parents: 13493
diff changeset
    13
662f7df89d06 Implement room config export
alfadur
parents: 13493
diff changeset
    14
        const NONE = 0b0000_0000;
662f7df89d06 Implement room config export
alfadur
parents: 13493
diff changeset
    15
        const DEFAULT = Self::NONE.bits;
13493
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    16
    }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    17
}
13486
1ee192f13456 Better packing for clients
alfadur
parents: 13450
diff changeset
    18
15096
e935b1ad23f3 normalize type names
alfadur
parents: 15095
diff changeset
    19
pub struct HwClient {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12853
diff changeset
    20
    pub id: ClientId,
12852
bd35cb2302b3 Quick dirty fix for building
unc0rr
parents: 12147
diff changeset
    21
    pub room_id: Option<usize>,
12141
78925eff02c2 Basic support for NICK message
unc0rr
parents: 12139
diff changeset
    22
    pub nick: String,
13486
1ee192f13456 Better packing for clients
alfadur
parents: 13450
diff changeset
    23
    pub protocol_number: u16,
13493
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    24
    pub flags: ClientFlags,
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13119
diff changeset
    25
    pub teams_in_game: u8,
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13419
diff changeset
    26
    pub team_indices: Vec<u8>,
14478
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    27
    pub clan: Option<u8>,
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    28
}
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    29
15096
e935b1ad23f3 normalize type names
alfadur
parents: 15095
diff changeset
    30
impl HwClient {
e935b1ad23f3 normalize type names
alfadur
parents: 15095
diff changeset
    31
    pub fn new(id: ClientId, protocol_number: u16, nick: String) -> HwClient {
e935b1ad23f3 normalize type names
alfadur
parents: 15095
diff changeset
    32
        HwClient {
13119
1e39b8749072 separated the server logic from all the async io mess.
alfadur
parents: 12853
diff changeset
    33
            id,
14714
6a2e13e36b7f add server anteroom
alfadur <mail@none>
parents: 14478
diff changeset
    34
            nick,
6a2e13e36b7f add server anteroom
alfadur <mail@none>
parents: 14478
diff changeset
    35
            protocol_number,
12146
8d8fb85bc09c SendAllButMe action, list all clients in lobby in LobbyJoined message to newcomers
unc0rr
parents: 12144
diff changeset
    36
            room_id: None,
13529
662f7df89d06 Implement room config export
alfadur
parents: 13493
diff changeset
    37
            flags: ClientFlags::DEFAULT,
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13119
diff changeset
    38
            teams_in_game: 0,
13423
87a6cad20c90 Implement game start & engine messages
alfadur
parents: 13419
diff changeset
    39
            team_indices: Vec::new(),
13419
81e0ed105f5d implementation of team related messages
alfadur
parents: 13119
diff changeset
    40
            clan: None,
12128
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    41
        }
f50876f3eff8 Refactor modules layout
unc0rr
parents:
diff changeset
    42
    }
13486
1ee192f13456 Better packing for clients
alfadur
parents: 13450
diff changeset
    43
14478
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    44
    fn contains(&self, mask: ClientFlags) -> bool {
13493
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    45
        self.flags.contains(mask)
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    46
    }
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    47
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    48
    fn set(&mut self, mask: ClientFlags, value: bool) {
282e5e54386f Something down in the food chain already uses bitflags, so might as well switch to them
alfadur
parents: 13486
diff changeset
    49
        self.flags.set(mask, value);
13486
1ee192f13456 Better packing for clients
alfadur
parents: 13450
diff changeset
    50
    }
1ee192f13456 Better packing for clients
alfadur
parents: 13450
diff changeset
    51
14478
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    52
    pub fn is_admin(&self) -> bool {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    53
        self.contains(ClientFlags::IS_ADMIN)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    54
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    55
    pub fn is_master(&self) -> bool {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    56
        self.contains(ClientFlags::IS_MASTER)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    57
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    58
    pub fn is_ready(&self) -> bool {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    59
        self.contains(ClientFlags::IS_READY)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    60
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    61
    pub fn is_in_game(&self) -> bool {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    62
        self.contains(ClientFlags::IS_IN_GAME)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    63
    }
14800
f43ab2bd76ae add a thread for internal server IO and implement account checking with it
alfadur
parents: 14714
diff changeset
    64
    pub fn is_contributor(&self) -> bool {
f43ab2bd76ae add a thread for internal server IO and implement account checking with it
alfadur
parents: 14714
diff changeset
    65
        self.contains(ClientFlags::IS_CONTRIBUTOR)
f43ab2bd76ae add a thread for internal server IO and implement account checking with it
alfadur
parents: 14714
diff changeset
    66
    }
14807
8ecdb5c6bb2a implement info, registered only & super power messages
alfadur
parents: 14800
diff changeset
    67
    pub fn has_super_power(&self) -> bool {
8ecdb5c6bb2a implement info, registered only & super power messages
alfadur
parents: 14800
diff changeset
    68
        self.contains(ClientFlags::HAS_SUPER_POWER)
8ecdb5c6bb2a implement info, registered only & super power messages
alfadur
parents: 14800
diff changeset
    69
    }
14812
b889d9e1115f improve lobby joining
alfadur
parents: 14807
diff changeset
    70
    pub fn is_registered(&self) -> bool {
b889d9e1115f improve lobby joining
alfadur
parents: 14807
diff changeset
    71
        self.contains(ClientFlags::IS_REGISTERED)
b889d9e1115f improve lobby joining
alfadur
parents: 14807
diff changeset
    72
    }
13486
1ee192f13456 Better packing for clients
alfadur
parents: 13450
diff changeset
    73
14478
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    74
    pub fn set_is_admin(&mut self, value: bool) {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    75
        self.set(ClientFlags::IS_ADMIN, value)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    76
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    77
    pub fn set_is_master(&mut self, value: bool) {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    78
        self.set(ClientFlags::IS_MASTER, value)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    79
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    80
    pub fn set_is_ready(&mut self, value: bool) {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    81
        self.set(ClientFlags::IS_READY, value)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    82
    }
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    83
    pub fn set_is_in_game(&mut self, value: bool) {
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    84
        self.set(ClientFlags::IS_IN_GAME, value)
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    85
    }
14800
f43ab2bd76ae add a thread for internal server IO and implement account checking with it
alfadur
parents: 14714
diff changeset
    86
    pub fn set_is_contributor(&mut self, value: bool) {
f43ab2bd76ae add a thread for internal server IO and implement account checking with it
alfadur
parents: 14714
diff changeset
    87
        self.set(ClientFlags::IS_CONTRIBUTOR, value)
f43ab2bd76ae add a thread for internal server IO and implement account checking with it
alfadur
parents: 14714
diff changeset
    88
    }
14807
8ecdb5c6bb2a implement info, registered only & super power messages
alfadur
parents: 14800
diff changeset
    89
    pub fn set_has_super_power(&mut self, value: bool) {
8ecdb5c6bb2a implement info, registered only & super power messages
alfadur
parents: 14800
diff changeset
    90
        self.set(ClientFlags::HAS_SUPER_POWER, value)
8ecdb5c6bb2a implement info, registered only & super power messages
alfadur
parents: 14800
diff changeset
    91
    }
14812
b889d9e1115f improve lobby joining
alfadur
parents: 14807
diff changeset
    92
    pub fn set_is_registered(&mut self, value: bool) {
b889d9e1115f improve lobby joining
alfadur
parents: 14807
diff changeset
    93
        self.set(ClientFlags::IS_REGISTERED, value)
b889d9e1115f improve lobby joining
alfadur
parents: 14807
diff changeset
    94
    }
14478
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14436
diff changeset
    95
}