From 4b1217d7b1dbefc6492de9009c8cfd3b6d13bc24 Mon Sep 17 00:00:00 2001 From: core Date: Thu, 13 Apr 2023 21:37:39 -0400 Subject: [PATCH] start switching to protobuf for the protocol --- protocol/src/pbuf/goodbye_reason.proto | 11 +++++ protocol/src/pbuf/message_c2s.proto | 29 ++++++++++++ protocol/src/pbuf/message_s2c.proto | 44 +++++++++++++++++++ protocol/src/pbuf/planet.proto | 13 ++++++ protocol/src/pbuf/player.proto | 9 ++++ protocol/src/pbuf/starkingdoms-protocol.proto | 14 ++++++ protocol/src/pbuf/state.proto | 9 ++++ 7 files changed, 129 insertions(+) create mode 100644 protocol/src/pbuf/goodbye_reason.proto create mode 100644 protocol/src/pbuf/message_c2s.proto create mode 100644 protocol/src/pbuf/message_s2c.proto create mode 100644 protocol/src/pbuf/planet.proto create mode 100644 protocol/src/pbuf/player.proto create mode 100644 protocol/src/pbuf/starkingdoms-protocol.proto create mode 100644 protocol/src/pbuf/state.proto diff --git a/protocol/src/pbuf/goodbye_reason.proto b/protocol/src/pbuf/goodbye_reason.proto new file mode 100644 index 0000000000000000000000000000000000000000..1e23025af05ada10bc885177aeb130af0c495f06 --- /dev/null +++ b/protocol/src/pbuf/goodbye_reason.proto @@ -0,0 +1,11 @@ +syntax = "proto3"; +package protocol.goodbye_reason; + +enum GoodbyeReason { + UnsupportedProtocol = 0; + UnexpectedPacket = 1; + UnexpectedNextState = 2; + UsernameTaken = 3; + PingPongTimeout = 4; + Done = 5; +} \ No newline at end of file diff --git a/protocol/src/pbuf/message_c2s.proto b/protocol/src/pbuf/message_c2s.proto new file mode 100644 index 0000000000000000000000000000000000000000..ee8f4d078bd4b69ff92ff280b5e0b5291ff9335d --- /dev/null +++ b/protocol/src/pbuf/message_c2s.proto @@ -0,0 +1,29 @@ +syntax = "proto3"; +package protocol.messagec2s; + +import "state.proto"; +import "goodbye_reason.proto"; + +message MessageC2SHello { + enum packet_info { unknown = 0; type = 0x01; } + + uint32 version = 1; // Version of the protocol. Currently always 1 + string requested_username = 2; // The username that the client is requesting. + State next_state = 3; // The state the connection will go into after the handshake. +} + +message MessageC2SGoodbye { + enum packet_info { unknown = 0; type = 0x02; } + + GoodbyeReason reason = 1; // The reason the client is disconnecting the server +} + +message MessageC2SChat { + enum packet_info { unknown = 0; type = 0x03; } + + string message = 1; // The chat message to sent +} + +message MessageC2SPing { + enum packet_info { unknown = 0; type = 0x04; } +} \ No newline at end of file diff --git a/protocol/src/pbuf/message_s2c.proto b/protocol/src/pbuf/message_s2c.proto new file mode 100644 index 0000000000000000000000000000000000000000..ff90fa0e15706549684819f7a34132ddadb68b50 --- /dev/null +++ b/protocol/src/pbuf/message_s2c.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; +package protocol.message_s2c; + +import "state.proto"; +import "goodbye_reason.proto"; +import "player.proto"; +import "planet.proto"; + +message MessageS2CHello { + enum packet_info { unknown = 0; type = 0x05; } + + uint32 version = 1; // The version of the protocol in use. Currently always 1. + string given_username = 2; // The username actually assigned to the player + State next_state = 3; // The state to switch the game into +} + +message MessageS2CGoodbye { + enum packet_info { unknown = 0; type = 0x06; } + + GoodbyeReason reason = 1; // The reason for the disconnect +} + +message MessageS2CChat { + enum packet_info { unknown = 0; type = 0x07; } + + string from = 1; // The username of the player who sent the message + string message = 2; // The contents of the chat message +} + +message MessageS2CPong { + enum packet_info { unknown = 0; type = 0x08; } +} + +message MessageS2CPlayersUpdate { + enum packet_info { unknown = 0; type = 0x09; } + + repeated Player players = 1; // List of all players in the server +} + +message MessageS2CPlanetData { + enum packet_info { unknown = 0; type = 0x0a; } + + repeated Planet planets = 1; // List of all planets on the server +} \ No newline at end of file diff --git a/protocol/src/pbuf/planet.proto b/protocol/src/pbuf/planet.proto new file mode 100644 index 0000000000000000000000000000000000000000..b85a736ff6d0210a3f8a450912e5dd03f8a1b60c --- /dev/null +++ b/protocol/src/pbuf/planet.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; +package protocol.planet; + +message Planet { + PlanetType type = 1; // Type of the planet + float x = 2; // Translation on the X axis, in game units + float y = 3; // Translation on the Y axis, in game units + float radius = 4; // The radius of the planet extending out from (x, y) +} + +enum PlanetType { + Earth = 0; +} \ No newline at end of file diff --git a/protocol/src/pbuf/player.proto b/protocol/src/pbuf/player.proto new file mode 100644 index 0000000000000000000000000000000000000000..d2b8359f6c7b787f98bc80c1f149e893e750f961 --- /dev/null +++ b/protocol/src/pbuf/player.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package protocol.player; + +message Player { + float rotation = 1; // The rotation, clockwise, in degrees, of the player + float x = 2; // The translation on the X axis, in game units, of the player + float y = 3; // The translation on the Y axis, in game units, of the player + string username = 4; // The username of the player +} \ No newline at end of file diff --git a/protocol/src/pbuf/starkingdoms-protocol.proto b/protocol/src/pbuf/starkingdoms-protocol.proto new file mode 100644 index 0000000000000000000000000000000000000000..9381472753e448ea9c4133b2b81e51e915608e4c --- /dev/null +++ b/protocol/src/pbuf/starkingdoms-protocol.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; +package protocol; + +import public "message_c2s.proto"; +import public "state.proto"; +import public "goodbye_reason.proto"; +import public "message_s2c.proto"; +import public "player.proto"; +import public "planet.proto"; + +message PacketWrapper { + int64 packet_id = 1; // What is the Packet ID of this packet? + bytes packet_data = 2; // Protobuf-encoded bytearray containing the actual packet +} \ No newline at end of file diff --git a/protocol/src/pbuf/state.proto b/protocol/src/pbuf/state.proto new file mode 100644 index 0000000000000000000000000000000000000000..fb8b36f9cb5b69a7b9bbba07e5da15e680ce9079 --- /dev/null +++ b/protocol/src/pbuf/state.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; +package protocol.state; + +import "state.proto"; + +enum State { + Handshake = 0; + Play = 1; +} \ No newline at end of file