Compare commits

..

No commits in common. "3342de60675f5edac486cc1b0ad233d98476dc13" and "dad0adeb8c8b6c6f802f834e4c455857386c5795" have entirely different histories.

3 changed files with 69 additions and 46 deletions

View File

@ -115,7 +115,8 @@ 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();
start_server(path, address, password); let partial_password = args.next();
start_server(path, address, password, partial_password);
ExitCode::FAILURE ExitCode::FAILURE
} }
@ -125,7 +126,12 @@ fn get_thread_pool_size() -> usize {
.unwrap_or(4) .unwrap_or(4)
} }
fn start_server(path: PathBuf, address: &str, password: Option<String>) { fn start_server(
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;
@ -154,7 +160,16 @@ fn start_server(path: PathBuf, address: &str, password: Option<String>) {
let context = context.clone(); let context = context.clone();
let path = path.clone(); let path = path.clone();
let password = password.clone(); let password = password.clone();
pool.execute(move || handle_connection(context, path, stream, password.as_deref())); let hidden_password = partial_password.clone();
pool.execute(move || {
handle_connection(
context,
path,
stream,
password.as_deref(),
hidden_password.as_deref(),
)
});
} }
} }
@ -168,6 +183,7 @@ 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!");
@ -189,6 +205,7 @@ fn handle_connection(
#[derive(PartialEq, Eq)] #[derive(PartialEq, Eq)]
enum Access { enum Access {
None, None,
Partial,
Full, Full,
} }
@ -206,6 +223,9 @@ 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;
} }
@ -234,6 +254,9 @@ 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;
} }
} }
} }
@ -362,12 +385,12 @@ fn handle_connection(
return; return;
} }
if let Some(pki_path) = &pki_path if let Some(pki_path) = &pki_path {
&& !Path::is_file(pki_path) if !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::*;
@ -521,12 +544,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) {
&& to_stream::<PortableSettings, _, _>(&info, &mut file).is_err() if 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 {
&& audio_path.is_file() if 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,20 +507,19 @@ 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) {
&& let Some(change) = changes[parameter].get(*state) if 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 {
&& let Ok(file) = File::open(mlc_path) if 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;
@ -539,6 +538,7 @@ 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() {
&& simulation.callable(Event(i)) if 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;