diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-04 22:11:51 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-04 22:11:51 +0200 |
commit | c646336dc3bf470d4185eec995d00a89c420127b (patch) | |
tree | e1ad02976adc2489b547242a513757014e2b4862 /server/src/commands.rs | |
parent | 4df50b07df35f8c75980ce19d954f3f366dae848 (diff) | |
download | hurrycurry-c646336dc3bf470d4185eec995d00a89c420127b.tar hurrycurry-c646336dc3bf470d4185eec995d00a89c420127b.tar.bz2 hurrycurry-c646336dc3bf470d4185eec995d00a89c420127b.tar.zst |
book as entity and /book command
Diffstat (limited to 'server/src/commands.rs')
-rw-r--r-- | server/src/commands.rs | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/server/src/commands.rs b/server/src/commands.rs index c33f5832..96d9ab75 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -19,7 +19,7 @@ use crate::{entity::bot::BotDriver, server::Server}; use anyhow::{anyhow, bail, Result}; use clap::{Parser, ValueEnum}; use hurrycurry_bot::algos::ALGO_CONSTRUCTORS; -use hurrycurry_protocol::{Message, PacketC, PlayerID}; +use hurrycurry_protocol::{Menu, Message, PacketC, PlayerID}; use std::{fmt::Write, time::Duration}; #[derive(Parser)] @@ -68,6 +68,8 @@ enum Command { /// Reload the current map #[clap(alias = "r")] Reload, + /// Shows the recipe book + Book, } #[derive(ValueEnum, Clone)] @@ -77,7 +79,12 @@ enum DownloadType { } impl Server { - pub async fn handle_command_parse(&mut self, player: PlayerID, command: &str) -> Result<()> { + pub async fn handle_command_parse( + &mut self, + player: PlayerID, + command: &str, + ) -> Result<Vec<PacketC>> { + let mut replies = Vec::new(); for line in command.split("\n") { self.handle_command( player, @@ -86,12 +93,18 @@ impl Server { .ok_or(anyhow!("quoting invalid"))? .into_iter(), )?, + &mut replies, ) .await?; } - Ok(()) + Ok(replies) } - async fn handle_command(&mut self, player: PlayerID, command: Command) -> Result<()> { + async fn handle_command( + &mut self, + player: PlayerID, + command: Command, + replies: &mut Vec<PacketC>, + ) -> Result<()> { match command { Command::Start { spec, timer } => { let data = self.index.generate(&spec).await?; @@ -124,6 +137,7 @@ impl Server { Command::ReloadIndex => { self.index.reload().await?; } + Command::Book => replies.push(PacketC::Menu(Menu::Book)), Command::Download { r#type, name } => { let source = match r#type { DownloadType::Map => self.index.read_map(&name).await, |