summaryrefslogtreecommitdiff
path: root/server/src/commands.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-04 21:13:18 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-04 21:13:18 +0200
commit56ac2f25ac1fdc23dbab04e83e41bffb48d410e1 (patch)
treeec4b0c77ff6c04bb1abe071901f9013bd2ce77d8 /server/src/commands.rs
parent55922742c94d8abca2361377ca616ea5143731c2 (diff)
downloadhurrycurry-56ac2f25ac1fdc23dbab04e83e41bffb48d410e1.tar
hurrycurry-56ac2f25ac1fdc23dbab04e83e41bffb48d410e1.tar.bz2
hurrycurry-56ac2f25ac1fdc23dbab04e83e41bffb48d410e1.tar.zst
top5 command
Diffstat (limited to 'server/src/commands.rs')
-rw-r--r--server/src/commands.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/server/src/commands.rs b/server/src/commands.rs
index e2d40f05..5354c266 100644
--- a/server/src/commands.rs
+++ b/server/src/commands.rs
@@ -20,7 +20,7 @@ use anyhow::{anyhow, bail, Result};
use clap::{Parser, ValueEnum};
use hurrycurry_bot::algos::ALGO_CONSTRUCTORS;
use hurrycurry_protocol::{Message, PacketC, PlayerID};
-use std::time::Duration;
+use std::{fmt::Write, time::Duration};
#[derive(Parser)]
#[clap(multicall = true)]
@@ -34,6 +34,12 @@ enum Command {
#[arg(default_value = "420")]
timer: u64,
},
+ /// Shows the best entries of the scoreboard for this map.
+ #[clap(alias = "top5")]
+ Top {
+ /// Name of the map, default: current
+ map: Option<String>,
+ },
/// Abort the current game
End,
/// Download recipe/map's source declaration
@@ -162,6 +168,22 @@ impl Server {
algo,
)));
}
+ Command::Top { map } => {
+ let mapname = map.as_ref().unwrap_or(&self.game.data.current_map);
+ if let Some(board) = self.scoreboard.get(mapname) {
+ let mut o = format!("Scoreboard for {}:\n", mapname);
+ for (i, entry) in board.best.iter().take(5).enumerate() {
+ writeln!(
+ o,
+ " {i}. {} points by {}",
+ entry.score.points,
+ entry.players.clone().join(", ")
+ )
+ .unwrap();
+ }
+ bail!("{o}");
+ }
+ }
}
Ok(())
}