Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Also check lobbies length in TimeoutPeer store method. #54

Merged
merged 3 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions internal/signaling/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,18 @@ func (p *Peer) HandleJoinPacket(ctx context.Context, packet JoinPacket) error {
if packet.Lobby == "" {
return fmt.Errorf("no lobby code supplied")
}
if len(packet.Lobby) > 20 {
return fmt.Errorf("lobby code too long")
}

p.Lobby = packet.Lobby

p.store.Subscribe(ctx, p.Game+p.Lobby+p.ID, p.ForwardMessage)

others, err := p.store.JoinLobby(ctx, p.Game, p.Lobby, p.ID)
others, err := p.store.JoinLobby(ctx, p.Game, packet.Lobby, p.ID)
if err != nil {
return err
}

p.Lobby = packet.Lobby
p.store.Subscribe(ctx, p.Game+p.Lobby+p.ID, p.ForwardMessage)

err = p.Send(ctx, JoinedPacket{
RequestID: packet.RequestID,
Type: "joined",
Expand Down
8 changes: 7 additions & 1 deletion internal/signaling/stores/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,18 @@ func (s *PostgresStore) ListLobbies(ctx context.Context, game, filter string) ([
}

func (s *PostgresStore) TimeoutPeer(ctx context.Context, peerID, secret, gameID string, lobbies []string) error {

if len(peerID) > 20 {
logger := logging.GetLogger(ctx)
logger.Warn("peer id too long", zap.String("peerID", peerID))
return ErrInvalidPeerID
}
for _, lobby := range lobbies {
if len(lobby) > 20 {
logger := logging.GetLogger(ctx)
logger.Warn("lobby code too long", zap.String("lobbyCode", lobby))
return ErrInvalidLobbyCode
}
}

now := util.Now(ctx)
_, err := s.DB.Exec(ctx, `
Expand Down