GPCM: Notify QR2 of status update

This commit is contained in:
mkwcat
2023-12-12 04:28:48 -05:00
parent a7d21b052e
commit 61221bddea
3 changed files with 35 additions and 5 deletions

View File

@@ -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 = ""
}

View File

@@ -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{

View File

@@ -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"`