From 41361621ef71e397b49202bab3f6be835da6070b Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Fri, 7 Jun 2024 13:58:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=94=E8=B5=9B=E6=97=A5=E5=BF=97=E7=94=A8?= =?UTF-8?q?=E5=BC=80=E5=A7=8B=E6=AF=94=E8=B5=9B=E6=97=B6=E5=A4=87=E4=BB=BD?= =?UTF-8?q?=E7=9A=84=E9=85=8D=E7=BD=AE=E4=B8=8D=E8=83=BD=E7=94=A8=E6=9C=80?= =?UTF-8?q?=E6=96=B0=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dbproxy/svc/l_matchlog.go | 3 +++ model/matchlog.go | 1 + worldsrv/action_tournament.go | 4 +++- worldsrv/tournament.go | 36 +++++++++++++++++++++++++---------- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/dbproxy/svc/l_matchlog.go b/dbproxy/svc/l_matchlog.go index 1fedaee..81bd681 100644 --- a/dbproxy/svc/l_matchlog.go +++ b/dbproxy/svc/l_matchlog.go @@ -22,6 +22,9 @@ func MatchLogCollection(plt string) *mongo.Collection { c, first := s.DB().C(model.MatchLogCollName) if first { c.EnsureIndex(mgo.Index{Key: []string{"gamefreeid"}, Background: true, Sparse: true}) + c.EnsureIndex(mgo.Index{Key: []string{"matchid"}, Background: true, Sparse: true}) + c.EnsureIndex(mgo.Index{Key: []string{"starttime"}, Background: true, Sparse: true}) + c.EnsureIndex(mgo.Index{Key: []string{"endtime"}, Background: true, Sparse: true}) } return c } diff --git a/model/matchlog.go b/model/matchlog.go index 5a3d792..33b2ce9 100644 --- a/model/matchlog.go +++ b/model/matchlog.go @@ -38,6 +38,7 @@ type MatchLog struct { StartTime time.Time //开始时间 EndTime time.Time //结束时间 Players []*MatchPlayer //参赛人员数据 + SortId int64 // 本场id } var ( diff --git a/worldsrv/action_tournament.go b/worldsrv/action_tournament.go index 8e9f114..3d44e47 100644 --- a/worldsrv/action_tournament.go +++ b/worldsrv/action_tournament.go @@ -59,6 +59,8 @@ func CSSignRace(s *netlib.Session, packetid int, data interface{}, sid int64) er pack.RetCode = code //0成功 1重复报名 2比赛没有开启 3道具不足 4不在报名时间段 5金币不足 6钻石不足 } + logger.Logger.Infof("player(%v) match(%v) SignUp is ok.", p.SnId, tmId) + if code == int32(tournament.SignRaceCode_OPRC_Close) || code == int32(tournament.SignRaceCode_OPRC_Time) { TournamentMgr.CancelSignUpAll(platform, tmId) @@ -73,7 +75,7 @@ func CSSignRace(s *netlib.Session, packetid int, data interface{}, sid int64) er logger.Logger.Trace("SCSignRace ", pack) // 检查是否可以开始比赛(关闭机器人时,比赛开赛) - if code == 0 && signSucc && !TournamentMgr.IsUseRobot(platform, tmId) { + if code == 0 && signSucc && !TournamentMgr.IsUseRobot(platform, tmId, 0) { if TournamentMgr.CanStart(platform, tmId) { TournamentMgr.Start(platform, tmId) } diff --git a/worldsrv/tournament.go b/worldsrv/tournament.go index 64aa182..dd5f25f 100644 --- a/worldsrv/tournament.go +++ b/worldsrv/tournament.go @@ -246,7 +246,18 @@ func (this *Tournament) UpdateData(init bool, data *webapiproto.GameMatchDateLis } // GetMatchInfo 比赛配置 -func (this *Tournament) GetMatchInfo(platform string, tmId int32) *webapiproto.GameMatchDate { +// !!!没有sortId会获取最新配置 +func (this *Tournament) GetMatchInfo(platform string, tmId int32, sortId int64) *webapiproto.GameMatchDate { + if sortId > 0 { + v := this.matches[tmId] + if v != nil { + vv := v[sortId] + if vv != nil { + return vv.gmd + } + } + return nil + } if list, ok := this.GameMatchDateList[platform]; ok { if gmd, ok1 := list[tmId]; ok1 { return gmd @@ -257,7 +268,7 @@ func (this *Tournament) GetMatchInfo(platform string, tmId int32) *webapiproto.G // MatchSwitch 比赛开关 func (this *Tournament) MatchSwitch(platform string, tmId int32) bool { - return this.IsMatchOn(this.GetMatchInfo(platform, tmId)) + return this.IsMatchOn(this.GetMatchInfo(platform, tmId, 0)) } // IsMatchOn 比赛开关 @@ -266,8 +277,8 @@ func (this *Tournament) IsMatchOn(match *webapiproto.GameMatchDate) bool { } // IsUseRobot 是否用机器人 -func (this *Tournament) IsUseRobot(platform string, tmId int32) bool { - return this.IsRobotOn(this.GetMatchInfo(platform, tmId)) +func (this *Tournament) IsUseRobot(platform string, tmId int32, sortId int64) bool { + return this.IsRobotOn(this.GetMatchInfo(platform, tmId, sortId)) } // IsRobotOn 是否用机器人 @@ -387,7 +398,7 @@ func (this *Tournament) IsMatchWaiting(platform string, snId int32) (bool, int32 // 报名费用 0成功 3道具不足 5金币不足 6钻石不足 7免费次数不足 func (this *Tournament) signUpCost(p *Player, tmId int32, cost bool) (bool, int32) { logger.Logger.Tracef("signUpCost 比赛id:%v 玩家:%v 报名:%v", tmId, p.SnId, cost) - gmd := this.GetMatchInfo(p.Platform, tmId) + gmd := this.GetMatchInfo(p.Platform, tmId, 0) if gmd == nil || p.IsRob { return true, 0 } @@ -482,7 +493,7 @@ func (this *Tournament) signUpCost(p *Player, tmId int32, cost bool) (bool, int3 func (this *Tournament) SignUp(tmId int32, p *Player) (bool, int32) { logger.Logger.Tracef("报名 比赛id:%v 玩家:%v", tmId, p.SnId) // 开启 - info := this.GetMatchInfo(p.Platform, tmId) + info := this.GetMatchInfo(p.Platform, tmId, 0) if !this.IsMatchOn(info) { return false, int32(tournament.SignRaceCode_OPRC_Close) } @@ -636,7 +647,7 @@ func (this *Tournament) ForceQuit(platform string, snId int32) { func (this *Tournament) CanStart(platform string, tmId int32) bool { if this.signupPlayers != nil && this.signupPlayers[platform] != nil { if signInfo, ok := this.signupPlayers[platform][tmId]; ok { - matchInfo := this.GetMatchInfo(signInfo.Platform, tmId) + matchInfo := this.GetMatchInfo(signInfo.Platform, tmId, 0) if matchInfo != nil { n := 0 for _, v := range signInfo.signup { @@ -669,7 +680,7 @@ func (this *Tournament) Start(platform string, tmId int32) { this.matches[tmId] = make(map[int64]*TmMatch) } - matchInfo := this.GetMatchInfo(platform, tmId) + matchInfo := this.GetMatchInfo(platform, tmId, 0) signInfo := this.signupPlayers[platform][tmId] if matchInfo == nil || signInfo == nil || len(signInfo.signup) == 0 { @@ -1409,7 +1420,11 @@ func (this *Tournament) GetSCTMInfosPack(platform, channelName string) *tourname } func (this *Tournament) MakeMatchLog(platform string, tmId int32, sortId int64) *model.MatchLog { - gameMatchDate := this.GetMatchInfo(platform, tmId) + gameMatchDate := this.GetMatchInfo(platform, tmId, sortId) + if gameMatchDate == nil { + logger.Logger.Errorf("MakeMatchLog gameMatchDate == nil tmId:%d sortId:%d", tmId, sortId) + return nil + } matchLog := model.NewMatchLog() _, ok := this.roundPlayers[sortId] if !ok { @@ -1463,6 +1478,7 @@ func (this *Tournament) MakeMatchLog(platform string, tmId int32, sortId int64) matchLog.GameFreeId = gameMatchDate.GameFreeId matchLog.StartTime = time.Unix(this.matches[tmId][sortId].StartTime, 0) matchLog.EndTime = time.Now() + matchLog.SortId = sortId return matchLog } @@ -1495,7 +1511,7 @@ func (this *Tournament) Update() { if info == nil || info.Ts <= 0 { continue } - matchInfo := this.GetMatchInfo(info.Platform, info.TmId) + matchInfo := this.GetMatchInfo(info.Platform, info.TmId, 0) if this.IsMatchOn(matchInfo) && !this.IsOutTime(matchInfo) && this.IsRobotOn(matchInfo) { needTime := this.playerWaitStart[snId] if time.Now().Unix()-info.Ts > needTime {