aboutsummaryrefslogtreecommitdiff
path: root/server/src/commands.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-09-19 22:27:46 +0200
committermetamuffin <metamuffin@disroot.org>2025-09-19 22:40:39 +0200
commit402067b8317195fd2bc4ab4d92b5ace94fadb7c0 (patch)
tree2437c52ae71a11c4d17a6fa4597f8152dae96ddc /server/src/commands.rs
parent2f311fec691cd7a62fa4f95ee0419089913b5dd8 (diff)
downloadhurrycurry-402067b8317195fd2bc4ab4d92b5ace94fadb7c0.tar
hurrycurry-402067b8317195fd2bc4ab4d92b5ace94fadb7c0.tar.bz2
hurrycurry-402067b8317195fd2bc4ab4d92b5ace94fadb7c0.tar.zst
Refactor book part 1
Diffstat (limited to 'server/src/commands.rs')
-rw-r--r--server/src/commands.rs105
1 files changed, 49 insertions, 56 deletions
diff --git a/server/src/commands.rs b/server/src/commands.rs
index 460f6581..0e57a013 100644
--- a/server/src/commands.rs
+++ b/server/src/commands.rs
@@ -24,9 +24,7 @@ use crate::{
use anyhow::Result;
use clap::{Parser, ValueEnum};
use hurrycurry_bot::algos::ALGO_CONSTRUCTORS;
-use hurrycurry_protocol::{
- Character, DocumentElement, Menu, Message, PacketC, PlayerClass, PlayerID,
-};
+use hurrycurry_protocol::{Character, Menu, Message, PacketC, PlayerClass, PlayerID};
use std::{fmt::Write, time::Duration};
#[derive(Parser)]
@@ -110,7 +108,7 @@ enum DownloadType {
}
impl Server {
- pub async fn handle_command_parse(
+ pub fn handle_command_parse(
&mut self,
player: PlayerID,
command: &str,
@@ -126,12 +124,11 @@ impl Server {
)
.map_err(|e| TrError::Plain(e.to_string()))?,
&mut replies,
- )
- .await?;
+ )?;
}
Ok(replies)
}
- async fn handle_command(
+ fn handle_command(
&mut self,
player: PlayerID,
command: Command,
@@ -162,8 +159,7 @@ impl Server {
}
let data = self
.index
- .generate(&spec)
- .await
+ .generate_with_book(&spec)
.map_err(|e| TrError::Plain(e.to_string()))?;
self.load(data, timer.map(Duration::from_secs));
if !skip_announce {
@@ -190,8 +186,7 @@ impl Server {
.ok();
self.load(
self.index
- .generate("lobby")
- .await
+ .generate_with_book("lobby")
.map_err(|e| TrError::Plain(e.to_string()))?,
None,
);
@@ -202,8 +197,7 @@ impl Server {
}
self.load(
self.index
- .generate(&self.game.data.current_map)
- .await
+ .generate_with_book(&self.game.data.current_map)
.map_err(|e| TrError::Plain(e.to_string()))?,
None,
);
@@ -211,14 +205,13 @@ impl Server {
Command::ReloadIndex => {
self.index
.reload()
- .await
.map_err(|e| TrError::Plain(e.to_string()))?;
}
- Command::Book => replies.push(PacketC::Menu(Menu::Document(self.data.book.clone()))),
+ Command::Book => replies.push(PacketC::Menu(Menu::Book(self.data.book.clone()))),
Command::Download { r#type, name } => {
let source = match r#type {
- DownloadType::Map => self.index.read_map(&name).await,
- DownloadType::Recipes => self.index.read_recipes(&name).await,
+ DownloadType::Map => self.index.read_map(&name),
+ DownloadType::Recipes => self.index.read_recipes(&name),
}
.map_err(|e| TrError::Plain(e.to_string()))?;
replies.push(PacketC::ServerMessage {
@@ -288,45 +281,45 @@ impl Server {
error: false,
});
} else {
- replies.push(PacketC::Menu(Menu::Document(DocumentElement::Document {
- es: vec![DocumentElement::Page {
- es: vec![
- DocumentElement::Par {
- es: vec![DocumentElement::Text {
- s: Message::Translation {
- id: "c.menu.scoreboard".to_string(),
- params: vec![],
- },
- size: 30.,
- bold: false,
- color: None,
- font: None,
- }],
- },
- DocumentElement::List {
- es: board
- .best
- .iter()
- .take(10)
- .enumerate()
- .map(|(place, entry)| DocumentElement::Text {
- s: trm!(
- "c.menu.scoreboard.entry",
- s = (place + 1).to_string(),
- s = entry.score.points.to_string(),
- s = entry.players.clone().join(", ")
- ),
- size: 15.,
- bold: false,
- color: None,
- font: None,
- })
- .collect(),
- },
- ],
- background: None,
- }],
- })));
+ // replies.push(PacketC::Menu(Menu::Document(DocumentElement::Document {
+ // es: vec![DocumentElement::Page {
+ // es: vec![
+ // DocumentElement::Par {
+ // es: vec![DocumentElement::Text {
+ // s: Message::Translation {
+ // id: "c.menu.scoreboard".to_string(),
+ // params: vec![],
+ // },
+ // size: 30.,
+ // bold: false,
+ // color: None,
+ // font: None,
+ // }],
+ // },
+ // DocumentElement::List {
+ // es: board
+ // .best
+ // .iter()
+ // .take(10)
+ // .enumerate()
+ // .map(|(place, entry)| DocumentElement::Text {
+ // s: trm!(
+ // "c.menu.scoreboard.entry",
+ // s = (place + 1).to_string(),
+ // s = entry.score.points.to_string(),
+ // s = entry.players.clone().join(", ")
+ // ),
+ // size: 15.,
+ // bold: false,
+ // color: None,
+ // font: None,
+ // })
+ // .collect(),
+ // },
+ // ],
+ // background: None,
+ // }],
+ // })));
}
} else {
replies.push(PacketC::ServerMessage {