package practice import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "time" ) // 踢馆(熊猫武馆) func (this *apiComp) QiecuoCheck(session comm.IUserSession, req *pb.PracticeQiecuoReq) (code pb.ErrorCode) { if req.Fid == "" { code = pb.ErrorCode_ReqParameterError } return } func (this *apiComp) Qiecuo(session comm.IUserSession, req *pb.PracticeQiecuoReq) (code pb.ErrorCode, data *pb.ErrorData) { if code = this.QiecuoCheck(session, req); code != pb.ErrorCode_Success { return } var ( err error result *pb.DBPracticeQiecuoRecord fresult *pb.DBPracticeQiecuoRecord user *pb.DBUser battle *pb.DBPvpBattle keep bool ) //切磋请求处理 if result, err = this.module.modelQiecuo.queryQiecuo(session.GetUserId()); err != nil { code = pb.ErrorCode_DBError return } if fresult, err = this.module.modelQiecuo.queryQiecuo(req.Fid); err != nil { code = pb.ErrorCode_DBError return } if result.Status == 1 || fresult.Status == 1 { //已经在战斗中了 if result.Battid == fresult.Battid { //两个人正在战斗中 if battle, err = this.module.pvp.QueryBattle(result.Battid); err != nil { this.module.Error("查询pvp数据失败!", log.Field{Key: "id", Value: result.Battid}, log.Field{Key: "err", Value: err.Error()}) code = pb.ErrorCode_SystemError return } if err = session.SendMsg(string(this.module.GetType()), "qiecuo", &pb.PracticeQiecuoResp{Fid: req.Fid, Isbattle: true, Battle: battle}); err != nil { code = pb.ErrorCode_SystemError return } return } else { if result.Status == 1 { code = pb.ErrorCode_PracticeYouQiecuoing return } else { code = pb.ErrorCode_PracticeTargetQiecuoing return } } } //目标是否在线 if !this.module.ModuleUser.IsOnline(req.Fid) { code = pb.ErrorCode_UserOffline return } if user = this.module.ModuleUser.GetUser(session.GetUserId()); user == nil { code = pb.ErrorCode_DBError return } keep = false for _, v := range result.Targets { if v.Uid == req.Fid { keep = true if configure.Now().Sub(time.Unix(v.Timestamp, 0)).Seconds() > 10 { v.Timestamp = configure.Now().Unix() } else { code = pb.ErrorCode_PracticeSent return } } } if !keep { result.Targets = append(result.Targets, &pb.DBPracticeQiecuoInvite{ Uid: req.Fid, Timestamp: configure.Now().Unix(), }) } this.module.modelQiecuo.Change(session.GetUserId(), map[string]interface{}{ "targets": result.Targets, }) if err = session.SendMsg(string(this.module.GetType()), "qiecuo", &pb.PracticeQiecuoResp{Fid: req.Fid}); err != nil { code = pb.ErrorCode_SystemError return } this.module.SendMsgToUser(string(this.module.GetType()), "qiecuonotify", &pb.PracticeQiecuonotifyPush{Uid: session.GetUserId(), Name: user.Name, NotifyType: 1}, req.Fid) return }