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) {
|
func (gm *GameManager) MarkPlayerOnline(roomID, playerID string) {
|
||||||
gm.mu.Lock()
|
gm.mu.Lock()
|
||||||
defer gm.mu.Unlock()
|
defer gm.mu.Unlock()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
room, err := gm.loadRoom(ctx, roomID)
|
room, err := gm.loadRoom(ctx, roomID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range room.Players {
|
for _, p := range room.Players {
|
||||||
if p.ID == playerID {
|
if p.ID == playerID {
|
||||||
p.IsOnline = true
|
p.IsOnline = true
|
||||||
gm.saveRoom(ctx, room)
|
gm.saveRoom(ctx, room)
|
||||||
gm.rdb.Delete(ctx, redis.PlayerTTLKey(playerID))
|
gm.rdb.Delete(ctx, redis.PlayerTTLKey(playerID))
|
||||||
|
// 刷新用户-房间关联的TTL
|
||||||
|
if p.UserID != "" {
|
||||||
|
gm.rdb.Set(ctx, redis.UserRoomKey(p.UserID), roomID, redis.RoomTTL)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user