Files
GaCy-GO/internal/gameserver/aa_round_sync.lua
T
2026-10-28 18:54:43 +07:00

51 lines
2.4 KiB
Lua

-- Current Client metadata: ChallengePeakModule exposes CurrentPeakGroupID and
-- SendGetChallengePeakDataRequest(). Request real server data; never set a
-- private group field, fake a response, remap a room or close a running mode.
do local function synchronize()
local data=_G.__GAC_AA_ROUND_REFRESH
if not data or data.deferred or not data.desired_group or data.desired_group==0 then return end
local flags=CS.System.Enum.ToObject(typeof(CS.System.Reflection.BindingFlags),60)
local manager=CS.RPG.Client.GlobalVars.s_GamePhaseManager
local phase=manager and typeof(CS.RPG.Client.GamePhaseManager):GetField('_CurrentPhase',flags):GetValue(manager)
if not phase or typeof(CS.RPG.Client.BattleGamePhase):IsInstanceOfType(phase) then return end
local modules=CS.RPG.Client.GlobalVars.s_ModuleManager
local module=modules and modules.ChallengePeakModule
if not module then return end
local state=_G.__GAC_AA_ROUND_REFRESH_STATE
if not state or state.module~=module then
state={module=module};_G.__GAC_AA_ROUND_REFRESH_STATE=state
end
local current=module.CurrentPeakGroupID
-- Wait for the native login initialization request; do not duplicate it.
if not current or current==0 then return end
if current==data.desired_group then
if state.applied~=data.revision then
CS.UnityEngine.Debug.Log('[GAC_AA_ROUND_SYNC] applied group='..current)
end
state.applied=data.revision;state.pending=nil;return
end
if state.pending then
-- A changed native group proves that the previous request completed. If
-- Srtool changed again while it was pending, now request the latest choice.
if current==state.pending.from then return end
state.pending=nil
end
if state.requested==data.revision then return end
local sender=module.SendGetChallengePeakDataRequest
if type(sender)~='function' then error('observed AA refresh API is unavailable') end
-- No known in-flight query is exposed by this module. Send once and wait
-- for its actual CurrentPeakGroupID change, instead of flooding retries.
state.requested=data.revision
state.pending={from=current,desired=data.desired_group}
module:SendGetChallengePeakDataRequest()
CS.UnityEngine.Debug.Log('[GAC_AA_ROUND_SYNC] requested group='..data.desired_group..' previous='..current)
end
local ok,err=pcall(synchronize)
if not ok then
local message=tostring(err)
if _G.__GAC_AA_ROUND_REFRESH_ERROR~=message then
_G.__GAC_AA_ROUND_REFRESH_ERROR=message
CS.UnityEngine.Debug.Log('[GAC_AA_ROUND_SYNC] ERROR '..message)
end
end end