From 3a57f683acf3b2be2c1180dfc438efa273dd1db6 Mon Sep 17 00:00:00 2001 From: zikaeroh <48577114+zikaeroh@users.noreply.github.com> Date: Sun, 14 Jun 2020 12:33:07 -0700 Subject: [PATCH] Revert "Reject duplicate client IDs" This reverts commit bee5fe4af30060dd39f9d52847545a3a58fe6646. --- internal/server/server.go | 43 ++++++++++++++------------------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/internal/server/server.go b/internal/server/server.go index 9af0bce..b0cd311 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -245,39 +245,26 @@ func (r *Room) HandleConn(ctx context.Context, playerID uuid.UUID, nickname stri g, ctx := errgroup.WithContext(ctx) - setup := func() (success bool) { - r.mu.Lock() - defer r.mu.Unlock() - - if _, ok := r.players[playerID]; ok { - ctxlog.Warn(ctx, "client with this ID already exists") - return false + r.mu.Lock() + r.players[playerID] = func(s protocol.ServerNote) { + if ctx.Err() != nil { + return } - r.players[playerID] = func(s protocol.ServerNote) { - if ctx.Err() != nil { + // It's not safe to start more group goroutines concurrently; just use a regular + // goroutine and hope that errors here will be reflected later via ping/receive failures. + go func() { + ctx, cancel := context.WithTimeout(ctx, time.Second) + defer cancel() + if err := wsjson.Write(ctx, c, &s); err != nil { return } - - // It's not safe to start more group goroutines concurrently; just use a regular - // goroutine and hope that errors here will be reflected later via ping/receive failures. - go func() { - ctx, cancel := context.WithTimeout(ctx, time.Second) - defer cancel() - if err := wsjson.Write(ctx, c, &s); err != nil { - return - } - metricSent.Inc() - }() - } - r.room.AddPlayer(playerID, nickname) - r.sendAll() - return true - } - - if !setup() { - return + metricSent.Inc() + }() } + r.room.AddPlayer(playerID, nickname) + r.sendAll() + r.mu.Unlock() defer func() { r.mu.Lock()