~starkingdoms/starkingdoms

aae675f31d3ca95ec4f678e48e318777b3662200 — ghostlyzsh 1 year, 11 months ago 9d56082
ok now saving saves everything in theory
3 files changed, 14 insertions(+), 14 deletions(-)

M savefile_decoder/src/main.rs
M server/src/main.rs
M starkingdoms-common/src/lib.rs
M savefile_decoder/src/main.rs => savefile_decoder/src/main.rs +1 -1
@@ 3,7 3,7 @@ use std::fs;
use starkingdoms_common::unpack_savefile;

fn main() {
    let save = std::env::args().next().unwrap();
    let save = std::env::args().nth(1).unwrap();
    let key = fs::read_to_string("/etc/starkingdoms/app_key").unwrap();
    let save_data = unpack_savefile(&key, save).unwrap();
    println!("{:#?}", save_data);

M server/src/main.rs => server/src/main.rs +11 -11
@@ 891,7 891,7 @@ fn on_message(
                            // HEY! GHOSTLY! PLEASE FILL THIS STRUCT WITH DATA!
                            // THANKS!
                            let save = SaveData {
                                module: construct_save_data(attach.clone(), &attached_query),
                                children: construct_save_data(attach.clone(), &attached_query),
                            };
                            let save_string = pack_savefile(&app_keys.app_key, save);
                            let packet = Packet::SaveData {


@@ 922,26 922,26 @@ fn construct_save_data(
            &Velocity,
            Option<&CanAttach>,
            Option<&LooseAttach>,
            &mut PartFlags,
        ),
        (Without<PlanetType>, Without<Player>),
    >,
) -> SaveModule {
    let mut save_module = SaveModule {
        part_type: starkingdoms_common::PartType::Placeholder,
        children: vec![None, None, None, None],
    };
) -> Vec<Option<SaveModule>> {
    let mut modules = vec![None, None, None, None];
    for (i, child) in attach.children.iter().enumerate() {
        if let Some(child) = child {
            let (_, part_type, _, attach, _, _, _) = attached_query.get(*child).unwrap();
            let (_, part_type, _, attach, _, _, _, _) = attached_query.get(*child).unwrap();
            if *part_type == PartType::LandingThrusterSuspension {
                continue;
            }
            let child_save_module = construct_save_data(attach.clone(), attached_query);
            save_module.part_type = (*part_type).into();
            save_module.children[i] = Some(child_save_module);
            modules[i] = Some(SaveModule {
                part_type: (*part_type).into(),
                children: child_save_module,
            });
        }
    }
    save_module
    modules
}

fn detach_recursive(


@@ 1454,7 1454,7 @@ fn break_modules(
            commands.entity(entity).insert(LooseAttach {
                children: attach.children,
            });
            if (attach.children[2].is_some()) {
            if attach.children[2].is_some() {
                commands
                    .entity(attach.children[2].unwrap())
                    .remove::<Attach>();

M starkingdoms-common/src/lib.rs => starkingdoms-common/src/lib.rs +2 -2
@@ 29,7 29,7 @@ pub struct SaveData {
    // FILL THIS WITH STUFF
    // ----------------------------------------------------------------------
    // THANKS! -core
    pub module: SaveModule,
    pub children: Vec<Option<SaveModule>>,
}

#[derive(Serialize, Deserialize, Debug)]


@@ 77,7 77,7 @@ pub fn unpack_savefile(key: &str, file: String) -> Result<SaveData, Box<dyn Erro

    let save_file: Savefile = rmp_serde::from_slice(&savefile_bytes).map_err(|e| format!("error decoding savefile wrapper: {e}"))?;

    let mut mac: Hmac<Sha256> = Hmac::new_from_slice(key.as_bytes()).map_err(|e| format!("error loading hmac-sha256: {e}"));
    let mut mac: Hmac<Sha256> = Hmac::new_from_slice(key.as_bytes()).map_err(|e| format!("error loading hmac-sha256: {e}"))?;
    mac.update(&save_file.data_msgpack);
    mac.verify_slice(&save_file.mac).map_err(|e| format!("error verifying signature: {e}"))?;