version & fixed some clippy linting

This commit is contained in:
2026-05-14 23:34:11 +01:00
parent 90c5e464d2
commit a5a45fa1f0
11 changed files with 34 additions and 30 deletions
BIN
View File
Binary file not shown.
+1 -1
View File
@@ -457,7 +457,7 @@ dependencies = [
[[package]] [[package]]
name = "happening-server" name = "happening-server"
version = "0.1.0" version = "0.0.2"
dependencies = [ dependencies = [
"env_logger", "env_logger",
"log", "log",
+8 -2
View File
@@ -1,7 +1,13 @@
[package] [package]
name = "happening-server" name = "happening-server"
version = "0.1.0" version = "0.0.2"
edition = "2024" edition = "2024"
license = "GPL-3"
repository = "https://git.javalsai.tuxcord.net/deadvey/happening/"
readme = "../README.md"
keywords = ["interactive", "storytelling", "server"]
categories = ["parsing", "games"]
description = "Server for happening: an interactive storytelling game"
[lints.clippy] [lints.clippy]
cargo = { level = "warn", priority = -1 } cargo = { level = "warn", priority = -1 }
@@ -14,7 +20,7 @@ option_if_let_else = { level = "allow" }
pedantic = { level = "deny", priority = -1 } pedantic = { level = "deny", priority = -1 }
perf = { level = "deny", priority = -1 } perf = { level = "deny", priority = -1 }
style = { level = "deny", priority = -1 } style = { level = "deny", priority = -1 }
unwrap_used = "deny" unwrap_used = "warn"
[dependencies] [dependencies]
env_logger = "0.11.10" env_logger = "0.11.10"
+6 -2
View File
@@ -61,6 +61,8 @@ pub async fn api_process
.and(warp::path::param::<String>()) .and(warp::path::param::<String>())
.and(characters_filter) .and(characters_filter)
.map(|name: String, characters: Arc<Mutex<HashMap<String, character::Character>>>| .map(|name: String, characters: Arc<Mutex<HashMap<String, character::Character>>>|
{
let reply =
{ {
let characters = match characters.lock() let characters = match characters.lock()
{ {
@@ -71,8 +73,10 @@ pub async fn api_process
poisoned.into_inner() poisoned.into_inner()
}, },
}; };
let Some(reply) = characters.get(&name) characters.get(&name).cloned()
else };
let Some(reply) = reply else
{ {
warn!("Client requested character that does not exist"); warn!("Client requested character that does not exist");
return warp::reply::json(&json!({"reply": "invalid character"})); return warp::reply::json(&json!({"reply": "invalid character"}));
+1 -3
View File
@@ -9,7 +9,7 @@ use crate::{
Mutex, Mutex,
Arc, Arc,
}; };
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize, Clone)]
pub struct Character pub struct Character
{ {
name: String, name: String,
@@ -20,7 +20,6 @@ pub struct Character
pronoun_deppos: String, pronoun_deppos: String,
pronoun_indpos: String, pronoun_indpos: String,
pronoun_reflex: String, pronoun_reflex: String,
animation: String,
head: String, head: String,
hair: String, hair: String,
torso: String, torso: String,
@@ -42,7 +41,6 @@ impl Character {
"pronoun_deppos" => self.pronoun_deppos = value.to_string(), "pronoun_deppos" => self.pronoun_deppos = value.to_string(),
"pronoun_indpos" => self.pronoun_indpos = value.to_string(), "pronoun_indpos" => self.pronoun_indpos = value.to_string(),
"pronoun_reflex" => self.pronoun_reflex = value.to_string(), "pronoun_reflex" => self.pronoun_reflex = value.to_string(),
"animation" => self.animation = value.to_string(),
"head" => self.head = value.to_string(), "head" => self.head = value.to_string(),
"hair" => self.hair = value.to_string(), "hair" => self.hair = value.to_string(),
"torso" => self.torso = value.to_string(), "torso" => self.torso = value.to_string(),
+1 -1
View File
@@ -121,7 +121,7 @@ async fn main()
let data_clone2 = Arc::clone(&data_to_send); let data_clone2 = Arc::clone(&data_to_send);
let characters_clone2 = Arc::clone(&characters); let characters_clone2 = Arc::clone(&characters);
// Run the parsing process for the DSL // Run the parsing process for the DSL
match parsing::token_parse(&tokens, characters_clone2, &data_clone2, &rx) match parsing::token_parse(&tokens, &characters_clone2, &data_clone2, &rx)
{ {
// Exit with error or success // Exit with error or success
Ok(()) => Ok(()) =>
+5 -4
View File
@@ -21,7 +21,7 @@ mod character_parse;
// Returns success or an error string // Returns success or an error string
pub fn token_parse( pub fn token_parse(
tokens: &Vec<&str>, tokens: &Vec<&str>,
characters: Arc<Mutex<HashMap::<String, character::Character>>>, characters: &Arc<Mutex<HashMap::<String, character::Character>>>,
data_to_send: &Arc<Mutex<api::DataToSend>>, data_to_send: &Arc<Mutex<api::DataToSend>>,
rx: &Receiver<(bool,usize)>, rx: &Receiver<(bool,usize)>,
) -> Result<(),String> ) -> Result<(),String>
@@ -48,7 +48,7 @@ pub fn token_parse(
let character_name: String = token.chars().skip(1).collect(); let character_name: String = token.chars().skip(1).collect();
debug!("Doing something with a character: {character_name}"); debug!("Doing something with a character: {character_name}");
// The index is incremented to after the character's instructions // The index is incremented to after the character's instructions
index = match character_parse::character_parse(index+1, tokens, character_name, &characters, &data_to_send) index = match character_parse::character_parse(index+1, tokens, character_name, characters, data_to_send)
{ {
Ok(increment) => increment, Ok(increment) => increment,
Err((err,increment)) => Err((err,increment)) =>
@@ -70,12 +70,12 @@ pub fn token_parse(
}, },
"choice" => "choice" =>
{ {
let (_,jump_points) = match choice_parse(index+1, tokens, &data_to_send) let (_,jump_points) = match choice_parse(index+1, tokens, data_to_send)
{ {
Ok((increment,jump_point)) => (increment,jump_point), Ok((increment,jump_point)) => (increment,jump_point),
Err(error) => return Err(error), Err(error) => return Err(error),
}; };
if rx.recv().is_err() { warn!("Error sending choices to client"); }; if rx.recv().is_err() { warn!("Error sending choices to client"); }
let (_, choice) = match rx.recv() let (_, choice) = match rx.recv()
{ {
Ok((_,choice)) => (None::<bool>, choice), Ok((_,choice)) => (None::<bool>, choice),
@@ -151,5 +151,6 @@ fn choice_parse
data.content = String::new(); data.content = String::new();
data.character = String::new(); data.character = String::new();
data.choices = choices; //TODO data.choices = choices; //TODO
drop(data);
Ok((sum_index + 1, choice_indeces)) Ok((sum_index + 1, choice_indeces))
} }
+5 -4
View File
@@ -48,6 +48,7 @@ pub fn character_parse
data.content = output_string; data.content = output_string;
data.character = character_name; data.character = character_name;
data.choices = vec![]; data.choices = vec![];
drop(data);
}, },
None => return Err(("Unable to read output string".to_string(), sum_index)), None => return Err(("Unable to read output string".to_string(), sum_index)),
} }
@@ -69,14 +70,14 @@ pub fn character_parse
info!("CHANGE command with character {character_name} feature {feature}"); info!("CHANGE command with character {character_name} feature {feature}");
let mut characters = characters.lock().expect("Data cannot be unlocked"); let mut characters = characters.lock().expect("Data cannot be unlocked");
if let Some(character) = characters.get_mut(&character_name) if let Some(character) = characters.get_mut(&character_name)
{ && character.set_field(feature, &output_string)
if character.set_field(feature, &output_string) .is_err() { warn!("Feature {feature} does not exist") }
.is_err() { warn!("Feature {feature} does not exist") }; drop(characters);
}
let mut data = data_to_send.lock().unwrap(); // TODO eh? let mut data = data_to_send.lock().unwrap(); // TODO eh?
data.action_type = String::from("change"); data.action_type = String::from("change");
data.content = String::new(); data.content = String::new();
data.character = character_name; data.character = character_name;
drop(data);
}, },
// Catch all condition, if the instruction is unrecognised as a // Catch all condition, if the instruction is unrecognised as a
// character command // character command
+1 -6
View File
@@ -23,10 +23,10 @@ pub fn extract_quoted(parts: &[&str])
for part in parts for part in parts
{ {
counter += 1; counter += 1;
vec_string.push(*part);
// End of the string // End of the string
if part.ends_with('\"') // TODO allow for backslashes and ' if part.ends_with('\"') // TODO allow for backslashes and '
{ {
vec_string.push(*part);
let final_string: String = vec_string.join(" "); let final_string: String = vec_string.join(" ");
let final_string: String = final_string let final_string: String = final_string
.chars() .chars()
@@ -37,11 +37,6 @@ pub fn extract_quoted(parts: &[&str])
.collect(); .collect();
return Some((final_string, counter)); return Some((final_string, counter));
} }
// Otherwise just add this to the list
else
{
vec_string.push(*part);
}
} }
None None
} }
-1
View File
@@ -9,7 +9,6 @@
"pronoun_deppos": "His", "pronoun_deppos": "His",
"pronoun_indpos": "His", "pronoun_indpos": "His",
"pronoun_reflex": "Himself", "pronoun_reflex": "Himself",
"animation": "",
"head": "", "head": "",
"hair": "", "hair": "",
"torso": "", "torso": "",
BIN
View File
Binary file not shown.