Skip to content

Commit

Permalink
Prevent announcement duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
rkfg committed Nov 7, 2020
1 parent 27042fd commit 5f888dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type ns2server struct {
players []string
serverState state
maxStateToMessage state
lastStateAnnounced state
lastStatePromotion time.Time
currentMap string
avgSkill int
Expand Down
28 changes: 16 additions & 12 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ func maybeNotify(srv *ns2server, sendChan chan string) {
if newState > srv.serverState && newState <= srv.maxStateToMessage {
srv.lastStatePromotion = time.Now()
srv.serverState = newState
switch newState {
case seedingstarted:
sendChan <- fmt.Sprintf("%s [%s] started seeding! Skill: %d. There are %d players there currently: %s",
srv.Name, srv.currentMap, srv.avgSkill, len(srv.players), srv.playersString())
srv.maxStateToMessage = specsonly
case almostfull:
sendChan <- fmt.Sprintf("%s [%s] is almost full! Skill: %d. There are %d players there currently",
srv.Name, srv.currentMap, srv.avgSkill, len(srv.players))
case specsonly:
srv.maxStateToMessage = seedingstarted
sendChan <- fmt.Sprintf("%s [%s] is full but you can still make it! Skill: %d. There are %d spectator slots available currently",
srv.Name, srv.currentMap, srv.avgSkill, srv.PlayerSlots+srv.SpecSlots-len(srv.players))
if srv.lastStateAnnounced != newState {
srv.lastStateAnnounced = newState
switch newState {
case seedingstarted:
sendChan <- fmt.Sprintf("%s [%s] started seeding! Skill: %d. There are %d players there currently: %s",
srv.Name, srv.currentMap, srv.avgSkill, len(srv.players), srv.playersString())
srv.maxStateToMessage = specsonly
case almostfull:
sendChan <- fmt.Sprintf("%s [%s] is almost full! Skill: %d. There are %d players there currently",
srv.Name, srv.currentMap, srv.avgSkill, len(srv.players))
case specsonly:
srv.maxStateToMessage = seedingstarted
sendChan <- fmt.Sprintf("%s [%s] is full but you can still make it! Skill: %d. There are %d spectator slots available currently",
srv.Name, srv.currentMap, srv.avgSkill, srv.PlayerSlots+srv.SpecSlots-len(srv.players))
}
}
} else {
if time.Since(srv.lastStatePromotion).Seconds() > float64(config.Seeding.Cooldown) {
Expand All @@ -55,6 +58,7 @@ func query(srv *ns2server, sendChan chan string) error {
srv.currentMap = "<unknown>"
srv.avgSkill = 0
srv.maxStateToMessage = full
srv.lastStateAnnounced = empty
for {
info, err := client.QueryInfo()
if err != nil {
Expand Down

0 comments on commit 5f888dd

Please sign in to comment.