diff -r 01f8ab45f806 -r 50fcef24003f rust/hedgewars-server/src/protocol/messages.rs --- a/rust/hedgewars-server/src/protocol/messages.rs Wed Apr 10 01:13:29 2019 +0300 +++ b/rust/hedgewars-server/src/protocol/messages.rs Wed Apr 10 16:14:33 2019 +0300 @@ -67,6 +67,49 @@ } #[derive(Debug)] +pub enum ProtocolFlags { + InRoom, + RoomMaster, + Ready, + InGame, + Authenticated, + Admin, + Contributor, +} + +impl ProtocolFlags { + #[inline] + fn flag_char(&self) -> char { + match self { + ProtocolFlags::InRoom => 'i', + ProtocolFlags::RoomMaster => 'h', + ProtocolFlags::Ready => 'r', + ProtocolFlags::InGame => 'g', + ProtocolFlags::Authenticated => 'u', + ProtocolFlags::Admin => 'a', + ProtocolFlags::Contributor => 'c', + } + } + + #[inline] + fn format(prefix: char, flags: &[ProtocolFlags]) -> String { + once(prefix) + .chain(flags.iter().map(|f| f.flag_char())) + .collect() + } +} + +#[inline] +pub fn add_flags(flags: &[ProtocolFlags]) -> String { + ProtocolFlags::format('+', flags) +} + +#[inline] +pub fn remove_flags(flags: &[ProtocolFlags]) -> String { + ProtocolFlags::format('-', flags) +} + +#[derive(Debug)] pub enum HWServerMessage { Ping, Pong,