summaryrefslogtreecommitdiff
path: root/server/src/commands.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-09-18 16:16:58 +0200
committermetamuffin <metamuffin@disroot.org>2024-09-18 16:16:58 +0200
commit9d1c30cf9ef5a057c760da49b52312de4a5afc6a (patch)
treef6532fd40259f7e54d068a656f3aaecf98c22682 /server/src/commands.rs
parentfb6ca2a4b9d78dd80dbdf37b2926d9ede4108e8b (diff)
downloadhurrycurry-9d1c30cf9ef5a057c760da49b52312de4a5afc6a.tar
hurrycurry-9d1c30cf9ef5a057c760da49b52312de4a5afc6a.tar.bz2
hurrycurry-9d1c30cf9ef5a057c760da49b52312de4a5afc6a.tar.zst
prevent multiple tutorials at once
Diffstat (limited to 'server/src/commands.rs')
-rw-r--r--server/src/commands.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/server/src/commands.rs b/server/src/commands.rs
index 8e6f32c7..f5792a22 100644
--- a/server/src/commands.rs
+++ b/server/src/commands.rs
@@ -239,7 +239,18 @@ impl Server {
.data
.get_item_by_name(&item)
.ok_or(anyhow!("unknown item"))?;
- // TODO prevent too many (> 1) tutorials for this player
+ #[cfg(not(test))] // TODO rust-analyser does not undestand trait upcasting
+ if self
+ .entities
+ .iter()
+ .find(|e| {
+ <dyn std::any::Any>::downcast_ref::<Tutorial>(e.as_ref())
+ .map_or(false, |t| t.player == player)
+ })
+ .is_some()
+ {
+ bail!("Tutorial already running")
+ }
self.entities.push(Box::new(Tutorial::new(player, item)));
}
Command::TranslateMessage {