Compare commits
2 Commits
dad0adeb8c
...
3342de6067
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3342de6067 | ||
|
|
20b1290821 |
49
src/main.rs
49
src/main.rs
@ -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,11 +362,11 @@ fn handle_connection(
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(pki_path) = &pki_path {
|
||||
if !Path::is_file(pki_path) {
|
||||
fail(stream);
|
||||
return;
|
||||
}
|
||||
if let Some(pki_path) = &pki_path
|
||||
&& !Path::is_file(pki_path)
|
||||
{
|
||||
fail(stream);
|
||||
return;
|
||||
}
|
||||
|
||||
let info = if let Ok(mut context) = context.lock() {
|
||||
@ -544,11 +521,11 @@ 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() {
|
||||
eprintln!("Error saving data!");
|
||||
eprintln!();
|
||||
}
|
||||
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 {
|
||||
|
||||
14
src/tabs.rs
14
src/tabs.rs
@ -129,13 +129,13 @@ impl TabInfo {
|
||||
|
||||
let _ = writeln!(stream, "<h2>Description</h2>");
|
||||
|
||||
if let Some(audio_path) = &file_paths.audio {
|
||||
if audio_path.is_file() {
|
||||
let _ = writeln!(
|
||||
stream,
|
||||
"<p><audio controls src=\"/{relative_path}.mp3\"/></p>"
|
||||
);
|
||||
}
|
||||
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);
|
||||
|
||||
52
src/vn.rs
52
src/vn.rs
@ -507,36 +507,36 @@ 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) {
|
||||
settings.change(change);
|
||||
*state += 1;
|
||||
}
|
||||
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) {
|
||||
for line in BufReader::new(file).lines() {
|
||||
let Ok(line) = line else {
|
||||
break;
|
||||
};
|
||||
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;
|
||||
};
|
||||
|
||||
if let Some((channel, default_value)) = line.split_once(':') {
|
||||
let _ = parser.add_new_channel(channel, default_value);
|
||||
continue;
|
||||
}
|
||||
|
||||
let line = line.trim();
|
||||
if line.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
return None;
|
||||
if let Some((channel, default_value)) = line.split_once(':') {
|
||||
let _ = parser.add_new_channel(channel, default_value);
|
||||
continue;
|
||||
}
|
||||
|
||||
let line = line.trim();
|
||||
if line.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
@ -601,10 +601,10 @@ 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)) {
|
||||
choices.push((i, block))
|
||||
}
|
||||
if let Some(block) = dialog_sequence.blocks.first()
|
||||
&& simulation.callable(Event(i))
|
||||
{
|
||||
choices.push((i, block))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user