fix: 玩家重连时刷新用户-房间关联的TTL
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user