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