(7 Kb)
Updated: 04-13-06 05:46 AM
Updated:04-13-06 05:46 AM


by: Shag [More]


This addons manages three communication channels ("guild", "raid" and "sync") and allows addons to use a RPC mechanism

How it works

Whenever there is need to join/change the chat-channels, CommChannel generates a unique name for the "guild", "raid" and "sync" channel and joins them. For each channel, there is a list with all installed channel-modules, a channel-module is uniquely defined by a name. There usualy is one channel-module for each addon, but it's also possibly to register more than one channel-module from within an addon. Each channel-module also has to provide a interface. This interface contains functions that the module provides.
Upon recieving a RPC-request, each client looks up if it has installed the module, if yes, it looks up if the module interface provides the requested function, and if that's also true, it calls that function with the given arguments.

Messages which are sent to the communication channel are encoded in a very simple way so that each request can be parsed efficiently. The argument list is serialized from lua-objects, so it may contain strings, numbers, booleans and tables.

channelModule:moduleFunction([arguments list])

for example:

-- just an idea how spell cooldowns could be reported:
userCache:reportCooldown("Innervate",360) -- 360 ist the remaining spell cooldown in seconds
-- or a more portable way:
-- where "spell:74:0:0" can be parsed just like an itemlink, each ID has to be defined globaly, 74 would be Innervate on an english client, the two remaining IDs could indicate spell upgrades through talents or items.

Public Interface

based on the above example of cooldown reporting an addon could loks like this:

-- define a module interface:
local userCacheModuleInterface = { }

function userCacheModuleInterface:reportColdown(spellName, remainingCooldown)
    -- sender name is available in arg2
    -- do something with the received data

-- create a channel client object
clientObject = CommChannel:Create("raid", "userCache", userCacheModuleInterface)

-- if we have a spell on cooldown:
local spellName = ...
local remainingCooldown = ...

-- the next two lines do exactly the same thing, the clientObject only saves the commChannel and channelModule names and calls CommChannel:Call(...), this makes it easier because you have to specify those only in one place.
clientObject:Call("reportCooldown", spellName, remainingCooldown)
CommChannel:Call("raid", "userCache", "reportCooldown", spellName, remainingCooldown)

-- now whoever is in the same raid as we and has an addon installed that has set up a "userCache" module for the raid channel recieves this message and CommChannels calls the corresponding function with the given arguments, just like normal RPC.
-- note that even our own function will be called !

There have been no comments posted to this file.
Be the first to add one.

Category Jump: