diff --git a/server/imserver_new/cache/cachedbmgr.go b/server/imserver_new/cache/cachedbmgr.go index 65a2398c..6ca0df6d 100644 --- a/server/imserver_new/cache/cachedbmgr.go +++ b/server/imserver_new/cache/cachedbmgr.go @@ -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) diff --git a/server/imserver_new/cache/cachemgr.go b/server/imserver_new/cache/cachemgr.go index ed57e310..90708a7b 100644 --- a/server/imserver_new/cache/cachemgr.go +++ b/server/imserver_new/cache/cachemgr.go @@ -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 } diff --git a/server/imserver_new/common/types.go b/server/imserver_new/common/types.go index 1a23ea01..6823015b 100644 --- a/server/imserver_new/common/types.go +++ b/server/imserver_new/common/types.go @@ -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 +} diff --git a/server/imserver_new/initialize/enter.go b/server/imserver_new/initialize/enter.go index 8f2a2395..0f9a65ab 100644 --- a/server/imserver_new/initialize/enter.go +++ b/server/imserver_new/initialize/enter.go @@ -3,6 +3,8 @@ package initialize import ( _ "main/app" _ "main/cache" + _ "main/chat" + _ "main/friend" _ "main/listener" . "main/global"