Skip to content

Commit

Permalink
Allow seeding messages after server becomes empty
Browse files Browse the repository at this point in the history
  • Loading branch information
rkfg committed Nov 8, 2020
1 parent e5e102c commit e29f4df
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func maybeNotify(srv *ns2server, sendChan chan string) {
} else {
if time.Since(srv.lastStatePromotion).Seconds() > float64(config.Seeding.Cooldown) {
srv.serverState = newState
if newState == empty {
// if the server goes empty we should allow seeding messages again
srv.lastStateAnnounced = empty
}
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ func TestNotification(t *testing.T) {
notif(t, srv, "")
srv.players = fillPlayers(4)
notif(t, srv, "Test [test] started seeding! Skill: 0. There are 4 players there currently: 1, 2, 3, 4")
// test demotion
// test demotion without cooldown
srv.players = fillPlayers(3)
notif(t, srv, "")
srv.players = fillPlayers(5)
notif(t, srv, "")
notif(t, srv, "") // no messages after quick demotion
passTime(srv)
notif(t, srv, "")
srv.players = fillPlayers(13)
Expand Down Expand Up @@ -98,4 +98,9 @@ func TestNotification(t *testing.T) {
notif(t, srv, "") // server became empty, seeding messages enabled again
srv.players = fillPlayers(4)
notif(t, srv, "Test [test] started seeding! Skill: 0. There are 4 players there currently: 1, 2, 3, 4")
srv.players = fillPlayers(3)
passTime(srv)
notif(t, srv, "") // server became empty
srv.players = fillPlayers(4)
notif(t, srv, "Test [test] started seeding! Skill: 0. There are 4 players there currently: 1, 2, 3, 4") // server is seeding again
}

0 comments on commit e29f4df

Please sign in to comment.