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