package friend import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" ) //接受切磋 func (this *apiComp) AcceptCheck(session comm.IUserSession, req *pb.FriendAcceptReq) (errdata *pb.ErrorData) { if req.Uid == "" { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } func (this *apiComp) Accept(session comm.IUserSession, req *pb.FriendAcceptReq) (errdata *pb.ErrorData) { if errdata = this.AcceptCheck(session, req); errdata != nil { return } //校验切磋请求是否超时 if qr := this.module.ModelFriendQiecuo.getQiecuo(req.Uid); qr != nil { now := configure.Now().Unix() if now-qr.Timestamp > 10 { //大于10s 切磋超时 errdata = &pb.ErrorData{ Code: pb.ErrorCode_FriendQiecuoTimeout, Title: pb.ErrorCode_FriendQiecuoTimeout.ToString(), } this.module.Debug("切磋接受超时", log.Field{Key: "uid", Value: session.GetUserId()}) return } } else { errdata = &pb.ErrorData{ Code: pb.ErrorCode_FriendQiecuoNoRequest, Title: pb.ErrorCode_FriendQiecuoNoRequest.ToString(), } return } if imodule, err := this.module.service.GetModule(comm.ModulePvp); err == nil { if ipvp, ok := imodule.(comm.IPvp); ok { //发起者 red red := this.module.ModuleUser.GetUser(req.Uid) if red == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_UserNofound, Title: pb.ErrorCode_UserNofound.ToString(), } this.module.Error("未找到红方信息", log.Field{Key: "uid", Value: req.Uid}) return } blue := this.module.ModuleUser.GetUser(session.GetUserId()) if blue == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_UserNofound, Title: pb.ErrorCode_UserNofound.ToString(), } this.module.Error("未找到蓝方信息", log.Field{Key: "uid", Value: session.GetUserId()}) return } matchId, c := 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, ) if c != nil { this.module.Debug("createPvp code:", log.Field{Key: "code", Value: c}) return } //更新状态 this.module.ModelFriendQiecuo.updateQiecuoRecord(req.Uid, session.GetUserId(), matchId) } } resp := &pb.FriendAcceptResp{ IsSucc: true, } session.SendMsg(string(this.module.GetType()), FriendSubTypeAccept, resp) this.module.SendMsgToUser(string(this.module.GetType()), "qiecuonotify", &pb.FriendQiecuonotifyPush{Uid: session.GetUserId(), NotifyType: 2}, req.Uid) return }