gameServer2/src/protocol/messages.rs
changeset 12147 03ccb89820f3
parent 12145 a482c7a5f6e3
child 13119 1e39b8749072
equal deleted inserted replaced
12146:8d8fb85bc09c 12147:03ccb89820f3
    74     Pong,
    74     Pong,
    75     Bye(&'a str),
    75     Bye(&'a str),
    76     Nick(&'a str),
    76     Nick(&'a str),
    77     LobbyLeft(&'a str),
    77     LobbyLeft(&'a str),
    78     LobbyJoined(&'a [&'a str]),
    78     LobbyJoined(&'a [&'a str]),
       
    79     ChatMsg(&'a str, &'a str),
       
    80     ClientFlags(&'a str, &'a [&'a str]),
    79 
    81 
       
    82     Warning(&'a str),
    80     Connected(u32),
    83     Connected(u32),
    81     Unreachable,
    84     Unreachable,
    82 }
    85 }
    83 
    86 
    84 fn construct_message(msg: & [&str]) -> String {
    87 fn construct_message(msg: & [&str]) -> String {
   107                     &protocol_version.to_string()
   110                     &protocol_version.to_string()
   108                 ]),
   111                 ]),
   109             &HWServerMessage::Bye(msg)
   112             &HWServerMessage::Bye(msg)
   110                 => construct_message(&["BYE", &msg]),
   113                 => construct_message(&["BYE", &msg]),
   111             &HWServerMessage::Nick(nick)
   114             &HWServerMessage::Nick(nick)
   112             => construct_message(&["NICK", &nick]),
   115                 => construct_message(&["NICK", &nick]),
   113             &HWServerMessage::LobbyLeft(msg)
   116             &HWServerMessage::LobbyLeft(nick)
   114                 => construct_message(&["LOBBY_LEFT", &msg]),
   117                 => construct_message(&["LOBBY_LEFT", &nick]),
   115             &HWServerMessage::LobbyJoined(msg)
   118             &HWServerMessage::LobbyJoined(nicks)
   116                 => {
   119                 => {
   117                 let mut v = vec!["LOBBY:JOINED"];
   120                 let mut v = vec!["LOBBY:JOINED"];
   118                 v.extend_from_slice(msg);
   121                 v.extend_from_slice(nicks);
   119                 construct_message(&v)
   122                 construct_message(&v)
   120             },
   123             },
       
   124             &HWServerMessage::ClientFlags(flags, nicks)
       
   125             => {
       
   126                 let mut v = vec!["CLIENT_FLAGS"];
       
   127                 v.push(flags);
       
   128                 v.extend_from_slice(nicks);
       
   129                 construct_message(&v)
       
   130             },
       
   131             &HWServerMessage::ChatMsg(nick, msg)
       
   132                 => construct_message(&["CHAT", &nick, &msg]),
       
   133             &HWServerMessage::Warning(msg)
       
   134                 => construct_message(&["WARNING", &msg]),
   121             _ => construct_message(&["ERROR", "UNIMPLEMENTED"]),
   135             _ => construct_message(&["ERROR", "UNIMPLEMENTED"]),
   122         }
   136         }
   123     }
   137     }
   124 }
   138 }