diff --git a/blastmud_game/src/message_handler/user_commands/movement.rs b/blastmud_game/src/message_handler/user_commands/movement.rs index a20ee67..04961e6 100644 --- a/blastmud_game/src/message_handler/user_commands/movement.rs +++ b/blastmud_game/src/message_handler/user_commands/movement.rs @@ -17,24 +17,29 @@ use crate::{ room::{self, Direction, ExitType}, dynzone::{dynzone_by_type, ExitTarget as DynExitTarget, DynzoneType}, }, - models::item::{ - Item, - ItemSpecialData, - SkillType, - LocationActionType, - DoorState, + models::{ + item::{ + Item, + ItemSpecialData, + SkillType, + LocationActionType, + DoorState, + }, + consent::ConsentType, }, services::{ comms::broadcast_to_room, skills::skill_check_and_grind, combat::stop_attacking_mut, combat::handle_resurrect, + check_consent, } }; use std::sync::Arc; use mockall_double::double; #[double] use crate::db::DBTrans; use std::time; +use ansi::ansi; pub async fn announce_move(trans: &DBTrans, character: &Item, leaving: &Item, arriving: &Item) -> DResult<()> { let msg_leaving_exp = format!("{} departs towards {}\n", @@ -137,6 +142,37 @@ async fn move_to_where( Ok((format!("room/{}", new_room.code), None)) } +pub async fn check_room_access(trans: &DBTrans, player: &Item, room: &Item) -> UResult<()> { + let (owner_t, owner_c) = match room.owner.as_ref().and_then(|o| o.split_once("/")) { + None => return Ok(()), + Some(v) => v + }; + if owner_t == &player.item_type && owner_c == &player.item_code { + return Ok(()); + } + let owner = match trans.find_item_by_type_code(owner_t, owner_c).await? { + None => return Ok(()), + Some(v) => v + }; + + if check_consent(trans, "enter", &ConsentType::Visit, player, &owner).await? { + return Ok(()); + } + + let mut player_hypothet = (*player).clone(); + // We are asking hypothetically if they entered the room, could they fight + // the owner? We won't save this yet. + player_hypothet.location = room.refstr(); + if check_consent(trans, "enter", &ConsentType::Fight, &player_hypothet, &owner).await? { + return Ok(()); + } + + user_error(ansi!("Your wristpad buzzes and your muscles lock up, stopping you entering. \ + It seems this is private property and you haven't been invited here with \ + allow visit, nor do you have a allow fight in force with \ + the owner here.").to_owned())? +} + pub async fn attempt_move_immediate( trans: &DBTrans, orig_mover: &Item, @@ -156,8 +192,10 @@ pub async fn attempt_move_immediate( match is_door_in_direction(trans, direction, orig_mover).await? { DoorSituation::NoDoor | - DoorSituation::DoorIntoRoom { state: DoorState { open: true, .. }, .. } | DoorSituation::DoorOutOfRoom { state: DoorState { open: true, .. }, .. } => {}, + DoorSituation::DoorIntoRoom { state: DoorState { open: true, .. }, room_with_door, .. } => { + check_room_access(trans, orig_mover, &room_with_door).await?; + } _ => { attempt_open_immediate(trans, player_ctx, orig_mover, direction).await?; match player_ctx.as_mut() {