From 48423752a13b8371a72f94d80fc2a2ec62372df1 Mon Sep 17 00:00:00 2001 From: hahwu <31872165+hahwu@users.noreply.github.com> Date: Mon, 30 Mar 2026 16:14:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/game/champship_mgr.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/server/game/champship_mgr.go b/src/server/game/champship_mgr.go index f9510804..50bf1232 100644 --- a/src/server/game/champship_mgr.go +++ b/src/server/game/champship_mgr.go @@ -2,6 +2,7 @@ package game import ( "fmt" + "maps" "math" avatarCfg "server/conf/avatar" @@ -136,9 +137,7 @@ func (c *ChampshipMgr) ZeroUpdate() (interface{}, error) { data.ZeroTime = GoUtil.ZeroTimestamp() // 深拷贝 map,避免多个协程持有同一个 map 引用导致并发读写 oldRank := make(map[int][]*ChampshipRank, len(data.Rank)) - for k, v := range data.Rank { - oldRank[k] = v - } + maps.Copy(oldRank, data.Rank) oldRobot := make(map[int]*ChampshipRobot, len(data.Robot)) for k, v := range data.Robot { oldRobot[k] = v @@ -162,11 +161,15 @@ func (c *ChampshipMgr) ZeroUpdate() (interface{}, error) { c.SetRankCache(k) } data.mu.Unlock() - - c.mDispatr.AfterFunc(time.Duration(GoUtil.NextZeroTimestampDuration())*time.Second, func() { + timeDuration := GoUtil.NextZeroTimestampDuration() + if timeDuration <= 0 { + log.Error("championship zero update error") + timeDuration = 24 * 3600 + } + c.mDispatr.AfterFunc(time.Duration(timeDuration)*time.Second, func() { c.ZeroUpdate() }) - c.mDispatr.AfterFunc(time.Duration(GoUtil.NextZeroTimestampDuration()+1800)*time.Second, func() { + c.mDispatr.AfterFunc(time.Duration(timeDuration+1800)*time.Second, func() { c.ZeroNotifyAll() }) // 在锁外通知玩家,避免在持有锁时调用外部函数