75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
package parkour
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) RaceMatchCancelCheck(session comm.IUserSession, req *pb.ParkourRaceMatchCancelReq) (errdata *pb.ErrorData) {
|
|
if session.GetUserId() != req.Captainid {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
///匹配请求
|
|
func (this *apiComp) RaceMatchCancel(session comm.IUserSession, req *pb.ParkourRaceMatchCancelReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
team *pb.DBParkour
|
|
users []string
|
|
err error
|
|
)
|
|
if errdata = this.RaceMatchCancelCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if team, err = this.module.parkourComp.queryinfo(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if team.Captainid != session.GetUserId() {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if err = this.module.match(team); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
users = make([]string, len(team.Member))
|
|
for i, v := range team.Member {
|
|
if !v.Isai {
|
|
users[i] = v.Uid
|
|
if err = this.module.parkourComp.Change(v.Uid, map[string]interface{}{
|
|
"state": pb.RaceTeamState_matching,
|
|
}); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
}
|
|
}
|
|
this.module.SendMsgToUsers(string(this.module.GetType()), "racematchstart",
|
|
&pb.ParkourRaceMatchCancelPush{Team: team}, users...)
|
|
|
|
session.SendMsg(string(this.module.GetType()), "racematch", &pb.ParkourRaceMatchResp{})
|
|
return
|
|
}
|