This commit is contained in:
殷勇 2023-09-26 13:16:58 +08:00
parent 12c11fa0e5
commit 2f23b0be33
7 changed files with 72 additions and 30 deletions

View File

@ -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 // 上次登录时间

View File

@ -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

View File

@ -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},
@ -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) {})
} }
}, },
) )

View File

@ -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)

View File

@ -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

View File

@ -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,
} }

View File

@ -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,6 +138,13 @@ 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),
} }
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.AddCacheProfile(1, playerProfile) cacheMgr.AddCacheProfile(1, playerProfile)
friendMgr.LoadUser(accountId) friendMgr.LoadUser(accountId)