From 07d8f3d079d8f7871cfa5addd88c4d0e01b7a369 Mon Sep 17 00:00:00 2001 From: mkwcat Date: Tue, 23 Jan 2024 17:20:33 -0500 Subject: [PATCH] QR2: Kick player on message ack timeout --- gpcm/kick.go | 5 +++++ gpcm/login.go | 1 + qr2/message.go | 21 ++++++++++++++++----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/gpcm/kick.go b/gpcm/kick.go index 0fd0f76..b37bd5c 100644 --- a/gpcm/kick.go +++ b/gpcm/kick.go @@ -22,6 +22,11 @@ func kickPlayer(profileID uint32, reason string) { case "invalid_elo": errorMessage = WWFCMsgInvalidELO + + case "network_error": + // No error message + session.Conn.Close() + return } session.replyError(GPError{ diff --git a/gpcm/login.go b/gpcm/login.go index 79b53e9..2549024 100644 --- a/gpcm/login.go +++ b/gpcm/login.go @@ -154,6 +154,7 @@ func (g *GameSpySession) login(command common.GameSpyCommand) { deviceId := uint32(0) g.GameName = command.OtherValues["gamename"] + logging.Info(g.ModuleName, "Game name:", aurora.Cyan(g.GameName)) g.GameCode = gamecd g.Region = region g.Language = lang diff --git a/qr2/message.go b/qr2/message.go index c653a27..89d7792 100644 --- a/qr2/message.go +++ b/qr2/message.go @@ -235,6 +235,10 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) { payload = append(payload, message...) receiver.MessageMutex.Lock() + if receiver.Login == nil { + receiver.MessageMutex.Unlock() + return + } s := sleep.Sleeper{} s.AddWaker(&receiver.MessageAckWaker) @@ -257,12 +261,19 @@ func SendClientMessage(senderIP string, destSearchID uint64, message []byte) { switch s.Fetch(true) { case &timeWaker: timeOutCount++ - if timeOutCount > 8 { - logging.Error(moduleName, "Timed out waiting for ack") - receiver.MessageMutex.Unlock() - return + if timeOutCount <= 8 { + break } - break + + logging.Error(moduleName, "Timed out waiting for ack") + // Kick the player + if login := receiver.Login; login != nil { + login.GPErrorCallback(login.ProfileID, "network_error") + receiver.Login = nil + } + + receiver.MessageMutex.Unlock() + return default: receiver.MessageMutex.Unlock()