GPCM: Disconnect other session on second login

This commit is contained in:
mkwcat 2023-12-30 19:00:00 -05:00
parent 2ee1a1de9d
commit 311eda1055
No known key found for this signature in database
GPG Key ID: 7A505679CE9E7AA9

View File

@ -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()