refactor: 优化Steam游戏状态检查逻辑
This commit is contained in:
@@ -315,15 +315,30 @@ func checkDiffSteamGameStatus(steamID []string, lastTimeStat map[string]string)
|
||||
return nil, nil, glbErr
|
||||
}
|
||||
gameStatusListStr := map[string]string{}
|
||||
currentGameStatus := map[string]string{} // 用于记录当前所有玩家的游戏状态
|
||||
|
||||
for _, userState := range Players {
|
||||
if lastTimeStat[userState.SteamID] == userState.GameID {
|
||||
continue
|
||||
if userState.GameID != "" {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user