package practice import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" "time" "google.golang.org/protobuf/proto" ) // 踢馆(熊猫武馆) 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 proto.Message) { if code = this.QiecuoCheck(session, req); code != pb.ErrorCode_Success { return } var ( err error result *pb.DBPracticeQiecuoRecord fresult *pb.DBPracticeQiecuoRecord keep bool ) //目标是否在线 if !this.module.ModuleUser.IsOnline(req.Fid) { code = pb.ErrorCode_UserOffline return } //切磋请求处理 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 { //已经在战斗中了 code = pb.ErrorCode_PracticeQiecuoing 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(), NotifyType: 1}, req.Fid) return }