Skip to content

Commit

Permalink
Rework object references in RPC calls
Browse files Browse the repository at this point in the history
Allows specifying explicit object id, a sysobj reference, or an
environment match in places where previously only an objid was
allowed.
  • Loading branch information
rdaum committed Aug 18, 2024
1 parent 9a3e897 commit b3b6057
Show file tree
Hide file tree
Showing 21 changed files with 983 additions and 873 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ rusty_paseto = { version = "0.7" }
signal-hook = "0.3"

# For the telnet host
termimad = "0.30"
termimad = "0.30"
2 changes: 1 addition & 1 deletion crates/compiler/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl TreeTransformer {
.map_prefix(|op, rhs| match op.as_rule() {
Rule::scatter_assign => {
let rhs = rhs?;

self.clone().parse_scatter_assign(op, rhs, false, false)
}
Rule::not => Ok(Expr::Unary(UnaryOp::Not, Box::new(rhs?))),
Expand Down
8 changes: 4 additions & 4 deletions crates/daemon/src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use moor_kernel::tasks::sessions::SessionError::DeliveryError;
use moor_kernel::tasks::sessions::{Session, SessionError, SessionFactory};
use moor_kernel::tasks::TaskHandle;
use moor_kernel::SchedulerClient;
use moor_values::model::{Named, PropFlag, ValSet, VerbFlag};
use moor_values::model::{Named, ObjectRef, PropFlag, ValSet, VerbFlag};
use moor_values::tasks::SchedulerError::CommandExecutionError;
use moor_values::tasks::{CommandError, NarrativeEvent, SchedulerError, TaskId};
use moor_values::util::parse_into_words;
Expand Down Expand Up @@ -544,7 +544,7 @@ impl RpcServer {
self: Arc<Self>,
scheduler_client: SchedulerClient,
player: Objid,
object: Symbol,
object: ObjectRef,
property: Symbol,
) -> Result<RpcResponse, RpcRequestError> {
let pv = match scheduler_client.request_system_property(player, object, property) {
Expand Down Expand Up @@ -829,8 +829,8 @@ impl RpcServer {
scheduler_client: SchedulerClient,
client_id: Uuid,
connection: Objid,
object: String,
verb: String,
object: ObjectRef,
verb: Symbol,
code: Vec<String>,
) -> Result<RpcResponse, RpcRequestError> {
if self.clone().new_session(client_id, connection).is_err() {
Expand Down
6 changes: 3 additions & 3 deletions crates/db/src/db_worldstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use lazy_static::lazy_static;
use uuid::Uuid;

use moor_values::model::HasUuid;
use moor_values::model::ObjSet;
use moor_values::model::Perms;
use moor_values::model::VerbInfo;
Expand All @@ -24,6 +23,7 @@ use moor_values::model::WorldStateError;
use moor_values::model::{ArgSpec, PrepSpec, VerbArgsSpec};
use moor_values::model::{BinaryType, VerbAttrs, VerbFlag};
use moor_values::model::{CommitResult, PropPerms, ValSet};
use moor_values::model::{HasUuid, ObjectRef};
use moor_values::model::{ObjAttrs, ObjFlag};
use moor_values::model::{PropAttrs, PropFlag};
use moor_values::model::{PropDef, PropDefs};
Expand Down Expand Up @@ -224,7 +224,7 @@ impl WorldState for DbTxWorldState {
pname: Symbol,
) -> Result<Var, WorldStateError> {
if obj == NOTHING || !self.valid(obj)? {
return Err(WorldStateError::ObjectNotFound(obj));
return Err(WorldStateError::ObjectNotFound(ObjectRef::Id(obj)));
}

// Special properties like namnne, location, and contents get treated specially.
Expand Down Expand Up @@ -592,7 +592,7 @@ impl WorldState for DbTxWorldState {
vname: Symbol,
) -> Result<VerbDef, WorldStateError> {
if !self.tx.object_valid(obj)? {
return Err(WorldStateError::ObjectNotFound(obj));
return Err(WorldStateError::ObjectNotFound(ObjectRef::Id(obj)));
}

let vh = self.tx.get_verb_by_name(obj, vname)?;
Expand Down
10 changes: 5 additions & 5 deletions crates/db/src/relational_worldstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use crate::{
};
use bytes::Bytes;
use moor_values::model::{
BinaryType, CommitResult, HasUuid, Named, ObjAttrs, ObjFlag, ObjSet, PropDef, PropDefs,
PropFlag, PropPerms, ValSet, VerbArgsSpec, VerbAttrs, VerbDef, VerbDefs, VerbFlag,
BinaryType, CommitResult, HasUuid, Named, ObjAttrs, ObjFlag, ObjSet, ObjectRef, PropDef,
PropDefs, PropFlag, PropPerms, ValSet, VerbArgsSpec, VerbAttrs, VerbDef, VerbDefs, VerbFlag,
WorldStateError,
};
use moor_values::util::BitEnum;
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<RTX: RelationalTransaction<WorldStateTable>> WorldStateTransaction
.unwrap()
.seek_unique_by_domain(WorldStateTable::ObjectFlags, obj)
.map_err(err_map)?
.ok_or(WorldStateError::ObjectNotFound(obj))
.ok_or(WorldStateError::ObjectNotFound(ObjectRef::Id(obj)))
}

fn get_players(&self) -> Result<ObjSet, WorldStateError> {
Expand Down Expand Up @@ -135,7 +135,7 @@ impl<RTX: RelationalTransaction<WorldStateTable>> WorldStateTransaction
.unwrap()
.seek_unique_by_domain(WorldStateTable::ObjectOwner, obj)
.map_err(err_map)?
.ok_or(WorldStateError::ObjectNotFound(obj))
.ok_or(WorldStateError::ObjectNotFound(ObjectRef::Id(obj)))
}

fn set_object_owner(&self, obj: Objid, owner: Objid) -> Result<(), WorldStateError> {
Expand All @@ -161,7 +161,7 @@ impl<RTX: RelationalTransaction<WorldStateTable>> WorldStateTransaction
.unwrap()
.seek_unique_by_domain(WorldStateTable::ObjectName, obj)
.map_err(err_map)?
.ok_or(WorldStateError::ObjectNotFound(obj))?;
.ok_or(WorldStateError::ObjectNotFound(ObjectRef::Id(obj)))?;
Ok(sh.0)
}

Expand Down
22 changes: 17 additions & 5 deletions crates/db/src/worldstate_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

use crate::worldstate_transaction::WorldStateTransaction;
use crate::{RelationalTransaction, RelationalWorldStateTransaction, WorldStateTable};
use moor_values::model::ObjSet;
use moor_values::model::VerbArgsSpec;
use moor_values::model::{BinaryType, VerbAttrs};
use moor_values::model::{CommitResult, WorldStateError};
use moor_values::model::{HasUuid, Named};
use moor_values::model::{ObjAttrs, PropFlag, ValSet};
use moor_values::model::{ObjSet, ObjectRef};
use moor_values::util::BitEnum;
use moor_values::var::Objid;
use moor_values::var::Symbol;
Expand Down Expand Up @@ -1049,7 +1049,10 @@ where

// Verify it's gone.
let result = tx.get_object_name(tobj);
assert_eq!(result.err().unwrap(), WorldStateError::ObjectNotFound(tobj));
assert_eq!(
result.err().unwrap(),
WorldStateError::ObjectNotFound(ObjectRef::Id(tobj))
);

// Create two new objects and root the second off the first.
let a = tx
Expand All @@ -1068,7 +1071,10 @@ where
// Recycle the child, and verify it's gone.
tx.recycle_object(b).expect("Unable to recycle object");
let result = tx.get_object_name(b);
assert_eq!(result.err().unwrap(), WorldStateError::ObjectNotFound(b));
assert_eq!(
result.err().unwrap(),
WorldStateError::ObjectNotFound(ObjectRef::Id(b))
);

// Verify that children list is empty for the parent.
assert!(tx.get_object_children(a).unwrap().is_empty());
Expand Down Expand Up @@ -1098,7 +1104,10 @@ where

tx.recycle_object(c).expect("Unable to recycle object");
let result = tx.get_object_name(c);
assert_eq!(result.err().unwrap(), WorldStateError::ObjectNotFound(c));
assert_eq!(
result.err().unwrap(),
WorldStateError::ObjectNotFound(ObjectRef::Id(c))
);

// Verify the property is still there.
let (prop, v, perms, _) = tx
Expand Down Expand Up @@ -1127,7 +1136,10 @@ where

tx.recycle_object(a).expect("Unable to recycle object");
let result = tx.get_object_name(a);
assert_eq!(result.err().unwrap(), WorldStateError::ObjectNotFound(a));
assert_eq!(
result.err().unwrap(),
WorldStateError::ObjectNotFound(ObjectRef::Id(a))
);

// Verify the child object is still there despite its parent being destroyed.
let result = tx.get_object_name(d);
Expand Down
4 changes: 2 additions & 2 deletions crates/kernel/src/matching/mock_matching_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

use std::collections::{HashMap, HashSet};

use moor_values::model::WorldStateError;
use moor_values::model::{ObjSet, ValSet};
use moor_values::model::{ObjectRef, WorldStateError};
use moor_values::var::Objid;
use moor_values::NOTHING;

Expand Down Expand Up @@ -75,7 +75,7 @@ impl MatchEnvironment for MockMatchEnv {
self.objects
.get(&oid)
.map(|o| o.location)
.ok_or(WorldStateError::ObjectNotFound(oid))
.ok_or(WorldStateError::ObjectNotFound(ObjectRef::Id(oid)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/kernel/src/matching/ws_match_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::matching::match_env::MatchEnvironment;

/// A "match environment" which matches out of the current DB world state.
pub struct WsMatchEnv<'a> {
pub(crate) ws: &'a mut dyn WorldState,
pub(crate) ws: &'a dyn WorldState,
pub(crate) perms: Objid,
}

Expand Down
Loading

0 comments on commit b3b6057

Please sign in to comment.