rust/hedgewars-server/src/protocol/messages.rs
changeset 14804 b3adc030104b
parent 14803 50fcef24003f
child 14805 8390d5e4e39c
equal deleted inserted replaced
14803:50fcef24003f 14804:b3adc030104b
   116     Bye(String),
   116     Bye(String),
   117 
   117 
   118     Nick(String),
   118     Nick(String),
   119     Proto(u16),
   119     Proto(u16),
   120     AskPassword(String),
   120     AskPassword(String),
   121 
       
   122     ServerAuth(String),
   121     ServerAuth(String),
       
   122 
   123     LobbyLeft(String, String),
   123     LobbyLeft(String, String),
   124     LobbyJoined(Vec<String>),
   124     LobbyJoined(Vec<String>),
   125     ChatMsg { nick: String, msg: String },
   125     ChatMsg { nick: String, msg: String },
   126     ClientFlags(String, Vec<String>),
   126     ClientFlags(String, Vec<String>),
   127     Rooms(Vec<String>),
   127     Rooms(Vec<String>),
   140     RunGame,
   140     RunGame,
   141     ForwardEngineMessage(Vec<String>),
   141     ForwardEngineMessage(Vec<String>),
   142     RoundFinished,
   142     RoundFinished,
   143 
   143 
   144     ServerMessage(String),
   144     ServerMessage(String),
       
   145     ServerVars(Vec<String>),
   145     Notice(String),
   146     Notice(String),
   146     Warning(String),
   147     Warning(String),
   147     Error(String),
   148     Error(String),
   148     Connected(u32),
   149     Connected(u32),
   149     Unreachable,
   150     Unreachable,
   154 
   155 
   155 pub fn server_chat(msg: String) -> HWServerMessage {
   156 pub fn server_chat(msg: String) -> HWServerMessage {
   156     HWServerMessage::ChatMsg {
   157     HWServerMessage::ChatMsg {
   157         nick: "[server]".to_string(),
   158         nick: "[server]".to_string(),
   158         msg,
   159         msg,
       
   160     }
       
   161 }
       
   162 
       
   163 impl ServerVar {
       
   164     pub fn to_protocol(&self) -> Vec<String> {
       
   165         match self {
       
   166             ServerVar::MOTDNew(s) => vec!["MOTD_NEW".to_string(), s.clone()],
       
   167             ServerVar::MOTDOld(s) => vec!["MOTD_OLD".to_string(), s.clone()],
       
   168             ServerVar::LatestProto(n) => vec!["LATEST_PROTO".to_string(), n.to_string()],
       
   169         }
   159     }
   170     }
   160 }
   171 }
   161 
   172 
   162 impl GameCfg {
   173 impl GameCfg {
   163     pub fn to_protocol(&self) -> (String, Vec<String>) {
   174     pub fn to_protocol(&self) -> (String, Vec<String>) {
   249             Ban(name, reason, time) => msg!["BAN", name, reason, time],
   260             Ban(name, reason, time) => msg!["BAN", name, reason, time],
   250             BanIP(ip, reason, time) => msg!["BAN_IP", ip, reason, time],
   261             BanIP(ip, reason, time) => msg!["BAN_IP", ip, reason, time],
   251             BanNick(nick, reason, time) => msg!("BAN_NICK", nick, reason, time),
   262             BanNick(nick, reason, time) => msg!("BAN_NICK", nick, reason, time),
   252             BanList => msg!["BANLIST"],
   263             BanList => msg!["BANLIST"],
   253             Unban(name) => msg!["UNBAN", name],
   264             Unban(name) => msg!["UNBAN", name],
   254             //SetServerVar(ServerVar), ???
   265             SetServerVar(var) => construct_message(&["SET_SERVER_VAR"], &var.to_protocol()),
   255             GetServerVar => msg!["GET_SERVER_VAR"],
   266             GetServerVar => msg!["GET_SERVER_VAR"],
   256             RestartServer => msg!["CMD", "RESTART_SERVER YES"],
   267             RestartServer => msg!["CMD", "RESTART_SERVER YES"],
   257             Stats => msg!["CMD", "STATS"],
   268             Stats => msg!["CMD", "STATS"],
   258             Part(None) => msg!["PART"],
   269             Part(None) => msg!["PART"],
   259             Part(Some(msg)) => msg!["PART", msg],
   270             Part(Some(msg)) => msg!["PART", msg],
   349             RunGame => msg!["RUN_GAME"],
   360             RunGame => msg!["RUN_GAME"],
   350             ForwardEngineMessage(em) => construct_message(&["EM"], &em),
   361             ForwardEngineMessage(em) => construct_message(&["EM"], &em),
   351             RoundFinished => msg!["ROUND_FINISHED"],
   362             RoundFinished => msg!["ROUND_FINISHED"],
   352             ChatMsg { nick, msg } => msg!["CHAT", nick, msg],
   363             ChatMsg { nick, msg } => msg!["CHAT", nick, msg],
   353             ServerMessage(msg) => msg!["SERVER_MESSAGE", msg],
   364             ServerMessage(msg) => msg!["SERVER_MESSAGE", msg],
       
   365             ServerVars(vars) => construct_message(&["SERVER_VARS"], &vars),
   354             Notice(msg) => msg!["NOTICE", msg],
   366             Notice(msg) => msg!["NOTICE", msg],
   355             Warning(msg) => msg!["WARNING", msg],
   367             Warning(msg) => msg!["WARNING", msg],
   356             Error(msg) => msg!["ERROR", msg],
   368             Error(msg) => msg!["ERROR", msg],
   357 
   369 
   358             LegacyReady(is_ready, nicks) => {
   370             LegacyReady(is_ready, nicks) => {