2023-11-06 12:06:37 +08:00

886 lines
23 KiB
Go

package main
import (
"cs"
"f5"
"github.com/golang/protobuf/proto"
"q5"
"sort"
)
type Player struct {
cs.MsgHandlerImpl
socket f5.WspCliConn
accountId string
sessionId string
chatChannel int
privateTargetAccountId string // 私聊对象 accountId
worldChannelLastId uint64 // 世界聊天 last id
guildChannelLastId uint64 // 公会聊天 last id
privateChatLastId uint64 // 私聊 last id
}
func (p *Player) GetAccountId() string {
return p.accountId
}
func (p *Player) GetSessionId() string {
return p.sessionId
}
func (p *Player) SendMsg(rspMsg proto.Message) {
wspListener.sendProxyMsg(p.socket.Conn, p.socket.SocketHandle, rspMsg)
}
func (p *Player) ReBind(socket f5.WspCliConn) {
if p.socket.IsValid() {
delete(playerMgr.socketHash, p.socket)
}
p.socket = socket
playerMgr.socketHash[p.socket] = p
}
// CMSearchUser 搜索用户
func (p *Player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) {
sinceId := msg.GetSinceId()
searchUsername := msg.GetUsername()
friendMgr.SearchUsers(
p.accountId,
searchUsername,
sinceId,
func(errCode int32, errMsg string, lastId int64, listFriend []*PlayerProfile) {
f5.GetSysLog().Info("CMSearchUser username:[%s], count:%d, \n", searchUsername, len(listFriend))
rspMsg := new(cs.SMSearchUser)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
rspMsg.SinceId = &lastId
for _, friendProfile := range listFriend {
rspUser := p.FillMFUser(friendProfile)
rspMsg.Users = append(rspMsg.Users, rspUser)
}
}
p.SendMsg(rspMsg)
})
}
// CMSearchUserByAccountId 搜索指定用户
func (p *Player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUserByAccountId) {
friendMgr.SearchByAccountId(msg.GetAccountId(),
func(errCode int32, errMsg string, playerProfile *PlayerProfile) {
rspMsg := new(cs.SMSearchUserByAccountId)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
if playerProfile != nil {
rspMsg.Users = p.FillMFUser(playerProfile)
}
}
p.SendMsg(rspMsg)
})
}
// CMListPendingFriendRequest 等待验证的好友请求
func (p *Player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPendingFriendRequest) {
accountId := p.accountId
user := friendMgr.GetUser(accountId)
rspMsg := &cs.SMListPendingFriendRequest{}
for targetAccountId, friendRequest := range user.Friendships {
if friendRequest.IsFriendship != FriendshipStatusPending {
continue
}
profile := cacheMgr.GetPlayerProfile(targetAccountId)
if profile == nil {
continue
}
pendingUser := p.FillMFUser(profile)
rspMsg.Users = append(rspMsg.Users, pendingUser)
}
f5.GetSysLog().Info("CMListPendingFriendRequest count:%d\n", len(rspMsg.Users))
p.SendMsg(rspMsg)
}
// CMListFriend 我的好友列表
func (p *Player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) {
accountId := p.accountId
user := friendMgr.GetUser(accountId)
var friendIds []string
for _, friendship := range user.Friendships {
if friendship.FriendAccountId == accountId || friendship.IsFriendship != FriendshipStatusOK {
continue
}
friendIds = append(friendIds, friendship.FriendAccountId)
}
rspMsg := &cs.SMListFriend{}
rspMsg.Users = make([]*cs.MFUser, 0)
cacheMgr.AsyncGetUsers(friendIds, func(ok bool) {
if !ok {
return
}
for _, fid := range friendIds {
userProfile := cacheMgr.GetPlayerProfile(fid)
rspUser := p.FillMFUser(userProfile)
rspMsg.Users = append(rspMsg.Users, rspUser)
}
p.SendMsg(rspMsg)
})
}
// CMBlacklist 黑名单列表
func (p *Player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) {
rspMsg := &cs.SMBlacklist{}
accountId := p.accountId
player := friendMgr.GetUser(accountId)
for _, blackList := range player.FriendBlackList {
if blackList.IsRemoved != 0 {
continue
}
blockedPlayerProfile := cacheMgr.GetPlayerProfile(blackList.AccountId)
if blockedPlayerProfile == nil {
continue
}
user := p.FillMFUser(blockedPlayerProfile)
rspMsg.Users = append(rspMsg.Users, user)
}
p.SendMsg(rspMsg)
}
// CMAddFriendRequest 添加好友请求
func (p *Player) CMAddFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAddFriendRequest) {
user1Id := p.accountId
user2Id := msg.GetTargetAccountId()
friendMgr.AddFriendRequest(user1Id, user2Id,
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMAddFriendRequest)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
}
p.SendMsg(rspMsg)
})
}
// CMAcceptFriendRequest 接受好友请求
func (p *Player) CMAcceptFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAcceptFriendRequest) {
user1Id := p.accountId
user2Id := msg.GetTargetAccountId()
friendMgr.AcceptFriendRequest(user1Id, user2Id,
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMAcceptFriendRequest)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
}
p.SendMsg(rspMsg)
})
}
// CMRejectFriendRequest 拒绝好友请求
func (p *Player) CMRejectFriendRequest(hdr *f5.MsgHdr, msg *cs.CMRejectFriendRequest) {
user1Id := p.accountId
user2Id := msg.GetTargetAccountId()
friendMgr.RejectFriendRequest(user1Id, user2Id,
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMRejectFriendRequest)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
}
p.SendMsg(rspMsg)
})
}
// CMDeleteFriendShip 删除好友
func (p *Player) CMDeleteFriendShip(hdr *f5.MsgHdr, msg *cs.CMDeleteFriendShip) {
user1Id := p.accountId
user2Id := msg.GetTargetAccountId()
friendMgr.DeleteFriendShip(user1Id, user2Id,
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMDeleteFriendShip)
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
p.SendMsg(rspMsg)
})
}
// CMAddBlacklist 加入黑名单
func (p *Player) CMAddBlacklist(hdr *f5.MsgHdr, msg *cs.CMAddBlacklist) {
user1Id := p.accountId
user2Id := msg.GetTargetAccountId()
friendMgr.AddBlacklist(user1Id, user2Id,
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMAddBlacklist)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
}
p.SendMsg(rspMsg)
})
}
// CMRemoveBlacklist 移除黑名单
func (p *Player) CMRemoveBlacklist(hdr *f5.MsgHdr, msg *cs.CMRemoveBlacklist) {
user1Id := p.accountId
user2Id := msg.GetTargetAccountId()
friendMgr.RemoveBlacklist(user1Id, user2Id,
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMRemoveBlacklist)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
}
p.SendMsg(rspMsg)
})
}
// CMInviteFriendMsg 邀请好友加入队伍
func (p *Player) CMInviteFriendMsg(hdr *f5.MsgHdr, msg *cs.CMInviteFriendMsg) {
rspMsg := new(cs.SMInviteFriendMsg)
p2 := playerMgr.GetPlayerByAccountId(msg.GetInviteAccountId())
if p2 == nil {
rspMsg.Errcode = proto.Int32(ERR_CODE_FRIEND_NO_EXISTS)
rspMsg.Errmsg = proto.String("friend no exists")
p.SendMsg(rspMsg)
} else {
rspMsg.Msg = msg.Msg
p2.SendMsg(rspMsg)
}
}
// CMSendChatMsg 发送聊天消息
func (p *Player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) {
if !IsValidChatChannel(msg.GetChatChannel()) {
return
}
switch msg.GetChatChannel() {
case kCCWorld:
chatMgr.ProcWorldChat(p, msg)
case kCCPrivate:
chatMgr.ProcPrivateChat(p, msg)
case kCCGuild:
chatMgr.ProcGuildChat(p, msg)
case kCCTeam:
chatMgr.ProcTeamChat(p, msg)
default:
return
}
}
func (p *Player) SyncPrivateChatRedPoint() {
msg := &cs.SMUpdatePrivateChatRedPointNotify{}
chatMgr.FillSMUpdatePrivateChatRedPointNotify(p, msg)
}
// CMReadMsgAndOpenChatNotify 读取聊天消息列表并且开启聊天通知
func (p *Player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAndOpenChatNotify) {
if !IsValidChatChannel(msg.GetCurrChannel()) {
return
}
p.chatChannel = int(msg.GetCurrChannel())
if p.chatChannel == kCCPrivate {
p.SyncPrivateChatRedPoint()
}
// lastIds [{key:1, value:0}, {key:1, value:0}, ]
for _, v := range msg.GetLastIds() {
chatChannel := q5.ToInt32(v.GetKey())
if !IsValidChatChannel(chatChannel) {
continue
}
chatChannelLastId := uint64(v.GetValue())
switch chatChannel {
case kCCWorld:
p.worldChannelLastId = chatChannelLastId
chatMgr.SyncWorldChatMsg(p)
case kCCGuild:
p.guildChannelLastId = chatChannelLastId
chatMgr.SyncGuildChatMsg(p)
default:
break
}
}
}
// CMSetCurrPrivateChatTarget 设置当前私聊目标
func (p *Player) CMSetCurrPrivateChatTarget(hdr *f5.MsgHdr, msg *cs.CMSetCurrPrivateChatTarget) {
p.privateTargetAccountId = msg.GetTargetAccountId()
chatMgr.SyncPrivateChatMsg(p)
}
func (p *Player) MarkNewMsg() {
rspMsg := &cs.SMUpdateChatRedPointNotify{}
chatMgr.FillSMUpdateChatRedPointNotify(p, rspMsg)
p.SendMsg(rspMsg)
}
func IsValidChatChannel(chatChannel int32) bool {
return chatChannel > kCCBegin && chatChannel < kCCEnd
}
// CMGuildInfo 公会信息
func (p *Player) CMGuildInfo(hdr *f5.MsgHdr, msg *cs.CMGuildInfo) {
rspMsg := new(cs.SMGuildInfo)
guild := guildMgr.GetGuildByAccountId(msg.GetAccountId())
if guild != nil {
rspMsg.Guild = p.FillMFGuild(guild)
}
p.SendMsg(rspMsg)
}
// CMRecommendGuildList 推荐公会列表
func (p *Player) CMRecommendGuildList(hdr *f5.MsgHdr, msg *cs.CMRecommendGuildList) {
rspMsg := new(cs.SMRecommendGuildList)
rspMsg.RecommendGuilds = p.FillMFGuilds(guildMgr.RandomGuilds())
p.SendMsg(rspMsg)
}
// CMGetTopGuildsByTotalStars 公会排行 总星星数排行
func (p *Player) CMGetTopGuildsByTotalStars(hdr *f5.MsgHdr, msg *cs.CMGetTopGuildsByTotalStars) {
rspMsg := new(cs.SMGetTopGuildsByTotalStars)
guildsNum := int(msg.GetGuildsNum())
var allMFGuilds []*cs.MFGuild
for _, g := range guildMgr.guilds {
guild := p.FillMFGuild(g)
allMFGuilds = append(allMFGuilds, guild)
}
sort.Slice(allMFGuilds, func(i, j int) bool {
return allMFGuilds[i].GetTotalStars() > allMFGuilds[j].GetTotalStars()
})
if guildsNum > len(allMFGuilds) {
guildsNum = len(allMFGuilds)
}
allMFGuilds = allMFGuilds[:guildsNum]
rspMsg.Guilds = allMFGuilds
p.SendMsg(rspMsg)
}
// CMCreateGuild 创建公会
func (p *Player) CMCreateGuild(hdr *f5.MsgHdr, msg *cs.CMCreateGuild) {
avatar := msg.GetAvatar()
guildMgr.CreateGuild(avatar, msg.Name, p.accountId,
func(errCode int32, errMsg string, guild *Guild) {
rspMsg := new(cs.SMCreateGuild)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
rspMsg.Guild = p.FillMFGuild(guild)
}
p.SendMsg(rspMsg)
})
}
// CMApplyToGuild 申请者加入公会
func (p *Player) CMApplyToGuild(hdr *f5.MsgHdr, msg *cs.CMApplyToGuild) {
guildMgr.ApplyToGuild(
msg.GetGuildId(), p.accountId,
func(errCode int32, errMsg string, guild *Guild) {
rspMsg := new(cs.SMApplyToGuild)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
if guild != nil {
// 成员通知消息
rspNotify := new(cs.SMApplyToGuildNotify)
rspNotify.GuildId = &guild.GuildId
rspNotify.Name = &guild.Name
rspNotify.AccountId = &p.accountId
playerProfile := cacheMgr.GetPlayerProfile(p.accountId)
if playerProfile != nil {
rspNotify.Username = &playerProfile.Username
}
for targetAccountId := range guild.Members {
target := playerMgr.GetPlayerByAccountId(targetAccountId)
if target != nil {
target.SendMsg(rspNotify)
}
}
}
},
)
}
// CMApplyList 请求申请者列表
func (p *Player) CMApplyList(hdr *f5.MsgHdr, msg *cs.CMApplyList) {
rspMsg := new(cs.SMApplyList)
guild := guildMgr.GetGuildByAccountId(p.accountId)
if guild != nil {
for accountId, isJoin := range guild.PendingReqs {
if isJoin != PendingReqIsJoinGuildStatusDefault {
continue
}
member := &GuildMember{
AccountId: accountId,
Level: q5.ToInt32(GuildMemberLevelDefault),
}
rspMember := p.FillMFGuildMember(member)
if rspMember != nil {
rspMsg.Members = append(rspMsg.Members, rspMember)
}
}
}
p.SendMsg(rspMsg)
}
// CMApprove 同意申请者加入公会
func (p *Player) CMApprove(hdr *f5.MsgHdr, msg *cs.CMApprove) {
guildMgr.Approve(
p.accountId, msg.GetApplicantAccountId(),
func(errCode int32, errMsg string, guild *Guild) {
rspMsg := new(cs.SMApprove)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
if guild != nil {
// 成员通知消息
rspNotify := new(cs.SMApproveJoinGuildNotify)
rspNotify.GuildId = &guild.GuildId
rspNotify.Name = &guild.Name
rspNotify.AccountId = msg.ApplicantAccountId
playerProfile := cacheMgr.GetPlayerProfile(msg.GetApplicantAccountId())
if playerProfile != nil {
rspNotify.Username = &playerProfile.Username
}
for targetAccountId := range guild.Members {
target := playerMgr.GetPlayerByAccountId(targetAccountId)
if target != nil {
target.SendMsg(rspNotify)
}
}
}
},
)
}
// CMReject 拒绝申请者加入公会
func (p *Player) CMReject(hdr *f5.MsgHdr, msg *cs.CMReject) {
guildMgr.Reject(
p.accountId, msg.GetApplicantAccountId(),
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMReject)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
},
)
}
// CMLeaveGuild 离开公会
func (p *Player) CMLeaveGuild(hdr *f5.MsgHdr, msg *cs.CMLeaveGuild) {
guildMgr.LeaveGuild(
p.accountId,
func(errCode int32, errMsg string, guild *Guild) {
rspMsg := new(cs.SMLeaveGuild)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
if guild != nil {
// 成员通知消息
rspNotify := new(cs.SMLeaveGuildNotify)
rspNotify.GuildId = &guild.GuildId
rspNotify.Name = &guild.Name
rspNotify.AccountId = &p.accountId
playerProfile := cacheMgr.GetPlayerProfile(p.accountId)
if playerProfile != nil {
rspNotify.Username = &playerProfile.Username
}
for targetAccountId := range guild.Members {
target := playerMgr.GetPlayerByAccountId(targetAccountId)
if target != nil {
target.SendMsg(rspNotify)
}
}
}
},
)
}
// CMDismissMember 开除成员
func (p *Player) CMDismissMember(hdr *f5.MsgHdr, msg *cs.CMDismissMember) {
guildMgr.DismissMember(
p.accountId,
msg.GetDismissAccountId(),
func(errCode int32, errMsg string, guild *Guild) {
rspMsg := new(cs.SMDismissMember)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
if guild != nil {
// 成员通知消息
rspNotify := new(cs.SMDismissMemberNotify)
rspNotify.GuildId = &guild.GuildId
rspNotify.Name = &guild.Name
rspNotify.AccountId = msg.DismissAccountId
playerProfile := cacheMgr.GetPlayerProfile(msg.GetDismissAccountId())
if playerProfile != nil {
rspNotify.Username = &playerProfile.Username
}
for targetAccountId := range guild.Members {
target := playerMgr.GetPlayerByAccountId(targetAccountId)
if target != nil {
target.SendMsg(rspNotify)
}
}
dismissAccount := playerMgr.GetPlayerByAccountId(msg.GetDismissAccountId())
if dismissAccount != nil {
dismissAccount.SendMsg(rspNotify)
}
}
},
)
}
// CMSetMemberLevel 设置公会成员等级
func (p *Player) CMSetMemberLevel(hdr *f5.MsgHdr, msg *cs.CMSetMemberLevel) {
guildMgr.SetMemberLevel(
p.accountId,
msg.GetMemberAccountId(),
msg.GetMemberLevel(),
func(errCode int32, errMsg string, guild *Guild) {
rspMsg := new(cs.SMSetMemberLevel)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
if guild != nil {
// 成员通知消息
rspNotify := new(cs.SMSetMemberLevelNotify)
rspNotify.GuildId = &guild.GuildId
rspNotify.Name = &guild.Name
rspNotify.MemberLevel = msg.MemberLevel
rspNotify.AccountId = msg.MemberAccountId
playerProfile := cacheMgr.GetPlayerProfile(msg.GetMemberAccountId())
if playerProfile != nil {
rspNotify.Username = &playerProfile.Username
}
for targetAccountId := range guild.Members {
target := playerMgr.GetPlayerByAccountId(targetAccountId)
if target != nil {
target.SendMsg(rspNotify)
}
}
}
})
}
// CMDisband 解散公会
func (p *Player) CMDisband(hdr *f5.MsgHdr, msg *cs.CMDisband) {
guildMgr.Disband(
p.accountId,
func(errCode int32, errMsg string, guild *Guild) {
rspMsg := new(cs.SMDisband)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
})
}
// CMSetNotice 设置公告
func (p *Player) CMSetNotice(hdr *f5.MsgHdr, msg *cs.CMSetNotice) {
guildMgr.SetNotice(
p.accountId,
msg.Content,
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMSetNotice)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
})
}
// CMSetAvatar 设置头像
func (p *Player) CMSetAvatar(hdr *f5.MsgHdr, msg *cs.CMSetAvatar) {
guildMgr.SetAvatar(
p.accountId,
msg.GetAvatar(),
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMSetAvatar)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
})
}
// CMSetName 设置公会名称
func (p *Player) CMSetName(hdr *f5.MsgHdr, msg *cs.CMSetName) {
guildMgr.SetName(
p,
msg.Name,
msg.GetItemId(),
msg.GetItemNum(),
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMSetName)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
})
}
// CMSetJoinCond 设置公会加入条件
func (p *Player) CMSetJoinCond(hdr *f5.MsgHdr, msg *cs.CMSetJoinCond) {
guildMgr.SetJoinCond(
p.accountId,
msg.GetJoinCond(),
msg.GetJoinCondValue(),
func(errCode int32, errMsg string) {
rspMsg := new(cs.SMSetJoinCond)
if errCode != 0 {
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
}
p.SendMsg(rspMsg)
})
}
// CMGuildMembersList 公会成员列表
func (p *Player) CMGuildMembersList(hdr *f5.MsgHdr, msg *cs.CMGuildMembersList) {
rspMsg := new(cs.SMGuildMembersList)
guild := guildMgr.GetGuildByAccountId(p.accountId)
if guild == nil {
errCode := q5.ToInt32(ERR_CODE_CREATE_GUILD_DB_FAIL)
errMsg := "No guild"
rspMsg.Errcode = &errCode
rspMsg.Errmsg = &errMsg
} else {
for _, member := range guild.Members {
guildMember := p.FillMFGuildMember(member)
if guildMember != nil {
rspMsg.Members = append(rspMsg.Members, guildMember)
}
}
}
p.SendMsg(rspMsg)
}
// CMSearchGuilds 搜索公会
func (p *Player) CMSearchGuilds(hdr *f5.MsgHdr, msg *cs.CMSearchGuilds) {
rspMsg := new(cs.SMSearchGuilds)
for _, guild := range guildMgr.guilds {
if guild.Name == msg.GetName() {
rspMsg.Guilds = append(rspMsg.Guilds, p.FillMFGuild(guild))
break
}
}
f5.GetSysLog().Info("CMSearchGuilds name[%s], result:%d \n", msg.GetName(), len(rspMsg.Guilds))
p.SendMsg(rspMsg)
// Like search
//guildMgr.SearchGuild(sinceId, name, func(errCode int32, errMsg string, lastId int64, guildIds []int64) {
// rspMsg := new(cs.SMSearchGuilds)
// if errCode != 0 {
// rspMsg.Errcode = &errCode
// rspMsg.Errmsg = &errMsg
// } else {
// for _, guildId := range guildIds {
// guild := guildMgr.GetGuild(guildId)
// if guild != nil {
// rspMsg.Guilds = append(rspMsg.Guilds, p.FillMFGuild(guild))
// }
// }
// }
// f5.GetSysLog().Info("CMSearchGuilds since:%, name[%s], result:%d \n", sinceId, msg.GetName(), len(rspMsg.Guilds))
// p.SendMsg(rspMsg)
//})
}
// CMGuildLogs 请求公会日志
func (p *Player) CMGuildLogs(hdr *f5.MsgHdr, msg *cs.CMGuildLogs) {
rspMsg := new(cs.SMGuildLogs)
guild := guildMgr.GetGuildByAccountId(p.accountId)
if guild == nil {
p.SendMsg(rspMsg)
return
}
for _, g := range guildMgr.GetGuildLogs(guild.GetGuildId()) {
guildLog := &cs.MFGuildLog{
GuildId: &g.GuildId,
AccountId: &g.AccountId,
LogType: &g.LogType,
Content: &g.Content,
}
rspMsg.GuildLogs = append(rspMsg.GuildLogs, guildLog)
}
p.SendMsg(rspMsg)
}
func (p *Player) FillMFGuildMember(member *GuildMember) *cs.MFGuildMember {
profile := cacheMgr.GetPlayerProfile(member.AccountId)
if profile == nil {
return nil
}
onlineStatus := playerMgr.GetOnlineStatus(member.AccountId)
guildMember := &cs.MFGuildMember{
AccountId: &member.AccountId,
Level: &member.Level,
Username: &profile.Username,
Avatar: &profile.Avatar,
AvatarHead: &profile.AvatarHead,
Star: &profile.Star,
Rank: &profile.Rank,
OnlineStatus: &onlineStatus,
LastLoginTime: &profile.LastLoginTime,
}
return guildMember
}
// FillMFGuild 填充公会
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 {
guildMember := p.FillMFGuildMember(member)
if guildMember == nil {
continue
}
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
resGuild = &cs.MFGuild{
AutoId: &guild.AutoId,
GuildId: &guild.GuildId,
Name: &guild.Name,
LeaderId: &guild.LeaderId,
Avatar: &guild.Avatar,
Notice: &guild.Notice,
JoinCond: &guild.JoinCond,
JoinCondValue: &guild.JoinCondValue,
TotalStars: &totalStar,
TotalKills: &totalKills,
ChickenDinners: &totalWinTimes,
MaxMembers: &guild.MaxMembers,
Members: guildMembers,
}
return resGuild
}
// FillMFGuilds 填充公会列表
func (p *Player) FillMFGuilds(guilds []*Guild) []*cs.MFGuild {
var resGuilds []*cs.MFGuild
for _, g := range guilds {
guild := p.FillMFGuild(g)
resGuilds = append(resGuilds, guild)
}
return resGuilds
}
// FillMFUser 填充好友信息
func (p *Player) FillMFUser(profile *PlayerProfile) *cs.MFUser {
var guildId int64 = 0
var guildName = ""
guild := guildMgr.GetGuildByAccountId(profile.AccountId)
if guild != nil {
guildId = guild.GuildId
guildName = guild.Name
}
onlineStatus := playerMgr.GetOnlineStatus(profile.AccountId)
resUser := &cs.MFUser{
AccountId: &profile.AccountId,
Username: &profile.Username,
Avatar: &profile.Avatar,
AvatarHead: &profile.AvatarHead,
GuildId: &guildId,
GuildName: &guildName,
Rank: &profile.Rank,
OnlineStatus: &onlineStatus,
LastLoginTime: &profile.LastLoginTime,
}
return resUser
}
// FillMFChatUser 填充聊天信息
func (p *Player) FillMFChatUser() *cs.MFChatUser {
accountId := p.accountId
profile := cacheMgr.GetPlayerProfile(accountId)
if profile == nil {
return nil
}
var guildId int64 = 0
var guildName = ""
var guildLevel int32 = 0
guild := guildMgr.GetGuildByAccountId(profile.AccountId)
if guild != nil {
guildId = guild.GuildId
guildName = guild.Name
guildLevel = guild.GetMemberLevel(accountId)
}
onlineStatus := playerMgr.GetOnlineStatus(profile.AccountId)
res := &cs.MFChatUser{
AccountId: &profile.AccountId,
Username: &profile.Username,
Avatar: &profile.Avatar,
AvatarHead: &profile.AvatarHead,
GuildId: &guildId,
GuildName: &guildName,
GuildLevel: &guildLevel,
OnlineStatus: &onlineStatus,
LastLoginTime: &profile.LastLoginTime,
}
return res
}
func (p *Player) IncrPrivateChatLastId() uint64 {
p.privateChatLastId++
return p.privateChatLastId
}