diff --git a/crates/kernel/src/builtins/bf_objects.rs b/crates/kernel/src/builtins/bf_objects.rs index d89063f4..78b91b60 100644 --- a/crates/kernel/src/builtins/bf_objects.rs +++ b/crates/kernel/src/builtins/bf_objects.rs @@ -199,6 +199,16 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result { return Err(BfErr::Code(E_TYPE)); }; + let valid = bf_args.world_state.valid(*obj); + if valid == Ok(false) + || valid + .err() + .map(|e| e.database_error_msg() == Some("NotFound")) + .unwrap_or_default() + { + return Err(BfErr::Code(E_INVARG)); + } + // Check if the given task perms can control the object before continuing. if !bf_args .world_state diff --git a/crates/kernel/src/builtins/bf_properties.rs b/crates/kernel/src/builtins/bf_properties.rs index 5531ab76..5c6666e9 100644 --- a/crates/kernel/src/builtins/bf_properties.rs +++ b/crates/kernel/src/builtins/bf_properties.rs @@ -204,7 +204,7 @@ fn bf_add_property(bf_args: &mut BfCallState<'_>) -> Result { *location, *location, name.as_str(), - bf_args.caller_perms(), + attrs.owner.unwrap(), attrs.flags.unwrap(), Some(value), ) diff --git a/crates/kernel/testsuite/moot/create.moot b/crates/kernel/testsuite/moot/create.moot index 245d7571..96618d89 100644 --- a/crates/kernel/testsuite/moot/create.moot +++ b/crates/kernel/testsuite/moot/create.moot @@ -88,4 +88,9 @@ OBJ 0 ; create($tmp2); ; return $tmp2.initialize_called; -1 \ No newline at end of file +1 + +// Test that the default owner is the caller +@programmer +; return create($nothing).owner; +#4 \ No newline at end of file diff --git a/crates/kernel/testsuite/moot/recycle.moot b/crates/kernel/testsuite/moot/recycle.moot index 9c645a2f..c19ff4bf 100644 --- a/crates/kernel/testsuite/moot/recycle.moot +++ b/crates/kernel/testsuite/moot/recycle.moot @@ -70,6 +70,7 @@ E_PERM > "$object.recycle_called = $object.recycle_called + 1;" > }); ; return $object.recycle_called; +0 // test_that_calling_recycle_on_a_recycled_object_fails @programmer diff --git a/crates/kernel/testsuite/moot_suite.rs b/crates/kernel/testsuite/moot_suite.rs index c2e9eb82..aa601830 100644 --- a/crates/kernel/testsuite/moot_suite.rs +++ b/crates/kernel/testsuite/moot_suite.rs @@ -56,21 +56,26 @@ impl MootRunner for SchedulerMootRunner { type Error = SchedulerError; fn eval>(&mut self, player: Objid, command: S) -> Result { + let command = command.into(); + eprintln!("{player} >> ; {command}"); scheduler_test_utils::call_eval( self.scheduler.clone(), self.session.clone(), player, - command.into(), + command, ) + .inspect(|var| eprintln!("{player} << {var}")) } fn command>(&mut self, player: Objid, command: S) -> Result { + eprintln!("{player} >> ; {}", command.as_ref()); scheduler_test_utils::call_command( self.scheduler.clone(), self.session.clone(), player, command.as_ref(), ) + .inspect(|var| eprintln!("{player} << {var}")) } fn none(&self) -> Var { diff --git a/crates/values/src/model/mod.rs b/crates/values/src/model/mod.rs index 25cd2336..05308f3b 100644 --- a/crates/values/src/model/mod.rs +++ b/crates/values/src/model/mod.rs @@ -126,6 +126,14 @@ impl WorldStateError { } } } + + pub fn database_error_msg(&self) -> Option<&str> { + if let Self::DatabaseError(msg) = self { + Some(msg) + } else { + None + } + } } pub trait ValSet: FromIterator {