1
This commit is contained in:
parent
f5ffe77505
commit
eae4eba9f1
5
server/imserver_new/cache/cachedbmgr.go
vendored
5
server/imserver_new/cache/cachedbmgr.go
vendored
@ -6,6 +6,7 @@ import (
|
||||
"q5"
|
||||
"time"
|
||||
"main/constant"
|
||||
"main/common"
|
||||
. "main/global"
|
||||
)
|
||||
|
||||
@ -102,7 +103,7 @@ func (cm *CacheMgr) loadUserProfile(accountId string) {
|
||||
for rows.Next() {
|
||||
aId := q5.ToString(rows.GetByName("account_id"))
|
||||
onlineStatus := GetPlayerMgr().GetOnlineStatus(accountId)
|
||||
profile := &PlayerProfile{
|
||||
profile := &common.PlayerProfile{
|
||||
AccountId: aId,
|
||||
Username: q5.ToString(rows.GetByName("name")),
|
||||
Avatar: q5.ToInt32(rows.GetByName("head_id")),
|
||||
@ -124,7 +125,7 @@ func (cm *CacheMgr) getCacheVersion() int {
|
||||
return week
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) GetProfileByAccountId(accountId string, cb func(err error, profile *PlayerProfile)) {
|
||||
func (cm *CacheMgr) GetProfileByAccountId(accountId string, cb func(err error, profile *common.PlayerProfile)) {
|
||||
cm.loadUserProfile(accountId)
|
||||
profile := cm.GetPlayerProfile(accountId)
|
||||
cb(nil, profile)
|
||||
|
37
server/imserver_new/cache/cachemgr.go
vendored
37
server/imserver_new/cache/cachemgr.go
vendored
@ -2,30 +2,13 @@ package cache
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"main/common"
|
||||
)
|
||||
|
||||
type PlayerProfile struct {
|
||||
AccountId string
|
||||
Username string // 用户名
|
||||
Avatar int32 // 头像
|
||||
AvatarHead int32 // 头像框
|
||||
Star int32 // 星星
|
||||
TotalKills int32 // 总击杀数
|
||||
TotalWinTimes int32 // 总赢数
|
||||
Rank int32 // 排位赛段位
|
||||
OnlineStatus int32 // 在线状态
|
||||
LastLoginTime int32 // 上次登录时间
|
||||
}
|
||||
|
||||
type CachePlayerProfile struct {
|
||||
version int
|
||||
data *PlayerProfile
|
||||
}
|
||||
|
||||
type CacheMgr struct {
|
||||
mu sync.Mutex
|
||||
cacheMutex sync.Mutex
|
||||
cachePlayerProfiles map[string]*CachePlayerProfile
|
||||
cachePlayerProfiles map[string]*common.CachePlayerProfile
|
||||
}
|
||||
|
||||
type Set map[string]struct{}
|
||||
@ -44,7 +27,7 @@ func (s Set) Delete(key string) {
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) init() {
|
||||
cm.cachePlayerProfiles = make(map[string]*CachePlayerProfile)
|
||||
cm.cachePlayerProfiles = make(map[string]*common.CachePlayerProfile)
|
||||
cm.LoadFromDB()
|
||||
}
|
||||
|
||||
@ -66,7 +49,7 @@ func (cm *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
cm.cacheMutex.Lock()
|
||||
cp, exists := cm.cachePlayerProfiles[accountId]
|
||||
cm.cacheMutex.Unlock()
|
||||
if exists && cp.version == cm.getCacheVersion() {
|
||||
if exists && cp.Version == cm.getCacheVersion() {
|
||||
mu.Lock()
|
||||
successCount++
|
||||
mu.Unlock()
|
||||
@ -88,16 +71,16 @@ func (cm *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) AddPlayerProfile(version int, playerProfile *PlayerProfile) {
|
||||
cm.cachePlayerProfiles[playerProfile.AccountId] = &CachePlayerProfile{
|
||||
version: version,
|
||||
data: playerProfile,
|
||||
func (cm *CacheMgr) AddPlayerProfile(version int, playerProfile *common.PlayerProfile) {
|
||||
cm.cachePlayerProfiles[playerProfile.AccountId] = &common.CachePlayerProfile{
|
||||
Version: version,
|
||||
Data: playerProfile,
|
||||
}
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) GetPlayerProfile(accountId string) *PlayerProfile {
|
||||
func (cm *CacheMgr) GetPlayerProfile(accountId string) *common.PlayerProfile {
|
||||
if profile, exists := cm.cachePlayerProfiles[accountId]; exists {
|
||||
return profile.data
|
||||
return profile.Data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -70,3 +70,21 @@ type GuildMgr interface {
|
||||
GetGuildByAccountId(string) Guild
|
||||
GetGuildIdByAccountId(string) int64
|
||||
}
|
||||
|
||||
type PlayerProfile struct {
|
||||
AccountId string
|
||||
Username string // 用户名
|
||||
Avatar int32 // 头像
|
||||
AvatarHead int32 // 头像框
|
||||
Star int32 // 星星
|
||||
TotalKills int32 // 总击杀数
|
||||
TotalWinTimes int32 // 总赢数
|
||||
Rank int32 // 排位赛段位
|
||||
OnlineStatus int32 // 在线状态
|
||||
LastLoginTime int32 // 上次登录时间
|
||||
}
|
||||
|
||||
type CachePlayerProfile struct {
|
||||
Version int
|
||||
Data *PlayerProfile
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package initialize
|
||||
import (
|
||||
_ "main/app"
|
||||
_ "main/cache"
|
||||
_ "main/chat"
|
||||
_ "main/friend"
|
||||
_ "main/listener"
|
||||
|
||||
. "main/global"
|
||||
|
Loading…
x
Reference in New Issue
Block a user