Skip to content

Commit

Permalink
fix: recycle() -> E_INVARG; owner handling in add_property
Browse files Browse the repository at this point in the history
  • Loading branch information
abesto authored and rdaum committed Jun 20, 2024
1 parent 31a1e48 commit a06f7e1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions crates/kernel/src/builtins/bf_objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ fn bf_recycle(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
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
Expand Down
2 changes: 1 addition & 1 deletion crates/kernel/src/builtins/bf_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn bf_add_property(bf_args: &mut BfCallState<'_>) -> Result<BfRet, BfErr> {
*location,
*location,
name.as_str(),
bf_args.caller_perms(),
attrs.owner.unwrap(),
attrs.flags.unwrap(),
Some(value),
)
Expand Down
7 changes: 6 additions & 1 deletion crates/kernel/testsuite/moot/create.moot
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ OBJ
0
; create($tmp2);
; return $tmp2.initialize_called;
1
1

// Test that the default owner is the caller
@programmer
; return create($nothing).owner;
#4
1 change: 1 addition & 0 deletions crates/kernel/testsuite/moot/recycle.moot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion crates/kernel/testsuite/moot_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,26 @@ impl MootRunner for SchedulerMootRunner {
type Error = SchedulerError;

fn eval<S: Into<String>>(&mut self, player: Objid, command: S) -> Result<Var, SchedulerError> {
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<S: AsRef<str>>(&mut self, player: Objid, command: S) -> Result<Var, SchedulerError> {
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 {
Expand Down
8 changes: 8 additions & 0 deletions crates/values/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<V: AsByteBuffer>: FromIterator<V> {
Expand Down

0 comments on commit a06f7e1

Please sign in to comment.