74 lines
1.6 KiB
Go
74 lines
1.6 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
"go_dreamfactory/utils"
|
|
)
|
|
|
|
// 搜索
|
|
func (this *apiComp) SearchCheck(session comm.IUserSession, req *pb.FriendSearchReq) (errdata *pb.ErrorData) {
|
|
if req.NickName == "" {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_FriendSearchNameEmpty,
|
|
Title: pb.ErrorCode_FriendSearchNameEmpty.ToString(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Search(session comm.IUserSession, req *pb.FriendSearchReq) (errdata *pb.ErrorData) {
|
|
if errdata = this.SearchCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
uid := session.GetUserId()
|
|
resp := &pb.FriendSearchResp{}
|
|
|
|
users, err := this.module.ModuleUser.SearchRmoteUser(req.NickName)
|
|
if err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
this.module.Error("搜索玩家",
|
|
log.Field{Key: "uid", Value: uid},
|
|
log.Field{Key: "params", Value: req.NickName},
|
|
log.Field{Key: "err", Value: err.Error()},
|
|
)
|
|
return
|
|
}
|
|
|
|
for _, u := range users {
|
|
// 排除自己
|
|
if u.Uid == session.GetUserId() {
|
|
continue
|
|
}
|
|
base := &pb.FriendBase{
|
|
UserId: u.Uid,
|
|
NickName: u.Name,
|
|
Level: u.Lv,
|
|
Skin: u.CurSkin,
|
|
ServerId: u.Sid,
|
|
Gender: u.Gender,
|
|
}
|
|
|
|
target, err := this.module.modelFriend.GetFriend(u.Uid)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
if _, ok := utils.Findx(target.ApplyIds, uid); ok {
|
|
base.IsApplied = true
|
|
}
|
|
resp.Friends = append(resp.Friends, base)
|
|
}
|
|
|
|
session.SendMsg(string(this.module.GetType()), FriendSubTypeSearch, resp)
|
|
|
|
return
|
|
}
|