diff options
| author | Rubens Brandao <git@rubens.io> | 2021-03-28 20:58:16 +0200 |
|---|---|---|
| committer | Rubens Brandao <git@rubens.io> | 2021-03-28 20:58:16 +0200 |
| commit | 4b12f3e87ed12ed5b070f23d73f8288cd5b109fd (patch) | |
| tree | 1f0ebc6d0a0af9f657badcc6eebe1d158ac6f83d /mumd/src | |
| parent | 8501432530f19cb2be86815697c82abbe4482275 (diff) | |
| download | mum-4b12f3e87ed12ed5b070f23d73f8288cd5b109fd.tar.gz | |
Finish the password implementation
Diffstat (limited to 'mumd/src')
| -rw-r--r-- | mumd/src/network/tcp.rs | 13 | ||||
| -rw-r--r-- | mumd/src/state.rs | 5 | ||||
| -rw-r--r-- | mumd/src/state/server.rs | 10 |
3 files changed, 26 insertions, 2 deletions
diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index fa2681e..8ce49cb 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -67,7 +67,9 @@ pub async fn handle( // Handshake (omitting `Version` message for brevity) let state_lock = state.lock().await; - authenticate(&mut sink, state_lock.username().unwrap().to_string()).await; + let username = state_lock.username().unwrap().to_string(); + let password = state_lock.password().map(|x| x.to_string()); + authenticate(&mut sink, username, password).await; let phase_watcher = state_lock.phase_receiver(); let input_receiver = state_lock.audio().input_receiver(); drop(state_lock); @@ -133,9 +135,16 @@ async fn connect( ClientControlCodec::new().framed(tls_stream).split() } -async fn authenticate(sink: &mut TcpSender, username: String) { +async fn authenticate( + sink: &mut TcpSender, + username: String, + password: Option<String> +) { let mut msg = msgs::Authenticate::new(); msg.set_username(username); + if let Some(password) = password { + msg.set_password(password); + } msg.set_opus(true); sink.send(msg.into()).await.unwrap(); } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index ae7ae70..b279dfd 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -309,6 +309,7 @@ impl State { host, port, username, + password, accept_invalid_cert, } => { if !matches!(*self.phase_receiver().borrow(), StatePhase::Disconnected) { @@ -316,6 +317,7 @@ impl State { } let mut server = Server::new(); *server.username_mut() = Some(username); + *server.password_mut() = password; *server.host_mut() = Some(format!("{}:{}", host, port)); self.server = Some(server); self.phase_watcher @@ -610,6 +612,9 @@ impl State { pub fn username(&self) -> Option<&str> { self.server.as_ref().map(|e| e.username()).flatten() } + pub fn password(&self) -> Option<&str> { + self.server.as_ref().map(|e| e.password()).flatten() + } fn get_users_channel(&self, user_id: u32) -> u32 { self.server() .unwrap() diff --git a/mumd/src/state/server.rs b/mumd/src/state/server.rs index 8a256b6..c9f8a69 100644 --- a/mumd/src/state/server.rs +++ b/mumd/src/state/server.rs @@ -14,6 +14,7 @@ pub struct Server { pub welcome_text: Option<String>, username: Option<String>, + password: Option<String>, session_id: Option<u32>, muted: bool, deafened: bool, @@ -28,6 +29,7 @@ impl Server { users: HashMap::new(), welcome_text: None, username: None, + password: None, session_id: None, muted: false, deafened: false, @@ -114,6 +116,14 @@ impl Server { &mut self.username } + pub fn password(&self) -> Option<&str> { + self.password.as_deref() + } + + pub fn password_mut(&mut self) -> &mut Option<String> { + &mut self.password + } + pub fn muted(&self) -> bool { self.muted } |
