119 lines
4.9 KiB
Lua
119 lines
4.9 KiB
Lua
-- Included in the owned original Blizzard_GuildControlUI asset, never loaded
|
|
-- by an addon. Original70334's final officer-bundle mask overwrites several
|
|
-- individual classic rights. Preserve the clicked intent before that lossy
|
|
-- serializer using the existing authenticated Source guild control channel.
|
|
local sourceRankState;
|
|
local sourceRankSerial = 0;
|
|
local sourceRankPending;
|
|
|
|
local function SourceRankTransport(text)
|
|
if not C_ChatInfo or not C_ChatInfo.SendAddonMessage then return false; end
|
|
local ok, result = pcall(C_ChatInfo.SendAddonMessage, "GWTURTLE", text, "WHISPER", UnitName("player"));
|
|
return ok and result ~= false;
|
|
end
|
|
|
|
local function SourceRankRefresh()
|
|
if GuildControlUI and GuildControlUI.rankUpdate and GuildControlUI.currFrame then
|
|
GuildControlUI.numSkipUpdates = 0;
|
|
GuildControlUI.rankUpdate(GuildControlUI.currFrame);
|
|
end
|
|
end
|
|
|
|
local function SourceRankError(message)
|
|
if UIErrorsFrame then UIErrorsFrame:AddMessage(message, 1, 0.2, 0.2); end
|
|
end
|
|
|
|
function GuildControlUI_SourceRankQuery()
|
|
if IsInGuild() then SourceRankTransport("guild1 state"); end
|
|
end
|
|
|
|
function GuildControlUI_SourceRankEvent(event, message)
|
|
if event == "PLAYER_GUILD_UPDATE" then
|
|
if message ~= "player" then return true; end
|
|
sourceRankState = nil;
|
|
sourceRankPending = nil;
|
|
GuildControlUI_SourceRankQuery();
|
|
return true;
|
|
end
|
|
if event ~= "CHAT_MSG_SYSTEM" then return false; end
|
|
if type(message) ~= "string" or not message:match("^GWTURTLE1 GUILD ") then return true; end
|
|
if not IsInGuild() then
|
|
sourceRankState = nil;
|
|
sourceRankPending = nil;
|
|
return true;
|
|
end
|
|
local guild, revision, serial = message:match("^GWTURTLE1 GUILD STATE (%d+) (%d+) (%d+)$");
|
|
if guild then
|
|
sourceRankState = {id = tonumber(guild), revision = tonumber(revision)};
|
|
sourceRankSerial = math.max(sourceRankSerial, tonumber(serial));
|
|
return true;
|
|
end
|
|
if not sourceRankPending then return true; end
|
|
local confirmed = message:match("^GWTURTLE1 GUILD CONFIRMED (%d+)$");
|
|
local rejected = message:match("^GWTURTLE1 GUILD REJECTED (%d+) ")
|
|
or message:match("^GWTURTLE1 GUILD ERROR (%d+) ");
|
|
if tonumber(confirmed) == sourceRankPending then
|
|
sourceRankPending = nil;
|
|
SourceRankRefresh();
|
|
elseif tonumber(rejected) == sourceRankPending then
|
|
sourceRankPending = nil;
|
|
SourceRankRefresh();
|
|
SourceRankError("The server did not confirm the guild change. Please try again after the ranks refresh.");
|
|
end
|
|
return true;
|
|
end
|
|
|
|
local function SourceRankSend(action, rank, argument)
|
|
if not IsInGuild() then return false; end
|
|
if sourceRankPending then
|
|
SourceRankRefresh();
|
|
SourceRankError("Waiting for the server to confirm the previous guild change.");
|
|
return false;
|
|
end
|
|
if not sourceRankState then
|
|
SourceRankRefresh();
|
|
GuildControlUI_SourceRankQuery();
|
|
SourceRankError("Guild controls are loading. Please try again after the ranks refresh.");
|
|
return false;
|
|
end
|
|
sourceRankSerial = sourceRankSerial + 1;
|
|
local serial = sourceRankSerial;
|
|
local request = "guild1 " .. serial .. " " .. sourceRankState.id .. " " .. sourceRankState.revision .. " " .. action .. " " .. rank .. " " .. argument;
|
|
if #request > 255 or not SourceRankTransport(request) then
|
|
SourceRankRefresh();
|
|
SourceRankError("The guild change could not be sent.");
|
|
return false;
|
|
end
|
|
sourceRankPending = serial;
|
|
if C_Timer and C_Timer.After then C_Timer.After(8, function()
|
|
if sourceRankPending == serial then
|
|
sourceRankPending = nil;
|
|
sourceRankState = nil;
|
|
if not IsInGuild() then return; end
|
|
SourceRankRefresh();
|
|
GuildControlUI_SourceRankQuery();
|
|
SourceRankError("No guild confirmation received. The ranks are being refreshed.");
|
|
end
|
|
end); end
|
|
return true;
|
|
end
|
|
|
|
function GuildControlUI_SourceRankFlag(index, checked)
|
|
if type(index) ~= "number" or index % 1 ~= 0 or index < 1 or index > 13 then return false; end
|
|
return SourceRankSend("flag", GuildControlUI.currentRank, index .. " " .. (checked and 1 or 0));
|
|
end
|
|
|
|
function GuildControlUI_SourceRankName(rank, name)
|
|
if type(rank) ~= "number" or rank % 1 ~= 0 or rank < 1 or rank > 10 or type(name) ~= "string" or name == "" or #name > 25 then return false; end
|
|
local hex = name:gsub(".", function(c) return string.format("%02x", string.byte(c)); end);
|
|
return SourceRankSend("name", rank, hex);
|
|
end
|
|
|
|
local addFilter = ChatFrameUtil and ChatFrameUtil.AddMessageEventFilter or ChatFrame_AddMessageEventFilter;
|
|
if type(addFilter) == "function" then
|
|
addFilter("CHAT_MSG_SYSTEM", function(_, _, message)
|
|
if issecretvalue and issecretvalue(message) then return false; end
|
|
return type(message) == "string" and message:match("^GWTURTLE1 GUILD ") ~= nil;
|
|
end);
|
|
end
|