|
|
|
@ -10,6 +10,38 @@ use crate::try_log;
|
|
|
|
|
use crate::world::Zone;
|
|
|
|
|
|
|
|
|
|
impl Db {
|
|
|
|
|
/// Get root zone
|
|
|
|
|
pub fn root_zone(&self, zone: &Zone) -> RudeResult<Zone> {
|
|
|
|
|
// get rid of the &
|
|
|
|
|
let mut zone = Zone {
|
|
|
|
|
id: zone.id,
|
|
|
|
|
parent: zone.parent,
|
|
|
|
|
name: zone.name.clone(),
|
|
|
|
|
users_visible: zone.users_visible,
|
|
|
|
|
areas: zone.areas.clone(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// loop until find the root
|
|
|
|
|
loop {
|
|
|
|
|
zone = match self.load_zone(zone.id) {
|
|
|
|
|
Ok(Some(z)) => z,
|
|
|
|
|
Ok(None) => {
|
|
|
|
|
log::error!(
|
|
|
|
|
"{}({}) :: Can't find parent zone :: None value",
|
|
|
|
|
file!(),
|
|
|
|
|
line!()
|
|
|
|
|
);
|
|
|
|
|
return Err(Box::from("None value"));
|
|
|
|
|
}
|
|
|
|
|
Err(e) => return Err(e),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if zone.id == zone.parent {
|
|
|
|
|
return Ok(zone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Save a zone to the database.
|
|
|
|
|
pub fn save_zone(&self, zone: &Zone) -> RudeResult<()> {
|
|
|
|
|
let mut statement = try_log!(
|
|
|
|
|