From 311eda1055642c3116dff02e917d0cc58fca1569 Mon Sep 17 00:00:00 2001 From: mkwcat Date: Sat, 30 Dec 2023 19:00:00 -0500 Subject: [PATCH] GPCM: Disconnect other session on second login --- gpcm/login.go | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/gpcm/login.go b/gpcm/login.go index 85eb81c..19c619f 100644 --- a/gpcm/login.go +++ b/gpcm/login.go @@ -203,12 +203,28 @@ func (g *GameSpySession) login(command common.GameSpyCommand) { // Check to see if a session is already open with this profile ID mutex.Lock() - _, exists := sessions[g.User.ProfileId] + otherSession, exists := sessions[g.User.ProfileId] if exists { - mutex.Unlock() - // TODO: Kick the other client, not this one - g.replyError(ErrForcedDisconnect) - return + otherSession.replyError(ErrForcedDisconnect) + otherSession.Conn.Close() + + for i := 0; ; i++ { + mutex.Unlock() + time.Sleep(300 * time.Millisecond) + mutex.Lock() + + if _, exists = sessions[g.User.ProfileId]; !exists { + break + } + + // Give up after 6 seconds + if i >= 20 { + mutex.Unlock() + logging.Error(g.ModuleName, "Failed to disconnect other session") + g.replyError(ErrForcedDisconnect) + return + } + } } sessions[g.User.ProfileId] = g mutex.Unlock()