From 716942f76668c6a6db559efb9046befd0a8ec8e1 Mon Sep 17 00:00:00 2001 From: core Date: Tue, 16 Jan 2024 11:31:26 -0500 Subject: [PATCH] q --- Cargo.lock | 12 +--- Cargo.toml | 3 +- bevy_tungstenite_stk/Cargo.toml | 11 ---- server/Cargo.toml | 3 +- server/src/main.rs | 55 ++++++++++++++++--- server/src/packet.rs | 2 +- .../src/lib.rs => server/src/ws.rs | 16 ++++++ 7 files changed, 68 insertions(+), 34 deletions(-) delete mode 100644 bevy_tungstenite_stk/Cargo.toml rename bevy_tungstenite_stk/src/lib.rs => server/src/ws.rs (90%) diff --git a/Cargo.lock b/Cargo.lock index fe671de415c92f8b96bec68756cfebbdd9328f13..bc2fd53a67709b2beab2f16530f2dbe4bb176580 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1057,15 +1057,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "bevy_tungstenite_stk" -version = "0.1.0" -dependencies = [ - "bevy", - "crossbeam-channel", - "tungstenite", -] - [[package]] name = "bevy_utils" version = "0.12.1" @@ -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]] diff --git a/Cargo.toml b/Cargo.toml index 495b497cceb38781b4c14fe947a3f8bcef773419..f69ca87dae8489e89c4fd3d7cec4da5f3a76e658 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,8 +3,7 @@ members = [ "server", "starkingdoms-backplane", "starkingdoms-common", - "savefile_decoder", - "bevy_tungstenite_stk" + "savefile_decoder" ] resolver = "2" diff --git a/bevy_tungstenite_stk/Cargo.toml b/bevy_tungstenite_stk/Cargo.toml deleted file mode 100644 index 25fb8e2b9dd9c37ad2dd10736787f67363f39a1e..0000000000000000000000000000000000000000 --- a/bevy_tungstenite_stk/Cargo.toml +++ /dev/null @@ -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 diff --git a/server/Cargo.toml b/server/Cargo.toml index 8cb11026b3a48097ae9da584b10b291080d90671..e075b4ebe05b1a5ada2242d8dbd0f52efca6df6d 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -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 = [] diff --git a/server/src/main.rs b/server/src/main.rs index 80fe988b636b108ec4249e1ba6154fc5a77a73e9..9d29c9edc2c112209cecc48fd089c956f0dd662c 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -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, Without), >, mut player_query: Query< - (Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags), + ( + Entity, + &mut Player, + &Transform, + &Velocity, + &mut Attach, + &mut PartFlags, + ), Without, >, mut packet_recv: Local>, @@ -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, Without), >, player_query: &mut Query< - (Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags), + ( + Entity, + &mut Player, + &Transform, + &Velocity, + &mut Attach, + &mut PartFlags, + ), Without, >, ) { @@ -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, Without, Without), >, player_query: &mut Query< - (Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags), + ( + Entity, + &mut Player, + &Transform, + &Velocity, + &mut Attach, + &mut PartFlags, + ), Without, >, ) -> bool { @@ -1508,7 +1530,17 @@ fn break_modules( ), (Without, Without), >, - mut player_query: Query<(Entity, &mut Player, &Transform, &Velocity, &mut Attach, &mut PartFlags), Without>, + mut player_query: Query< + ( + Entity, + &mut Player, + &Transform, + &Velocity, + &mut Attach, + &mut PartFlags, + ), + Without, + >, ) { 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, + ); } } diff --git a/server/src/packet.rs b/server/src/packet.rs index 787219790fcb0a821cb9444e6aede215ea4c0abd..f9d6a1f83c3bf20a4f7813df3952cd87ec9d2a43 100644 --- a/server/src/packet.rs +++ b/server/src/packet.rs @@ -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 . 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 { diff --git a/bevy_tungstenite_stk/src/lib.rs b/server/src/ws.rs similarity index 90% rename from bevy_tungstenite_stk/src/lib.rs rename to server/src/ws.rs index 995f65b7b80898f17a289a38019bcad809f6d61c..aa4b69dce236a649510bb4d4d8b87fa3d46ca672 100644 --- a/bevy_tungstenite_stk/src/lib.rs +++ b/server/src/ws.rs @@ -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 . + use bevy::app::{App, Plugin, PostUpdate, Startup}; use bevy::ecs::event::ManualEventReader; use bevy::log::{error, warn};