~starkingdoms/starkingdoms

b66c1c42a35fb0a9ce2460ce0ff86ed4ebb7f9a7 — ghostlyzsh 1 year, 8 months ago fc14e3a
appease the clippy
M server/src/component.rs => server/src/component.rs +1 -1
@@ 13,7 13,7 @@
//
//     You should have received a copy of the GNU Affero General Public License
//     along with this program.  If not, see <https://www.gnu.org/licenses/>.
use std::{collections::HashMap, net::SocketAddr};
use std::{net::SocketAddr};

use bevy::prelude::*;
use serde::{Deserialize, Serialize};

M server/src/main.rs => server/src/main.rs +48 -56
@@ 33,13 33,11 @@ use bevy::{
};
use bevy_rapier2d::prelude::*;
use component::*;
use hmac::{Hmac, Mac};
use jwt::VerifyWithKey;
//use hmac::Mac;
use packet::*;
use part::{HEARTY_THRUST_ENERGY, LANDING_THRUSTER_ENERGY};
use rand::Rng;
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use starkingdoms_common::SaveModule;
use starkingdoms_common::{pack_savefile, unpack_savefile, SaveData};
use std::f32::consts::PI;


@@ 216,50 214,48 @@ fn module_spawn(
    part_query: Query<&PartType, Without<Attach>>,
    mut packet_send: EventWriter<WsEvent>,
) {
    if module_timer.0.tick(time.delta()).just_finished() {
        if part_query.iter().count() < part::FREE_MODULE_CAP {
            let angle: f32 = {
                let mut rng = rand::thread_rng();
                rng.gen::<f32>() * std::f32::consts::PI * 2.
            };
            let mut transform = Transform::from_xyz(angle.cos() * 30.0, angle.sin() * 30.0, 0.0);
            transform.rotate_z(angle);
            let flags = PartFlags { attached: false };
            let mut entity = commands.spawn(PartBundle {
    if module_timer.0.tick(time.delta()).just_finished() && part_query.iter().count() < part::FREE_MODULE_CAP {
        let angle: f32 = {
            let mut rng = rand::thread_rng();
            rng.gen::<f32>() * std::f32::consts::PI * 2.
        };
        let mut transform = Transform::from_xyz(angle.cos() * 30.0, angle.sin() * 30.0, 0.0);
        transform.rotate_z(angle);
        let flags = PartFlags { attached: false };
        let mut entity = commands.spawn(PartBundle {
            part_type: PartType::Cargo,
            transform: TransformBundle::from(transform),
            flags,
        });
        entity
            .insert(RigidBody::Dynamic)
            .with_children(|children| {
                children
                    .spawn(Collider::cuboid(0.375, 0.46875))
                    .insert(TransformBundle::from(Transform::from_xyz(0., 0.03125, 0.)));
            })
            .insert(AdditionalMassProperties::MassProperties(MassProperties {
                local_center_of_mass: vec2(0.0, 0.0),
                mass: part::CARGO_MASS,
                principal_inertia: 7.5,
            }))
            .insert(ExternalForce::default())
            .insert(ExternalImpulse::default())
            .insert(Velocity::default())
            .insert(ReadMassProperties::default());

        let packet = Packet::SpawnPart {
            id: entity.id().index(),
            part: Part {
                part_type: PartType::Cargo,
                transform: TransformBundle::from(transform),
                flags,
            });
            entity
                .insert(RigidBody::Dynamic)
                .with_children(|children| {
                    children
                        .spawn(Collider::cuboid(0.375, 0.46875))
                        .insert(TransformBundle::from(Transform::from_xyz(0., 0.03125, 0.)));
                })
                .insert(AdditionalMassProperties::MassProperties(MassProperties {
                    local_center_of_mass: vec2(0.0, 0.0),
                    mass: part::CARGO_MASS,
                    principal_inertia: 7.5,
                }))
                .insert(ExternalForce::default())
                .insert(ExternalImpulse::default())
                .insert(Velocity::default())
                .insert(ReadMassProperties::default());

            let packet = Packet::SpawnPart {
                id: entity.id().index(),
                part: Part {
                    part_type: PartType::Cargo,
                    transform: proto_transform!(transform),
                    flags: proto_part_flags!(flags),
                },
            };
                transform: proto_transform!(transform),
                flags: proto_part_flags!(flags),
            },
        };

            packet_send.send(WsEvent::Broadcast {
                message: packet.into(),
            });
        }
        packet_send.send(WsEvent::Broadcast {
            message: packet.into(),
        });
    }
}



@@ 314,7 310,7 @@ fn on_message(
                Packet::ClientLogin {
                    username,
                    save,
                    jwt,
                    jwt: _,
                } => {
                    // auth
                    // plz no remove


@@ 708,11 704,9 @@ fn on_message(
                                    bound = [-0.375, 0.375, -0.5, 0.4375];
                                }

                                if bound[0] < x && x < bound[1] && bound[2] < y && y < bound[3] {
                                    if m_attach.associated_player.unwrap() == entity {
                                        q_player.selected = Some(m_entity);
                                        break;
                                    }
                                if bound[0] < x && x < bound[1] && bound[2] < y && y < bound[3] && m_attach.associated_player.unwrap() == entity {
                                    q_player.selected = Some(m_entity);
                                    break;
                                }
                            }
                            for (entity, part_type, transform, _, _, _) in &part_query {


@@ 1167,7 1161,7 @@ fn attach_on_module_tree(
    };
    for this in attach.clone().children.iter().flatten() {
        let module = part_query.get(select).unwrap();
        let part_type = module.1.clone();
        let part_type = *module.1;
        ret |= if part_type != PartType::LandingThruster {
            attach_on_module_tree(
                x,


@@ 2060,10 2054,8 @@ fn search_thrusters(
            }
        }

        if *part_type != PartType::LandingThruster {
            if *energy >= energy_lose_by {
                search_thrusters(input, attach.clone(), p_transform, energy, attached_query);
            }
        if *part_type != PartType::LandingThruster && *energy >= energy_lose_by {
            search_thrusters(input, attach.clone(), p_transform, energy, attached_query);
        }
    }
}

M server/src/packet.rs => server/src/packet.rs +0 -1
@@ 16,7 16,6 @@ use std::fmt::{Display, Formatter};
//     along with this program.  If not, see <https://www.gnu.org/licenses/>.
use crate::component::{PartType, PlanetType};
use serde::{Deserialize, Serialize};
use starkingdoms_common::Savefile;
use tungstenite::Message;

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]

M server/src/part.rs => server/src/part.rs +14 -14
@@ 21,14 21,14 @@ pub const LANDING_THRUSTER_ENERGY: u32 = 3;
#[macro_export]
macro_rules! mass {
    ($p:expr) => {
        if $p == crate::component::PartType::Hearty {
            crate::part::HEARTY_MASS
        } else if $p == crate::component::PartType::Cargo {
            crate::part::CARGO_MASS
        } else if $p == crate::component::PartType::Hub {
            crate::part::HUB_MASS
        } else if $p == crate::component::PartType::LandingThruster {
            crate::part::LANDING_THRUSTER_MASS
        if $p == $crate::component::PartType::Hearty {
            $crate::part::HEARTY_MASS
        } else if $p == $crate::component::PartType::Cargo {
            $crate::part::CARGO_MASS
        } else if $p == $crate::component::PartType::Hub {
            $crate::part::HUB_MASS
        } else if $p == $crate::component::PartType::LandingThruster {
            $crate::part::LANDING_THRUSTER_MASS
        } else {
            1.
        }


@@ 38,12 38,12 @@ macro_rules! mass {
#[macro_export]
macro_rules! capacity {
    ($p:expr) => {
        if $p == crate::component::PartType::Hearty {
            crate::part::HEARTY_CAPACITY
        } else if $p == crate::component::PartType::Hub {
            crate::part::HUB_CAPACITY
        } else if $p == crate::component::PartType::LandingThruster {
            crate::part::LANDING_THRUSTER_CAPACITY
        if $p == $crate::component::PartType::Hearty {
            $crate::part::HEARTY_CAPACITY
        } else if $p == $crate::component::PartType::Hub {
            $crate::part::HUB_CAPACITY
        } else if $p == $crate::component::PartType::LandingThruster {
            $crate::part::LANDING_THRUSTER_CAPACITY
        } else {
            0
        }

M server/src/ws.rs => server/src/ws.rs +4 -4
@@ 18,7 18,7 @@ use bevy::app::{App, Plugin, PostUpdate, Startup};
use bevy::ecs::event::ManualEventReader;
use bevy::log::{error, warn};
use bevy::prelude::{Commands, Event, Events, Local, Res, ResMut, Resource};
use crossbeam_channel::{unbounded, Receiver, Sender};
use crossbeam_channel::{unbounded, Receiver};
use std::collections::HashMap;
use std::net::{IpAddr, SocketAddr, TcpListener};
use std::sync::{Arc, RwLock};


@@ 60,8 60,8 @@ pub struct StkTungsteniteServerConfig {
#[derive(Resource)]
pub struct Rx<A>(Receiver<A>);

#[derive(Resource)]
pub struct Tx<A>(Sender<A>);
//#[derive(Resource)]
//pub struct Tx<A>(Sender<A>);

impl StkTungsteniteServerPlugin {
    pub fn init_server(config: Res<StkTungsteniteServerConfig>, mut commands: Commands) {


@@ 74,7 74,7 @@ impl StkTungsteniteServerPlugin {

        commands.insert_resource(clients.clone());
        commands.insert_resource(Rx(rx.clone()));
        commands.insert_resource(Tx(tx.clone()));
        //commands.insert_resource(Tx(tx.clone()));

        let clients = clients.0.clone();


M starkingdoms-common/src/lib.rs => starkingdoms-common/src/lib.rs +1 -1
@@ 18,7 18,7 @@ use base64::Engine;
use hmac::{Hmac, Mac};
use serde::{Deserialize, Serialize};
use sha2::Sha256;
use std::{collections::HashMap, error::Error};
use std::error::Error;

#[derive(Clone, Serialize, Deserialize, Debug, PartialEq)]
pub struct SaveData {