I was thinking, it would be possible to make an addon template of sorts where the addon code itself is tucked into a capsule like a string "[=[ <code> ]=]" and the code surrounding it would handle receiving or serving update requests.
The whole idea is using the addon channel to broadcast the user current version and potentially receive a update from a fellow gamer that has a newer version.
Once the new code is downloaded it's stored in the .toc SavedVariables and the user must reload the UI or relog to load the new code. This way you can update the addon(s) without having to download the new version from a site but rather trust your friends that have updated it manually (or if you know the author he will work as a seed and spread it around the guild and raid/BGs that form).
The flow of information (partial):
- A>* "uniqueIdent" "1000" -- basic interval broadcast indicating the current version of user A
- B>A "uniqueIdent" "1001 newhash" -- replies with that B has later version of A's code
- A>B "uniqueIdent" "newhash" -- confirm and let B know he can send the new code over
- B>A "uniqueIdent" "chunkOfTheCode248Chars" -- B sends piece by piece over to A
- <...>
At some point the hash of the string would fit the "newhash" send by B earlier, A knows by then that the code is complete (if the integer grows too large then it means there is something wrong or inconsistent with the code read, hence aborts).
Just a draft I made, by far not usable but just a more visual version of the idea:
(also my hash function is down the toilet :P)
lua Code:
-- CONSTANT BLOCK
local function hash(str, hex)
local m, c = "", 0
for i = 1, s:len() do
c = c + (s:sub(i,i):byte() * i)
if c >= 0xFFFFFF00 then
m = m..string.format("%X", c)
c = 0
end
end
if c > 0 then
m = m..string.format("%X", c)
end
c = 0
local f = m:len()
f = f/(f > 32 and 16 or 1)
f = math.ceil(f)
for i = 1, m:len(), f do
c = c + (tonumber("0x"..m:sub(i,i+3)) * i)
end
return hex and string.format("%X", c) or c
end
-- ADDON BLOCK
local addonInfo = {
WWW = "http://www.google.com",
NAM = "My Test Addon",
VER = 1000,
}
local aID = addonInfo.NAM:gsub("[^%a%d]", "-")
local preName = "LAName_"..aID
local preCode = "LACode_"..aID -- should be the SavedVariables in the .toc
local preChnk = "LAChnk_"..aID
_G[preName] = "My Addon"
_G[preCode] = [=[
print("Hello World!")
]=]
chunck, errno = loadstring(_G["LACode_"..aID], preChnk) -- should load the addon after savedvariables are loaded, otherwise we don't load the new addon at all
print(preCode, chunck, errno, _G[preChnk])
-- CONSTANT BLOCK
local upd = CreateFrame("Frame")
upd:RegisterEvent("CHAT_MSG_ADDON")
upd:SetScript("OnEvent", function(upd, event, pre, msg, cha, src)
if event == "CHAT_MSG_ADDON" then
if pre == preName then
local version, newhash = msg:split(" ", 2)
version = tonumber(version)
if version and version > addonInfo.VER then
upd.newcode = ""
upd.newhash = newhash
SendAddonMessage(preCode, newhash, cha, src)
end
elseif pre == preCode then
-- NYI (should be sending parts of code to the src/cha)
elseif pre == preChnk then
upd.newcode = upd.newcode..msg
if hash(upd.newcode, 1) == upd.newhash then
-- done, we got all the data we needed
end
end
end
end)
The huge problem here is actually being able to identify what is safe code and not, for example if you get replies by other addons that say "hey I got version 1001 here" and the hashes they offer are not the same, hence it would indicate someone is a rogue or trying to taint the distribution.
If I update the code on my own I could bump the version build up and fake being the proper update, hence the hashing has to be in some way or have an additional .lua code the author uses to generate some sort of hash or something that can be read and used to compare the incoming versions but not the other way around, I wouldn't be able to edit the code and build without generating some code and putting it in the file, something like the .sig files used by Blizzard to avoid people editing the files.
If by some point we manage to do this would could essentially reduce the need to use sites to update some addons (small once for instance) or addons that someone makes for their guild, the guild members wouldn't have to fetch updates from a site and could use the addon channel to get the new code.
What is your point of view on the idea?