-
Notifications
You must be signed in to change notification settings - Fork 4
/
offline_process.go
28 lines (26 loc) · 1.04 KB
/
offline_process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package game
import (
"github.com/fish-tennis/gentity"
"github.com/fish-tennis/gserver/cache"
"github.com/fish-tennis/gserver/db"
"github.com/fish-tennis/gserver/logger"
)
// 对离线玩家的数据处理
func OfflinePlayerProcess(playerId int64, data interface{}, f func(offlinePlayerId int64, offlineData interface{}) bool) bool {
accountId,_ := db.GetPlayerDb().FindAccountIdByPlayerId(playerId)
logger.Debug("OfflinePlayerProcess playerId:%v accountId:%v", playerId, accountId)
if accountId == 0 {
return false
}
// 防止离线数据处理期间,玩家上线,导致数据覆盖
if !cache.AddOnlineAccount(accountId, playerId, gentity.GetApplication().GetId()) {
logger.Debug("OfflinePlayerProcess AddOnlineAccount failed playerId:%v accountId:%v", playerId, accountId)
return false
}
defer cache.RemoveOnlineAccount(accountId)
if has, _ := db.GetPlayerDb().FindEntityById(playerId, data); has {
return f(playerId, data)
}
logger.Debug("OfflinePlayerProcess not find data playerId:%v accountId:%v", playerId, accountId)
return false
}