mirror of
https://github.com/zyllian/classics.git
synced 2025-05-10 00:16:39 -07:00
add per-user server passwords
This commit is contained in:
parent
38164a6cc5
commit
d56bf8b7e4
2 changed files with 34 additions and 6 deletions
|
@ -14,6 +14,7 @@ use crate::{
|
|||
client::ClientPacket, server::ServerPacket, PacketReader, PacketWriter, ARRAY_LENGTH,
|
||||
},
|
||||
player::{Player, PlayerType},
|
||||
server::config::ServerProtectionMode,
|
||||
};
|
||||
|
||||
use super::ServerData;
|
||||
|
@ -113,9 +114,21 @@ async fn handle_stream_inner(
|
|||
|
||||
let mut data = data.write().await;
|
||||
|
||||
if let Some(password) = &data.config.password {
|
||||
if verification_key != *password {
|
||||
return Ok(Some("Incorrect password!".to_string()));
|
||||
match &data.config.protection_mode {
|
||||
ServerProtectionMode::None => {}
|
||||
ServerProtectionMode::Password(password) => {
|
||||
if verification_key != *password {
|
||||
return Ok(Some("Incorrect password!".to_string()));
|
||||
}
|
||||
}
|
||||
ServerProtectionMode::PasswordsByUser(passwords) => {
|
||||
if !passwords
|
||||
.get(&username)
|
||||
.map(|password| verification_key == *password)
|
||||
.unwrap_or_default()
|
||||
{
|
||||
return Ok(Some("Incorrect password!".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue