gameServer2/src/protocol/messages.rs
changeset 13433 fb104e150878
parent 13432 ee3fa3b8809d
child 13439 c4f917c6be51
equal deleted inserted replaced
13432:ee3fa3b8809d 13433:fb104e150878
   138     [$($part: expr),*] => {
   138     [$($part: expr),*] => {
   139         format!(concat!($(const_braces!($part)),*, "\n"), $($part),*);
   139         format!(concat!($(const_braces!($part)),*, "\n"), $($part),*);
   140     };
   140     };
   141 }
   141 }
   142 
   142 
   143 impl<'a> HWProtocolMessage {
   143 impl HWProtocolMessage {
   144     pub fn to_raw_protocol(&self) -> String {
   144     /** Converts the message to a raw `String`, which can be sent over the network.
       
   145      *
       
   146      * This is the inverse of the `message` parser.
       
   147      */
       
   148     pub(crate) fn to_raw_protocol(&self) -> String {
   145         use self::HWProtocolMessage::*;
   149         use self::HWProtocolMessage::*;
   146         match self {
   150         match self {
   147             Ping => msg!["PING"],
   151             Ping => msg!["PING"],
   148             Pong => msg!["PONG"],
   152             Pong => msg!["PONG"],
   149             Quit(None) => msg!["QUIT"],
   153             Quit(None) => msg!["QUIT"],
   164                 msg!["CREATE_ROOM", name, password],
   168                 msg!["CREATE_ROOM", name, password],
   165             JoinRoom(name, None) => msg!["JOIN_ROOM", name],
   169             JoinRoom(name, None) => msg!["JOIN_ROOM", name],
   166             JoinRoom(name, Some(password)) =>
   170             JoinRoom(name, Some(password)) =>
   167                 msg!["JOIN_ROOM", name, password],
   171                 msg!["JOIN_ROOM", name, password],
   168             Follow(name) => msg!["FOLLOW", name],
   172             Follow(name) => msg!["FOLLOW", name],
   169             Rnd(args) => msg!["RND", args.join(" ")],
   173             Rnd(args) => if args.is_empty() {
       
   174                 msg!["CMD", "RND"]
       
   175             } else {
       
   176                 msg!["CMD", format!("RND {}", args.join(" "))]
       
   177             },
   170             Kick(name) => msg!["KICK", name],
   178             Kick(name) => msg!["KICK", name],
   171             Ban(name, reason, time) => msg!["BAN", name, reason, time],
   179             Ban(name, reason, time) => msg!["BAN", name, reason, time],
   172             BanIP(ip, reason, time) => msg!["BAN_IP", ip, reason, time],
   180             BanIP(ip, reason, time) => msg!["BAN_IP", ip, reason, time],
   173             BanNick(nick, reason, time) =>
   181             BanNick(nick, reason, time) =>
   174                 msg!("BAN_NICK", nick, reason, time),
   182                 msg!("BAN_NICK", nick, reason, time),