diff --git a/assets/robocraft/config.json b/assets/robocraft/config.json index 84beb2b..1ecd992 100644 --- a/assets/robocraft/config.json +++ b/assets/robocraft/config.json @@ -14519,6 +14519,15 @@ }, "permission": "Developer" }, + { + "regex": "\\?nofactory", + "op": { + "type": "BuiltIn", + "built_in": "System", + "system": "ClearGarageFactoryFlag" + }, + "permission": "Administrator" + }, { "regex": "\\?help", "op": { diff --git a/rc_chat_room/src/state/chat/config.rs b/rc_chat_room/src/state/chat/config.rs index dbc0848..784ce52 100644 --- a/rc_chat_room/src/state/chat/config.rs +++ b/rc_chat_room/src/state/chat/config.rs @@ -325,6 +325,7 @@ impl Intercom { enum System { Permissions, + ClearGarageFactoryFlag, } enum SystemPermission { @@ -383,6 +384,7 @@ impl System { fn from_persist(sys: oj_rc_core::persist::SystemChatOperation) -> Self { match sys { oj_rc_core::persist::SystemChatOperation::Permissions => Self::Permissions, + oj_rc_core::persist::SystemChatOperation::ClearGarageFactoryFlag => Self::ClearGarageFactoryFlag, } } @@ -410,6 +412,24 @@ impl System { format!("Granted {} to {} (they should re-log)", perm.display(), ¶ms[2]) } }, + Self::ClearGarageFactoryFlag => { + match ctx.user.clear_factory_flag().await { + Err(e) => { + if let Some(msg) = e.error_msg() { + format!("Failed to clear flag: {}", msg) + } else { + format!("Failed to clear flag (code {})", e.error_code()) + } + }, + Ok(is_changed) => { + if is_changed { + "Cleared flag from selected garage".to_owned() + } else { + "Cleared flag from selected garage (but it already was?)".to_owned() + } + } + } + } } } @@ -417,6 +437,7 @@ impl System { fn do_help(&self) -> String { match self { Self::Permissions => "Grant permissions to an account".to_owned(), + Self::ClearGarageFactoryFlag => "Clear crf_id on currently-selected garage".to_owned(), } } } diff --git a/rc_core/src/persist/chat.rs b/rc_core/src/persist/chat.rs index a068dd2..faf19fe 100644 --- a/rc_core/src/persist/chat.rs +++ b/rc_core/src/persist/chat.rs @@ -138,6 +138,7 @@ pub enum IntercomChatOperation { #[serde(tag = "system")] pub enum SystemChatOperation { Permissions, + ClearGarageFactoryFlag, } diff --git a/rc_core/src/persist/user/chat.rs b/rc_core/src/persist/user/chat.rs index 3eb0a70..b0f0712 100644 --- a/rc_core/src/persist/user/chat.rs +++ b/rc_core/src/persist/user/chat.rs @@ -216,4 +216,40 @@ impl super::ChatUser for UserData { )) } } + + async fn clear_factory_flag(&self) -> Result { + let selected_garage_opt = self.db.garage_selected(self.account.id).await + .map_err(|e| { + log::error!("Failed to retrieve selected garage for user {}: {}", self.account.id, e); + polariton_server::operations::SimpleOpError::with_message( + crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16, + format!("Failed to retrieve selected garage: {}", e), + ) + })?; + match selected_garage_opt { + Some(selected_garage) => { + self.db.update_garage(oj_rc_database::schema::garage::ActiveModel { + id: oj_rc_database::sea_orm::ActiveValue::Set(selected_garage.id), + user_id: oj_rc_database::sea_orm::ActiveValue::Set(self.account.id), + crf_id: oj_rc_database::sea_orm::ActiveValue::Set(None), + ..Default::default() + }).await + .map_err(|e| { + log::error!("Failed to clear garage {} factory flag for user {}: {}", selected_garage.id, self.account.id, e); + polariton_server::operations::SimpleOpError::with_message( + crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16, + format!("Failed to clear garage {} factory flag: {}", selected_garage.id, e), + ) + })?; + Ok(selected_garage.crf_id.is_some()) + }, + None => { + log::error!("Failed to find selected garage for user {}", self.account.id); + return Err(polariton_server::operations::SimpleOpError::with_message( + crate::data::error_codes::ChatErrorCodes::UnexpectedError as i16, + format!("Failed to find selected garage"), + )); + } + } + } } diff --git a/rc_core/src/persist/user/traits.rs b/rc_core/src/persist/user/traits.rs index f307224..e417e82 100644 --- a/rc_core/src/persist/user/traits.rs +++ b/rc_core/src/persist/user/traits.rs @@ -240,6 +240,7 @@ pub trait ChatUser: CommonUser + IntercomUser { async fn set_sanction(&self, sanction: SetSanction) -> Result<(), i16>; async fn get_total_registered_users(&self) -> Result; async fn set_permission(&self, username: String, permission: UserRole, value: bool) -> Result<(), polariton_server::operations::SimpleOpError>; + async fn clear_factory_flag(&self) -> Result; } pub struct SetSanction {