From bb799da2c53eeb85619ce42125ba73a3b7474ce7 Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Sat, 11 Apr 2026 12:40:45 +0700 Subject: [PATCH] feat(proto): port caro protobuf schemas with com.miti99.gomoku.proto namespace Copies request.proto and response.proto from caro, renames package to com.miti99.gomoku.proto, drops Java options, adds go_package option, and appends SpectatorCannotActResponse (field 21) to the Response oneof. --- common/proto/.gitkeep | 0 common/proto/request.proto | 43 +++++++++++++ common/proto/response.proto | 121 ++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+) delete mode 100644 common/proto/.gitkeep create mode 100644 common/proto/request.proto create mode 100644 common/proto/response.proto diff --git a/common/proto/.gitkeep b/common/proto/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/common/proto/request.proto b/common/proto/request.proto new file mode 100644 index 0000000..f1e3e04 --- /dev/null +++ b/common/proto/request.proto @@ -0,0 +1,43 @@ +syntax = "proto3"; + +package com.miti99.gomoku.proto; + +option go_package = "github.com/tiennm99/gomoku/server/protocol;protocol"; + +// Wrapper for all client -> server messages. The oneof case IS the event code. +message Request { + oneof payload { + HeartbeatRequest heartbeat = 1; + SetNicknameRequest set_nickname = 2; + SetClientInfoRequest set_client_info = 3; + CreateRoomRequest create_room = 4; + CreatePveRoomRequest create_pve_room = 5; + GetRoomsRequest get_rooms = 6; + JoinRoomRequest join_room = 7; + GameStartingRequest game_starting = 8; + GameReadyRequest game_ready = 9; + GameMoveRequest game_move = 10; + GameResetRequest game_reset = 11; + WatchGameRequest watch_game = 12; + WatchGameExitRequest watch_game_exit = 13; + ClientExitRequest client_exit = 14; + } +} + +message HeartbeatRequest {} +message SetNicknameRequest { string nickname = 1; } +message SetClientInfoRequest { string version = 1; } +message CreateRoomRequest {} +message CreatePveRoomRequest { int32 difficulty = 1; } +message GetRoomsRequest {} +message JoinRoomRequest { int32 room_id = 1; } +message GameStartingRequest {} +message GameReadyRequest {} +message GameMoveRequest { + int32 row = 1; + int32 col = 2; +} +message GameResetRequest {} +message WatchGameRequest { int32 room_id = 1; } +message WatchGameExitRequest {} +message ClientExitRequest {} diff --git a/common/proto/response.proto b/common/proto/response.proto new file mode 100644 index 0000000..6a14684 --- /dev/null +++ b/common/proto/response.proto @@ -0,0 +1,121 @@ +syntax = "proto3"; + +package com.miti99.gomoku.proto; + +option go_package = "github.com/tiennm99/gomoku/server/protocol;protocol"; + +// Wrapper for all server -> client messages. The oneof case IS the event code. +message Response { + oneof payload { + ClientConnectResponse client_connect = 1; + NicknameSetResponse nickname_set = 2; + ShowOptionsResponse show_options = 3; + ShowRoomsResponse show_rooms = 4; + RoomCreateSuccessResponse room_create_success = 5; + RoomJoinSuccessResponse room_join_success = 6; + RoomJoinFailFullResponse room_join_fail_full = 7; + RoomJoinFailNotFoundResponse room_join_fail_not_found = 8; + RoomPlayFailNotFoundResponse room_play_fail_not_found = 9; + GameStartingResponse game_starting = 10; + GameReadyResponse game_ready = 11; + GameMoveSuccessResponse game_move_success = 12; + GameMoveInvalidResponse game_move_invalid = 13; + GameMoveOccupiedResponse game_move_occupied = 14; + GameMoveOutOfBoundsResponse game_move_out_of_bounds = 15; + GameMoveNotYourTurnResponse game_move_not_your_turn = 16; + GameOverResponse game_over = 17; + PveDifficultyNotSupportResponse pve_difficulty_not_support = 18; + WatchGameSuccessResponse watch_game_success = 19; + ClientExitResponse client_exit = 20; + SpectatorCannotActResponse spectator_cannot_act = 21; + } +} + +message ClientConnectResponse { int32 client_id = 1; } + +// invalid_length = 0 means "prompt only — ask the user for a nickname" +message NicknameSetResponse { int32 invalid_length = 1; } + +message ShowOptionsResponse {} + +message RoomSummary { + int32 room_id = 1; + string room_owner = 2; + int32 room_client_count = 3; + string room_type = 4; +} + +message ShowRoomsResponse { repeated RoomSummary rooms = 1; } + +message RoomCreateSuccessResponse { + int32 id = 1; + string room_owner = 2; + string room_type = 3; +} + +message RoomJoinSuccessResponse { + int32 client_id = 1; + string client_nickname = 2; + int32 room_id = 3; + string room_owner = 4; + int32 room_client_count = 5; +} + +message RoomJoinFailFullResponse { + int32 room_id = 1; + string room_owner = 2; +} + +message RoomJoinFailNotFoundResponse { int32 room_id = 1; } + +message RoomPlayFailNotFoundResponse {} + +message GameStartingResponse { + int32 room_id = 1; + int32 black_player_id = 2; + string black_player_nickname = 3; + int32 white_player_id = 4; + string white_player_nickname = 5; + int32 board_size = 6; +} + +message GameReadyResponse { + string client_nickname = 1; + string status = 2; + int32 client_id = 3; +} + +message GameMoveSuccessResponse { + int32 row = 1; + int32 col = 2; + string piece = 3; + string player_nickname = 4; + int32 player_id = 5; +} + +message GameMoveInvalidResponse {} +message GameMoveOccupiedResponse {} +message GameMoveOutOfBoundsResponse {} +message GameMoveNotYourTurnResponse {} + +message GameOverResponse { + string result = 1; + string winner_nickname = 2; +} + +message PveDifficultyNotSupportResponse {} + +message WatchGameSuccessResponse { + string owner = 1; + string status = 2; +} + +message ClientExitResponse { + int32 room_id = 1; + int32 exit_client_id = 2; + string exit_client_nickname = 3; +} + +// Sent when a spectator attempts an action that requires being a player. +// Phase-07 dispatch sends this in response to GameMoveRequest from a spectator. +message SpectatorCannotActResponse {}