Send match list automatically

This commit is contained in:
Trevor Slocum 2024-08-21 11:04:55 -07:00
parent 591a96d2e5
commit 92a9180ed2
2 changed files with 23 additions and 13 deletions

View file

@ -258,6 +258,7 @@ func (s *server) removeClient(c *serverClient) {
}
}
// Send followed player notifications.
if c.accountID > 0 {
for _, sc := range s.clients {
if sc.accountID <= 0 {
@ -468,6 +469,22 @@ func (s *server) sendMOTD(c *serverClient) {
c.sendNotice(motd)
}
func (s *server) sendMatchList(c *serverClient) {
ev := &bgammon.EventList{}
s.gamesLock.RLock()
for _, g := range s.games {
listing := g.listing(c.name)
if listing == nil {
continue
}
ev.Games = append(ev.Games, *listing)
}
s.gamesLock.RUnlock()
c.sendEvent(ev)
}
func (s *server) gameByClient(c *serverClient) *serverGame {
s.gamesLock.RLock()
defer s.gamesLock.RUnlock()

View file

@ -198,6 +198,9 @@ func (s *server) handleFirstCommand(cmd serverCommand, keyword string, params []
})
}
// Send match list.
s.sendMatchList(cmd.client)
// Send message of the day.
s.sendMOTD(cmd.client)
@ -218,6 +221,7 @@ func (s *server) handleFirstCommand(cmd serverCommand, keyword string, params []
}
}
// Send followed player notifications.
c := cmd.client
if c.accountID != 0 {
s.clientsLock.Lock()
@ -312,6 +316,7 @@ COMMANDS:
continue
}
cmd := cmd
go func() {
time.Sleep(500 * time.Millisecond)
s.commands <- cmd
@ -390,19 +395,7 @@ COMMANDS:
}
}
case bgammon.CommandList, "ls":
ev := &bgammon.EventList{}
s.gamesLock.RLock()
for _, g := range s.games {
listing := g.listing(cmd.client.name)
if listing == nil {
continue
}
ev.Games = append(ev.Games, *listing)
}
s.gamesLock.RUnlock()
cmd.client.sendEvent(ev)
s.sendMatchList(cmd.client)
case bgammon.CommandCreate, "c":
if clientGame != nil {
cmd.client.sendNotice(gotext.GetD(cmd.client.language, "Failed to create match: Please leave the match you are in before creating another."))