~starkingdoms/starkingdoms

716942f76668c6a6db559efb9046befd0a8ec8e1 — core 1 year, 10 months ago 60668da
q
7 files changed, 68 insertions(+), 34 deletions(-)

M Cargo.lock
M Cargo.toml
D bevy_tungstenite_stk/Cargo.toml
M server/Cargo.toml
M server/src/main.rs
M server/src/packet.rs
R {bevy_tungstenite_stk/src/lib => server/src/ws}.rs
M Cargo.lock => Cargo.lock +2 -10
@@ 1058,15 1058,6 @@ dependencies = [
]

[[package]]
name = "bevy_tungstenite_stk"
version = "0.1.0"
dependencies = [
 "bevy",
 "crossbeam-channel",
 "tungstenite",
]

[[package]]
name = "bevy_utils"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"


@@ 3589,7 3580,7 @@ version = "0.1.0-alpha1"
dependencies = [
 "bevy",
 "bevy_rapier2d",
 "bevy_tungstenite_stk",
 "crossbeam-channel",
 "hex",
 "hmac",
 "jwt",


@@ 3600,6 3591,7 @@ dependencies = [
 "starkingdoms-common",
 "tikv-jemallocator",
 "tracing-subscriber",
 "tungstenite",
]

[[package]]

M Cargo.toml => Cargo.toml +1 -2
@@ 3,8 3,7 @@ members = [
    "server",
    "starkingdoms-backplane",
    "starkingdoms-common",
    "savefile_decoder",
    "bevy_tungstenite_stk"
    "savefile_decoder"
]
resolver = "2"


D bevy_tungstenite_stk/Cargo.toml => bevy_tungstenite_stk/Cargo.toml +0 -11
@@ 1,11 0,0 @@
[package]
name = "bevy_tungstenite_stk"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = { version = "0.12", default-features = false }
crossbeam-channel = "0.5"
tungstenite = "0.21"
\ No newline at end of file

M server/Cargo.toml => server/Cargo.toml +2 -1
@@ 16,8 16,9 @@ jwt = "0.16"
sha2 = "0.10"
hmac = "0.12"
hex = "0.4"
bevy_tungstenite_stk = { version = "0.1", path = "../bevy_tungstenite_stk" }
tikv-jemallocator = "0.5.0"
crossbeam-channel = "0.5"
tungstenite = "0.21"

[features]
default = []

M server/src/main.rs => server/src/main.rs +46 -9
@@ 22,6 22,7 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
use std::net::IpAddr;

use crate::mathutil::rot2d;
use crate::ws::{StkTungsteniteServerConfig, StkTungsteniteServerPlugin, WsEvent};
use bevy::math::{vec2, vec3};
use bevy::{
    app::{PluginGroupBuilder, ScheduleRunnerPlugin},


@@ 30,7 31,6 @@ use bevy::{
    time::TimePlugin,
};
use bevy_rapier2d::prelude::*;
use bevy_tungstenite_stk::{StkTungsteniteServerConfig, StkTungsteniteServerPlugin, WsEvent};
use component::Input;
use component::*;
use hmac::{Hmac, Mac};


@@ 49,6 49,7 @@ pub mod component;
pub mod macros;
pub mod mathutil;
pub mod packet;
pub mod ws;

const CLIENT_SCALE: f32 = 50.0;



@@ 297,7 298,14 @@ fn on_message(
        (Without<PlanetType>, Without<Player>),
    >,
    mut player_query: Query<
        (Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags),
        (
            Entity,
            &mut Player,
            &Transform,
            &Velocity,
            &mut Attach,
            &mut PartFlags,
        ),
        Without<PlanetType>,
    >,
    mut packet_recv: Local<ManualEventReader<WsEvent>>,


@@ 648,7 656,8 @@ fn on_message(
                                    module.2.translation = vec3(x, y, 0.);
                                    if *module.1 == PartType::LandingThruster {
                                        let sub_entity = attach.children[2].unwrap();
                                        let mut suspension = attached_query.get_mut(sub_entity).unwrap();
                                        let mut suspension =
                                            attached_query.get_mut(sub_entity).unwrap();
                                        suspension.2.translation = vec3(x, y, 0.);
                                    }
                                    break;


@@ 1017,7 1026,14 @@ fn detach_recursive(
        (Without<PlanetType>, Without<Player>),
    >,
    player_query: &mut Query<
        (Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags),
        (
            Entity,
            &mut Player,
            &Transform,
            &Velocity,
            &mut Attach,
            &mut PartFlags,
        ),
        Without<PlanetType>,
    >,
) {


@@ 1030,8 1046,7 @@ fn detach_recursive(
        detach_recursive(commands, *child, attached_query, player_query);
    }
    let (entity, part_type, attach, mut flags) = if attached_query.contains(this) {
        let (entity, part_type, _, attach, _, _, _, flags) =
            attached_query.get_mut(this).unwrap();
        let (entity, part_type, _, attach, _, _, _, flags) = attached_query.get_mut(this).unwrap();
        (entity, part_type, attach, flags)
    } else {
        let (entity, _, _, _, attach, part_flags) = player_query.get_mut(this).unwrap();


@@ 1102,7 1117,14 @@ fn attach_on_module_tree(
        (Without<PlanetType>, Without<Player>, Without<Attach>),
    >,
    player_query: &mut Query<
        (Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags),
        (
            Entity,
            &mut Player,
            &Transform,
            &Velocity,
            &mut Attach,
            &mut PartFlags,
        ),
        Without<PlanetType>,
    >,
) -> bool {


@@ 1508,7 1530,17 @@ fn break_modules(
        ),
        (Without<PlanetType>, Without<Player>),
    >,
    mut player_query: Query<(Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags), Without<PlanetType>>,
    mut player_query: Query<
        (
            Entity,
            &mut Player,
            &Transform,
            &Velocity,
            &mut Attach,
            &mut PartFlags,
        ),
        Without<PlanetType>,
    >,
) {
    let joints = rapier_context.entity2impulse_joint();
    let mut detach_list = Vec::new();


@@ 1524,7 1556,12 @@ fn break_modules(
        }
    }
    for (entity, _part_type, _attach) in detach_list {
        detach_recursive(&mut commands, entity, &mut attached_query, &mut player_query);
        detach_recursive(
            &mut commands,
            entity,
            &mut attached_query,
            &mut player_query,
        );
    }
}


M server/src/packet.rs => server/src/packet.rs +1 -1
@@ 15,8 15,8 @@ use std::fmt::{Display, Formatter};
//     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 crate::component::{PartType, PlanetType};
use bevy_tungstenite_stk::tungstenite::Message;
use serde::{Deserialize, Serialize};
use tungstenite::Message;

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

R bevy_tungstenite_stk/src/lib.rs => server/src/ws.rs +16 -0
@@ 1,3 1,19 @@
// StarKingdoms.IO, a browser game about drifting through space
//     Copyright (C) 2024 ghostly_zsh, TerraMaster85, core
//
//     This program is free software: you can redistribute it and/or modify
//     it under the terms of the GNU Affero General Public License as published by
//     the Free Software Foundation, either version 3 of the License, or
//     (at your option) any later version.
//
//     This program is distributed in the hope that it will be useful,
//     but WITHOUT ANY WARRANTY; without even the implied warranty of
//     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//     GNU Affero General Public License for more details.
//
//     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 bevy::app::{App, Plugin, PostUpdate, Startup};
use bevy::ecs::event::ManualEventReader;
use bevy::log::{error, warn};