diff --git a/backend/internal/ws/results.go b/backend/internal/ws/results.go index 50005c5..0605a28 100644 --- a/backend/internal/ws/results.go +++ b/backend/internal/ws/results.go @@ -91,12 +91,12 @@ func (s *serverImpl) Results(gameId string) { s.logger.Debugw("radelci dodani vsem udeležencem igre") go func() { - for i := 0; i <= 10; i++ { + for i := 0; i <= 15; i++ { s.Broadcast( "", gameId, &messages.Message{ - Data: &messages.Message_GameStartCountdown{GameStartCountdown: &messages.GameStartCountdown{Countdown: int32(10 - i)}}, + Data: &messages.Message_GameStartCountdown{GameStartCountdown: &messages.GameStartCountdown{Countdown: int32(15 - i)}}, }, ) time.Sleep(time.Second) @@ -113,7 +113,14 @@ func (s *serverImpl) Results(gameId string) { } } if (game.GameCount == game.GamesRequired || game.GamesRequired == -1) && !game.Replay { - if game.VotedAdditionOfGames <= 0 && game.GamesRequired != -1 { + noClients := 0 + for _, v := range game.Players { + if !v.GetBotStatus() && len(v.GetClients()) == 0 { + noClients++ + } + } + + if noClients > 0 || (game.VotedAdditionOfGames <= 0 && game.GamesRequired != -1) { s.EndGame(gameId) return } diff --git a/backend/internal/ws/server.go b/backend/internal/ws/server.go index 4921a20..9b721c7 100644 --- a/backend/internal/ws/server.go +++ b/backend/internal/ws/server.go @@ -536,6 +536,7 @@ type GameDescriptor struct { type SimpleUser struct { ID string Name string + Bot bool } func (s *serverImpl) GetGames(userId string) ([]GameDescriptor, []GameDescriptor) { @@ -548,12 +549,10 @@ func (s *serverImpl) GetGames(userId string) ([]GameDescriptor, []GameDescriptor players := make([]SimpleUser, 0) for _, p := range v.Players { - if !p.GetBotStatus() && len(p.GetClients()) == 0 { - continue - } players = append(players, SimpleUser{ ID: p.GetUser().ID, Name: p.GetUser().Name, + Bot: p.GetBotStatus(), }) } desc := GameDescriptor{ @@ -570,8 +569,8 @@ func (s *serverImpl) GetGames(userId string) ([]GameDescriptor, []GameDescriptor NapovedanMondfang: v.NapovedanMondfang, KontraKazen: v.KazenZaKontro, } - if v.Private { - if !helpers.Contains(v.InvitedPlayers, userId) { + if v.Private || v.Started { + if v.Private && !(helpers.Contains(v.InvitedPlayers, userId) || v.Owner == userId) { continue } priorityGames = append(priorityGames, desc) @@ -644,10 +643,6 @@ func (s *serverImpl) sendPlayers(client Client) { sent := make([]string, 0) for _, user := range game.Players { - if len(user.GetClients()) == 0 { - continue - } - if client.GetUserID() == user.GetUser().ID { continue } @@ -671,5 +666,19 @@ func (s *serverImpl) sendPlayers(client Client) { } client.Send(msg) + + if len(user.GetClients()) == 0 { + client.Send(&messages.Message{ + PlayerId: user.GetUser().ID, + Data: &messages.Message_Connection{ + Connection: &messages.Connection{ + Rating: int32(user.GetUser().Rating), + Type: &messages.Connection_Disconnect{ + Disconnect: &messages.Disconnect{}, + }, + }, + }, + }) + } } }