Add InstanceConfig::force_username setting
This commit is contained in:
parent
6660313200
commit
cd4b65d9cc
1 changed files with 17 additions and 4 deletions
|
|
@ -107,6 +107,9 @@ pub struct InstanceConfig {
|
||||||
pub human: bool,
|
pub human: bool,
|
||||||
/// Username to set upon connecting.
|
/// Username to set upon connecting.
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
|
/// Whether to set the username even if the server reports that the session
|
||||||
|
/// already has a username set.
|
||||||
|
pub force_username: bool,
|
||||||
/// Password to use if room requires authentication.
|
/// Password to use if room requires authentication.
|
||||||
pub password: Option<String>,
|
pub password: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
@ -119,6 +122,7 @@ impl InstanceConfig {
|
||||||
room: room.to_string(),
|
room: room.to_string(),
|
||||||
human: false,
|
human: false,
|
||||||
username: None,
|
username: None,
|
||||||
|
force_username: false,
|
||||||
password: None,
|
password: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +142,11 @@ impl InstanceConfig {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn force_username(mut self, force_username: bool) -> Self {
|
||||||
|
self.force_username = force_username;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn password<S: ToString>(mut self, password: Option<S>) -> Self {
|
pub fn password<S: ToString>(mut self, password: Option<S>) -> Self {
|
||||||
self.password = password.map(|s| s.to_string());
|
self.password = password.map(|s| s.to_string());
|
||||||
self
|
self
|
||||||
|
|
@ -401,11 +410,15 @@ impl Instance {
|
||||||
};
|
};
|
||||||
|
|
||||||
match &packet.content {
|
match &packet.content {
|
||||||
Ok(Data::SnapshotEvent(_)) => {
|
Ok(Data::SnapshotEvent(snapshot)) => {
|
||||||
if let Some(username) = &config.username {
|
if let Some(username) = &config.username {
|
||||||
|
if config.force_username || snapshot.nick.is_none() {
|
||||||
debug!("{}: Setting nick to username {}", config.name, username);
|
debug!("{}: Setting nick to username {}", config.name, username);
|
||||||
let name = username.to_string();
|
let name = username.to_string();
|
||||||
let _ = conn.tx().send(Nick { name });
|
let _ = conn.tx().send(Nick { name });
|
||||||
|
} else if let Some(nick) = &snapshot.nick {
|
||||||
|
debug!("{}: Not setting nick, already set to {}", config.name, nick);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Data::BounceEvent(_)) => {
|
Ok(Data::BounceEvent(_)) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue