Skip to content

Commit

Permalink
Remove code for fakeJoinPacket on reconnect (#104)
Browse files Browse the repository at this point in the history
This code was added 2 years ago together with the TimeoutManager. It is
currently impossible to leave a lobby while being disconnected, so the
code isn't needed anymore. This code was probably only for backwards
compatibility with existing lobbies when it was deployed.
  • Loading branch information
erikdubbelboer authored Jun 18, 2024
1 parent efab28f commit be5f72a
Showing 1 changed file with 5 additions and 22 deletions.
27 changes: 5 additions & 22 deletions internal/signaling/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,28 +207,11 @@ func (p *Peer) HandleHelloPacket(ctx context.Context, packet HelloPacket) error
logger.Info("peer connecting", zap.String("game", p.Game), zap.String("peer", p.ID))
}

if hasReconnected && len(reconnectingLobbies) > 0 && reconnectingLobbies[0] != "" {
lobby := reconnectingLobbies[0]
inLobby, err := p.store.IsPeerInLobby(ctx, p.Game, lobby, p.ID)
if err != nil {
return err
}
if inLobby {
logger.Info("peer rejoining lobby", zap.String("game", p.Game), zap.String("peer", p.ID), zap.String("lobby", p.Lobby))
p.Lobby = lobby
p.store.Subscribe(ctx, p.Game+p.Lobby+p.ID, p.ForwardMessage)
go metrics.Record(ctx, "lobby", "reconnected", p.Game, p.ID, p.Lobby)
} else {
fakeJoinPacket := JoinPacket{
Type: "join",
Lobby: lobby,
}
err := p.HandleJoinPacket(ctx, fakeJoinPacket)
if err != nil {
return err
}
go metrics.Record(ctx, "lobby", "joined", p.Game, p.ID, p.Lobby)
}
if hasReconnected && len(reconnectingLobbies) > 0 {
p.Lobby = reconnectingLobbies[0]
p.store.Subscribe(ctx, p.Game+p.Lobby+p.ID, p.ForwardMessage)
go metrics.Record(ctx, "lobby", "reconnected", p.Game, p.ID, p.Lobby)
logger.Info("peer rejoining lobby", zap.String("game", p.Game), zap.String("peer", p.ID), zap.String("lobby", p.Lobby))
}

return p.Send(ctx, WelcomePacket{
Expand Down

0 comments on commit be5f72a

Please sign in to comment.