aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mumctl/src/main.rs13
-rw-r--r--mumd/src/network/tcp.rs13
-rw-r--r--mumd/src/state.rs5
-rw-r--r--mumd/src/state/server.rs10
-rw-r--r--mumlib/src/command.rs1
5 files changed, 37 insertions, 5 deletions
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs
index d07a482..65dac61 100644
--- a/mumctl/src/main.rs
+++ b/mumctl/src/main.rs
@@ -59,6 +59,7 @@ fn main() {
.about("Connect to a server")
.arg(Arg::with_name("host").required(true))
.arg(Arg::with_name("username"))
+ .arg(Arg::with_name("password"))
.arg(
Arg::with_name("port")
.long("port")
@@ -395,13 +396,14 @@ fn process_matches(matches: ArgMatches, config: &mut Config, app: &mut App) -> R
fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config::Config) -> Result<(), Error> {
let host = matches.value_of("host").unwrap();
let username = matches.value_of("username");
+ let password = matches.value_of("password");
let port = match matches.value_of("port").map(|e| e.parse()) {
None => Some(mumlib::DEFAULT_PORT),
Some(Err(_)) => None,
Some(Ok(v)) => Some(v),
};
if let Some(port) = port {
- let (host, port, username) = match config.servers.iter().find(|e| e.name == host) {
+ let (host, port, username, password) = match config.servers.iter().find(|e| e.name == host) {
Some(server_config) => {
let host = server_config.host.as_str();
let port = server_config.port.unwrap_or(port);
@@ -413,20 +415,25 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config:
error!("no username specified");
return Ok(()); //TODO? return as error
}
- (host, port, username.unwrap())
+ let password = server_config
+ .password
+ .as_deref()
+ .or(password);
+ (host, port, username.unwrap(), password)
}
None => {
if username.is_none() {
error!("no username specified");
return Ok(()); //TODO? return as error
}
- (host, port, username.unwrap())
+ (host, port, username.unwrap(), password)
}
};
let response = send_command(Command::ServerConnect {
host: host.to_string(),
port,
username: username.to_string(),
+ password: password.map(|x| x.to_string()),
accept_invalid_cert: true, //TODO
})?
.map(|e| (e, host));
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
}
diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs
index 73a065d..d2e8477 100644
--- a/mumlib/src/command.rs
+++ b/mumlib/src/command.rs
@@ -19,6 +19,7 @@ pub enum Command {
host: String,
port: u16,
username: String,
+ password: Option<String>,
accept_invalid_cert: bool,
},
ServerDisconnect,