go_dreamfactory/modules/friend/api_cross_search.go
2022-10-31 15:12:01 +08:00

53 lines
1.1 KiB
Go

package friend
import (
"go_dreamfactory/comm"
"go_dreamfactory/pb"
"google.golang.org/protobuf/proto"
)
func (this *apiComp) SearchCheck(session comm.IUserSession, req *pb.FriendSearchReq) (code pb.ErrorCode) {
if req.NickName == "" {
code = pb.ErrorCode_FriendSearchNameEmpty
return
}
return
}
//搜索
func (this *apiComp) Search(session comm.IUserSession, req *pb.FriendSearchReq) (code pb.ErrorCode, data proto.Message) {
if code = this.SearchCheck(session, req); code != pb.ErrorCode_Success {
return
}
resp := &pb.FriendSearchResp{}
users, err := this.moduleFriend.ModuleUser.SearchRmoteUser(req.NickName)
if err != nil {
code = pb.ErrorCode_DBError
this.moduleFriend.Errorf("搜索玩家 err:%v", err)
return
}
for _, u := range users {
// 排除自己
if u.Uid == session.GetUserId() {
continue
}
resp.Friends = append(resp.Friends, &pb.FriendBase{
UserId: u.Uid,
NickName: u.Name,
Level: u.Lv,
Avatar: u.Avatar,
ServerId: u.Sid,
})
}
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeSearch, resp); err != nil {
code = pb.ErrorCode_SystemError
}
return
}