Add consent check on accessing private property.
This commit is contained in:
parent
ed3d77dcbe
commit
10351fdf18
@ -17,24 +17,29 @@ use crate::{
|
|||||||
room::{self, Direction, ExitType},
|
room::{self, Direction, ExitType},
|
||||||
dynzone::{dynzone_by_type, ExitTarget as DynExitTarget, DynzoneType},
|
dynzone::{dynzone_by_type, ExitTarget as DynExitTarget, DynzoneType},
|
||||||
},
|
},
|
||||||
models::item::{
|
models::{
|
||||||
|
item::{
|
||||||
Item,
|
Item,
|
||||||
ItemSpecialData,
|
ItemSpecialData,
|
||||||
SkillType,
|
SkillType,
|
||||||
LocationActionType,
|
LocationActionType,
|
||||||
DoorState,
|
DoorState,
|
||||||
},
|
},
|
||||||
|
consent::ConsentType,
|
||||||
|
},
|
||||||
services::{
|
services::{
|
||||||
comms::broadcast_to_room,
|
comms::broadcast_to_room,
|
||||||
skills::skill_check_and_grind,
|
skills::skill_check_and_grind,
|
||||||
combat::stop_attacking_mut,
|
combat::stop_attacking_mut,
|
||||||
combat::handle_resurrect,
|
combat::handle_resurrect,
|
||||||
|
check_consent,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use mockall_double::double;
|
use mockall_double::double;
|
||||||
#[double] use crate::db::DBTrans;
|
#[double] use crate::db::DBTrans;
|
||||||
use std::time;
|
use std::time;
|
||||||
|
use ansi::ansi;
|
||||||
|
|
||||||
pub async fn announce_move(trans: &DBTrans, character: &Item, leaving: &Item, arriving: &Item) -> DResult<()> {
|
pub async fn announce_move(trans: &DBTrans, character: &Item, leaving: &Item, arriving: &Item) -> DResult<()> {
|
||||||
let msg_leaving_exp = format!("{} departs towards {}\n",
|
let msg_leaving_exp = format!("{} departs towards {}\n",
|
||||||
@ -137,6 +142,37 @@ async fn move_to_where(
|
|||||||
Ok((format!("room/{}", new_room.code), None))
|
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!("<yellow>Your wristpad buzzes and your muscles lock up, stopping you entering.<reset> \
|
||||||
|
It seems this is private property and you haven't been invited here with \
|
||||||
|
<bold>allow visit<reset>, nor do you have a <bold>allow fight<reset> in force with \
|
||||||
|
the owner here.").to_owned())?
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn attempt_move_immediate(
|
pub async fn attempt_move_immediate(
|
||||||
trans: &DBTrans,
|
trans: &DBTrans,
|
||||||
orig_mover: &Item,
|
orig_mover: &Item,
|
||||||
@ -156,8 +192,10 @@ pub async fn attempt_move_immediate(
|
|||||||
|
|
||||||
match is_door_in_direction(trans, direction, orig_mover).await? {
|
match is_door_in_direction(trans, direction, orig_mover).await? {
|
||||||
DoorSituation::NoDoor |
|
DoorSituation::NoDoor |
|
||||||
DoorSituation::DoorIntoRoom { state: DoorState { open: true, .. }, .. } |
|
|
||||||
DoorSituation::DoorOutOfRoom { 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?;
|
attempt_open_immediate(trans, player_ctx, orig_mover, direction).await?;
|
||||||
match player_ctx.as_mut() {
|
match player_ctx.as_mut() {
|
||||||
|
Loading…
Reference in New Issue
Block a user