refactor: 优化Steam游戏状态检查逻辑
This commit is contained in:
parent
db054c6a70
commit
300fdbd957
@ -315,15 +315,30 @@ func checkDiffSteamGameStatus(steamID []string, lastTimeStat map[string]string)
|
|||||||
return nil, nil, glbErr
|
return nil, nil, glbErr
|
||||||
}
|
}
|
||||||
gameStatusListStr := map[string]string{}
|
gameStatusListStr := map[string]string{}
|
||||||
|
currentGameStatus := map[string]string{} // 用于记录当前所有玩家的游戏状态
|
||||||
|
|
||||||
for _, userState := range Players {
|
for _, userState := range Players {
|
||||||
if lastTimeStat[userState.SteamID] == userState.GameID {
|
if userState.GameID != "" {
|
||||||
continue
|
currentGameStatus[userState.SteamID] = userState.GameID
|
||||||
|
// 只有当玩家的游戏状态发生变化时才添加到通知列表
|
||||||
|
if lastGameID, exists := lastTimeStat[userState.SteamID]; !exists || lastGameID != userState.GameID {
|
||||||
|
if userState.ToGameStatus() != "" {
|
||||||
|
gameStatusListStr[userState.SteamID] = userState.ToGameStatus()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if userState.ToGameStatus() != "" {
|
|
||||||
gameStatusListStr[userState.SteamID] = userState.ToGameStatus()
|
|
||||||
}
|
|
||||||
lastTimeStat[userState.SteamID] = userState.GameID
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否有玩家退出游戏
|
||||||
|
for steamID, lastGameID := range lastTimeStat {
|
||||||
|
if lastGameID != "" {
|
||||||
|
if currentGameID, exists := currentGameStatus[steamID]; !exists || currentGameID == "" {
|
||||||
|
// 玩家已退出游戏,不需要添加到通知列表,但需要更新状态
|
||||||
|
currentGameStatus[steamID] = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return gameStatusListStr, Players, nil
|
return gameStatusListStr, Players, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,10 +211,17 @@ func RoundCheckSteamPlaying() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更新退出游戏信息
|
// 更新退出游戏信息
|
||||||
for steamId, oldGameStatus := range playingMap {
|
for steamId := range playingMap {
|
||||||
if newGameStatus, exists := gamePlayingMap[steamId]; !exists {
|
var currentGameID string
|
||||||
// 玩家退出游戏,记录退出信息
|
for _, player := range players {
|
||||||
// 从API响应中获取玩家信息以获取GameID
|
if player.SteamID == steamId {
|
||||||
|
currentGameID = player.GameID
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if currentGameID == "" { // 玩家退出游戏
|
||||||
|
// 从API响应中获取玩家之前的游戏信息
|
||||||
for _, player := range players {
|
for _, player := range players {
|
||||||
if player.SteamID == steamId {
|
if player.SteamID == steamId {
|
||||||
exitInfoMap[steamId] = GameExitInfo{
|
exitInfoMap[steamId] = GameExitInfo{
|
||||||
@ -224,9 +231,18 @@ func RoundCheckSteamPlaying() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if oldGameStatus != newGameStatus {
|
} else { // 玩家在玩游戏
|
||||||
// 玩家切换了游戏,清除退出记录
|
if oldStatus, exists := playingMap[steamId]; exists && oldStatus != currentGameID {
|
||||||
delete(exitInfoMap, steamId)
|
// 玩家切换了游戏,清除退出记录
|
||||||
|
delete(exitInfoMap, steamId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理新上线的玩家
|
||||||
|
for steamId := range gamePlayingMap {
|
||||||
|
if _, exists := playingMap[steamId]; !exists {
|
||||||
|
delete(exitInfoMap, steamId) // 新上线的玩家,清除可能存在的退出记录
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,8 +298,10 @@ func RoundCheckSteamPlaying() {
|
|||||||
|
|
||||||
// 更新playingMap
|
// 更新playingMap
|
||||||
playingMap = make(map[string]string)
|
playingMap = make(map[string]string)
|
||||||
for k, v := range gamePlayingMap {
|
for _, player := range players {
|
||||||
playingMap[k] = v
|
if player.GameID != "" {
|
||||||
|
playingMap[player.SteamID] = player.GameID
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
once = false
|
once = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user