117 lines
5.4 KiB
Lua
117 lines
5.4 KiB
Lua
-- Owned Source branch for the original GlueParent decision functions.
|
|
-- It never manufactures native login enums, connection, or error states.
|
|
return function(source, enabled)
|
|
local adapter = {};
|
|
local pending = false;
|
|
local chosen = false;
|
|
local hasConnected = false;
|
|
local connectingSince = nil;
|
|
local holding = false;
|
|
local latestGeneration = 0;
|
|
local retiredGeneration = nil;
|
|
local failureGeneration = nil;
|
|
local presentedFailure = nil;
|
|
local acknowledgedFailure = nil;
|
|
|
|
function adapter.Refresh()
|
|
holding = false;
|
|
if enabled ~= true then pending = false; chosen = false; return false; end
|
|
source.Refresh();
|
|
local valid = source.GetStatus();
|
|
local status = source.GetLoginStatus();
|
|
-- The backend retains a genuine terminal header after its worker is
|
|
-- retired. Keep that failure until acknowledgement or a fresh Login
|
|
-- generation, independently of realm-list/proof eligibility.
|
|
if status and status.generation > latestGeneration then
|
|
latestGeneration = status.generation;
|
|
failureGeneration, presentedFailure, acknowledgedFailure = nil, nil, nil;
|
|
connectingSince = nil;
|
|
hasConnected = false;
|
|
end
|
|
if status and status.state == 3 and status.cancel == 0
|
|
and status.generation > 0 and status.generation == latestGeneration
|
|
and status.generation ~= retiredGeneration
|
|
and acknowledgedFailure ~= status.generation then
|
|
failureGeneration = status.generation;
|
|
end
|
|
-- A delayed older snapshot cannot replace the current generation's
|
|
-- presentation or restart its deadline. Keep evaluating that deadline
|
|
-- and the real native connection even while such a snapshot arrives.
|
|
if not status or status.generation >= latestGeneration then
|
|
local current = status and status.generation > 0
|
|
and status.generation == latestGeneration and status.generation ~= retiredGeneration;
|
|
pending = not not (valid and current and status.state == 5
|
|
and status.server_proof_verified == 1
|
|
and status.genuine_discovery == 1 and status.auth_result == 0
|
|
and status.discovery_result == 0 and status.error == 0
|
|
and status.selected_index == -1 and status.transport_prepared == 0);
|
|
chosen = not not (current and status.state == 2
|
|
and status.server_proof_verified == 1 and status.error == 0
|
|
and status.selected_index >= 0 and status.transport_prepared == 1);
|
|
end
|
|
-- After the realm choice the chosen Source realm is connecting; the
|
|
-- native connection is not up yet, so the original screen choice
|
|
-- would fall back to Login (whose disconnect tears the world socket
|
|
-- down). Hold the realm screen for a bounded time instead.
|
|
local waitingForConnection = false;
|
|
if chosen then
|
|
local native = C_Login and C_Login.GetState and C_Login.GetState();
|
|
if native and native.connectedToWoW then hasConnected = true; end
|
|
local now = type(GetTime) == "function" and GetTime() or nil;
|
|
if type(now) ~= "number" then now = 0; end
|
|
connectingSince = connectingSince or now;
|
|
-- Character select's Back button disconnects before the last chosen
|
|
-- snapshot retires. That generation already reached its world.
|
|
waitingForConnection = not hasConnected and (now - connectingSince) < 30;
|
|
end
|
|
-- The timer belongs to the generation, including across missing snapshots.
|
|
holding = pending or waitingForConnection;
|
|
return pending;
|
|
end
|
|
|
|
function adapter.OnAccountBack()
|
|
if enabled ~= true then return; end
|
|
-- Character Select's Back action calls this before the native disconnect.
|
|
-- Unsolicited disconnects keep their genuine terminal error handling.
|
|
adapter.Refresh();
|
|
if latestGeneration > 0 then
|
|
retiredGeneration = latestGeneration;
|
|
if failureGeneration == latestGeneration then failureGeneration = nil; end
|
|
end
|
|
end
|
|
|
|
function adapter.IsPending() return pending; end
|
|
|
|
-- Pending choice, or chosen realm still connecting before native World/charselect.
|
|
function adapter.IsHolding() return holding; end
|
|
|
|
function adapter.GetFailureGeneration() return failureGeneration or 0; end
|
|
|
|
function adapter.AcknowledgeFailure(generation)
|
|
if generation ~= failureGeneration then return false; end
|
|
acknowledgedFailure = generation;
|
|
failureGeneration = nil;
|
|
return true;
|
|
end
|
|
|
|
function adapter.HandleFailure()
|
|
if not failureGeneration then return false; end
|
|
if presentedFailure == failureGeneration then return true; end
|
|
local generation = failureGeneration;
|
|
-- Match the original AccountLogin error cleanup and popup mechanism.
|
|
-- This does not manufacture native GetState/GetLastError responses.
|
|
presentedFailure = generation;
|
|
C_Login.DisconnectFromServer();
|
|
StaticPopup_Hide("CANCEL");
|
|
StaticPopup_Show("OKAY", "Unable to log in to the game server. Please try again.", nil, nil, nil,
|
|
function() adapter.AcknowledgeFailure(generation); end);
|
|
return true;
|
|
end
|
|
|
|
function adapter.GetSourceStatus()
|
|
return source.GetLoginStatus();
|
|
end
|
|
|
|
return adapter;
|
|
end
|