Skip to content

Commit

Permalink
Set public setting when creating lobby.
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbollen committed Oct 18, 2023
1 parent aac100f commit 4d81ea4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
32 changes: 31 additions & 1 deletion features/lobbies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,44 @@ Feature: Lobby Discovery
Given "green" creates a network for game "f666036d-d9e1-4d70-b0c3-4a68b24a9884"
And "blue" is connected and ready for game "f666036d-d9e1-4d70-b0c3-4a68b24a9884"

When "blue" creates a lobby
When "blue" creates a lobby with these settings:
"""
{
"public": true
}
"""
And "blue" receives the network event "lobby" with the argument "prb67ouj837u"

When "green" requests all lobbies
Then "green" should have received only these lobbies
| code | playerCount |
| prb67ouj837u | 1 |

Scenario: Only list public lobbies
Given "green" creates a network for game "f666036d-d9e1-4d70-b0c3-4a68b24a9884"
And "blue" is connected and ready for game "f666036d-d9e1-4d70-b0c3-4a68b24a9884"
And "yellow" is connected and ready for game "f666036d-d9e1-4d70-b0c3-4a68b24a9884"

When "blue" creates a lobby with these settings:
"""
{
"public": true
}
"""
And "blue" receives the network event "lobby" with the argument "dhgp75mn2bll"
And "yellow" creates a lobby with these settings:
"""
{
"public": false
}
"""
And "yellow" receives the network event "lobby" with the argument "1qva9vyurwbbl"

When "green" requests all lobbies
Then "green" should have received only these lobbies
| code | playerCount |
| dhgp75mn2bll | 1 |




Expand Down
2 changes: 1 addition & 1 deletion internal/signaling/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (p *Peer) HandleCreatePacket(ctx context.Context, packet CreatePacket) erro
p.Lobby = util.GenerateLobbyCode(ctx)
}

err := p.store.CreateLobby(ctx, p.Game, p.Lobby, p.ID)
err := p.store.CreateLobby(ctx, p.Game, p.Lobby, p.ID, packet.Public)
if err != nil {
if err == stores.ErrLobbyExists {
continue
Expand Down
6 changes: 3 additions & 3 deletions internal/signaling/stores/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (s *PostgresStore) Publish(ctx context.Context, topic string, data []byte)
return nil
}

func (s *PostgresStore) CreateLobby(ctx context.Context, game, lobbyCode, peerID string) error {
func (s *PostgresStore) CreateLobby(ctx context.Context, game, lobbyCode, peerID string, public bool) error {
if len(lobbyCode) > 20 {
logger := logging.GetLogger(ctx)
logger.Warn("lobby code too long", zap.String("lobbyCode", lobbyCode))
Expand All @@ -154,9 +154,9 @@ func (s *PostgresStore) CreateLobby(ctx context.Context, game, lobbyCode, peerID
now := util.Now(ctx)
res, err := s.DB.Exec(ctx, `
INSERT INTO lobbies (code, game, public, created_at, updated_at)
VALUES ($1, $2, true, $3, $3)
VALUES ($1, $2, $3, $4, $4)
ON CONFLICT DO NOTHING
`, lobbyCode, game, now)
`, lobbyCode, game, public, now)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/signaling/stores/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var ErrInvalidPeerID = errors.New("invalid peer id")
type SubscriptionCallback func(context.Context, []byte)

type Store interface {
CreateLobby(ctx context.Context, game, lobby, id string) error
CreateLobby(ctx context.Context, game, lobby, id string, public bool) error
JoinLobby(ctx context.Context, game, lobby, id string) ([]string, error)
IsPeerInLobby(ctx context.Context, game, lobby, id string) (bool, error)
LeaveLobby(ctx context.Context, game, lobby, id string) ([]string, error)
Expand Down

0 comments on commit 4d81ea4

Please sign in to comment.