Skip to content

Commit ed77eda

Browse files
authored
improve check for active players (#140)
1 parent d389434 commit ed77eda

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

internal/gameServer/server.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ func (g *GameServer) isConnClosed(err error) bool {
9494
}
9595

9696
func (g *GameServer) bufferHealthAverage(playerNumber int) (float32, error) {
97-
var bufferHealth float32
9897
if g.GameData.BufferHealth[playerNumber].Len() > 0 {
98+
var bufferHealth float32
9999
for _, k := range g.GameData.BufferHealth[playerNumber].Keys() {
100100
value, _ := g.GameData.BufferHealth[playerNumber].Peek(k)
101101
bufferHealth += float32(value)
@@ -115,20 +115,22 @@ func (g *GameServer) ManageBuffer() {
115115

116116
// Find the largest buffer health
117117
var bufferHealth float32
118-
var foundPlayer bool
118+
var activePlayers bool
119119
g.GameDataMutex.Lock() // BufferHealth can be modified by processUDP in a different thread
120120
for i := range 4 {
121121
if g.GameData.CountLag[i] == 0 {
122122
playerBufferHealth, err := g.bufferHealthAverage(i)
123-
if err == nil && playerBufferHealth > bufferHealth {
123+
if err == nil {
124+
activePlayers = true
125+
}
126+
if playerBufferHealth > bufferHealth {
124127
bufferHealth = playerBufferHealth
125-
foundPlayer = true
126128
}
127129
}
128130
}
129131
g.GameDataMutex.Unlock()
130132

131-
if foundPlayer {
133+
if activePlayers {
132134
if bufferHealth > float32(g.BufferTarget)+0.5 && g.GameData.BufferSize > 0 {
133135
g.GameData.BufferSize--
134136
g.Logger.Info("reduced buffer size", "bufferHealth", bufferHealth, "bufferSize", g.GameData.BufferSize)

0 commit comments

Comments
 (0)