Compare commits

..

2 Commits

Author SHA1 Message Date
p11
3342de6067 Removed partial password feature 2025-08-09 21:49:52 +02:00
p11
20b1290821 Collapsed some if-let-ifs 2025-08-09 21:48:54 +02:00
3 changed files with 46 additions and 69 deletions

View File

@ -115,8 +115,7 @@ fn main() -> ExitCode {
let address = args.next(); let address = args.next();
let address = address.as_deref().unwrap_or("127.0.0.1:8080"); let address = address.as_deref().unwrap_or("127.0.0.1:8080");
let password = args.next(); let password = args.next();
let partial_password = args.next(); start_server(path, address, password);
start_server(path, address, password, partial_password);
ExitCode::FAILURE ExitCode::FAILURE
} }
@ -126,12 +125,7 @@ fn get_thread_pool_size() -> usize {
.unwrap_or(4) .unwrap_or(4)
} }
fn start_server( fn start_server(path: PathBuf, address: &str, password: Option<String>) {
path: PathBuf,
address: &str,
password: Option<String>,
partial_password: Option<String>,
) {
let Ok(listener) = TcpListener::bind(address) else { let Ok(listener) = TcpListener::bind(address) else {
eprintln!("Invalid bind address {address:?}!"); eprintln!("Invalid bind address {address:?}!");
return; return;
@ -160,16 +154,7 @@ fn start_server(
let context = context.clone(); let context = context.clone();
let path = path.clone(); let path = path.clone();
let password = password.clone(); let password = password.clone();
let hidden_password = partial_password.clone(); pool.execute(move || handle_connection(context, path, stream, password.as_deref()));
pool.execute(move || {
handle_connection(
context,
path,
stream,
password.as_deref(),
hidden_password.as_deref(),
)
});
} }
} }
@ -183,7 +168,6 @@ fn handle_connection(
path: PathBuf, path: PathBuf,
mut stream: TcpStream, mut stream: TcpStream,
password: Option<&str>, password: Option<&str>,
partial_password: Option<&str>,
) { ) {
let Some(request) = Request::from(&stream) else { let Some(request) = Request::from(&stream) else {
eprintln!("Invalid request!"); eprintln!("Invalid request!");
@ -205,7 +189,6 @@ fn handle_connection(
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
enum Access { enum Access {
None, None,
Partial,
Full, Full,
} }
@ -223,9 +206,6 @@ fn handle_connection(
if input == password { if input == password {
access = Access::Full; access = Access::Full;
cookie = Some(password); cookie = Some(password);
} else if Some(input) == partial_password {
access = Access::Partial;
cookie = partial_password;
} }
break; break;
} }
@ -254,9 +234,6 @@ fn handle_connection(
if state == password { if state == password {
access = Access::Full; access = Access::Full;
break; break;
} else if Some(state) == partial_password {
access = Access::Partial;
break;
} }
} }
} }
@ -385,12 +362,12 @@ fn handle_connection(
return; return;
} }
if let Some(pki_path) = &pki_path { if let Some(pki_path) = &pki_path
if !Path::is_file(pki_path) { && !Path::is_file(pki_path)
{
fail(stream); fail(stream);
return; return;
} }
}
let info = if let Ok(mut context) = context.lock() { let info = if let Ok(mut context) = context.lock() {
use Entry::*; use Entry::*;
@ -544,12 +521,12 @@ fn handle_relative_connection(
let info = info.update(name, text, up, down); let info = info.update(name, text, up, down);
if let Ok(mut file) = File::create(file_paths.data) { if let Ok(mut file) = File::create(file_paths.data)
if to_stream::<PortableSettings, _, _>(&info, &mut file).is_err() { && to_stream::<PortableSettings, _, _>(&info, &mut file).is_err()
{
eprintln!("Error saving data!"); eprintln!("Error saving data!");
eprintln!(); eprintln!();
} }
}
let SiteInfo { let SiteInfo {
comments, comments,

View File

@ -129,14 +129,14 @@ impl TabInfo {
let _ = writeln!(stream, "<h2>Description</h2>"); let _ = writeln!(stream, "<h2>Description</h2>");
if let Some(audio_path) = &file_paths.audio { if let Some(audio_path) = &file_paths.audio
if audio_path.is_file() { && audio_path.is_file()
{
let _ = writeln!( let _ = writeln!(
stream, stream,
"<p><audio controls src=\"/{relative_path}.mp3\"/></p>" "<p><audio controls src=\"/{relative_path}.mp3\"/></p>"
); );
} }
}
let lines = BufReader::new(pki_file).lines().map_while(Result::ok); let lines = BufReader::new(pki_file).lines().map_while(Result::ok);
convert_subheader(lines, stream, 1); convert_subheader(lines, stream, 1);

View File

@ -507,19 +507,20 @@ fn apply_block_changes(
.flat_map(|l| &l.actions) .flat_map(|l| &l.actions)
.chain(&block.final_actions) .chain(&block.final_actions)
{ {
if let Some(state) = states.get_mut(parameter) { if let Some(state) = states.get_mut(parameter)
if let Some(change) = changes[parameter].get(*state) { && let Some(change) = changes[parameter].get(*state)
{
settings.change(change); settings.change(change);
*state += 1; *state += 1;
} }
} }
}
} }
fn load_multilinear(mlc_path: Option<&Path>, mld_path: &Path) -> Option<NamedMultilinearInfo> { fn load_multilinear(mlc_path: Option<&Path>, mld_path: &Path) -> Option<NamedMultilinearInfo> {
let mut parser = MultilinearParser::default(); let mut parser = MultilinearParser::default();
if let Some(mlc_path) = mlc_path { if let Some(mlc_path) = mlc_path
if let Ok(file) = File::open(mlc_path) { && let Ok(file) = File::open(mlc_path)
{
for line in BufReader::new(file).lines() { for line in BufReader::new(file).lines() {
let Ok(line) = line else { let Ok(line) = line else {
break; break;
@ -538,7 +539,6 @@ fn load_multilinear(mlc_path: Option<&Path>, mld_path: &Path) -> Option<NamedMul
return None; return None;
} }
} }
}
if let Err(e) = parser.parse(File::open(mld_path).ok()?, &[]) { if let Err(e) = parser.parse(File::open(mld_path).ok()?, &[]) {
eprintln!("Error parsing multilinear definition: {e}"); eprintln!("Error parsing multilinear definition: {e}");
@ -601,12 +601,12 @@ pub fn render_novel(
let mut choices = Vec::new(); let mut choices = Vec::new();
for (i, dialog_sequence) in dialogs.iter().enumerate() { for (i, dialog_sequence) in dialogs.iter().enumerate() {
if let Some(block) = dialog_sequence.blocks.first() { if let Some(block) = dialog_sequence.blocks.first()
if simulation.callable(Event(i)) { && simulation.callable(Event(i))
{
choices.push((i, block)) choices.push((i, block))
} }
} }
}
if choices.len() == 1 { if choices.len() == 1 {
let next_choice = choices[0].0; let next_choice = choices[0].0;