From c628f8876fdbcff979a50d4a820060a95a297581 Mon Sep 17 00:00:00 2001 From: sk <123456@qq.com> Date: Sun, 29 Sep 2024 11:51:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=AF=94=E8=B5=9B=E5=9C=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worldsrv/tournament.go | 48 +++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/worldsrv/tournament.go b/worldsrv/tournament.go index 3dd4624..a51bf06 100644 --- a/worldsrv/tournament.go +++ b/worldsrv/tournament.go @@ -560,6 +560,7 @@ func (this *Tournament) IsGaming(snId int32) bool { } // IsMatchWaiting 判断是否在匹配中,已报名 +// 返回 是否匹配中,比赛配置id func (this *Tournament) IsMatchWaiting(platform string, snId int32) (bool, int32) { // 未使用机器人 for k, v := range this.signupPlayers[platform] { @@ -845,22 +846,36 @@ func (this *Tournament) Quit(platform string, snid int32) { } } -// ForceQuit 强制退赛 +// ForceQuit 强制退赛,异常时才使用 func (this *Tournament) ForceQuit(platform string, snId int32) { logger.Logger.Tracef("TournamentMgr.ForceQuit: snId:%d", snId) + if snId <= 0 { + return + } this.Quit(platform, snId) - var info *PlayerMatchContext - var ok bool - for _, v := range this.players { - info, ok = v[snId] - if ok { - break + p := PlayerMgrSington.GetPlayerBySnId(snId) + if p != nil { + if p.matchCtx != nil && p.matchCtx.tm != nil { + this.StopMatch(p.matchCtx.tm.TMId, p.matchCtx.tm.SortId) + return } } - if info != nil && info.tm != nil { - this.StopMatch(info.tm.TMId, info.tm.SortId) - MatchSceneMgrSingleton.MatchStop(info.tm) + + for _, v := range this.matches { + for _, vv := range v { + if vv != nil && vv.TmPlayer[snId] != nil { + this.StopMatch(vv.TMId, vv.SortId) + return + } + } + } + + for _, v := range this.players { + if info, ok := v[snId]; ok && info != nil && info.tm != nil { + this.StopMatch(info.tm.TMId, info.tm.SortId) + return + } } } @@ -1089,7 +1104,7 @@ func (this *Tournament) GetRank(sortId int64, snid int32) int32 { } } -func (this *Tournament) stopMatch(matchId int32, sortId int64) (isOver bool) { +func (this *Tournament) CanStopMatch(matchId int32, sortId int64) (isOver bool) { if this.players[sortId] != nil { hasReal := false for snId, context := range this.players[sortId] { @@ -1101,7 +1116,7 @@ func (this *Tournament) stopMatch(matchId int32, sortId int64) (isOver bool) { //没有真人比赛解散 if !hasReal { isOver = true - logger.Logger.Trace("没有真人比赛解散") + logger.Logger.Tracef("没有真人比赛解散 matchId:%v sortId:%v", matchId, sortId) this.StopMatch(matchId, sortId) } } @@ -1352,10 +1367,9 @@ func (this *Tournament) NextRoundStart(sortId int64, playerCtx *PlayerMatchConte for _, v := range info.players { logger.Logger.Tracef("淘汰 %+v", *v) this.sendPromotionInfo(v, sortId, TaoTai, true, false) //淘汰 - //真人被淘汰,如果剩下的都是机器人,比赛解散 if !v.p.IsRob { - isOver = this.stopMatch(playerCtx.tm.TMId, sortId) + isOver = this.CanStopMatch(playerCtx.tm.TMId, sortId) } } } @@ -1502,7 +1516,7 @@ func (this *Tournament) sendPromotionInfo(mc *PlayerMatchContext, sortId int64, delete(this.players[sortId], mc.p.SnId) //真人被淘汰,如果剩下的都是机器人,比赛解散 if !mc.p.IsRob { - this.stopMatch(mc.tm.TMId, sortId) + this.CanStopMatch(mc.tm.TMId, sortId) } } } @@ -2039,7 +2053,7 @@ func (this *Tournament) OnHourTimer() { for _, v := range this.matches { for _, vv := range v { if vv != nil && (now.Sub(vv.RoundTime).Hours() >= 1 || now.Sub(vv.StartTime).Hours() > 5) { - logger.Logger.Errorf("比赛异常 %v", vv) + logger.Logger.Errorf("比赛异常,长时间未结束 %v", vv) this.StopMatch(vv.TMId, vv.SortId) } } @@ -2049,7 +2063,7 @@ func (this *Tournament) OnHourTimer() { if _, ok := tm[sortId]; !ok { for _, v := range this.players[sortId] { if v != nil { - logger.Logger.Errorf("比赛异常 %v", v.tm) + logger.Logger.Errorf("比赛异常,比赛已经不存在了 %v", v.tm) } break }