From 61221bddeab074fd469699bc520507822de5415e Mon Sep 17 00:00:00 2001 From: mkwcat Date: Tue, 12 Dec 2023 04:28:48 -0500 Subject: [PATCH] GPCM: Notify QR2 of status update --- gpcm/friend.go | 10 ++++++---- gpcm/main.go | 5 ++++- qr2/group.go | 25 +++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/gpcm/friend.go b/gpcm/friend.go index a327943..730d50b 100644 --- a/gpcm/friend.go +++ b/gpcm/friend.go @@ -109,19 +109,21 @@ func (g *GameSpySession) authAddFriend(command common.GameSpyCommand) { } func (g *GameSpySession) setStatus(command common.GameSpyCommand) { - // TODO: Some games don't make it obvious to QR2 when they leave a group, so try checking via a status update - status := command.CommandValue + if g.QR2IP != 0 { + qr2.ProcessGPStatusUpdate(g.QR2IP, status) + } + statstring, ok := command.OtherValues["statstring"] if !ok { - logging.Notice(g.ModuleName, "Missing statstring") + logging.Warn(g.ModuleName, "Missing statstring") statstring = "" } locstring, ok := command.OtherValues["locstring"] if !ok { - logging.Notice(g.ModuleName, "Missing locstring") + logging.Warn(g.ModuleName, "Missing locstring") locstring = "" } diff --git a/gpcm/main.go b/gpcm/main.go index 4ba7c62..d2c11a5 100644 --- a/gpcm/main.go +++ b/gpcm/main.go @@ -82,6 +82,9 @@ func StartServer() { func (g *GameSpySession) closeSession() { if g.LoggedIn { qr2.Logout(g.User.ProfileId) + if g.QR2IP != 0 { + qr2.ProcessGPStatusUpdate(g.QR2IP, "0") + } g.sendLogoutStatus() } @@ -115,7 +118,7 @@ func handleRequest(conn net.Conn) { err := conn.(*net.TCPConn).SetKeepAlive(true) if err != nil { - logging.Notice(session.ModuleName, "Unable to set keepalive (1):", err.Error()) + logging.Notice(session.ModuleName, "Unable to set keepalive:", err.Error()) } payload := common.CreateGameSpyMessage(common.GameSpyCommand{ diff --git a/qr2/group.go b/qr2/group.go index 2667880..ea49b62 100644 --- a/qr2/group.go +++ b/qr2/group.go @@ -95,6 +95,31 @@ func ProcessGPResvOK(cmd common.MatchCommandDataResvOK, senderIP uint64, senderP return processResvOK(moduleName, cmd, from, to) } +func ProcessGPStatusUpdate(senderIP uint64, status string) { + if status == "0" || status == "1" || status == "3" || status == "4" { + mutex.Lock() + defer mutex.Unlock() + + session := sessionByPublicIP[senderIP] + if session == nil || session.GroupPointer == nil { + return + } + + delete(session.GroupPointer.Players, session) + + if len(session.GroupPointer.Players) == 0 { + logging.Notice("QR2", "Deleting group", aurora.Cyan(session.GroupPointer.GroupName)) + delete(groups, session.GroupPointer.GroupName) + } else if session.GroupPointer.Server == session { + logging.Notice("QR2", "Server down in group", aurora.Cyan(session.GroupPointer.GroupName)) + session.GroupPointer.Server = nil + // TODO: Search for new host via dwc_hoststate + } + + session.GroupPointer = nil + } +} + type GroupInfo struct { GroupName string `json:"id"` GameName string `json:"gamename"`