This commit is contained in:
aozhiwei 2024-03-23 10:31:19 +08:00
parent 3b6ad65bf6
commit 89c788c19b
3 changed files with 63 additions and 0 deletions

View File

@ -56,6 +56,8 @@ type PlayerMgr interface {
type FriendMgr interface {
IsFriend(string, string) bool
GetFriendList(string) []string
AsyncGetApplyList(int64, string, func(int32, string, int64, []string))
}
type Guild interface {

View File

@ -1,6 +1,7 @@
package friend
import (
"q5"
)
type FriendMgr struct {
@ -56,9 +57,25 @@ func (this *FriendMgr) TraverseFriend(accountId string, cb func(string, int32) b
}
}
func (this *FriendMgr) GetFriendList(accountId string) []string {
friendList := []string{}
this.TraverseFriend(
accountId,
func (friendId string, addTime int32) bool {
ele := q5.NewSliceElement(&friendList)
*ele = friendId
return true
})
return friendList
}
func (this *FriendMgr) getFriends(accountId string) *map[string]int32 {
if friends, ok := this.friendHash[accountId]; ok {
return friends
}
return nil
}
func (this *FriendMgr) AsyncGetApplyList(int64, string, func(int32, string, int64, []string)) {
}

View File

@ -91,9 +91,53 @@ func (this *player) CMSearchUserByAccountId(hdr *f5.MsgHdr, msg *cs.CMSearchUser
}
func (this *player) CMListPendingFriendRequest(hdr *f5.MsgHdr, msg *cs.CMListPendingFriendRequest) {
GetFriendMgr().AsyncGetApplyList(
0,
this.GetAccountId(),
func (errCode int32, errMsg string, sinceId int64, accountIds []string) {
rspMsg := new(cs.SMListPendingFriendRequest)
if errCode != 0 {
this.SendMsg(rspMsg.Err(1, "internal server error"))
return
}
GetCacheMgr().AsyncGetUsers(
accountIds,
func (errCode int32, errMsg string) {
if errCode != 0 {
this.SendMsg(rspMsg.Err(1, "internal server error"))
return
}
for _, accountId := range(accountIds) {
userProfile := GetCacheMgr().GetUserProfile(accountId)
if userProfile != nil {
ele := q5.NewSliceElement(&rspMsg.Users)
userProfile.FillMFUser(*ele)
}
}
this.SendMsg(rspMsg)
})
})
}
func (this *player) CMListFriend(hdr *f5.MsgHdr, msg *cs.CMListFriend) {
friendList := GetFriendMgr().GetFriendList(this.GetAccountId())
GetCacheMgr().AsyncGetUsers(
friendList,
func (errCode int32, errMsg string) {
rspMsg := new(cs.SMListFriend)
if errCode != 0 {
this.SendMsg(rspMsg.Err(1, "internal server error"))
return
}
for _, accountId := range(friendList) {
userProfile := GetCacheMgr().GetUserProfile(accountId)
if userProfile != nil {
ele := q5.NewSliceElement(&rspMsg.Users)
userProfile.FillMFUser(*ele)
}
}
this.SendMsg(rspMsg)
})
}
func (this *player) CMBlacklist(hdr *f5.MsgHdr, msg *cs.CMBlacklist) {