rust/hedgewars-server/src/core/types.rs
author unc0rr
Wed, 23 Jun 2021 23:41:51 +0200
changeset 15804 747278149393
parent 15547 863059f61793
child 15882 f185e7367dd3
permissions -rw-r--r--
Extract network protocol into a separate crate
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15804
747278149393 Extract network protocol into a separate crate
unc0rr
parents: 15547
diff changeset
     1
use hedgewars_network_protocol::types::{RoomConfig, TeamInfo, VoteType};
14785
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
     2
use serde_derive::{Deserialize, Serialize};
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
     3
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
     4
pub type ClientId = usize;
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
     5
pub type RoomId = usize;
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
     6
15102
80ff12edf5e6 handle response from IO result handler
alfadur
parents: 15074
diff changeset
     7
#[derive(Debug)]
14785
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
     8
pub struct Replay {
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
     9
    pub config: RoomConfig,
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
    10
    pub teams: Vec<TeamInfo>,
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
    11
    pub message_log: Vec<String>,
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
    12
}
a1077e8d26f4 implement watch message apart from replay deserializing
alfadur
parents: 14783
diff changeset
    13
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    14
#[derive(Clone, Debug)]
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    15
pub struct Voting {
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    16
    pub ttl: u32,
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    17
    pub voters: Vec<ClientId>,
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    18
    pub votes: Vec<(ClientId, bool)>,
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    19
    pub kind: VoteType,
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    20
}
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    21
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    22
impl Voting {
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    23
    pub fn new(kind: VoteType, voters: Vec<ClientId>) -> Voting {
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    24
        Voting {
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    25
            kind,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    26
            voters,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    27
            ttl: 2,
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    28
            votes: Vec::new(),
13478
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    29
        }
d79795acaa73 Mostly implement voting
alfadur
parents: 13422
diff changeset
    30
    }
14457
98ef2913ec73 Apply rustfmt to all files
unc0rr
parents: 14415
diff changeset
    31
}