1
This commit is contained in:
commit
6c1d10338a
@ -85,6 +85,14 @@ func (this *App) registerDataSources() {
|
||||
mt.Table.GameDb.GetById(0).GetPasswd(),
|
||||
mt.Table.GameDb.GetById(0).GetDatabase(),
|
||||
30)
|
||||
f5.GetGoStyleDb().RegisterDataSource(
|
||||
GAME_DB,
|
||||
mt.Table.GameDb.GetById(0).GetHost(),
|
||||
mt.Table.GameDb.GetById(0).GetPort(),
|
||||
mt.Table.GameDb.GetById(0).GetUser(),
|
||||
mt.Table.GameDb.GetById(0).GetPasswd(),
|
||||
mt.Table.GameDb.GetById(0).GetDatabase(),
|
||||
30)
|
||||
f5.GetJsStyleDb().RegisterDataSource(
|
||||
FRIEND_DB,
|
||||
mt.Table.FriendDb.GetById(0).GetHost(),
|
||||
@ -93,4 +101,12 @@ func (this *App) registerDataSources() {
|
||||
mt.Table.FriendDb.GetById(0).GetPasswd(),
|
||||
mt.Table.FriendDb.GetById(0).GetDatabase(),
|
||||
30)
|
||||
f5.GetGoStyleDb().RegisterDataSource(
|
||||
FRIEND_DB,
|
||||
mt.Table.FriendDb.GetById(0).GetHost(),
|
||||
mt.Table.FriendDb.GetById(0).GetPort(),
|
||||
mt.Table.FriendDb.GetById(0).GetUser(),
|
||||
mt.Table.FriendDb.GetById(0).GetPasswd(),
|
||||
mt.Table.FriendDb.GetById(0).GetDatabase(),
|
||||
30)
|
||||
}
|
||||
|
@ -3,93 +3,120 @@ package main
|
||||
import (
|
||||
"f5"
|
||||
"fmt"
|
||||
"mt"
|
||||
"q5"
|
||||
)
|
||||
|
||||
var tableName = make(map[string]string)
|
||||
|
||||
func (cm *CacheMgr) LoadFromDB() {
|
||||
tableName["user"] = fmt.Sprintf("%s.t_user", mt.Table.GameDb.GetById(0).GetDatabase())
|
||||
tableName["friendships"] = fmt.Sprintf("%s.t_friend_ships", mt.Table.FriendDb.GetById(0).GetDatabase())
|
||||
tableName["guild_member"] = fmt.Sprintf("%s.t_guild_members", mt.Table.FriendDb.GetById(0).GetDatabase())
|
||||
// 加载所有好友信息
|
||||
cm.loadAllFriendUserProfile()
|
||||
// 加载所有工会成员信息
|
||||
cm.loadAllGuildUserProfile()
|
||||
uniAccountIds := Set{}
|
||||
uniAccountIds = make(Set)
|
||||
|
||||
// Load friendships
|
||||
{
|
||||
lastIdx := int64(0)
|
||||
done := false
|
||||
for !done {
|
||||
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
fmt.Sprintf("SELECT idx, account1_id, account2_id FROM t_friend_ships WHERE idx > %d limit 1000", lastIdx),
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("LoadFromDB FRIENDSHIP err:%v \n", err)
|
||||
panic(err)
|
||||
}
|
||||
empty := true
|
||||
for rows.Next() {
|
||||
empty = false
|
||||
account1Id := q5.ToString(*rows.GetByName("account1_id"))
|
||||
account2Id := q5.ToString(*rows.GetByName("account2_id"))
|
||||
|
||||
if !uniAccountIds.Has(account1Id) {
|
||||
cm.loadUserProfile(account1Id)
|
||||
}
|
||||
uniAccountIds.Add(account1Id)
|
||||
|
||||
if !uniAccountIds.Has(account2Id) {
|
||||
cm.loadUserProfile(account2Id)
|
||||
}
|
||||
uniAccountIds.Add(account2Id)
|
||||
|
||||
lastIdx = q5.ToInt64(*rows.GetByName("idx"))
|
||||
}
|
||||
if empty {
|
||||
done = true
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Load guild members
|
||||
{
|
||||
lastIdx := int64(0)
|
||||
done := false
|
||||
for !done {
|
||||
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
fmt.Sprintf("SELECT idx, account_id FROM t_guild_members WHERE idx > %d", lastIdx),
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("LoadFromDB GUILD err:%v \n", err)
|
||||
panic(err)
|
||||
}
|
||||
empty := true
|
||||
for rows.Next() {
|
||||
empty = false
|
||||
accountId := q5.ToString(*rows.GetByName("account_id"))
|
||||
|
||||
if !uniAccountIds.Has(accountId) {
|
||||
cm.loadUserProfile(accountId)
|
||||
}
|
||||
uniAccountIds.Add(accountId)
|
||||
|
||||
lastIdx = q5.ToInt64(*rows.GetByName("idx"))
|
||||
}
|
||||
if empty {
|
||||
done = true
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
uniAccountIds = nil
|
||||
}
|
||||
|
||||
// TODO 重加载数据,1000 迭代
|
||||
func (cm *CacheMgr) loadAllFriendUserProfile() {
|
||||
sql := fmt.Sprintf("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 %s AS fs JOIN %s 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 %s AS fs JOIN %s AS u ON fs.account2_id = u.account_id) AS friend_info_table;", tableName["friendships"], tableName["user"], tableName["friendships"], tableName["user"])
|
||||
cm.loadUsersProfile(sql)
|
||||
}
|
||||
|
||||
// loadGuildFromDB 加载公会成员信息
|
||||
func (cm *CacheMgr) loadAllGuildUserProfile() {
|
||||
sql := fmt.Sprintf("select a.account_id, a.name, a.head_id, a.head_frame, a.star_num, a.`rank`, a.last_login_time from %s a,%s b where a.account_id = b.account_id", tableName["user"], tableName["guild_member"])
|
||||
cm.loadUsersProfile(sql)
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) loadUsersProfile(sql string) {
|
||||
f5.GetJsStyleDb().SelectCustomQuery(
|
||||
FRIEND_DB,
|
||||
func (cm *CacheMgr) loadUserProfile(accountId string) {
|
||||
// "account_id", "name", "head_id", "head_frame", "star_num", "rank", "last_login_time"
|
||||
sql := fmt.Sprintf("select * from t_user where account_id='%s'", accountId)
|
||||
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||
GAME_DB,
|
||||
sql,
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadUsersProfile err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
accountId := q5.ToString(*rows.GetByIndex(0))
|
||||
aId := q5.ToString(*rows.GetByName("account_id"))
|
||||
onlineStatus := playerMgr.GetOnlineStatus(accountId)
|
||||
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)),
|
||||
AccountId: aId,
|
||||
Username: q5.ToString(*rows.GetByName("name")),
|
||||
Avatar: q5.ToInt32(*rows.GetByName("head_id")),
|
||||
AvatarHead: q5.ToInt32(*rows.GetByName("head_frame")),
|
||||
Star: q5.ToInt32(*rows.GetByName("star_num")),
|
||||
Rank: q5.ToInt32(*rows.GetByName("rank")),
|
||||
LastLoginTime: q5.ToInt32(*rows.GetByName("last_login_time")),
|
||||
OnlineStatus: onlineStatus,
|
||||
}
|
||||
cm.AddCacheProfile(1, profile)
|
||||
cm.AddPlayerProfile(1, profile)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
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))
|
||||
onlineStatue := playerMgr.GetOnlineStatus(aId)
|
||||
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)
|
||||
},
|
||||
)
|
||||
cm.loadUserProfile(accountId)
|
||||
profile := cm.GetPlayerProfile(accountId)
|
||||
cb(nil, profile)
|
||||
}
|
||||
|
@ -10,8 +10,8 @@ type PlayerProfile struct {
|
||||
Avatar int32 // 头像
|
||||
AvatarHead int32 // 头像框
|
||||
Star int32 // 星星
|
||||
totalKills int32 // 总击杀数
|
||||
totalWinTimes int32 // 总赢数
|
||||
TotalKills int32 // 总击杀数
|
||||
TotalWinTimes int32 // 总赢数
|
||||
Rank int32 // 排位赛段位
|
||||
OnlineStatus int32 // 在线状态
|
||||
LastLoginTime int32 // 上次登录时间
|
||||
@ -51,13 +51,6 @@ func (cm *CacheMgr) init() {
|
||||
func (cm *CacheMgr) UnInit() {
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) GetPlayerProfile(accountId string) *PlayerProfile {
|
||||
if profile, exists := cm.cachePlayerProfiles[accountId]; exists {
|
||||
return profile.data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) SyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
|
||||
}
|
||||
@ -74,7 +67,6 @@ func (cm *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
cm.cacheMutex.Lock()
|
||||
_, exists := cm.cachePlayerProfiles[accountId]
|
||||
cm.cacheMutex.Unlock()
|
||||
|
||||
if exists {
|
||||
mu.Lock()
|
||||
successCount++
|
||||
@ -82,20 +74,10 @@ func (cm *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
return
|
||||
}
|
||||
|
||||
cm.GetProfileByAccountId(accountId, func(err error, playerProfile *PlayerProfile) {
|
||||
if err != nil {
|
||||
cb(false)
|
||||
return
|
||||
}
|
||||
|
||||
cm.cacheMutex.Lock()
|
||||
cm.AddCacheProfile(1, playerProfile)
|
||||
cm.cacheMutex.Unlock()
|
||||
|
||||
mu.Lock()
|
||||
successCount++
|
||||
mu.Unlock()
|
||||
})
|
||||
cm.loadUserProfile(accountId)
|
||||
mu.Lock()
|
||||
successCount++
|
||||
mu.Unlock()
|
||||
}(accountId)
|
||||
}
|
||||
|
||||
@ -107,26 +89,16 @@ func (cm *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
}
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) LoadPlayerProfile(user *User, cb func(*PlayerProfile)) {
|
||||
if profile, exists := cm.cachePlayerProfiles[user.AccountId]; exists {
|
||||
cb(profile.data)
|
||||
return
|
||||
func (cm *CacheMgr) AddPlayerProfile(version int, playerProfile *PlayerProfile) {
|
||||
cm.cachePlayerProfiles[playerProfile.AccountId] = &CachePlayerProfile{
|
||||
version: version,
|
||||
data: playerProfile,
|
||||
}
|
||||
cm.GetProfileByAccountId(user.AccountId, func(err error, profile *PlayerProfile) {
|
||||
if err != nil {
|
||||
cb(nil)
|
||||
return
|
||||
}
|
||||
cm.cachePlayerProfiles[user.AccountId].data = profile
|
||||
cb(profile)
|
||||
})
|
||||
}
|
||||
|
||||
func (cm *CacheMgr) AddCacheProfile(version int, playerProfile *PlayerProfile) {
|
||||
if _, exists := cm.cachePlayerProfiles[playerProfile.AccountId]; !exists {
|
||||
cm.cachePlayerProfiles[playerProfile.AccountId] = &CachePlayerProfile{
|
||||
version: version,
|
||||
data: playerProfile,
|
||||
}
|
||||
func (cm *CacheMgr) GetPlayerProfile(accountId string) *PlayerProfile {
|
||||
if profile, exists := cm.cachePlayerProfiles[accountId]; exists {
|
||||
return profile.data
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ const (
|
||||
ERR_CODE_SEARCH_USER_DB_FAIL = 11015
|
||||
ERR_CODE_SEARCH_NO_RESULT = 11016
|
||||
ERR_CODE_FRIEND_NO_EXISTS = 11017
|
||||
ERR_CODE_ALREADY_FRIEND = 11018
|
||||
|
||||
// Guild
|
||||
ERR_CODE_GUILD_NO_EXISTS = 12001
|
||||
|
@ -38,6 +38,7 @@ func (fm *FriendsMgr) upsertFriendShip(account1Id string, account2Id string, isF
|
||||
}
|
||||
|
||||
func (fm *FriendsMgr) updateFriendShip(account1Id string, account2Id string, fields [][]string, cb func(error)) {
|
||||
account1Id, account2Id = SwapAccountIds(account1Id, account2Id)
|
||||
where := [][]string{
|
||||
{"account1_id", account1Id},
|
||||
{"account2_id", account2Id},
|
||||
@ -139,7 +140,7 @@ func (fm *FriendsMgr) loadFriendships() {
|
||||
where,
|
||||
func(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
userMap := make(map[string]*User)
|
||||
for rows.Next() {
|
||||
@ -147,7 +148,6 @@ func (fm *FriendsMgr) loadFriendships() {
|
||||
account2Id := q5.ToString(*rows.GetByIndex(1))
|
||||
isFriendship := q5.ToInt32(*rows.GetByIndex(2))
|
||||
requestTime := q5.ToInt64(*rows.GetByIndex(3))
|
||||
|
||||
// 检查用户是否已经存在,如果不存在则创建
|
||||
user1, exists1 := userMap[account1Id]
|
||||
if !exists1 {
|
||||
@ -175,9 +175,6 @@ func (fm *FriendsMgr) loadFriendships() {
|
||||
RequestTime: requestTime,
|
||||
}
|
||||
user2.Friendships[account1Id] = friendship2
|
||||
// 加载用户配置信息
|
||||
//cacheMgr.LoadPlayerProfile(user1, func(playerProfile *PlayerProfile) {})
|
||||
//cacheMgr.LoadPlayerProfile(user2, func(playerProfile *PlayerProfile) {})
|
||||
}
|
||||
},
|
||||
)
|
||||
@ -215,7 +212,7 @@ func (fm *FriendsMgr) loadUserFriendships(user *User, where [][]string) {
|
||||
RequestTime: requestTime,
|
||||
}
|
||||
user2.Friendships[account1Id] = friendship2
|
||||
cacheMgr.LoadPlayerProfile(user2, func(playerProfile *PlayerProfile) {})
|
||||
cacheMgr.loadUserProfile(account2Id)
|
||||
}
|
||||
|
||||
if user.AccountId == account2Id {
|
||||
@ -227,7 +224,7 @@ func (fm *FriendsMgr) loadUserFriendships(user *User, where [][]string) {
|
||||
RequestTime: requestTime,
|
||||
}
|
||||
user.Friendships[account1Id] = friendship
|
||||
cacheMgr.LoadPlayerProfile(friendUser, func(playerProfile *PlayerProfile) {})
|
||||
cacheMgr.loadUserProfile(account1Id)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -75,11 +75,17 @@ func (fm *FriendsMgr) AddFriendRequest(account1Id string, account2Id string, cb
|
||||
// return
|
||||
//}
|
||||
|
||||
// 已发送请求
|
||||
// 检查已发送请求
|
||||
friendship, exists := user1.Friendships[account2Id]
|
||||
if exists && friendship.IsFriendship == 0 {
|
||||
cb(ERR_CODE_OK, "AddFriendRequest ok")
|
||||
return
|
||||
if exists {
|
||||
if friendship.IsFriendship == 0 {
|
||||
cb(ERR_CODE_OK, "AddFriendRequest ok")
|
||||
return
|
||||
}
|
||||
if friendship.IsFriendship == 1 {
|
||||
cb(ERR_CODE_ALREADY_FRIEND, "Already a friend")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 好友已满
|
||||
@ -105,9 +111,6 @@ func (fm *FriendsMgr) AddFriendRequest(account1Id string, account2Id string, cb
|
||||
user1.AddFriendRequest(account2Id, FriendshipStatusPending, requestTime)
|
||||
user2.AddFriendRequest(account1Id, FriendshipStatusPending, requestTime)
|
||||
|
||||
// Load user2 profile to cache
|
||||
// cacheMgr.LoadPlayerProfile(user2, func(playerProfile *PlayerProfile) {})
|
||||
|
||||
cb(ERR_CODE_OK, "AddFriendRequest ok")
|
||||
})
|
||||
}
|
||||
@ -120,10 +123,15 @@ func (fm *FriendsMgr) AcceptFriendRequest(account1Id string, account2Id string,
|
||||
user2 = fm.LoadUser(account2Id)
|
||||
}
|
||||
|
||||
if !user1.IsInReq(account2Id) {
|
||||
friendship, exists := user1.Friendships[account2Id]
|
||||
if !exists {
|
||||
cb(ERR_CODE_NO_IN_REQ, "AcceptFriendRequest user2 no in user1 pending request")
|
||||
return
|
||||
}
|
||||
if friendship.IsFriendship != 0 {
|
||||
cb(ERR_CODE_ALREADY_FRIEND, "Already a friend")
|
||||
return
|
||||
}
|
||||
|
||||
if fm.GetFriendCount(account1Id) >= MaxFriendMembers || fm.GetFriendCount(account2Id) >= MaxFriendMembers {
|
||||
cb(ERR_CODE_USERS_IS_FULL, "AcceptFriendRequest users is full")
|
||||
@ -167,6 +175,16 @@ func (fm *FriendsMgr) RejectFriendRequest(account1Id string, account2Id string,
|
||||
return
|
||||
}
|
||||
|
||||
friendship, exists := user1.Friendships[account2Id]
|
||||
if !exists {
|
||||
cb(ERR_CODE_NO_IN_REQ, "AcceptFriendRequest user2 no in user1 pending request")
|
||||
return
|
||||
}
|
||||
if friendship.IsFriendship == 1 {
|
||||
cb(ERR_CODE_ALREADY_FRIEND, "Already a friend")
|
||||
return
|
||||
}
|
||||
|
||||
requestTime := time.Now().Unix()
|
||||
fm.upsertFriendShip(account2Id, account1Id, FriendshipStatusReject, requestTime, func(err error) {
|
||||
if err != nil {
|
||||
@ -191,6 +209,13 @@ func (fm *FriendsMgr) DeleteFriendShip(account1Id, account2Id string, cb func(er
|
||||
cb(ERR_CODE_USERS_NO_EXISTS, "DeleteFriendShip user no exists")
|
||||
return
|
||||
}
|
||||
|
||||
friendship, exists := user1.Friendships[account2Id]
|
||||
if !exists || friendship.IsFriendship != 1 {
|
||||
cb(ERR_CODE_FRIEND_NO_EXISTS, "DeleteFriendShip user no exists")
|
||||
return
|
||||
}
|
||||
|
||||
user1.RemoveFriendShip(account2Id)
|
||||
user2.RemoveFriendShip(account1Id)
|
||||
|
||||
|
@ -16,9 +16,9 @@ type Guild struct {
|
||||
Notice string // 公告
|
||||
JoinCond int32 // 公会加入条件
|
||||
JoinCondValue int32 // 公会加入条件值
|
||||
TotalStars int32 // 公会统计信息, 总星星数量
|
||||
TotalKills int32 // 公会统计信息, 单局总击杀数
|
||||
ChickenDinners int32 // 公会统计信息, 单局第一名数
|
||||
TotalStars int32 // 公会统计信息, 总星星数量 从api获取
|
||||
TotalKills int32 // 公会统计信息, 单局总击杀数 从api获取
|
||||
ChickenDinners int32 // 公会统计信息, 单局第一名数 从api获取
|
||||
MaxMembers int32 // 公会最大成员数 default 30
|
||||
Members map[string]*GuildMember // accountId -> GuildMember
|
||||
PendingReqs map[string]int32 // pendingAccountId -> status 0,1,2,3 pending, accept, reject, leave
|
||||
|
@ -37,7 +37,7 @@ func (gm *GuildMgr) loadGuildFromDB() {
|
||||
func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadGuildFromDBResult err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
guildId := q5.ToInt64(*rows.GetByIndex(1))
|
||||
@ -80,7 +80,7 @@ func (gm *GuildMgr) loadGuildMemberFromDB() {
|
||||
func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadGuildMemberFromDBResult err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
var (
|
||||
@ -121,7 +121,7 @@ func (gm *GuildMgr) loadPendingReqsFromDB() {
|
||||
func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
|
||||
if err != nil {
|
||||
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
|
||||
return
|
||||
panic(err)
|
||||
}
|
||||
for rows.Next() {
|
||||
var (
|
||||
|
@ -368,10 +368,6 @@ func (gm *GuildMgr) JoinGuild(guild *Guild, accountId string, cb func(errCode in
|
||||
gm.AddUserGuild(accountId, guildId)
|
||||
|
||||
cb(ERR_CODE_OK, "ApplyToGuild OK", guild)
|
||||
|
||||
user := friendMgr.GetUser(accountId)
|
||||
cacheMgr.LoadPlayerProfile(user, func(playerProfile *PlayerProfile) {})
|
||||
|
||||
// Add event
|
||||
prop := make(map[string]string)
|
||||
prop["guild_id"] = q5.ToString(guild.GuildId)
|
||||
@ -766,9 +762,7 @@ func (gm *GuildMgr) SetNameConsume(player *Player, itemId, itemNum int32, cb fun
|
||||
"item_num": q5.ToString(itemNum),
|
||||
}
|
||||
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
||||
|
||||
f5.GetSysLog().Info("SetNameConsume url:%s, params:%+v\n", url, params)
|
||||
|
||||
f5.GetHttpCliMgr().SendJsStyleRequest(
|
||||
url,
|
||||
params,
|
||||
|
@ -17,28 +17,6 @@ func TestInit(t *testing.T) {
|
||||
fmt.Printf("test init")
|
||||
}
|
||||
|
||||
func TestCreateGuild(t *testing.T) {
|
||||
guildMgr.CreateGuild(
|
||||
randomGuildName(),
|
||||
leaderId,
|
||||
func(errCode int32, errMsg string, guildId int64) {
|
||||
newGuildId = guildId
|
||||
fmt.Println("Created guild:", guildId)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGuildMember(t *testing.T) {
|
||||
guildMgr.ApplyToGuild(
|
||||
newGuildId, member1Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
if errCode != 0 {
|
||||
t.Errorf("Error:%s", errMsg)
|
||||
}
|
||||
fmt.Println("Applied to guild")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
func randomGuildName() string {
|
||||
return q5.RandomString(6)
|
||||
}
|
||||
|
@ -748,6 +748,8 @@ func (p *Player) FillMFGuildMember(member *GuildMember) *cs.MFGuildMember {
|
||||
func (p *Player) FillMFGuild(guild *Guild) *cs.MFGuild {
|
||||
// 总星星数
|
||||
var totalStar int32 = 0
|
||||
var totalKills int32 = 0
|
||||
var totalWinTimes int32 = 0
|
||||
|
||||
var guildMembers []*cs.MFGuildMember
|
||||
for _, member := range guild.Members {
|
||||
@ -757,6 +759,12 @@ func (p *Player) FillMFGuild(guild *Guild) *cs.MFGuild {
|
||||
}
|
||||
guildMembers = append(guildMembers, guildMember)
|
||||
totalStar += guildMember.GetStar()
|
||||
|
||||
profile := cacheMgr.GetPlayerProfile(member.AccountId)
|
||||
if profile != nil {
|
||||
totalKills += profile.TotalKills
|
||||
totalWinTimes += profile.TotalWinTimes
|
||||
}
|
||||
}
|
||||
|
||||
var resGuild *cs.MFGuild
|
||||
@ -770,8 +778,8 @@ func (p *Player) FillMFGuild(guild *Guild) *cs.MFGuild {
|
||||
JoinCond: &guild.JoinCond,
|
||||
JoinCondValue: &guild.JoinCondValue,
|
||||
TotalStars: &totalStar,
|
||||
TotalKills: &guild.TotalKills,
|
||||
ChickenDinners: &guild.ChickenDinners,
|
||||
TotalKills: &totalKills,
|
||||
ChickenDinners: &totalWinTimes,
|
||||
MaxMembers: &guild.MaxMembers,
|
||||
Members: guildMembers,
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ func (this *PlayerMgr) unInit() {
|
||||
func (this *PlayerMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
|
||||
params := map[string]string{
|
||||
"c": "User",
|
||||
"a": "info",
|
||||
"a": "detailInfo",
|
||||
"account_id": msg.GetAccountId(),
|
||||
"session_id": msg.GetSessionId(),
|
||||
"target_id": msg.GetAccountId(),
|
||||
@ -88,20 +88,25 @@ func (this *PlayerMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
|
||||
})
|
||||
}
|
||||
|
||||
type HistorySeasons struct {
|
||||
TotalKills int `json:"total_kills"`
|
||||
WinTimes int `json:"win_times"`
|
||||
}
|
||||
|
||||
func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.HttpCliResponse) {
|
||||
resObj := struct {
|
||||
Errcode int `json:"errcode"`
|
||||
Errmsg string `json:"errmsg"`
|
||||
Info struct {
|
||||
Activated string `json:"activated"`
|
||||
RenameCount string `json:"rename_count"`
|
||||
AccountID string `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"head_id"`
|
||||
AvatarHead string `json:"head_frame"`
|
||||
Star string `json:"current_star_num"`
|
||||
Rank string `json:"rank"`
|
||||
LastLoginTime string `json:"last_login_time"`
|
||||
Activated string `json:"activated"`
|
||||
AccountID string `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"head_id"`
|
||||
AvatarHead string `json:"head_frame"`
|
||||
Star string `json:"current_star_num"`
|
||||
Rank string `json:"current_rank"`
|
||||
LastLoginTime string `json:"last_login_time"`
|
||||
HistorySeasons []HistorySeasons `json:"history_seasons"`
|
||||
} `json:"info"`
|
||||
}{}
|
||||
err := json.Unmarshal([]byte(rsp.GetRawData()), &resObj)
|
||||
@ -122,7 +127,6 @@ func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.Htt
|
||||
// Add to online user
|
||||
this.addPlayer(&player)
|
||||
this.addSocketHash(hdr.GetSocket(), &player)
|
||||
|
||||
// Add player profile
|
||||
playerProfile := &PlayerProfile{
|
||||
AccountId: accountId,
|
||||
@ -134,7 +138,14 @@ func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.Htt
|
||||
OnlineStatus: OnlineStatus,
|
||||
LastLoginTime: q5.ToInt32(resObj.Info.LastLoginTime),
|
||||
}
|
||||
cacheMgr.AddCacheProfile(1, playerProfile)
|
||||
if len(resObj.Info.HistorySeasons) == 1 {
|
||||
playerProfile.TotalKills = q5.ToInt32(resObj.Info.HistorySeasons[0].TotalKills)
|
||||
playerProfile.TotalWinTimes = q5.ToInt32(resObj.Info.HistorySeasons[0].WinTimes)
|
||||
} else {
|
||||
playerProfile.TotalKills = 0
|
||||
playerProfile.TotalWinTimes = 0
|
||||
}
|
||||
cacheMgr.AddPlayerProfile(1, playerProfile)
|
||||
friendMgr.LoadUser(accountId)
|
||||
|
||||
serverInfo := proto.String(mt.Table.IMCluster.GetServerInfo())
|
||||
@ -220,3 +231,65 @@ func (this *PlayerMgr) CMReconnect(hdr *f5.MsgHdr, msg *cs.CMReconnect) {
|
||||
hum.ReBind(hdr.GetSocket())
|
||||
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
||||
}
|
||||
|
||||
// GetRemotePlayerInfo TODO 优化
|
||||
func (this *PlayerMgr) GetRemotePlayerInfo(player *Player, cb func(errCode int32, errMsg string, p *PlayerProfile)) {
|
||||
params := map[string]string{
|
||||
"c": "User",
|
||||
"a": "detailInfo",
|
||||
"account_id": player.GetAccountId(),
|
||||
"session_id": player.GetSessionId(),
|
||||
"target_id": player.GetAccountId(),
|
||||
}
|
||||
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
||||
f5.GetSysLog().Info("GetPlayerInfo url:%s, params:%+v\n", url, params)
|
||||
f5.GetHttpCliMgr().SendJsStyleRequest(
|
||||
url,
|
||||
params,
|
||||
func(rsp f5.HttpCliResponse) {
|
||||
resObj := struct {
|
||||
ErrCode int32 `json:"errcode"`
|
||||
ErrMsg string `json:"errmsg"`
|
||||
Info struct {
|
||||
Activated string `json:"activated"`
|
||||
AccountId string `json:"account_id"`
|
||||
Name string `json:"name"`
|
||||
Avatar string `json:"head_id"`
|
||||
AvatarHead string `json:"head_frame"`
|
||||
Star string `json:"current_star_num"`
|
||||
Rank string `json:"current_rank"`
|
||||
LastLoginTime string `json:"last_login_time"`
|
||||
HistorySeasons []HistorySeasons `json:"history_seasons"`
|
||||
} `json:"info"`
|
||||
}{}
|
||||
err := json.Unmarshal([]byte(rsp.GetRawData()), &resObj)
|
||||
if err != nil {
|
||||
cb(ERR_CODE_GUILD_SETNAME_API_ERROR, "SetNameConsume Api服务器JSON解析错误", nil)
|
||||
f5.GetSysLog().Info("SetNameConsume Api服务器JSON解析错误:%s\n", err)
|
||||
return
|
||||
}
|
||||
if resObj.ErrCode != 0 {
|
||||
cb(resObj.ErrCode, "Api服务器errcode", nil)
|
||||
f5.GetSysLog().Error("Api服务器errcode:%d", resObj.ErrCode)
|
||||
return
|
||||
}
|
||||
playerProfile := &PlayerProfile{
|
||||
AccountId: resObj.Info.AccountId,
|
||||
Username: resObj.Info.Name,
|
||||
Avatar: q5.ToInt32(resObj.Info.Avatar),
|
||||
AvatarHead: q5.ToInt32(resObj.Info.AvatarHead),
|
||||
Star: q5.ToInt32(resObj.Info.Star),
|
||||
Rank: q5.ToInt32(resObj.Info.Rank),
|
||||
OnlineStatus: this.GetOnlineStatus(resObj.Info.AccountId),
|
||||
LastLoginTime: q5.ToInt32(resObj.Info.LastLoginTime),
|
||||
}
|
||||
if len(resObj.Info.HistorySeasons) == 1 {
|
||||
playerProfile.TotalKills = q5.ToInt32(resObj.Info.HistorySeasons[0].TotalKills)
|
||||
playerProfile.TotalWinTimes = q5.ToInt32(resObj.Info.HistorySeasons[0].WinTimes)
|
||||
} else {
|
||||
playerProfile.TotalKills = 0
|
||||
playerProfile.TotalWinTimes = 0
|
||||
}
|
||||
cb(resObj.ErrCode, resObj.ErrMsg, playerProfile)
|
||||
})
|
||||
}
|
||||
|
2
third_party/f5
vendored
2
third_party/f5
vendored
@ -1 +1 @@
|
||||
Subproject commit f79618418ed89343a56ca53b8acc9a3cbd07ac30
|
||||
Subproject commit eb482c3b277db6792f5a63a7d9eea835fee3fc90
|
2
third_party/q5
vendored
2
third_party/q5
vendored
@ -1 +1 @@
|
||||
Subproject commit aa48a0c5241057cd9fe00ab712638c61acd23a21
|
||||
Subproject commit 72f4aa81328cc4705a44276f2b0d5ecb3cd4763b
|
Loading…
x
Reference in New Issue
Block a user