diff --git a/report.odt b/report.odt index eefef77..adf9b53 100644 Binary files a/report.odt and b/report.odt differ diff --git a/server/Cargo.lock b/server/Cargo.lock index c752ae0..e873a43 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -457,7 +457,7 @@ dependencies = [ [[package]] name = "happening-server" -version = "0.1.0" +version = "0.0.2" dependencies = [ "env_logger", "log", diff --git a/server/Cargo.toml b/server/Cargo.toml index 43f666a..5e67b23 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,7 +1,13 @@ [package] name = "happening-server" -version = "0.1.0" +version = "0.0.2" 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] cargo = { level = "warn", priority = -1 } @@ -14,7 +20,7 @@ option_if_let_else = { level = "allow" } pedantic = { level = "deny", priority = -1 } perf = { level = "deny", priority = -1 } style = { level = "deny", priority = -1 } -unwrap_used = "deny" +unwrap_used = "warn" [dependencies] env_logger = "0.11.10" diff --git a/server/src/api.rs b/server/src/api.rs index 5bee681..b741011 100644 --- a/server/src/api.rs +++ b/server/src/api.rs @@ -62,17 +62,21 @@ pub async fn api_process .and(characters_filter) .map(|name: String, characters: Arc>>| { - let characters = match characters.lock() + let reply = { - Ok(data) => data, - Err(poisoned) => + let characters = match characters.lock() { - warn!("Character Mutex is poisoned"); - poisoned.into_inner() - }, + Ok(data) => data, + Err(poisoned) => + { + warn!("Character Mutex is poisoned"); + poisoned.into_inner() + }, + }; + characters.get(&name).cloned() }; - let Some(reply) = characters.get(&name) - else + + let Some(reply) = reply else { warn!("Client requested character that does not exist"); return warp::reply::json(&json!({"reply": "invalid character"})); diff --git a/server/src/character.rs b/server/src/character.rs index 2b7d601..adf6883 100644 --- a/server/src/character.rs +++ b/server/src/character.rs @@ -9,7 +9,7 @@ use crate::{ Mutex, Arc, }; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, Clone)] pub struct Character { name: String, @@ -20,7 +20,6 @@ pub struct Character pronoun_deppos: String, pronoun_indpos: String, pronoun_reflex: String, - animation: String, head: String, hair: String, torso: String, @@ -42,7 +41,6 @@ impl Character { "pronoun_deppos" => self.pronoun_deppos = value.to_string(), "pronoun_indpos" => self.pronoun_indpos = value.to_string(), "pronoun_reflex" => self.pronoun_reflex = value.to_string(), - "animation" => self.animation = value.to_string(), "head" => self.head = value.to_string(), "hair" => self.hair = value.to_string(), "torso" => self.torso = value.to_string(), diff --git a/server/src/main.rs b/server/src/main.rs index 65c28df..55a4f08 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -121,7 +121,7 @@ async fn main() let data_clone2 = Arc::clone(&data_to_send); let characters_clone2 = Arc::clone(&characters); // 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 Ok(()) => diff --git a/server/src/parsing.rs b/server/src/parsing.rs index b33240b..6cc2baf 100644 --- a/server/src/parsing.rs +++ b/server/src/parsing.rs @@ -21,7 +21,7 @@ mod character_parse; // Returns success or an error string pub fn token_parse( tokens: &Vec<&str>, - characters: Arc>>, + characters: &Arc>>, data_to_send: &Arc>, rx: &Receiver<(bool,usize)>, ) -> Result<(),String> @@ -48,7 +48,7 @@ pub fn token_parse( let character_name: String = token.chars().skip(1).collect(); debug!("Doing something with a character: {character_name}"); // 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, Err((err,increment)) => @@ -70,12 +70,12 @@ pub fn token_parse( }, "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), 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() { Ok((_,choice)) => (None::, choice), @@ -151,5 +151,6 @@ fn choice_parse data.content = String::new(); data.character = String::new(); data.choices = choices; //TODO + drop(data); Ok((sum_index + 1, choice_indeces)) } diff --git a/server/src/parsing/character_parse.rs b/server/src/parsing/character_parse.rs index d298c71..5067b89 100644 --- a/server/src/parsing/character_parse.rs +++ b/server/src/parsing/character_parse.rs @@ -48,6 +48,7 @@ pub fn character_parse data.content = output_string; data.character = character_name; data.choices = vec![]; + drop(data); }, 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}"); let mut characters = characters.lock().expect("Data cannot be unlocked"); if let Some(character) = characters.get_mut(&character_name) - { - if character.set_field(feature, &output_string) - .is_err() { warn!("Feature {feature} does not exist") }; - } + && character.set_field(feature, &output_string) + .is_err() { warn!("Feature {feature} does not exist") } + drop(characters); let mut data = data_to_send.lock().unwrap(); // TODO eh? data.action_type = String::from("change"); data.content = String::new(); data.character = character_name; + drop(data); }, // Catch all condition, if the instruction is unrecognised as a // character command diff --git a/server/src/parsing/strings.rs b/server/src/parsing/strings.rs index ce42ff7..6545911 100644 --- a/server/src/parsing/strings.rs +++ b/server/src/parsing/strings.rs @@ -23,10 +23,10 @@ pub fn extract_quoted(parts: &[&str]) for part in parts { counter += 1; + vec_string.push(*part); // End of the string if part.ends_with('\"') // TODO allow for backslashes and ' { - vec_string.push(*part); let final_string: String = vec_string.join(" "); let final_string: String = final_string .chars() @@ -37,11 +37,6 @@ pub fn extract_quoted(parts: &[&str]) .collect(); return Some((final_string, counter)); } - // Otherwise just add this to the list - else - { - vec_string.push(*part); - } } None } diff --git a/stories/characters.json b/stories/characters.json index c120f30..5580eb9 100644 --- a/stories/characters.json +++ b/stories/characters.json @@ -9,7 +9,6 @@ "pronoun_deppos": "His", "pronoun_indpos": "His", "pronoun_reflex": "Himself", - "animation": "", "head": "", "hair": "", "torso": "", diff --git a/stories/test.zip b/stories/test.zip index 2fed764..a14af52 100644 Binary files a/stories/test.zip and b/stories/test.zip differ