From 2d2813610bc96def59bb3e54d9e061bc368914b0 Mon Sep 17 00:00:00 2001 From: ghostlyzsh Date: Wed, 19 Apr 2023 21:55:56 -0500 Subject: [PATCH] added ModulesUpdate packet --- client/src/gateway.ts | 2 +- protocol/build.rs | 3 ++- protocol/src/lib.rs | 15 +++++++++++---- protocol/src/pbuf/message_s2c.proto | 9 ++++++++- protocol/src/pbuf/module.proto | 15 +++++++++++++++ 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 protocol/src/pbuf/module.proto diff --git a/client/src/gateway.ts b/client/src/gateway.ts index 7a24b4cd5f0369139225db21f926cee089e7a19d..3d9ca94a69f2dd03ec0b86df09ff3015aecd5e30 100644 --- a/client/src/gateway.ts +++ b/client/src/gateway.ts @@ -68,7 +68,7 @@ export async function gateway_connect(gateway_url: string, username: string): Ga client.ping_timeout = setTimeout(ping_fn, 5 * 1000); let handshake_start_msg = MessageC2SHello.encode({ - version: 1, + version: 3, requestedUsername: username, nextState: State.Play }).finish(); diff --git a/protocol/build.rs b/protocol/build.rs index c4c9bcd3b4d587db2c243e6c5e5722093fe579f9..a456eda25274303da528ae990bf8e36d89c79724 100644 --- a/protocol/build.rs +++ b/protocol/build.rs @@ -9,5 +9,6 @@ fn main() { .input("src/pbuf/player.proto") .input("src/pbuf/state.proto") .input("src/pbuf/goodbye_reason.proto") + .input("src/pbuf/module.proto") .run_from_script(); -} \ No newline at end of file +} diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index f06873473540c38c723e408ad1c6bbebf4846e5e..22e5e49cacae6251daee3bb4505f37ba7582f842 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -1,12 +1,12 @@ use std::error::Error; use protobuf::{Enum, Message}; use crate::message_c2s::{MessageC2SAuthenticateAndBeamOut, MessageC2SChat, MessageC2SGoodbye, MessageC2SHello, MessageC2SInput, MessageC2SPing}; -use crate::message_s2c::{MessageS2CChat, MessageS2CGoodbye, MessageS2CHello, MessageS2CPlanetData, MessageS2CPlayersUpdate, MessageS2CPong}; +use crate::message_s2c::{MessageS2CChat, MessageS2CGoodbye, MessageS2CHello, MessageS2CPlanetData, MessageS2CPlayersUpdate, MessageS2CPong, MessageS2CModulesUpdate}; use crate::planet::PlanetType; use crate::starkingdoms_protocol::PacketWrapper; include!(concat!(env!("OUT_DIR"), "/protos/mod.rs")); -pub const PROTOCOL_VERSION: u32 = 2; +pub const PROTOCOL_VERSION: u32 = 3; pub mod api; @@ -27,7 +27,8 @@ pub enum MessageS2C { Chat(MessageS2CChat), Pong(MessageS2CPong), PlayersUpdate(MessageS2CPlayersUpdate), - PlanetData(MessageS2CPlanetData) + PlanetData(MessageS2CPlanetData), + ModulesUpdate(MessageS2CModulesUpdate), } impl TryFrom<&[u8]> for MessageC2S { @@ -122,6 +123,9 @@ impl TryFrom<&[u8]> for MessageS2C { _id if _id == message_s2c::message_s2cplanet_data::Packet_info::type_.value() as i64 => { MessageS2C::PlanetData(MessageS2CPlanetData::parse_from_bytes(&pkt.packet_data)?) }, + _id if _id == message_s2c::message_s2cmodules_update::Packet_info::type_.value() as i64 => { + MessageS2C::ModulesUpdate(MessageS2CModulesUpdate::parse_from_bytes(&pkt.packet_data)?) + }, _ => { return Err("Not a S2C packet".into()); } }; @@ -152,6 +156,9 @@ impl TryInto> for MessageS2C { MessageS2C::PlanetData(p) => { (message_s2c::message_s2cplanet_data::Packet_info::type_.value(), p.write_to_bytes()?) } + MessageS2C::ModulesUpdate(p) => { + (message_s2c::message_s2cmodules_update::Packet_info::type_.value(), p.write_to_bytes()?) + } }; let pkt = PacketWrapper { @@ -171,4 +178,4 @@ impl planet::PlanetType { PlanetType::Moon => "moon".to_string() } } -} \ No newline at end of file +} diff --git a/protocol/src/pbuf/message_s2c.proto b/protocol/src/pbuf/message_s2c.proto index 08c6e31aa3dd3e10c2ebbd7822eabdb6f0dafcdc..55dd1a317665fbea4e4f3e9e912256237adaf1ea 100644 --- a/protocol/src/pbuf/message_s2c.proto +++ b/protocol/src/pbuf/message_s2c.proto @@ -5,6 +5,7 @@ import "state.proto"; import "goodbye_reason.proto"; import "player.proto"; import "planet.proto"; +import "module.proto"; message MessageS2CHello { enum packet_info { unknown = 0; type = 0x05; } @@ -41,4 +42,10 @@ message MessageS2CPlanetData { enum packet_info { unknown = 0; type = 0x0a; } repeated protocol.planet.Planet planets = 1; // List of all planets on the server -} \ No newline at end of file +} + +message MessageS2CModulesUpdate { + enum packet_info { unknown = 0; type = 0x0b; } + + repeated protocol.module.Module modules = 1; +} diff --git a/protocol/src/pbuf/module.proto b/protocol/src/pbuf/module.proto new file mode 100644 index 0000000000000000000000000000000000000000..2755d7cc74e8c0b08a45def914642c74ee342f0a --- /dev/null +++ b/protocol/src/pbuf/module.proto @@ -0,0 +1,15 @@ +syntax = "proto3"; +package protocol.module; + +message Module { + ModuleType module_type = 1; + float rotation = 2; + float x = 3; + float y = 4; +} + +enum ModuleType { + Cargo = 0; + LandingThruster = 1; + Hub = 2; +}