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

View File

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

View File

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