| 86 | } |
| 87 | |
| 88 | fn parse_client_command(msg: &str) -> Option<codec::ChatRequest> { |
| 89 | let m = msg.trim(); |
| 90 | |
| 91 | if m.is_empty() { |
| 92 | return None; |
| 93 | } |
| 94 | |
| 95 | // we check for /sss type of messages |
| 96 | if m.starts_with('/') { |
| 97 | let v: Vec<&str> = m.splitn(2, ' ').collect(); |
| 98 | match v[0] { |
| 99 | "/list" => Some(codec::ChatRequest::List), |
| 100 | "/join" => { |
| 101 | if v.len() == 2 { |
| 102 | Some(codec::ChatRequest::Join(v[1].to_owned())) |
| 103 | } else { |
| 104 | println!("!!! room name is required"); |
| 105 | None |
| 106 | } |
| 107 | } |
| 108 | _ => { |
| 109 | println!("!!! unknown command"); |
| 110 | None |
| 111 | } |
| 112 | } |
| 113 | } else { |
| 114 | Some(codec::ChatRequest::Message(m.to_owned())) |
| 115 | } |
| 116 | } |