Skip to content

Commit

Permalink
implemented deadline, on each turn timeout player 20 sec. fixed #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Longwater1234 committed Sep 14, 2024
1 parent dc71795 commit 4a0f99c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions room/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func RunMatch(p1 *player.Player, p2 *player.Player, gameOver chan bool) {
if isPlayerRedTurn {
// ============= IT'S PLAYER 1 (RED's) TURN =============//
var rawBytes []byte
p1.Conn.SetReadDeadline(time.Now().Add(time.Second * 20))
if err := websocket.Message.Receive(p1.Conn, &rawBytes); err != nil {
log.Println(p1.Name, "disconnected. Cause:", err)
p2.SendMessage(&game.BasePayload{
Expand Down Expand Up @@ -102,6 +103,7 @@ func RunMatch(p1 *player.Player, p2 *player.Player, gameOver chan bool) {
} else if !isPlayerRedTurn {
// ============= IT'S PLAYER 2 (BLACK's) TURN =============//
var rawBytes []byte
p2.Conn.SetReadDeadline(time.Now().Add(time.Second * 20))
if err := websocket.Message.Receive(p2.Conn, &rawBytes); err != nil {
log.Println(p2.Name, "disconnected. Cause:", err.Error())
p1.SendMessage(&game.BasePayload{
Expand Down

0 comments on commit 4a0f99c

Please sign in to comment.