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).GetPasswd(),
|
||||||
mt.Table.GameDb.GetById(0).GetDatabase(),
|
mt.Table.GameDb.GetById(0).GetDatabase(),
|
||||||
30)
|
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(
|
f5.GetJsStyleDb().RegisterDataSource(
|
||||||
FRIEND_DB,
|
FRIEND_DB,
|
||||||
mt.Table.FriendDb.GetById(0).GetHost(),
|
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).GetPasswd(),
|
||||||
mt.Table.FriendDb.GetById(0).GetDatabase(),
|
mt.Table.FriendDb.GetById(0).GetDatabase(),
|
||||||
30)
|
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 (
|
import (
|
||||||
"f5"
|
"f5"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mt"
|
|
||||||
"q5"
|
"q5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var tableName = make(map[string]string)
|
|
||||||
|
|
||||||
func (cm *CacheMgr) LoadFromDB() {
|
func (cm *CacheMgr) LoadFromDB() {
|
||||||
tableName["user"] = fmt.Sprintf("%s.t_user", mt.Table.GameDb.GetById(0).GetDatabase())
|
uniAccountIds := Set{}
|
||||||
tableName["friendships"] = fmt.Sprintf("%s.t_friend_ships", mt.Table.FriendDb.GetById(0).GetDatabase())
|
uniAccountIds = make(Set)
|
||||||
tableName["guild_member"] = fmt.Sprintf("%s.t_guild_members", mt.Table.FriendDb.GetById(0).GetDatabase())
|
|
||||||
// 加载所有好友信息
|
// Load friendships
|
||||||
cm.loadAllFriendUserProfile()
|
{
|
||||||
// 加载所有工会成员信息
|
lastIdx := int64(0)
|
||||||
cm.loadAllGuildUserProfile()
|
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) loadUserProfile(accountId string) {
|
||||||
func (cm *CacheMgr) loadAllFriendUserProfile() {
|
// "account_id", "name", "head_id", "head_frame", "star_num", "rank", "last_login_time"
|
||||||
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"])
|
sql := fmt.Sprintf("select * from t_user where account_id='%s'", accountId)
|
||||||
cm.loadUsersProfile(sql)
|
f5.GetGoStyleDb().SyncSelectCustomQuery(
|
||||||
}
|
GAME_DB,
|
||||||
|
|
||||||
// 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,
|
|
||||||
sql,
|
sql,
|
||||||
func(err error, rows *f5.DataSet) {
|
func(err error, rows *f5.DataSet) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f5.GetSysLog().Info("loadUsersProfile err:%v \n", err)
|
f5.GetSysLog().Info("loadUsersProfile err:%v \n", err)
|
||||||
return
|
panic(err)
|
||||||
}
|
}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
accountId := q5.ToString(*rows.GetByIndex(0))
|
aId := q5.ToString(*rows.GetByName("account_id"))
|
||||||
onlineStatus := playerMgr.GetOnlineStatus(accountId)
|
onlineStatus := playerMgr.GetOnlineStatus(accountId)
|
||||||
profile := &PlayerProfile{
|
profile := &PlayerProfile{
|
||||||
AccountId: accountId,
|
AccountId: aId,
|
||||||
Username: q5.ToString(*rows.GetByIndex(1)),
|
Username: q5.ToString(*rows.GetByName("name")),
|
||||||
Avatar: q5.ToInt32(*rows.GetByIndex(2)),
|
Avatar: q5.ToInt32(*rows.GetByName("head_id")),
|
||||||
AvatarHead: q5.ToInt32(*rows.GetByIndex(3)),
|
AvatarHead: q5.ToInt32(*rows.GetByName("head_frame")),
|
||||||
Star: q5.ToInt32(*rows.GetByIndex(4)),
|
Star: q5.ToInt32(*rows.GetByName("star_num")),
|
||||||
Rank: q5.ToInt32(*rows.GetByIndex(5)),
|
Rank: q5.ToInt32(*rows.GetByName("rank")),
|
||||||
LastLoginTime: q5.ToInt32(*rows.GetByIndex(6)),
|
LastLoginTime: q5.ToInt32(*rows.GetByName("last_login_time")),
|
||||||
OnlineStatus: onlineStatus,
|
OnlineStatus: onlineStatus,
|
||||||
}
|
}
|
||||||
cm.AddCacheProfile(1, profile)
|
cm.AddPlayerProfile(1, profile)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *CacheMgr) GetProfileByAccountId(accountId string, cb func(err error, profile *PlayerProfile)) {
|
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"}
|
cm.loadUserProfile(accountId)
|
||||||
where := [][]string{
|
profile := cm.GetPlayerProfile(accountId)
|
||||||
{"account_id", accountId},
|
cb(nil, profile)
|
||||||
}
|
|
||||||
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)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ type PlayerProfile struct {
|
|||||||
Avatar int32 // 头像
|
Avatar int32 // 头像
|
||||||
AvatarHead int32 // 头像框
|
AvatarHead int32 // 头像框
|
||||||
Star int32 // 星星
|
Star int32 // 星星
|
||||||
totalKills int32 // 总击杀数
|
TotalKills int32 // 总击杀数
|
||||||
totalWinTimes int32 // 总赢数
|
TotalWinTimes int32 // 总赢数
|
||||||
Rank int32 // 排位赛段位
|
Rank int32 // 排位赛段位
|
||||||
OnlineStatus int32 // 在线状态
|
OnlineStatus int32 // 在线状态
|
||||||
LastLoginTime int32 // 上次登录时间
|
LastLoginTime int32 // 上次登录时间
|
||||||
@ -51,13 +51,6 @@ func (cm *CacheMgr) init() {
|
|||||||
func (cm *CacheMgr) UnInit() {
|
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)) {
|
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()
|
cm.cacheMutex.Lock()
|
||||||
_, exists := cm.cachePlayerProfiles[accountId]
|
_, exists := cm.cachePlayerProfiles[accountId]
|
||||||
cm.cacheMutex.Unlock()
|
cm.cacheMutex.Unlock()
|
||||||
|
|
||||||
if exists {
|
if exists {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
successCount++
|
successCount++
|
||||||
@ -82,20 +74,10 @@ func (cm *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
cm.GetProfileByAccountId(accountId, func(err error, playerProfile *PlayerProfile) {
|
cm.loadUserProfile(accountId)
|
||||||
if err != nil {
|
mu.Lock()
|
||||||
cb(false)
|
successCount++
|
||||||
return
|
mu.Unlock()
|
||||||
}
|
|
||||||
|
|
||||||
cm.cacheMutex.Lock()
|
|
||||||
cm.AddCacheProfile(1, playerProfile)
|
|
||||||
cm.cacheMutex.Unlock()
|
|
||||||
|
|
||||||
mu.Lock()
|
|
||||||
successCount++
|
|
||||||
mu.Unlock()
|
|
||||||
})
|
|
||||||
}(accountId)
|
}(accountId)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,26 +89,16 @@ func (cm *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *CacheMgr) LoadPlayerProfile(user *User, cb func(*PlayerProfile)) {
|
func (cm *CacheMgr) AddPlayerProfile(version int, playerProfile *PlayerProfile) {
|
||||||
if profile, exists := cm.cachePlayerProfiles[user.AccountId]; exists {
|
cm.cachePlayerProfiles[playerProfile.AccountId] = &CachePlayerProfile{
|
||||||
cb(profile.data)
|
version: version,
|
||||||
return
|
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) {
|
func (cm *CacheMgr) GetPlayerProfile(accountId string) *PlayerProfile {
|
||||||
if _, exists := cm.cachePlayerProfiles[playerProfile.AccountId]; !exists {
|
if profile, exists := cm.cachePlayerProfiles[accountId]; exists {
|
||||||
cm.cachePlayerProfiles[playerProfile.AccountId] = &CachePlayerProfile{
|
return profile.data
|
||||||
version: version,
|
|
||||||
data: playerProfile,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,7 @@ const (
|
|||||||
ERR_CODE_SEARCH_USER_DB_FAIL = 11015
|
ERR_CODE_SEARCH_USER_DB_FAIL = 11015
|
||||||
ERR_CODE_SEARCH_NO_RESULT = 11016
|
ERR_CODE_SEARCH_NO_RESULT = 11016
|
||||||
ERR_CODE_FRIEND_NO_EXISTS = 11017
|
ERR_CODE_FRIEND_NO_EXISTS = 11017
|
||||||
|
ERR_CODE_ALREADY_FRIEND = 11018
|
||||||
|
|
||||||
// Guild
|
// Guild
|
||||||
ERR_CODE_GUILD_NO_EXISTS = 12001
|
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)) {
|
func (fm *FriendsMgr) updateFriendShip(account1Id string, account2Id string, fields [][]string, cb func(error)) {
|
||||||
|
account1Id, account2Id = SwapAccountIds(account1Id, account2Id)
|
||||||
where := [][]string{
|
where := [][]string{
|
||||||
{"account1_id", account1Id},
|
{"account1_id", account1Id},
|
||||||
{"account2_id", account2Id},
|
{"account2_id", account2Id},
|
||||||
@ -139,7 +140,7 @@ func (fm *FriendsMgr) loadFriendships() {
|
|||||||
where,
|
where,
|
||||||
func(err error, rows *f5.DataSet) {
|
func(err error, rows *f5.DataSet) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
panic(err)
|
||||||
}
|
}
|
||||||
userMap := make(map[string]*User)
|
userMap := make(map[string]*User)
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
@ -147,7 +148,6 @@ func (fm *FriendsMgr) loadFriendships() {
|
|||||||
account2Id := q5.ToString(*rows.GetByIndex(1))
|
account2Id := q5.ToString(*rows.GetByIndex(1))
|
||||||
isFriendship := q5.ToInt32(*rows.GetByIndex(2))
|
isFriendship := q5.ToInt32(*rows.GetByIndex(2))
|
||||||
requestTime := q5.ToInt64(*rows.GetByIndex(3))
|
requestTime := q5.ToInt64(*rows.GetByIndex(3))
|
||||||
|
|
||||||
// 检查用户是否已经存在,如果不存在则创建
|
// 检查用户是否已经存在,如果不存在则创建
|
||||||
user1, exists1 := userMap[account1Id]
|
user1, exists1 := userMap[account1Id]
|
||||||
if !exists1 {
|
if !exists1 {
|
||||||
@ -175,9 +175,6 @@ func (fm *FriendsMgr) loadFriendships() {
|
|||||||
RequestTime: requestTime,
|
RequestTime: requestTime,
|
||||||
}
|
}
|
||||||
user2.Friendships[account1Id] = friendship2
|
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,
|
RequestTime: requestTime,
|
||||||
}
|
}
|
||||||
user2.Friendships[account1Id] = friendship2
|
user2.Friendships[account1Id] = friendship2
|
||||||
cacheMgr.LoadPlayerProfile(user2, func(playerProfile *PlayerProfile) {})
|
cacheMgr.loadUserProfile(account2Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.AccountId == account2Id {
|
if user.AccountId == account2Id {
|
||||||
@ -227,7 +224,7 @@ func (fm *FriendsMgr) loadUserFriendships(user *User, where [][]string) {
|
|||||||
RequestTime: requestTime,
|
RequestTime: requestTime,
|
||||||
}
|
}
|
||||||
user.Friendships[account1Id] = friendship
|
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
|
// return
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// 已发送请求
|
// 检查已发送请求
|
||||||
friendship, exists := user1.Friendships[account2Id]
|
friendship, exists := user1.Friendships[account2Id]
|
||||||
if exists && friendship.IsFriendship == 0 {
|
if exists {
|
||||||
cb(ERR_CODE_OK, "AddFriendRequest ok")
|
if friendship.IsFriendship == 0 {
|
||||||
return
|
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)
|
user1.AddFriendRequest(account2Id, FriendshipStatusPending, requestTime)
|
||||||
user2.AddFriendRequest(account1Id, FriendshipStatusPending, requestTime)
|
user2.AddFriendRequest(account1Id, FriendshipStatusPending, requestTime)
|
||||||
|
|
||||||
// Load user2 profile to cache
|
|
||||||
// cacheMgr.LoadPlayerProfile(user2, func(playerProfile *PlayerProfile) {})
|
|
||||||
|
|
||||||
cb(ERR_CODE_OK, "AddFriendRequest ok")
|
cb(ERR_CODE_OK, "AddFriendRequest ok")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -120,10 +123,15 @@ func (fm *FriendsMgr) AcceptFriendRequest(account1Id string, account2Id string,
|
|||||||
user2 = fm.LoadUser(account2Id)
|
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")
|
cb(ERR_CODE_NO_IN_REQ, "AcceptFriendRequest user2 no in user1 pending request")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if friendship.IsFriendship != 0 {
|
||||||
|
cb(ERR_CODE_ALREADY_FRIEND, "Already a friend")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if fm.GetFriendCount(account1Id) >= MaxFriendMembers || fm.GetFriendCount(account2Id) >= MaxFriendMembers {
|
if fm.GetFriendCount(account1Id) >= MaxFriendMembers || fm.GetFriendCount(account2Id) >= MaxFriendMembers {
|
||||||
cb(ERR_CODE_USERS_IS_FULL, "AcceptFriendRequest users is full")
|
cb(ERR_CODE_USERS_IS_FULL, "AcceptFriendRequest users is full")
|
||||||
@ -167,6 +175,16 @@ func (fm *FriendsMgr) RejectFriendRequest(account1Id string, account2Id string,
|
|||||||
return
|
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()
|
requestTime := time.Now().Unix()
|
||||||
fm.upsertFriendShip(account2Id, account1Id, FriendshipStatusReject, requestTime, func(err error) {
|
fm.upsertFriendShip(account2Id, account1Id, FriendshipStatusReject, requestTime, func(err error) {
|
||||||
if err != nil {
|
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")
|
cb(ERR_CODE_USERS_NO_EXISTS, "DeleteFriendShip user no exists")
|
||||||
return
|
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)
|
user1.RemoveFriendShip(account2Id)
|
||||||
user2.RemoveFriendShip(account1Id)
|
user2.RemoveFriendShip(account1Id)
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ type Guild struct {
|
|||||||
Notice string // 公告
|
Notice string // 公告
|
||||||
JoinCond int32 // 公会加入条件
|
JoinCond int32 // 公会加入条件
|
||||||
JoinCondValue int32 // 公会加入条件值
|
JoinCondValue int32 // 公会加入条件值
|
||||||
TotalStars int32 // 公会统计信息, 总星星数量
|
TotalStars int32 // 公会统计信息, 总星星数量 从api获取
|
||||||
TotalKills int32 // 公会统计信息, 单局总击杀数
|
TotalKills int32 // 公会统计信息, 单局总击杀数 从api获取
|
||||||
ChickenDinners int32 // 公会统计信息, 单局第一名数
|
ChickenDinners int32 // 公会统计信息, 单局第一名数 从api获取
|
||||||
MaxMembers int32 // 公会最大成员数 default 30
|
MaxMembers int32 // 公会最大成员数 default 30
|
||||||
Members map[string]*GuildMember // accountId -> GuildMember
|
Members map[string]*GuildMember // accountId -> GuildMember
|
||||||
PendingReqs map[string]int32 // pendingAccountId -> status 0,1,2,3 pending, accept, reject, leave
|
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) {
|
func (gm *GuildMgr) loadGuildFromDBResult(err error, rows *f5.DataSet) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f5.GetSysLog().Info("loadGuildFromDBResult err:%v \n", err)
|
f5.GetSysLog().Info("loadGuildFromDBResult err:%v \n", err)
|
||||||
return
|
panic(err)
|
||||||
}
|
}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
guildId := q5.ToInt64(*rows.GetByIndex(1))
|
guildId := q5.ToInt64(*rows.GetByIndex(1))
|
||||||
@ -80,7 +80,7 @@ func (gm *GuildMgr) loadGuildMemberFromDB() {
|
|||||||
func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
func (gm *GuildMgr) loadGuildMemberFromDBResult(err error, rows *f5.DataSet) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f5.GetSysLog().Info("loadGuildMemberFromDBResult err:%v \n", err)
|
f5.GetSysLog().Info("loadGuildMemberFromDBResult err:%v \n", err)
|
||||||
return
|
panic(err)
|
||||||
}
|
}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
@ -121,7 +121,7 @@ func (gm *GuildMgr) loadPendingReqsFromDB() {
|
|||||||
func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
|
func (gm *GuildMgr) loadPendingReqsFromDBResult(err error, rows *f5.DataSet) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
|
f5.GetSysLog().Info("loadPendingReqsFromDBResult err:%v \n", err)
|
||||||
return
|
panic(err)
|
||||||
}
|
}
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var (
|
||||||
|
@ -368,10 +368,6 @@ func (gm *GuildMgr) JoinGuild(guild *Guild, accountId string, cb func(errCode in
|
|||||||
gm.AddUserGuild(accountId, guildId)
|
gm.AddUserGuild(accountId, guildId)
|
||||||
|
|
||||||
cb(ERR_CODE_OK, "ApplyToGuild OK", guild)
|
cb(ERR_CODE_OK, "ApplyToGuild OK", guild)
|
||||||
|
|
||||||
user := friendMgr.GetUser(accountId)
|
|
||||||
cacheMgr.LoadPlayerProfile(user, func(playerProfile *PlayerProfile) {})
|
|
||||||
|
|
||||||
// Add event
|
// Add event
|
||||||
prop := make(map[string]string)
|
prop := make(map[string]string)
|
||||||
prop["guild_id"] = q5.ToString(guild.GuildId)
|
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),
|
"item_num": q5.ToString(itemNum),
|
||||||
}
|
}
|
||||||
url := fmt.Sprintf("%s/webapp/index.php", mt.Table.Config.GetById(0).GetGameapiUrl())
|
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.GetSysLog().Info("SetNameConsume url:%s, params:%+v\n", url, params)
|
||||||
|
|
||||||
f5.GetHttpCliMgr().SendJsStyleRequest(
|
f5.GetHttpCliMgr().SendJsStyleRequest(
|
||||||
url,
|
url,
|
||||||
params,
|
params,
|
||||||
|
@ -17,28 +17,6 @@ func TestInit(t *testing.T) {
|
|||||||
fmt.Printf("test init")
|
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 {
|
func randomGuildName() string {
|
||||||
return q5.RandomString(6)
|
return q5.RandomString(6)
|
||||||
}
|
}
|
||||||
|
@ -748,6 +748,8 @@ func (p *Player) FillMFGuildMember(member *GuildMember) *cs.MFGuildMember {
|
|||||||
func (p *Player) FillMFGuild(guild *Guild) *cs.MFGuild {
|
func (p *Player) FillMFGuild(guild *Guild) *cs.MFGuild {
|
||||||
// 总星星数
|
// 总星星数
|
||||||
var totalStar int32 = 0
|
var totalStar int32 = 0
|
||||||
|
var totalKills int32 = 0
|
||||||
|
var totalWinTimes int32 = 0
|
||||||
|
|
||||||
var guildMembers []*cs.MFGuildMember
|
var guildMembers []*cs.MFGuildMember
|
||||||
for _, member := range guild.Members {
|
for _, member := range guild.Members {
|
||||||
@ -757,6 +759,12 @@ func (p *Player) FillMFGuild(guild *Guild) *cs.MFGuild {
|
|||||||
}
|
}
|
||||||
guildMembers = append(guildMembers, guildMember)
|
guildMembers = append(guildMembers, guildMember)
|
||||||
totalStar += guildMember.GetStar()
|
totalStar += guildMember.GetStar()
|
||||||
|
|
||||||
|
profile := cacheMgr.GetPlayerProfile(member.AccountId)
|
||||||
|
if profile != nil {
|
||||||
|
totalKills += profile.TotalKills
|
||||||
|
totalWinTimes += profile.TotalWinTimes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var resGuild *cs.MFGuild
|
var resGuild *cs.MFGuild
|
||||||
@ -770,8 +778,8 @@ func (p *Player) FillMFGuild(guild *Guild) *cs.MFGuild {
|
|||||||
JoinCond: &guild.JoinCond,
|
JoinCond: &guild.JoinCond,
|
||||||
JoinCondValue: &guild.JoinCondValue,
|
JoinCondValue: &guild.JoinCondValue,
|
||||||
TotalStars: &totalStar,
|
TotalStars: &totalStar,
|
||||||
TotalKills: &guild.TotalKills,
|
TotalKills: &totalKills,
|
||||||
ChickenDinners: &guild.ChickenDinners,
|
ChickenDinners: &totalWinTimes,
|
||||||
MaxMembers: &guild.MaxMembers,
|
MaxMembers: &guild.MaxMembers,
|
||||||
Members: guildMembers,
|
Members: guildMembers,
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (this *PlayerMgr) unInit() {
|
|||||||
func (this *PlayerMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
|
func (this *PlayerMgr) CMLogin(hdr *f5.MsgHdr, msg *cs.CMLogin) {
|
||||||
params := map[string]string{
|
params := map[string]string{
|
||||||
"c": "User",
|
"c": "User",
|
||||||
"a": "info",
|
"a": "detailInfo",
|
||||||
"account_id": msg.GetAccountId(),
|
"account_id": msg.GetAccountId(),
|
||||||
"session_id": msg.GetSessionId(),
|
"session_id": msg.GetSessionId(),
|
||||||
"target_id": msg.GetAccountId(),
|
"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) {
|
func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.HttpCliResponse) {
|
||||||
resObj := struct {
|
resObj := struct {
|
||||||
Errcode int `json:"errcode"`
|
Errcode int `json:"errcode"`
|
||||||
Errmsg string `json:"errmsg"`
|
Errmsg string `json:"errmsg"`
|
||||||
Info struct {
|
Info struct {
|
||||||
Activated string `json:"activated"`
|
Activated string `json:"activated"`
|
||||||
RenameCount string `json:"rename_count"`
|
AccountID string `json:"account_id"`
|
||||||
AccountID string `json:"account_id"`
|
Name string `json:"name"`
|
||||||
Name string `json:"name"`
|
Avatar string `json:"head_id"`
|
||||||
Avatar string `json:"head_id"`
|
AvatarHead string `json:"head_frame"`
|
||||||
AvatarHead string `json:"head_frame"`
|
Star string `json:"current_star_num"`
|
||||||
Star string `json:"current_star_num"`
|
Rank string `json:"current_rank"`
|
||||||
Rank string `json:"rank"`
|
LastLoginTime string `json:"last_login_time"`
|
||||||
LastLoginTime string `json:"last_login_time"`
|
HistorySeasons []HistorySeasons `json:"history_seasons"`
|
||||||
} `json:"info"`
|
} `json:"info"`
|
||||||
}{}
|
}{}
|
||||||
err := json.Unmarshal([]byte(rsp.GetRawData()), &resObj)
|
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
|
// Add to online user
|
||||||
this.addPlayer(&player)
|
this.addPlayer(&player)
|
||||||
this.addSocketHash(hdr.GetSocket(), &player)
|
this.addSocketHash(hdr.GetSocket(), &player)
|
||||||
|
|
||||||
// Add player profile
|
// Add player profile
|
||||||
playerProfile := &PlayerProfile{
|
playerProfile := &PlayerProfile{
|
||||||
AccountId: accountId,
|
AccountId: accountId,
|
||||||
@ -134,7 +138,14 @@ func (this *PlayerMgr) CMLoginResult(hdr *f5.MsgHdr, msg *cs.CMLogin, rsp f5.Htt
|
|||||||
OnlineStatus: OnlineStatus,
|
OnlineStatus: OnlineStatus,
|
||||||
LastLoginTime: q5.ToInt32(resObj.Info.LastLoginTime),
|
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)
|
friendMgr.LoadUser(accountId)
|
||||||
|
|
||||||
serverInfo := proto.String(mt.Table.IMCluster.GetServerInfo())
|
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())
|
hum.ReBind(hdr.GetSocket())
|
||||||
wspListener.sendProxyMsg(hdr.Conn, hdr.SocketHandle, rspMsg)
|
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