From ba7985161ed36c492cbb75e7c455277c6b3b6da0 Mon Sep 17 00:00:00 2001 From: deadvey Date: Thu, 14 May 2026 14:51:47 +0100 Subject: [PATCH] moved default sories location and added some proper error handling --- server/src/api.rs | 2 +- server/src/main.rs | 9 +++++---- server/src/parsing.rs | 24 ++++++++++++++++++++---- server/stories/characters.json | 23 ----------------------- server/stories/no-characters.zip | Bin 265 -> 0 bytes server/stories/no-story.zip | Bin 344 -> 0 bytes server/stories/nothing.zip | Bin 373 -> 0 bytes server/stories/story.ha | 8 -------- server/stories/test.zip | Bin 587 -> 0 bytes 9 files changed, 26 insertions(+), 40 deletions(-) delete mode 100644 server/stories/characters.json delete mode 100644 server/stories/no-characters.zip delete mode 100644 server/stories/no-story.zip delete mode 100644 server/stories/nothing.zip delete mode 100644 server/stories/story.ha delete mode 100644 server/stories/test.zip diff --git a/server/src/api.rs b/server/src/api.rs index 7efc52f..d142709 100644 --- a/server/src/api.rs +++ b/server/src/api.rs @@ -49,7 +49,7 @@ pub async fn api_process // Perform this code on a GET request .map(|state: Arc>, tx_handle: Sender<(bool,usize)>| { - info!("GET: {:?}", state); + debug!("GET: {:?}", state); let reply = state.as_ref(); let _ = tx_handle.send((true,0)); warp::reply::json(&reply) // Send the reply data (data_to_send formatted as JSON) diff --git a/server/src/main.rs b/server/src/main.rs index 3939e10..7313434 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -28,6 +28,7 @@ mod character; mod config; mod api; +#[warn(clippy::all, clippy::pedantic)] #[tokio::main] async fn main() { @@ -42,7 +43,7 @@ async fn main() error!("No filename specified"); std::process::exit(5); }); - let file = File::open(format!("stories/{}",file_name)) + let file = File::open(format!("../stories/{}",file_name)) .unwrap_or_else (|err| { error!("Failed to open file: {}", err); @@ -59,7 +60,7 @@ async fn main() { Ok(result) => { - info!("{:?}", result); + debug!("{:?}", result); result }, Err(error) => @@ -72,8 +73,8 @@ async fn main() let data_to_send = Arc::new(Mutex::new(api::DataToSend { action_type: "begin".to_string(), - content: "".to_string(), - character: "".to_string(), + content: String::new(), + character: String::new(), choices: vec![], })); diff --git a/server/src/parsing.rs b/server/src/parsing.rs index 682b884..3acfa8f 100644 --- a/server/src/parsing.rs +++ b/server/src/parsing.rs @@ -25,12 +25,14 @@ pub async fn token_parse( rx: &Receiver<(bool,usize)>, ) -> Result<(),String> { + info!("DSL parsing begun"); let mut index: usize = 0; if rx.recv().is_err() { warn!("Some issue with api"); // TOD eh? }; + info!("Client has connected"); // Run an infinite loop 'parse_loop: loop { @@ -43,7 +45,7 @@ pub async fn token_parse( if token.starts_with('@') { let character_name: String = token.chars().skip(1).collect(); - info!("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 index = match character_parse(index+1, tokens, character_name, &characters, &data_to_send).await { @@ -59,7 +61,7 @@ pub async fn token_parse( "end" => { info!("END command, exiting"); - return Ok(()) // quit + return Ok(()) // quit successfully }, "choice" => { @@ -69,14 +71,28 @@ pub async fn token_parse( Err(error) => return Err(error), }; if rx.recv().is_err() { warn!("Error sending choices to client"); }; - let (_, choice) = rx.recv().unwrap(); // TODO eh + let (_, choice) = match rx.recv() + { + Ok((_,choice)) => (None::, choice), + Err(err) => + { + warn!("Error receiving choice from client, defaulting to choice 0 {}", err); + (None::, 0) + } + }; index = jump_points[choice]; + info!("CHOICE command with {} choices", jump_points.len()); debug!("{:?} {} {}",jump_points, choice, index); continue 'parse_loop }, "or" => { - index += strings::closing_char(&tokens[index..], '{','}').unwrap(); // TODO eh + info!("OR command, jumping over"); + index += match strings::closing_char(&tokens[index..], '{','}') // TODO eh + { + Ok(index) => index, + Err(_) => return Err(String::from("Unable to find closing brace to OR command")), + }; continue }, "}" => diff --git a/server/stories/characters.json b/server/stories/characters.json deleted file mode 100644 index a5ec8d4..0000000 --- a/server/stories/characters.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "tim": { - "name": "Timothy Sharpshooter", - "gender": "", - "skin_color": "", - "eye_color": "", - "pronoun_subject": "", - "pronoun_object": "", - "pronoun_deppos": "", - "pronoun_indpos": "", - "pronoun_reflex": "", - "animation": "", - "head": "", - "hair": "", - "torso": "", - "arm": "", - "leg": "", - "hair_color": "", - "top_clothing": "", - "bottom_clothing": "", - "shoes": "" - } -} diff --git a/server/stories/no-characters.zip b/server/stories/no-characters.zip deleted file mode 100644 index dd9ff219232122092146856903e11b150a0a3ddb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 265 zcmWIWW@Zs#U|`^2@ZYl{=1CJzN-_fj!*sBS3`22Aeo>`fMq+3PCj;}hlz*Ap|5>t1 zE4UdLSza(RFo20-jgx0WHT>4-gaw@PID7JBxW;+?Q=S(CPv`{dhk1l}oImd$=;660 zXbukWW@Q7ZV`N}t@MBS}Wg7iw$ttbjW?*D_!OXw_CQ2tb@--_6xLz;dI=oB$h3T!mjx)J*&j?6NmU?{G z`?1riGV}ju|DXIbb7{bvrd?*6MVuD$1*DahH{S3&d-j#cX4NE*SD#9G8kU_oy7|?g zq8s0ytV}XED0kGwLwQ@}n|T*L7dqDOXq3>D-|1X@O4!C`kNLWbtY`ZQoW-`RoKkjm zu8(H$RKG-FxwiW^_NfHtRL9Fb-%wO`#OGm3;6JWxW=*l3C-?)r8JXmmad}sQ0R$Ks k7#Nl`f>;=yXN7nk&Eo;ytZX3Vj0}tnp$rTRZ$TUe0IZ06Gynhq diff --git a/server/stories/nothing.zip b/server/stories/nothing.zip deleted file mode 100644 index 670361456d97a258599dcede8a75ce5857fc134a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 373 zcmWIWW@Zs#U|`^2aM-jaW<}`q=SLYB7(y8t7g_y|R z>Rr5DrOH2EfB)Ma{B_mNm15axq3wT8JY4ikZtce0XA|9251ryJ71bqJ9Gk4v;-}^Nd>+YCc_1O}{+V_YP diff --git a/server/stories/story.ha b/server/stories/story.ha deleted file mode 100644 index a8799fb..0000000 --- a/server/stories/story.ha +++ /dev/null @@ -1,8 +0,0 @@ -@tim says "hello world, it's a good day" -choice "choice numero uno" { - @tim says "super sad" -} -or "choice numero duo" { - @tim says "super unsad" -} -END diff --git a/server/stories/test.zip b/server/stories/test.zip deleted file mode 100644 index 3575183923da886b1bbd8404b991d016e6afbd27..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 587 zcmWIWW@Zs#U|`^2@ZYl{=BebCiX{vT3_Xkt4Ezi-49OXZMTyBJsYS(lS;hHzp&^_M z%->S}Wg7iw$ttbjW?*D_!OXw_CQ2tb@--_6xLz;dI=oB$h3T!mjx)J*&j?6NmU?{G z`?1riGV}ju|DXIbb7{bvrd?*6MVuD$1*DahH{S3&d-j#cX4NE*SD#9G8kU_oy7|?g zq8s0ytV}XED0kGwLwQ@}n|T*L7dqDOXq3>D-|1X@O4!C`kNLWbtY`ZQoW-`RoKkjm zu8(H$RKG-FxwiW^_NfHtRL9Fb-%wO`#OGm3;6JWxW=*l3C-_l4`=p5{C7FSNVLI6R zG7QBf`9+m_8HsRTYGeAcSmWfGPz}E|I$;5)JkFjx8Ln|&|CHy&z!N%w`e7a+9_P>d z2YPs}33=po?!g~= c0|Qb>;4+Ps4P-eJ0~5ny1_p*nAonl;0E(5%`2YX_