1
This commit is contained in:
parent
e61c34c069
commit
dc001de7e1
23
server/imserver_new/cache/cachemgr.go
vendored
23
server/imserver_new/cache/cachemgr.go
vendored
@ -6,12 +6,12 @@ import (
|
||||
)
|
||||
|
||||
type CacheMgr struct {
|
||||
cacheMutex sync.Mutex
|
||||
cachePlayerProfiles map[string]*common.CachePlayerProfile
|
||||
lock sync.Mutex
|
||||
userHash map[string]*userProfile
|
||||
}
|
||||
|
||||
func (this *CacheMgr) init() {
|
||||
this.cachePlayerProfiles = make(map[string]*common.CachePlayerProfile)
|
||||
this.userHash = make(map[string]*userProfile)
|
||||
}
|
||||
|
||||
func (this *CacheMgr) UnInit() {
|
||||
@ -19,13 +19,13 @@ func (this *CacheMgr) UnInit() {
|
||||
|
||||
func (this *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
var wg sync.WaitGroup
|
||||
successCount := 0
|
||||
var mu sync.Mutex
|
||||
successCount := 0
|
||||
for _, accountId := range accountIds {
|
||||
wg.Add(1)
|
||||
go func(accountId string) {
|
||||
defer wg.Done()
|
||||
this.cacheMutex.Lock()
|
||||
this.lock.Lock()
|
||||
/*
|
||||
cp, exists := this.cachePlayerProfiles[accountId]
|
||||
this.cacheMutex.Unlock()
|
||||
@ -52,16 +52,9 @@ func (this *CacheMgr) AsyncGetUsers(accountIds []string, cb func(bool)) {
|
||||
}
|
||||
}
|
||||
|
||||
func (this *CacheMgr) addPlayerProfile(version int, playerProfile *common.PlayerProfile) {
|
||||
this.cachePlayerProfiles[playerProfile.AccountId] = &common.CachePlayerProfile{
|
||||
Version: version,
|
||||
Data: playerProfile,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *CacheMgr) GetPlayerProfile(accountId string) *common.PlayerProfile {
|
||||
if profile, exists := this.cachePlayerProfiles[accountId]; exists {
|
||||
return profile.Data
|
||||
func (this *CacheMgr) GetPlayerProfile(accountId string) common.UserProfile {
|
||||
if user, ok := this.userHash[accountId]; ok {
|
||||
return user
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
54
server/imserver_new/cache/user_profile.go
vendored
Normal file
54
server/imserver_new/cache/user_profile.go
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
package cache
|
||||
|
||||
type userProfile struct {
|
||||
accountId string
|
||||
name string
|
||||
avatarUrl string
|
||||
head string
|
||||
star int32
|
||||
totalKills int32
|
||||
totalWinTimes int32
|
||||
rank int32
|
||||
lastLoginTime int32
|
||||
}
|
||||
|
||||
func (this *userProfile) GetAccountId() string {
|
||||
return this.accountId
|
||||
}
|
||||
|
||||
func (this *userProfile) GetUserName() string {
|
||||
return this.name
|
||||
}
|
||||
|
||||
func (this *userProfile) GetAvatar() string {
|
||||
return this.avatarUrl
|
||||
}
|
||||
|
||||
func (this *userProfile) GetAvatarHead() string {
|
||||
return this.head
|
||||
}
|
||||
|
||||
func (this *userProfile) GetStar() int32 {
|
||||
return this.star
|
||||
}
|
||||
|
||||
func (this *userProfile)GetTotalKills() int32 {
|
||||
return this.totalKills
|
||||
}
|
||||
|
||||
|
||||
func (this *userProfile) GetTotalWinTimes() int32 {
|
||||
return this.totalWinTimes
|
||||
}
|
||||
|
||||
func (this *userProfile) GetRank() int32 {
|
||||
return this.rank
|
||||
}
|
||||
|
||||
func (this *userProfile) GetOnlineStatus() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (this *userProfile) GetLastLoginTime() int32 {
|
||||
return this.lastLoginTime
|
||||
}
|
@ -93,14 +93,6 @@ type FriendMgr interface {
|
||||
AddUser(string, User)
|
||||
GetUser(string) User
|
||||
LoadUserFriendships(user User, where [][]string)
|
||||
SearchUsers(accountId, username string, sinceId int64, cb func(errCode int32, errMsg string, lastId int64, listFriend []*PlayerProfile))
|
||||
SearchByAccountId(accountId string, cb func(errCode int32, errMsg string, playerProfile *PlayerProfile))
|
||||
AddFriendRequest(account1Id string, account2Id string, cb func(errCode int32, errMsg string))
|
||||
AcceptFriendRequest(account1Id string, account2Id string, cb func(errCode int32, errMsg string))
|
||||
RejectFriendRequest(account1Id string, account2Id string, cb func(errCode int32, errMsg string))
|
||||
DeleteFriendShip(account1Id, account2Id string, cb func(errCode int32, errMsg string))
|
||||
AddBlacklist(account1Id string, account2Id string, cb func(errCode int32, errMsg string))
|
||||
RemoveBlacklist(account1Id string, account2Id string, cb func(errCode int32, errMsg string))
|
||||
}
|
||||
|
||||
type Guild interface {
|
||||
@ -119,8 +111,7 @@ type GuildMgr interface {
|
||||
}
|
||||
|
||||
type CacheMgr interface {
|
||||
GetProfileByAccountId(accountId string, cb func(err error, profile *PlayerProfile))
|
||||
GetPlayerProfile(accountId string) *PlayerProfile
|
||||
GetPlayerProfile(accountId string) UserProfile
|
||||
LoadUserProfile(string)
|
||||
AsyncGetUsers(accountIds []string, cb func(bool))
|
||||
}
|
||||
@ -137,20 +128,15 @@ type ChatMgr interface {
|
||||
SyncPrivateChatMsg(p Player)
|
||||
}
|
||||
|
||||
type PlayerProfile struct {
|
||||
AccountId string
|
||||
Username string // 用户名
|
||||
Avatar int32 // 头像
|
||||
AvatarHead int32 // 头像框
|
||||
Star int32 // 星星
|
||||
TotalKills int32 // 总击杀数
|
||||
TotalWinTimes int32 // 总赢数
|
||||
Rank int32 // 排位赛段位
|
||||
OnlineStatus int32 // 在线状态
|
||||
LastLoginTime int32 // 上次登录时间
|
||||
}
|
||||
|
||||
type CachePlayerProfile struct {
|
||||
Version int
|
||||
Data *PlayerProfile
|
||||
type UserProfile interface {
|
||||
GetAccountId() string
|
||||
GetUserName() string
|
||||
GetAvatar() string
|
||||
GetAvatarHead() string
|
||||
GetStar() int32
|
||||
GetTotalKills() int32
|
||||
GetTotalWinTimes() int32
|
||||
GetRank() int32
|
||||
GetOnlineStatus() int32
|
||||
GetLastLoginTime() int32
|
||||
}
|
||||
|
@ -4,8 +4,6 @@ import (
|
||||
"cs"
|
||||
"f5"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"q5"
|
||||
"sort"
|
||||
"main/constant"
|
||||
"main/common"
|
||||
. "main/global"
|
||||
@ -106,239 +104,43 @@ func (this *player) CMPing(hdr *f5.MsgHdr, msg *cs.CMPing) {
|
||||
this.SendMsg(rspMsg)
|
||||
}
|
||||
|
||||
// CMSearchUser 搜索用户
|
||||
func (this *player) CMSearchUser(hdr *f5.MsgHdr, msg *cs.CMSearchUser) {
|
||||
sinceId := msg.GetSinceId()
|
||||
searchUsername := msg.GetUsername()
|
||||
GetFriendMgr().SearchUsers(
|
||||
this.accountId,
|
||||
searchUsername,
|
||||
sinceId,
|
||||
func(errCode int32, errMsg string, lastId int64, listFriend []*common.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)
|
||||
}*/
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
// CMSearchUserByAccountId 搜索指定用户
|
||||
func (this *player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUserByAccountId) {
|
||||
GetFriendMgr().SearchByAccountId(msg.GetAccountId(),
|
||||
func(errCode int32, errMsg string, playerProfile *common.PlayerProfile) {
|
||||
rspMsg := new(cs.SMSearchUserByAccountId)
|
||||
if errCode != 0 {
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
} else {
|
||||
if playerProfile != nil {
|
||||
//rspMsg.Users = p.FillMFUser(playerProfile)
|
||||
}
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
// CMListPendingFriendRequest 等待验证的好友请求
|
||||
func (this *player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPendingFriendRequest) {
|
||||
accountId := this.accountId
|
||||
user := GetFriendMgr().GetUser(accountId)
|
||||
rspMsg := &cs.SMListPendingFriendRequest{}
|
||||
|
||||
for targetAccountId, friendRequest := range user.GetFriendships() {
|
||||
if friendRequest.IsFriendship() != constant.FriendshipStatusPending {
|
||||
continue
|
||||
}
|
||||
profile := GetCacheMgr().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))
|
||||
this.SendMsg(rspMsg)
|
||||
}
|
||||
|
||||
func (this *player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) {
|
||||
accountId := this.accountId
|
||||
user := GetFriendMgr().GetUser(accountId)
|
||||
|
||||
var friendIds []string
|
||||
for _, friendship := range user.GetFriendships() {
|
||||
if friendship.FriendAccountId() == accountId || friendship.IsFriendship() != constant.FriendshipStatusOK {
|
||||
continue
|
||||
}
|
||||
friendIds = append(friendIds, friendship.FriendAccountId())
|
||||
}
|
||||
|
||||
rspMsg := &cs.SMListFriend{}
|
||||
rspMsg.Users = make([]*cs.MFUser, len(friendIds))
|
||||
GetCacheMgr().AsyncGetUsers(friendIds, func(ok bool) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
/*
|
||||
for _, fid := range friendIds {
|
||||
userProfile := GetCacheMgr().GetPlayerProfile(fid)
|
||||
rspUser := p.FillMFUser(userProfile)
|
||||
rspMsg.Users = append(rspMsg.Users, rspUser)
|
||||
}
|
||||
p.SendMsg(rspMsg)
|
||||
*/
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) {
|
||||
rspMsg := &cs.SMBlacklist{}
|
||||
accountId := this.accountId
|
||||
player := GetFriendMgr().GetUser(accountId)
|
||||
for _, blackList := range player.GetFriendBlackList() {
|
||||
if blackList.IsRemoved() != 0 {
|
||||
continue
|
||||
}
|
||||
blockedPlayerProfile := GetCacheMgr().GetPlayerProfile(blackList.GetAccountId())
|
||||
if blockedPlayerProfile == nil {
|
||||
continue
|
||||
}
|
||||
/*
|
||||
user := p.FillMFUser(blockedPlayerProfile)
|
||||
rspMsg.Users = append(rspMsg.Users, user)
|
||||
*/
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
}
|
||||
|
||||
func (this *player) CMAddFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAddFriendRequest) {
|
||||
user1Id := this.accountId
|
||||
user2Id := msg.GetTargetAccountId()
|
||||
GetFriendMgr().AddFriendRequest(user1Id, user2Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
rspMsg := new(cs.SMAddFriendRequest)
|
||||
if errCode != 0 {
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
} else {
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) CMAcceptFriendRequest(hdr *f5.MsgHdr, msg *cs.CMAcceptFriendRequest) {
|
||||
user1Id := this.accountId
|
||||
user2Id := msg.GetTargetAccountId()
|
||||
GetFriendMgr().AcceptFriendRequest(user1Id, user2Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
rspMsg := new(cs.SMAcceptFriendRequest)
|
||||
if errCode != 0 {
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
} else {
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) CMRejectFriendRequest(hdr *f5.MsgHdr, msg *cs.CMRejectFriendRequest) {
|
||||
user1Id := this.accountId
|
||||
user2Id := msg.GetTargetAccountId()
|
||||
GetFriendMgr().RejectFriendRequest(user1Id, user2Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
rspMsg := new(cs.SMRejectFriendRequest)
|
||||
if errCode != 0 {
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
} else {
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) CMDeleteFriendShip(hdr *f5.MsgHdr, msg *cs.CMDeleteFriendShip) {
|
||||
user1Id := this.accountId
|
||||
user2Id := msg.GetTargetAccountId()
|
||||
GetFriendMgr().DeleteFriendShip(user1Id, user2Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
rspMsg := new(cs.SMDeleteFriendShip)
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) CMAddBlacklist(hdr *f5.MsgHdr, msg *cs.CMAddBlacklist) {
|
||||
user1Id := this.accountId
|
||||
user2Id := msg.GetTargetAccountId()
|
||||
GetFriendMgr().AddBlacklist(user1Id, user2Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
rspMsg := new(cs.SMAddBlacklist)
|
||||
if errCode != 0 {
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
} else {
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) CMRemoveBlacklist(hdr *f5.MsgHdr, msg *cs.CMRemoveBlacklist) {
|
||||
user1Id := this.accountId
|
||||
user2Id := msg.GetTargetAccountId()
|
||||
GetFriendMgr().RemoveBlacklist(user1Id, user2Id,
|
||||
func(errCode int32, errMsg string) {
|
||||
rspMsg := new(cs.SMRemoveBlacklist)
|
||||
if errCode != 0 {
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
} else {
|
||||
}
|
||||
this.SendMsg(rspMsg)
|
||||
})
|
||||
}
|
||||
|
||||
func (this *player) CMInviteFriendMsg(hdr *f5.MsgHdr, msg *cs.CMInviteFriendMsg) {
|
||||
rspMsg := new(cs.SMInviteFriendMsg)
|
||||
p2 := GetPlayerMgr().GetPlayerByAccountId(msg.GetInviteAccountId())
|
||||
if p2 == nil {
|
||||
rspMsg.Errcode = proto.Int32(constant.ERR_CODE_FRIEND_NO_EXISTS)
|
||||
rspMsg.Errmsg = proto.String("friend no exists")
|
||||
this.SendMsg(rspMsg)
|
||||
} else {
|
||||
rspMsg.Msg = msg.Msg
|
||||
p2.SendMsg(rspMsg)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *player) CMSendChatMsg(hdr *f5.MsgHdr, msg *cs.CMSendChatMsg) {
|
||||
if !IsValidChatChannel(msg.GetChatChannel()) {
|
||||
return
|
||||
}
|
||||
|
||||
switch msg.GetChatChannel() {
|
||||
case constant.CCWorld:
|
||||
GetChatMgr().ProcWorldChat(this, msg)
|
||||
case constant.CCPrivate:
|
||||
GetChatMgr().ProcPrivateChat(this, msg)
|
||||
case constant.CCGuild:
|
||||
GetChatMgr().ProcGuildChat(this, msg)
|
||||
case constant.CCTeam:
|
||||
GetChatMgr().ProcTeamChat(this, msg)
|
||||
default:
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (this *player) SyncPrivateChatRedPoint() {
|
||||
@ -346,37 +148,9 @@ func (this *player) SyncPrivateChatRedPoint() {
|
||||
//GetChatMgr().FillSMUpdatePrivateChatRedPointNotify(p, msg)
|
||||
}
|
||||
|
||||
// CMReadMsgAndOpenChatNotify 读取聊天消息列表并且开启聊天通知
|
||||
func (this *player) CMReadMsgAndOpenChatNotify(hdr *f5.MsgHdr, msg *cs.CMReadMsgAndOpenChatNotify) {
|
||||
if !IsValidChatChannel(msg.GetCurrChannel()) {
|
||||
return
|
||||
}
|
||||
this.chatChannel = int(msg.GetCurrChannel())
|
||||
if this.chatChannel == constant.CCPrivate {
|
||||
this.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 constant.CCWorld:
|
||||
this.worldChannelLastId = chatChannelLastId
|
||||
//GetChatMgr().SyncWorldChatMsg(p)
|
||||
case constant.CCGuild:
|
||||
this.guildChannelLastId = chatChannelLastId
|
||||
//GetChatMgr().SyncGuildChatMsg(p)
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CMSetCurrPrivateChatTarget 设置当前私聊目标
|
||||
func (this *player) CMSetCurrPrivateChatTarget(hdr *f5.MsgHdr, msg *cs.CMSetCurrPrivateChatTarget) {
|
||||
//p.privateTargetAccountId = msg.GetTargetAccountId()
|
||||
//GetChatMgr().SyncPrivateChatMsg(p)
|
||||
@ -392,614 +166,68 @@ func IsValidChatChannel(chatChannel int32) bool {
|
||||
return chatChannel > constant.CCBegin && chatChannel < constant.CCEnd
|
||||
}
|
||||
|
||||
// CMGuildInfo 公会信息
|
||||
func (this *player) CMGuildInfo(hdr *f5.MsgHdr, msg *cs.CMGuildInfo) {
|
||||
/*
|
||||
var accountId = p.GetAccountId()
|
||||
if len(msg.GetAccountId()) > 0 {
|
||||
accountId = msg.GetAccountId()
|
||||
}
|
||||
rspMsg := new(cs.SMGuildInfo)
|
||||
guild := GetGuildMgr().GetGuildByAccountId(accountId)
|
||||
if guild != nil {
|
||||
rspMsg.Guild = p.FillMFGuild(guild)
|
||||
}
|
||||
p.SendMsg(rspMsg)
|
||||
*/
|
||||
}
|
||||
|
||||
// CMRecommendGuildList 推荐公会列表
|
||||
func (this *player) CMRecommendGuildList(hdr *f5.MsgHdr, msg *cs.CMRecommendGuildList) {
|
||||
/*
|
||||
rspMsg := new(cs.SMRecommendGuildList)
|
||||
rspMsg.RecommendGuilds = p.FillMFGuilds(GetGuildMgr().RandomGuilds())
|
||||
p.SendMsg(rspMsg)
|
||||
*/
|
||||
}
|
||||
|
||||
// CMGetTopGuildsByTotalStars 公会排行 总星星数排行
|
||||
func (this *player) CMGetTopGuildsByTotalStars(hdr *f5.MsgHdr, msg *cs.CMGetTopGuildsByTotalStars) {
|
||||
rspMsg := new(cs.SMGetTopGuildsByTotalStars)
|
||||
guildsNum := int(msg.GetGuildsNum())
|
||||
|
||||
var allMFGuilds []*cs.MFGuild
|
||||
/*
|
||||
for _, g := range GetGuildMgr().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
|
||||
|
||||
this.SendMsg(rspMsg)
|
||||
}
|
||||
|
||||
// CMCreateGuild 创建公会
|
||||
func (this *player) CMCreateGuild(hdr *f5.MsgHdr, msg *cs.CMCreateGuild) {
|
||||
/*
|
||||
avatar := msg.GetAvatar()
|
||||
guildMgr.CreateGuild(
|
||||
p, avatar, msg.GetName(), 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 (this *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 (this *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 != constant.PendingReqIsJoinGuildStatusDefault {
|
||||
continue
|
||||
}
|
||||
member := &GuildMember{
|
||||
AccountId: accountId,
|
||||
Level: q5.ToInt32(constant.GuildMemberLevelDefault),
|
||||
}
|
||||
rspMember := p.FillMFGuildMember(member)
|
||||
if rspMember != nil {
|
||||
rspMsg.Members = append(rspMsg.Members, rspMember)
|
||||
}
|
||||
}
|
||||
}
|
||||
p.SendMsg(rspMsg)
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
// CMApprove 同意申请者加入公会
|
||||
func (this *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 (this *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 (this *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 (this *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 (this *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 (this *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 (this *player) CMSetNotice(hdr *f5.MsgHdr, msg *cs.CMSetNotice) {
|
||||
/*
|
||||
guildMgr.SetNotice(
|
||||
p.accountId,
|
||||
msg.GetContent(),
|
||||
func(errCode int32, errMsg string) {
|
||||
rspMsg := new(cs.SMSetNotice)
|
||||
if errCode != 0 {
|
||||
rspMsg.Errcode = &errCode
|
||||
rspMsg.Errmsg = &errMsg
|
||||
}
|
||||
p.SendMsg(rspMsg)
|
||||
})
|
||||
*/
|
||||
}
|
||||
|
||||
// CMSetAvatar 设置头像
|
||||
func (this *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 (this *player) CMSetName(hdr *f5.MsgHdr, msg *cs.CMSetName) {
|
||||
/*
|
||||
guildMgr.SetName(
|
||||
p,
|
||||
msg.GetName(),
|
||||
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 (this *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 (this *player) CMGuildMembersList(hdr *f5.MsgHdr, msg *cs.CMGuildMembersList) {
|
||||
/*rspMsg := new(cs.SMGuildMembersList)
|
||||
|
||||
guild := guildMgr.GetGuildByAccountId(p.accountId)
|
||||
if guild == nil {
|
||||
errCode := q5.ToInt32(constant.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 (this *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 (this *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 (this *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
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// FillMFGuild 填充公会
|
||||
func (this *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 (this *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 (this *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
|
||||
}
|
||||
*/
|
||||
|
||||
func (this *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
|
||||
*/
|
||||
return nil
|
||||
}
|
||||
|
||||
/*
|
||||
func (this *player) IncrPrivateChatLastId() uint64 {
|
||||
p.privateChatLastId++
|
||||
return p.privateChatLastId
|
||||
}
|
||||
*/
|
||||
|
||||
func (this *player) onOffline() {
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user