From 92a9180ed2bbf6287cc95fa3b4d30cfccdb8bc9c Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Wed, 21 Aug 2024 11:04:55 -0700 Subject: [PATCH] Send match list automatically --- pkg/server/server.go | 17 +++++++++++++++++ pkg/server/server_command.go | 19 ++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pkg/server/server.go b/pkg/server/server.go index 353fdef..31a016c 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -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() diff --git a/pkg/server/server_command.go b/pkg/server/server_command.go index f537298..fe77bad 100644 --- a/pkg/server/server_command.go +++ b/pkg/server/server_command.go @@ -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."))