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