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:
Zoey 2024-04-19 13:17:06 -07:00
parent 38164a6cc5
commit d56bf8b7e4
No known key found for this signature in database
GPG key ID: 8611B896D1AAFAF2
2 changed files with 34 additions and 6 deletions

View file

@ -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()));
}
}
}