96 lines
3.1 KiB
Go
96 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"f5"
|
|
"q5"
|
|
)
|
|
|
|
func (cm *CacheMgr) LoadFromDB() {
|
|
// 加载所有好友信息
|
|
cm.loadAllFriendUserProfile()
|
|
// 加载所有工会成员信息
|
|
cm.loadAllGuildUserProfile()
|
|
}
|
|
|
|
func (cm *CacheMgr) loadAllFriendUserProfile() {
|
|
sql := "SELECT account_id, name, head_id, head_frame, star_num, rank, last_login_time FROM ( SELECT account1_id AS account_id, name, head_id, head_frame, star_num, rank, last_login_time FROM frienddb_dev_1.t_friend_ships AS fs JOIN gamedb2006_dev_1.t_user AS u ON fs.account1_id = u.account_id UNION SELECT account2_id AS account_id, name, head_id, head_frame, star_num, rank, last_login_time FROM frienddb_dev_1.t_friend_ships AS fs JOIN gamedb2006_dev_1.t_user AS u ON fs.account2_id = u.account_id) AS friend_info_table;"
|
|
cm.loadUsersProfile(sql)
|
|
}
|
|
|
|
// loadGuildFromDB 加载公会成员信息
|
|
func (cm *CacheMgr) loadAllGuildUserProfile() {
|
|
sql := "select a.account_id, a.name, a.head_id, a.head_frame, a.star_num, a.`rank`, a.last_login_time from gamedb2006_dev_1.t_user a,frienddb_dev_1.t_guild_members b where a.account_id = b.account_id"
|
|
cm.loadUsersProfile(sql)
|
|
}
|
|
|
|
func (cm *CacheMgr) GetProfileByAccountId(accountId string, cb func(err error, profile *PlayerProfile)) {
|
|
fields := []string{"account_id", "name", "head_id", "head_frame", "star_num", "rank", "last_login_time"}
|
|
where := [][]string{
|
|
{"account_id", accountId},
|
|
}
|
|
f5.GetJsStyleDb().SelectOne(
|
|
GAME_DB,
|
|
"t_user",
|
|
fields,
|
|
where,
|
|
func(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
cb(err, nil)
|
|
return
|
|
}
|
|
if rows.Next() {
|
|
aId := q5.ToString(*rows.GetByIndex(0))
|
|
player := playerMgr.GetPlayerByAccountId(aId)
|
|
var onlineStatue int32 = 0
|
|
if player != nil {
|
|
onlineStatue = 1
|
|
}
|
|
profile := &PlayerProfile{
|
|
AccountId: q5.ToString(*rows.GetByIndex(0)),
|
|
Username: q5.ToString(*rows.GetByIndex(1)),
|
|
Avatar: q5.ToInt32(*rows.GetByIndex(2)),
|
|
AvatarHead: q5.ToInt32(*rows.GetByIndex(3)),
|
|
Star: q5.ToInt32(*rows.GetByIndex(4)),
|
|
Rank: q5.ToInt32(*rows.GetByIndex(5)),
|
|
LastLoginTime: q5.ToInt32(*rows.GetByIndex(6)),
|
|
OnlineStatus: onlineStatue,
|
|
}
|
|
cb(nil, profile)
|
|
}
|
|
cb(nil, nil)
|
|
},
|
|
)
|
|
}
|
|
|
|
func (cm *CacheMgr) loadUsersProfile(sql string) {
|
|
f5.GetJsStyleDb().SelectCustomQuery(
|
|
FRIEND_DB,
|
|
sql,
|
|
func(err error, rows *f5.DataSet) {
|
|
if err != nil {
|
|
f5.GetSysLog().Info("loadUsersProfile err:%v \n", err)
|
|
return
|
|
}
|
|
for rows.Next() {
|
|
accountId := q5.ToString(*rows.GetByIndex(0))
|
|
player := playerMgr.GetPlayerByAccountId(accountId)
|
|
var onlineStatue int32 = 0
|
|
if player != nil {
|
|
onlineStatue = 1
|
|
}
|
|
profile := &PlayerProfile{
|
|
AccountId: accountId,
|
|
Username: q5.ToString(*rows.GetByIndex(1)),
|
|
Avatar: q5.ToInt32(*rows.GetByIndex(2)),
|
|
AvatarHead: q5.ToInt32(*rows.GetByIndex(3)),
|
|
Star: q5.ToInt32(*rows.GetByIndex(4)),
|
|
Rank: q5.ToInt32(*rows.GetByIndex(5)),
|
|
LastLoginTime: q5.ToInt32(*rows.GetByIndex(6)),
|
|
OnlineStatus: onlineStatue,
|
|
}
|
|
cm.AddCacheProfile(1, profile)
|
|
}
|
|
},
|
|
)
|
|
}
|