diff --git a/cmd/v2/ui/protocol.go b/cmd/v2/ui/protocol.go index 4ac0a9013..056041f30 100644 --- a/cmd/v2/ui/protocol.go +++ b/cmd/v2/ui/protocol.go @@ -462,6 +462,19 @@ var ( MainType: string(comm.ModuleFriend), SubType: friend.FriendSubTypeRandList, Enabled: true, + Print: func(rsp proto.Message) string { + var formatStr strings.Builder + if in, ok := rsp.(*pb.UserMessage); ok { + out := &pb.FriendRandlistResp{} + if !comm.ProtoUnmarshal(in, out) { + return errors.New("unmarshal err").Error() + } + for i, v := range out.List { + formatStr.WriteString(fmt.Sprintf("%d- %v\n", (i + 1), v)) + } + } + return formatStr.String() + }, }, ff(comm.ModuleFriend, friend.FriendSubTypeList): { NavLabel: "好友列表", diff --git a/modules/friend/api_randlist.go b/modules/friend/api_randlist.go index 00e92eeed..acd8b6f37 100644 --- a/modules/friend/api_randlist.go +++ b/modules/friend/api_randlist.go @@ -13,61 +13,64 @@ func (this *apiComp) RandlistCheck(session comm.IUserSession, req *pb.FriendRand } func (this *apiComp) Randlist(session comm.IUserSession, req *pb.FriendRandlistReq) (code pb.ErrorCode, data proto.Message) { - var ( - self *pb.DBFriend - ) - //在线玩家 + + // 当前玩家好友数据 + self := this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) + if self == nil { + code = pb.ErrorCode_FriendSelfNoData + return + } + + //在线玩家列表 cuList, err := this.moduleFriend.ModuleUser.UserOnlineList() if err != nil { code = pb.ErrorCode_DBError return } + //过滤 + var newList []*pb.CacheUser + for _, v := range cuList { + // 将自己从在线玩家中过滤掉 + if v.Uid == session.GetUserId() { + continue + } + // 将自己的好友从在线玩家中过滤掉 + if _, ok := utils.Findx(self.FriendIds, v.Uid); ok { + continue + } + newList = append(newList, v) + } + // 只随机选择5个在线玩家 var randOnlineUsers []string - if len(cuList) > 5 { - randArr := utils.Numbers(0, len(cuList), 5) + if len(newList) > 5 { + randArr := utils.Numbers(0, len(newList), 5) for _, v := range randArr { - if cuList[v] != nil { - randOnlineUsers = append(randOnlineUsers, cuList[v].Uid) + if newList[v] != nil { + randOnlineUsers = append(randOnlineUsers, newList[v].Uid) } } } else { - for _, v := range cuList { + for _, v := range newList { randOnlineUsers = append(randOnlineUsers, v.Uid) } } - // 当前玩家好友数据 - self = this.moduleFriend.modelFriend.GetFriend(session.GetUserId()) - if self == nil { - code = pb.ErrorCode_FriendSelfNoData - return - } - var userList []*pb.FriendBase for _, uid := range randOnlineUsers { - // 将自己从在线玩家中过滤掉 - if uid == session.GetUserId() { - continue - } - // 将自己的好友从在线玩家中过滤掉 - if _, ok := utils.Findx(self.FriendIds, uid); ok { - continue - } - // 判断当前在线好友是否在自己的申请列表中,如果存在也过滤掉 target := this.moduleFriend.modelFriend.GetFriend(uid) if target == nil { continue } - // 获取在线好友的信息 - user := this.moduleFriend.ModuleUser.GetUser(uid) - if user == nil { - continue - } + // // 获取在线好友的信息 + // user := this.moduleFriend.ModuleUser.GetUser(uid) + // if user == nil { + // continue + // } base := this.setDefaultFriendUserBaseInfo(uid) if base == nil {