Thread Tools Display Modes
05-25-11, 04:10 AM   #1
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Would this practically work? A theory in work with some sample code I drafted.

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):
  1. A>* "uniqueIdent" "1000" -- basic interval broadcast indicating the current version of user A
  2. B>A "uniqueIdent" "1001 newhash" -- replies with that B has later version of A's code
  3. A>B "uniqueIdent" "newhash" -- confirm and let B know he can send the new code over
  4. B>A "uniqueIdent" "chunkOfTheCode248Chars" -- B sends piece by piece over to A
  5. <...>
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:
  1. -- CONSTANT BLOCK
  2. local function hash(str, hex)
  3.   local m, c = "", 0
  4.   for i = 1, s:len() do
  5.     c = c + (s:sub(i,i):byte() * i)
  6.     if c >= 0xFFFFFF00 then
  7.       m = m..string.format("%X", c)
  8.       c = 0
  9.     end
  10.   end
  11.   if c > 0 then
  12.     m = m..string.format("%X", c)
  13.   end
  14.   c = 0
  15.   local f = m:len()
  16.   f = f/(f > 32 and 16 or 1)
  17.   f = math.ceil(f)
  18.   for i = 1, m:len(), f do
  19.     c = c + (tonumber("0x"..m:sub(i,i+3)) * i)
  20.   end
  21.   return hex and string.format("%X", c) or c
  22. end
  23.  
  24. -- ADDON BLOCK
  25. local addonInfo = {
  26.   WWW = "http://www.google.com",
  27.   NAM = "My Test Addon",
  28.   VER = 1000,
  29. }
  30.  
  31. local aID = addonInfo.NAM:gsub("[^%a%d]", "-")
  32. local preName = "LAName_"..aID
  33. local preCode = "LACode_"..aID -- should be the SavedVariables in the .toc
  34. local preChnk = "LAChnk_"..aID
  35.  
  36. _G[preName] = "My Addon"
  37. _G[preCode] = [=[
  38.  
  39. print("Hello World!")
  40.  
  41. ]=]
  42.  
  43. 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
  44. print(preCode, chunck, errno, _G[preChnk])
  45.  
  46. -- CONSTANT BLOCK
  47. local upd = CreateFrame("Frame")
  48. upd:RegisterEvent("CHAT_MSG_ADDON")
  49. upd:SetScript("OnEvent", function(upd, event, pre, msg, cha, src)
  50.   if event == "CHAT_MSG_ADDON" then
  51.     if pre == preName then
  52.       local version, newhash = msg:split(" ", 2)
  53.       version = tonumber(version)
  54.       if version and version > addonInfo.VER then
  55.         upd.newcode = ""
  56.         upd.newhash = newhash
  57.         SendAddonMessage(preCode, newhash, cha, src)
  58.       end
  59.     elseif pre == preCode then
  60.       -- NYI (should be sending parts of code to the src/cha)
  61.     elseif pre == preChnk then
  62.       upd.newcode = upd.newcode..msg
  63.       if hash(upd.newcode, 1) == upd.newhash then
  64.         -- done, we got all the data we needed
  65.       end
  66.     end
  67.   end
  68. 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?
  Reply With Quote
05-25-11, 07:09 AM   #2
Foxlit
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 91
Originally Posted by Vladinator View Post
What is your point of view on the idea?
It makes for a rather impractical addon distribution method. You're basically limiting yourself to only supporting pure Lua scripts, without any (reasonable) way to handle other types of resources addons may include; and the amount of computation required to ensure safety is unreasonably large.

It'd make more sense to identify just why your addon requires such frequent updates that the traditional "I'll go get an update once in a blue moon" method fails. In some cases, it may make sense for addons to distribute data to older versions -- think bossmods data expressed as some sort of data structure rather than code -- which would lessen the safety requirements as you aren't sharing code.

Finally, you've invented your own hashing function. Never implement your own cryptography unless you know what you're doing. In this case, you're actually looking for the concept of digital signatures, as without some sort of asymmetric secret component, you'll not be able to verify whether an update stems from the author or from a malicious third party.
__________________
... and you do get used to it, after a while.

Last edited by Foxlit : 05-25-11 at 03:15 PM.
  Reply With Quote
05-25-11, 09:40 AM   #3
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
You seem like you know something, I tried looking up some hashing and compression classes for LUA that will work with the game, perhaps any ideas on some that are small in length and efficient enough?

I was thinking to apply a system like this mostly for fun, try work on my coding and get some practice with addon communicating with each other.

I had a feeling this would really require a lot of work to accomplish if it were to be a main stream kind of deal, really impractical but perhaps usable in very small communities.

Now this got me thinking of a small addon I could code for me and my friends, simple "plugin" that could be sent and received trough the chat. Practical example where this could come in handy:
Friend: hey Vlad, could you make me an addon that alerts me when I don't got my self buff on?
Vlad: sure, hang on a sec. <coding> <send plugin>
Friend: <receive popup> <accepts> thanks!
Then they could use a simple GUI to delete/enable/disable plugins.
Again this could use of some compression to make the code smaller and require less messages to send.
  Reply With Quote
05-25-11, 10:13 AM   #4
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by Vladinator View Post
Now this got me thinking of a small addon I could code for me and my friends, simple "plugin" that could be sent and received trough the chat.
There is a slightly similar addon, called Bi
maybe you could check it's code out a bit, although it's very outdated (addon comm messages)
  Reply With Quote
05-25-11, 01:34 PM   #5
Saiket
A Chromatic Dragonspawn
 
Saiket's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 154
If you only need to manually send scripts to friends, you could try _DevPad. It doesn't do any auto-updating, though.
  Reply With Quote
05-26-11, 10:16 AM   #6
sigg
Featured Artist
 
sigg's Avatar
Featured
Join Date: Aug 2008
Posts: 1,251
RDX means Raid Data eXchange

http://www.wowinterface.com/forums/s...ad.php?t=31717

__________________
RDX manager
Sigg
  Reply With Quote
05-26-11, 01:07 PM   #7
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
I've managed to make a small plugin exchange system, in short one can write some mini "addon" (plugin may seem more appropriate term) and they can be easily enabled and disabled while playing.

It uses reusable frames and for now can run code when it is enabled, disabled (to cleanup or prepare) and triggers the code on specific events.
So far it works just fine, no problems sending code to myself.

Only wish I had a compression method for the strings, maybe I should use a library that is made for sending addon messages (usually once that are too big, thus get automatically split into parts). At the moment I split them up myself but no compression so you quickly end up sending 5 addon messages if I have to share: the code around 500 chars + introduction message + end of transmition message + onenable/ondisable/events to monitor message.

In any case you could use this but not for whole addons, would be messy. :P
  Reply With Quote
05-26-11, 04:22 PM   #8
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
There's always LibCompress.
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
05-27-11, 08:34 AM   #9
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
Torhal, good suggestion!

So far I've managed to make this: http://pastebin.com/embed_iframe.php?i=5BnvYJVW (for the interested)

The second time I make a options UI and must say you learn a lot while practicing. Anyway I know transfers could be improved by filling each message to 248 before sending it, but one step at a time.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Would this practically work? A theory in work with some sample code I drafted.


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off