Notify system

This commit is contained in:
2025-08-16 16:30:16 +02:00
parent bc298fe0fa
commit 8308b9e011
7 changed files with 198 additions and 59 deletions
+19 -8
View File
@@ -4,13 +4,14 @@ use crate::response::{Error, Response, Result};
use super::{player, Session};
pub fn set_cloak(session: &Session, cloak: String) -> Result {
pub fn set_cloak(session: &Session, cloak: String, notify: Vec<&str>) -> Result {
match player::player(session, session.local_player.id.clone())? {
Response::Player(crate::response::PlayerResponse::Player { cloaks, .. }) => {
if !cloaks.contains(&cloak) && !cloak.is_empty() {
return Err(Error::ValidationError(
format!("Player does not own cloak: {}", cloak)
));
return Err(Error::ValidationError(format!(
"Player does not own cloak: {}",
cloak
)));
}
session
@@ -27,12 +28,22 @@ pub fn set_cloak(session: &Session, cloak: String) -> Result {
},
)
.run()
.map_err(|e| Error::DatabaseError(
format!("Failed to update cloak: {}", e)
))?;
.map_err(|e| Error::DatabaseError(format!("Failed to update cloak: {}", e)))?;
if notify.len() > 0 {
session.notify(
&notify,
&format!(
"update_cloak@uuid={}@cloak={cloak}",
session.local_player.id
),
)?;
}
Ok(Response::Success)
}
_ => Err(Error::ValidationError("Invalid player data received".to_string())),
_ => Err(Error::ValidationError(
"Invalid player data received".to_string(),
)),
}
}