Skip to content

Commit

Permalink
Merge pull request #50 from Longwater1234/dev
Browse files Browse the repository at this point in the history
Remove dangerous actions
  • Loading branch information
Longwater1234 authored Jan 18, 2025
2 parents ea76d0f + 2d83f8e commit 3d65760
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"golang.org/x/net/websocket"
)

const SERVER_VERSION = "1.0.9"
const ServerVersion = "1.0.9"
const maxRequestSize int = 1 << 10 // 1KB

var numPlayers atomic.Uint32 // total number of LIVE players
Expand Down Expand Up @@ -81,7 +81,7 @@ func listenForJoins() {
Inner: &game.BasePayload_Welcome{
Welcome: &game.WelcomePayload{
MyTeam: game.TeamColor_TEAM_RED,
ServerVersion: SERVER_VERSION,
ServerVersion: ServerVersion,
},
},
}
Expand Down Expand Up @@ -112,7 +112,6 @@ func listenForJoins() {
room.StartMatch(p1, p2, gameOver)
<-gameOver //block until match ends
log.Println("🔴 GAME OVER!")
close(gameOver)
p1.Dead <- true
p2.Dead <- true
}(p1, p2)
Expand Down
6 changes: 4 additions & 2 deletions player/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (p *Player) HasThisPiece(pieceId int32) bool {
return slices.Contains(p.Pieces, pieceId)
}

// StartHeartbeat keeps checking (every second) if this player is still connected (when waiting for opponent)
// StartHeartbeat for checking (every second) if this Player is still connected (when waiting for opponent)
func (p *Player) StartHeartbeat(ctx context.Context) {
tt := time.NewTicker(time.Second)
qq := make(chan bool)
Expand All @@ -60,11 +60,13 @@ func (p *Player) StartHeartbeat(ctx context.Context) {
select {
case <-tt.C:
if err := pingCodec.Send(p.Conn, nil); err != nil {
//This player has quit early
// This player has quit early
qq <- true
close(qq)
return
}
case <-ctx.Done():
// timeout waiting for [p2] expired
tt.Stop()
return
}
Expand Down
3 changes: 2 additions & 1 deletion room/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func generateGameMap(p1 *player.Player, p2 *player.Player) map[int32]*game.Piece
return gameMap
}

// generatePieces using Secure RNG for both player 1 (RED) and player 2 (BLACK)
// generatePieces using secure RNG for the two players. If an error occurs,
// it sends a signal to the `gameOver` channel and panics.
func generatePieces(p1 *player.Player, p2 *player.Player, gameOver chan<- bool) {
bigMax := big.NewInt(int64(upperLimit))
for i := 0; i < len(p1.Pieces); i++ {
Expand Down

0 comments on commit 3d65760

Please sign in to comment.