|
|
|
|
@ -3,7 +3,7 @@ package event
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"texas-poker-bk/internal/service/store" |
|
|
|
|
"texas-poker-bk/internal/session" |
|
|
|
|
"texas-poker-bk/tool/async" |
|
|
|
|
"texas-poker-bk/tool/collect" |
|
|
|
|
"texas-poker-bk/tool/watcher" |
|
|
|
|
"time" |
|
|
|
|
@ -13,14 +13,14 @@ var (
|
|
|
|
|
// OfflineWatcher 离线动作
|
|
|
|
|
OfflineWatcher *watcher.Watcher[int64, bool] |
|
|
|
|
|
|
|
|
|
//OfflineQueue *collect.DelayQueue[*session.NetAccount]
|
|
|
|
|
|
|
|
|
|
offlineCleanDelayer *async.DelayQueue[int64] |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
OfflineWatcher = watcher.NewWatcher(128, handleOffline) |
|
|
|
|
go OfflineWatcher.Run() |
|
|
|
|
|
|
|
|
|
offlineCleanDelayer = async.NewDelayQueue(time.Second, 128, removeMemoryAccount) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func handleOffline(e *watcher.Event[int64, bool]) { |
|
|
|
|
@ -33,15 +33,15 @@ func handleOffline(e *watcher.Event[int64, bool]) {
|
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if account.Player == nil { |
|
|
|
|
// 不在游戏中,直接下线
|
|
|
|
|
removeMemoryAccount(account) |
|
|
|
|
// 不在游戏中,n秒后移除
|
|
|
|
|
account.OfflineCleanCanceler = offlineCleanDelayer.Delay(10*time.Second, account.Id) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if collect.In(account.Player.GameTable.Stage, 1, 9) { |
|
|
|
|
// 牌局未在进行中直接移除玩家并下线
|
|
|
|
|
account.Player.GameTable.RemovePlayer(account.Id) |
|
|
|
|
account.SettlePlayerChip() |
|
|
|
|
removeMemoryAccount(account) |
|
|
|
|
account.OfflineCleanCanceler = offlineCleanDelayer.Delay(10*time.Second, account.Id) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
// 判断当前是玩家回合(60s自动过牌/弃牌)
|
|
|
|
|
@ -51,8 +51,10 @@ func handleOffline(e *watcher.Event[int64, bool]) {
|
|
|
|
|
// 待玩家回合时还是offline(自动过牌/弃牌)
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func removeMemoryAccount(account *session.NetAccount) { |
|
|
|
|
store.NetAccounts.Delete(account.Id) |
|
|
|
|
store.TokenVersions.Delete(account.Id) |
|
|
|
|
// func removeMemoryAccount(account *session.NetAccount) {
|
|
|
|
|
func removeMemoryAccount(accountId int64, now time.Time) { |
|
|
|
|
_ = store.NetAccounts.Get(accountId) |
|
|
|
|
store.NetAccounts.Delete(accountId) |
|
|
|
|
store.TokenVersions.Delete(accountId) |
|
|
|
|
// TODO 持久化账户金额
|
|
|
|
|
} |
|
|
|
|
|