处理切磋pvp失败情况
This commit is contained in:
parent
4d69b0c3dc
commit
01476853e0
@ -1,6 +1,7 @@
|
||||
package friend
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/pb"
|
||||
|
||||
@ -25,21 +26,15 @@ func (this *apiComp) Qiecuo(session comm.IUserSession, req *pb.FriendQiecuoReq)
|
||||
return
|
||||
}
|
||||
|
||||
//校验目标是否已正在切磋
|
||||
if targetQr := this.moduleFriend.ModelFriendQiecuo.getQiecuo(req.TargetUid); targetQr != nil {
|
||||
code = pb.ErrorCode_FriendQiecuoTargetPk
|
||||
return
|
||||
}
|
||||
|
||||
qr, err := this.moduleFriend.ModelFriendQiecuo.createQiecuoRecord(session.GetUserId(), req.TargetUid)
|
||||
//切磋请求处理
|
||||
err := this.moduleFriend.ModelFriendQiecuo.qiecuoReq(session.GetUserId(), req.TargetUid)
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_DBError
|
||||
return
|
||||
}
|
||||
|
||||
//判断是否切磋中
|
||||
if qr.MatchId != "" {
|
||||
code = pb.ErrorCode_FriendQiecuoing
|
||||
var customErr = new(comm.CustomError)
|
||||
if errors.As(err, &customErr) {
|
||||
code = customErr.Code
|
||||
} else {
|
||||
code = pb.ErrorCode_DBError
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -37,10 +37,11 @@ func (this *ModelFriendQiecuo) getQiecuo(uid string) *pb.QiecuoRecord {
|
||||
return record
|
||||
}
|
||||
|
||||
// 保存切磋记录
|
||||
func (this *ModelFriendQiecuo) createQiecuoRecord(uid, targetUid string) (*pb.QiecuoRecord, error) {
|
||||
// 切磋请求处理
|
||||
func (this *ModelFriendQiecuo) qiecuoReq(uid, targetUid string) error {
|
||||
qr := this.getQiecuo(uid)
|
||||
if qr == nil {
|
||||
//创建切磋记录
|
||||
qr = &pb.QiecuoRecord{
|
||||
Uid: uid,
|
||||
TargetId: targetUid,
|
||||
@ -49,25 +50,27 @@ func (this *ModelFriendQiecuo) createQiecuoRecord(uid, targetUid string) (*pb.Qi
|
||||
}
|
||||
if err := this.Add(uid, qr); err != nil {
|
||||
this.moduleFriend.Errorln(err)
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
//如果目标未接受且在超时时间内,不允许再次发送
|
||||
now := configure.Now().Unix()
|
||||
if qr.Status == 1 && now-qr.Timestamp < 10 {
|
||||
return qr, comm.NewCustomError(pb.ErrorCode_FriendQiecuoRequested)
|
||||
return comm.NewCustomError(pb.ErrorCode_FriendQiecuoRequested)
|
||||
} else if qr.Status == 2 || qr.MatchId != "" {
|
||||
return comm.NewCustomError(pb.ErrorCode_FriendQiecuoing)
|
||||
} else {
|
||||
update := map[string]interface{}{
|
||||
"targetId": targetUid,
|
||||
"timestamp": configure.Now().Unix(),
|
||||
}
|
||||
if err := this.Change(uid, update); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return qr, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
// 更新切磋记录
|
||||
|
@ -7,6 +7,6 @@ import (
|
||||
|
||||
// 贸易
|
||||
|
||||
func (this *apiComp) TradeCheck(session comm.IUserSession, req *pb.SmithyTradeReq) (code pb.ErrorCode) {
|
||||
func (this *apiComp) TradeCheck(session comm.IUserSession, req *pb.SmithySellItemReq) (code pb.ErrorCode) {
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user