parent
bee5fe4af3
commit
3a57f683ac
|
@ -245,15 +245,7 @@ func (r *Room) HandleConn(ctx context.Context, playerID uuid.UUID, nickname stri
|
||||||
|
|
||||||
g, ctx := errgroup.WithContext(ctx)
|
g, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
setup := func() (success bool) {
|
|
||||||
r.mu.Lock()
|
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.players[playerID] = func(s protocol.ServerNote) {
|
r.players[playerID] = func(s protocol.ServerNote) {
|
||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return
|
return
|
||||||
|
@ -272,12 +264,7 @@ func (r *Room) HandleConn(ctx context.Context, playerID uuid.UUID, nickname stri
|
||||||
}
|
}
|
||||||
r.room.AddPlayer(playerID, nickname)
|
r.room.AddPlayer(playerID, nickname)
|
||||||
r.sendAll()
|
r.sendAll()
|
||||||
return true
|
r.mu.Unlock()
|
||||||
}
|
|
||||||
|
|
||||||
if !setup() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
|
|
Loading…
Reference in New Issue