~starkingdoms/starkingdoms

4b1217d7b1dbefc6492de9009c8cfd3b6d13bc24 — core 2 years ago b8f880c
start switching to protobuf for the protocol
A protocol/src/pbuf/goodbye_reason.proto => protocol/src/pbuf/goodbye_reason.proto +11 -0
@@ 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

A protocol/src/pbuf/message_c2s.proto => protocol/src/pbuf/message_c2s.proto +29 -0
@@ 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

A protocol/src/pbuf/message_s2c.proto => protocol/src/pbuf/message_s2c.proto +44 -0
@@ 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

A protocol/src/pbuf/planet.proto => protocol/src/pbuf/planet.proto +13 -0
@@ 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

A protocol/src/pbuf/player.proto => protocol/src/pbuf/player.proto +9 -0
@@ 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

A protocol/src/pbuf/starkingdoms-protocol.proto => protocol/src/pbuf/starkingdoms-protocol.proto +14 -0
@@ 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

A protocol/src/pbuf/state.proto => protocol/src/pbuf/state.proto +9 -0
@@ 0,0 1,9 @@
syntax = "proto3";
package protocol.state;

import "state.proto";

enum State {
  Handshake = 0;
  Play = 1;
}
\ No newline at end of file