fix: 玩家重连时刷新用户-房间关联的TTL

This commit is contained in:
wtz
2026-02-22 23:04:05 +08:00
parent 546a176a9f
commit 79fee6bc06

View File

@@ -454,18 +454,20 @@ func (gm *GameManager) LeaveRoomWithTTL(roomID, playerID string) error {
func (gm *GameManager) MarkPlayerOnline(roomID, playerID string) {
gm.mu.Lock()
defer gm.mu.Unlock()
ctx := context.Background()
room, err := gm.loadRoom(ctx, roomID)
if err != nil {
return
}
for _, p := range room.Players {
if p.ID == playerID {
p.IsOnline = true
gm.saveRoom(ctx, room)
gm.rdb.Delete(ctx, redis.PlayerTTLKey(playerID))
// 刷新用户-房间关联的TTL
if p.UserID != "" {
gm.rdb.Set(ctx, redis.UserRoomKey(p.UserID), roomID, redis.RoomTTL)
}
return
}
}