diff --git a/crates/daemon/src/rpc_server.rs b/crates/daemon/src/rpc_server.rs index 69ca67c9..d688848f 100644 --- a/crates/daemon/src/rpc_server.rs +++ b/crates/daemon/src/rpc_server.rs @@ -603,7 +603,7 @@ impl RpcServer { connection, ObjectRef::Id(SYSTEM_OBJECT), Symbol::mk("do_login_command"), - args.iter().map(|s| v_str(&s)).collect(), + args.iter().map(|s| v_str(s)).collect(), args.join(" "), SYSTEM_OBJECT, session, diff --git a/crates/db/src/db_worldstate.rs b/crates/db/src/db_worldstate.rs index 7f192510..b6dfb557 100644 --- a/crates/db/src/db_worldstate.rs +++ b/crates/db/src/db_worldstate.rs @@ -29,11 +29,11 @@ use moor_values::model::{PropAttrs, PropFlag}; use moor_values::model::{PropDef, PropDefs}; use moor_values::model::{VerbDef, VerbDefs}; use moor_values::util::BitEnum; -use moor_values::Objid; use moor_values::Variant; use moor_values::NOTHING; -use moor_values::{v_int, v_objid, Var}; +use moor_values::{v_bool, Objid}; use moor_values::{v_list, Symbol}; +use moor_values::{v_objid, Var}; use crate::worldstate_transaction::WorldStateTransaction; @@ -83,6 +83,22 @@ impl DbTxWorldState { self.tx.update_verb(obj, verbdef.uuid(), verb_attrs)?; Ok(()) } + + /// Check the permissions for the application of an application of inheritance to a parent. + /// This is a helper function for `create_object` and `change_parent`. + /// It checks that the parent is writable and fertile, and that the parent is either the + /// NOTHING object or that the parent is usable by the object's owner. + fn check_parent(&self, perms: Objid, parent: Objid) -> Result<(), WorldStateError> { + if parent != NOTHING { + let (parentflags, parentowner) = (self.flags_of(parent)?, self.owner_of(parent)?); + self.perms(perms)?.check_object_allows( + parentowner, + parentflags, + BitEnum::new_with(ObjFlag::Write) | ObjFlag::Fertile, + )?; + } + Ok(()) + } } impl WorldState for DbTxWorldState { @@ -148,14 +164,7 @@ impl WorldState for DbTxWorldState { owner: Objid, flags: BitEnum, ) -> Result { - if parent != NOTHING { - let (flags, parent_owner) = (self.flags_of(parent)?, self.owner_of(parent)?); - self.perms(perms)?.check_object_allows( - parent_owner, - flags, - BitEnum::new_with(ObjFlag::Read) | ObjFlag::Fertile, - )?; - } + self.check_parent(perms, parent)?; // TODO: ownership_quota support // If the intended owner of the new object has a property named `ownership_quota' and the value of that property is an integer, then `create()' treats that value @@ -227,7 +236,7 @@ impl WorldState for DbTxWorldState { return Err(WorldStateError::ObjectNotFound(ObjectRef::Id(obj))); } - // Special properties like namnne, location, and contents get treated specially. + // Special properties like name, location, and contents get treated specially. if pname == *NAME_SYM { return self.names_of(perms, obj).map(|(name, _)| Var::from(name)); } else if pname == *LOCATION_SYM { @@ -239,39 +248,34 @@ impl WorldState for DbTxWorldState { return self.owner_of(obj).map(Var::from); } else if pname == *PROGRAMMER_SYM { let flags = self.flags_of(obj)?; - return if flags.contains(ObjFlag::Programmer) { - Ok(v_int(1)) - } else { - Ok(v_int(0)) - }; + return Ok(flags + .contains(ObjFlag::Programmer) + .then(|| v_bool(true)) + .unwrap_or(v_bool(false))); } else if pname == *WIZARD_SYM { let flags = self.flags_of(obj)?; - return if flags.contains(ObjFlag::Wizard) { - Ok(v_int(1)) - } else { - Ok(v_int(0)) - }; + return Ok(flags + .contains(ObjFlag::Wizard) + .then(|| v_bool(true)) + .unwrap_or(v_bool(false))); } else if pname == *R_SYM { let flags = self.flags_of(obj)?; - return if flags.contains(ObjFlag::Read) { - Ok(v_int(1)) - } else { - Ok(v_int(0)) - }; + return Ok(flags + .contains(ObjFlag::Read) + .then(|| v_bool(true)) + .unwrap_or(v_bool(false))); } else if pname == *W_SYM { let flags = self.flags_of(obj)?; - return if flags.contains(ObjFlag::Write) { - Ok(v_int(1)) - } else { - Ok(v_int(0)) - }; + return Ok(flags + .contains(ObjFlag::Write) + .then(|| v_bool(true)) + .unwrap_or(v_bool(false))); } else if pname == *F_SYM { let flags = self.flags_of(obj)?; - return if flags.contains(ObjFlag::Fertile) { - Ok(v_int(1)) - } else { - Ok(v_int(0)) - }; + return Ok(flags + .contains(ObjFlag::Fertile) + .then(|| v_bool(true)) + .unwrap_or(v_bool(false))); } let (_, value, propperms, _) = self.tx.resolve_property(obj, pname)?; @@ -712,15 +716,7 @@ impl WorldState for DbTxWorldState { let (objflags, owner) = (self.flags_of(obj)?, self.owner_of(obj)?); - if new_parent != NOTHING { - let (parentflags, parentowner) = - (self.flags_of(new_parent)?, self.owner_of(new_parent)?); - self.perms(perms)?.check_object_allows( - parentowner, - parentflags, - BitEnum::new_with(ObjFlag::Write) | ObjFlag::Fertile, - )?; - } + self.check_parent(perms, new_parent)?; self.perms(perms)? .check_object_allows(owner, objflags, ObjFlag::Write.into())?; diff --git a/crates/kernel/src/builtins/bf_server.rs b/crates/kernel/src/builtins/bf_server.rs index f3cffec1..df52579a 100644 --- a/crates/kernel/src/builtins/bf_server.rs +++ b/crates/kernel/src/builtins/bf_server.rs @@ -321,7 +321,7 @@ fn bf_ctime(bf_args: &mut BfCallState<'_>) -> Result { let tz_str = get_timezone().unwrap(); let tz: Tz = tz_str.parse().unwrap(); let offset = tz.offset_from_local_date(&date_time.date_naive()).unwrap(); - let abbreviation = offset.abbreviation().unwrap_or_else(|| "??"); + let abbreviation = offset.abbreviation().unwrap_or("??"); let datetime_str = format!( "{} {}", date_time.format("%a %b %d %H:%M:%S %Y"), diff --git a/crates/kernel/src/tasks/scheduler.rs b/crates/kernel/src/tasks/scheduler.rs index 7bba7321..ec20335f 100644 --- a/crates/kernel/src/tasks/scheduler.rs +++ b/crates/kernel/src/tasks/scheduler.rs @@ -399,11 +399,11 @@ impl Scheduler { }; vloc } else { - let vloc = match vloc { + + match vloc { ObjectRef::Id(id) => id, _ => panic!("Unexpected object reference in vloc"), - }; - vloc + } }; let task_start = Arc::new(TaskStart::StartVerb { diff --git a/crates/moot/src/lib.rs b/crates/moot/src/lib.rs index 11d386ff..45fb2e39 100644 --- a/crates/moot/src/lib.rs +++ b/crates/moot/src/lib.rs @@ -244,7 +244,7 @@ impl MootState { ) -> eyre::Result<()> { match command_kind { CommandKind::Eval => { - runner.eval(player, &format!("{command} \"moot-line:{line_no}\";")) + runner.eval(player, format!("{command} \"moot-line:{line_no}\";")) } CommandKind::Command => runner.command(player, command), }?; diff --git a/crates/values/src/model/mod.rs b/crates/values/src/model/mod.rs index d054e40e..7ba0877d 100644 --- a/crates/values/src/model/mod.rs +++ b/crates/values/src/model/mod.rs @@ -63,7 +63,7 @@ pub trait ValSet: FromIterator { } pub fn uuid_fb(&uuid: &Uuid) -> values_flatbuffers::moor::values::Uuid { - values_flatbuffers::moor::values::Uuid::new(&uuid.as_bytes()) + values_flatbuffers::moor::values::Uuid::new(uuid.as_bytes()) } #[derive(Debug, Error, Clone, Decode, Encode, PartialEq)] diff --git a/crates/values/src/model/verbdef.rs b/crates/values/src/model/verbdef.rs index 0b90f42d..767d7b46 100644 --- a/crates/values/src/model/verbdef.rs +++ b/crates/values/src/model/verbdef.rs @@ -155,7 +155,7 @@ impl Named for VerbDef { self.get_flatbuffer() .names() .map(|names| names.iter().collect()) - .unwrap_or_else(Vec::new) + .unwrap_or_default() } } diff --git a/crates/values/src/var/var.rs b/crates/values/src/var/var.rs index 102f4d16..b22453ab 100644 --- a/crates/values/src/var/var.rs +++ b/crates/values/src/var/var.rs @@ -584,7 +584,7 @@ mod tests { #[test] fn test_float_pack_unpack() { - let f = Var::mk_float(42.0.into()); + let f = Var::mk_float(42.0); match f.variant() { Variant::Float(f) => assert_eq!(f, 42.0), diff --git a/crates/web-host/src/host/mod.rs b/crates/web-host/src/host/mod.rs index e951db51..c2070f6d 100644 --- a/crates/web-host/src/host/mod.rs +++ b/crates/web-host/src/host/mod.rs @@ -67,7 +67,7 @@ pub fn var_as_json(v: &Var) -> serde_json::Value { pub fn json_as_var(j: &serde_json::Value) -> Option { match j { serde_json::Value::Null => Some(v_none()), - serde_json::Value::String(s) => Some(v_str(&s)), + serde_json::Value::String(s) => Some(v_str(s)), serde_json::Value::Number(n) => Some(if n.is_i64() { v_int(n.as_i64().unwrap()) } else {