73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package friend
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/pb"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//接受切磋
|
|
|
|
func (this *apiComp) AcceptCheck(session comm.IUserSession, req *pb.FriendAcceptReq) (code pb.ErrorCode) {
|
|
if req.Uid == "" {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) Accept(session comm.IUserSession, req *pb.FriendAcceptReq) (code pb.ErrorCode, data proto.Message) {
|
|
if code = this.AcceptCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if this.moduleFriend.ModelFriendQiecuo.after != nil {
|
|
this.moduleFriend.ModelFriendQiecuo.after.Stop()
|
|
}
|
|
//校验切磋请求是否超时
|
|
if qr := this.moduleFriend.ModelFriendQiecuo.getQiecuo(req.Uid); qr == nil {
|
|
code = pb.ErrorCode_FriendQiecuoTimeout
|
|
return
|
|
}
|
|
|
|
if imodule, err := this.moduleFriend.service.GetModule(comm.ModulePvp); err == nil {
|
|
if ipvp, ok := imodule.(comm.IPvp); ok {
|
|
//发起者 red
|
|
red := this.moduleFriend.ModuleUser.GetUser(req.Uid)
|
|
if red == nil {
|
|
code = pb.ErrorCode_UserNofound
|
|
this.moduleFriend.Error("未找到红方信息", log.Field{Key: "uid", Value: req.Uid})
|
|
return
|
|
}
|
|
blue := this.moduleFriend.ModuleUser.GetUser(session.GetUserId())
|
|
if blue == nil {
|
|
code = pb.ErrorCode_UserNofound
|
|
this.moduleFriend.Error("未找到蓝方信息", log.Field{Key: "uid", Value: session.GetUserId()})
|
|
return
|
|
}
|
|
if _, code = ipvp.CreatePvp(
|
|
&pb.PvpUserInfo{Uid: red.Uid, Name: red.Name, Avatar: red.Avatar, Lv: red.Lv},
|
|
&pb.PvpUserInfo{Uid: blue.Uid, Name: blue.Name, Avatar: blue.Avatar, Lv: blue.Lv},
|
|
pb.PvpType_friends,
|
|
); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
this.moduleFriend.ModelFriendQiecuo.updateQiecuoRecord(req.Uid, session.GetUserId(), 2)
|
|
|
|
resp := &pb.FriendAcceptResp{
|
|
IsSucc: true,
|
|
}
|
|
if err := session.SendMsg(string(this.moduleFriend.GetType()), FriendSubTypeAccept, resp); err != nil {
|
|
code = pb.ErrorCode_SystemError
|
|
return
|
|
}
|
|
|
|
this.moduleFriend.SendMsgToUser(string(this.moduleFriend.GetType()), "qiecuonotify",
|
|
&pb.FriendQiecuonotifyPush{Uid: session.GetUserId(), NotifyType: 2}, req.Uid)
|
|
|
|
return
|
|
}
|