mirror of
https://github.com/tiennm99/gomoku.git
synced 2026-07-30 12:23:15 +00:00
The "Start Game" button in the waiting room is gone — as soon as a second player joins a PVP room, the server flips to Playing and both clients transition into the game in lockstep. Server: - Proto: remove GameStartingRequest message + oneof field (now unused). - state/home.go handleJoinRoom: after a successful join that fills the room, call assignColors, set Status=Playing + CurrentTurn=Black, close StartCh, broadcast GameStartingResponse, return StateGamePvp for the joining player. If still only one player, return StateWaiting as before. - state/waiting.go: collapse ownerWait + joinerWait into a single unified loop. Both roles just select on StartCh (auto-start signal) and CmdCh (for ClientExit). No more GameStartingRequest handling or PlayerCount checks. - network/dispatch.go: drop Request_GameStarting from the stateful routing list. Client: - connection-service.js: remove sendGameStarting() helper. - menu-ui-rooms.js showWaiting: drop the isOwner parameter + Start Game button + owner/joiner branching. Both views show the same passive 'Waiting for opponent...' message that flips to 'Opponent joined: <name> - starting game...' when the second player arrives. - menu-scene.js: update _onRoomCreateSuccess + _onRoomJoinSuccess to call the simpler showWaiting(ownerNickname, playerCount, onLeave) signature. Tests: - Remove TestWaitingOwnerGameStartingRequiresFullRoom (obsolete). - Rewrite TestWaitingOwnerStartsWhenFull into TestWaitingOwner TransitionsOnStartCh: simulate handleJoinRoom closing StartCh, verify owner transitions to StateGamePvp. - Add TestFlow_JoinAutoStartsGame: end-to-end drive where owner is in waitingState, joiner sends JoinRoomRequest from home, and both goroutines must land in StateGamePvp with colors assigned and GameStartingResponse broadcast. Regen Go + JS proto stubs. go vet + go test ./... green. npm --prefix client run build green.
44 lines
1.4 KiB
Protocol Buffer
44 lines
1.4 KiB
Protocol Buffer
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.
|
|
//
|
|
// Note: PVP games auto-start as soon as a second player joins — there is no
|
|
// explicit "Start Game" request from the owner. Room creation + join is
|
|
// enough to begin the game.
|
|
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;
|
|
GameMoveRequest game_move = 8;
|
|
GameResetRequest game_reset = 9;
|
|
WatchGameRequest watch_game = 10;
|
|
WatchGameExitRequest watch_game_exit = 11;
|
|
ClientExitRequest client_exit = 12;
|
|
}
|
|
}
|
|
|
|
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 GameMoveRequest {
|
|
int32 row = 1;
|
|
int32 col = 2;
|
|
}
|
|
message GameResetRequest {}
|
|
message WatchGameRequest { int32 room_id = 1; }
|
|
message WatchGameExitRequest {}
|
|
message ClientExitRequest {}
|