Mercurial > wow > breuesk
view Comm.lua @ 74:15844864a5f7
Admin mode
author | John@Doomsday |
---|---|
date | Mon, 09 Apr 2012 09:40:14 -0400 |
parents | 9e5b0a2368ad |
children | 22b37c800bc4 |
line wrap: on
line source
local bsk=bsk local _G=_G local table=table local pairs=pairs local setmetatable=setmetatable local ipairs=ipairs local unpack=unpack local string=string local sformat=string.format local tostring=tostring local type=type local getn=getn local commlib = LibStub("AceComm-3.0") or _G.error("Couldn't load up AceComm") local s = LibStub("AceSerializer-3.0") or _G.error("Couldn't load up AceSerializer") setfenv(1,bsk) local function BuildPacket(handler,message) local p = {handler,message} local str = s:Serialize({handler,message}) print("sending",str) return p,str end local function SendMessage(str) --commlib:SendCommMessage("BSKADDON",str,"GUILD") commlib:SendCommMessage("BSKADDON",str,"RAID") end local function Send(handler,message) local p,str = BuildPacket(handler,message) SendMessage(str) end -- todo: ActivateList and AddReserve -> state Comm = { ["SS"] = function(self,packet,sender,isloop) print("isloop",isloop) if not isloop then DispatchState(packet) end end, ["SendStateChange"] = function(self,...) local p,str = BuildPacket("SS",{...}) DispatchState(p[2]) SendMessage(str) end, ["AR"] = function(self,packet,sender,isloop) if isloop then return end PersonList:AddReserve(packet) changeListener:DataEvent() end, ["AddReserve"] = function(self,packet) if changeListener then changeListener:DataEvent(change) end Send("AR",packet) end, ["SendChange"] = function(self,change) if changeListener then changeListener:DataEvent(change) end Send("CC",change) end, ["CC"] = function(self,change,sender,isloop) if isloop then return end ProcessChange(change) changeListener:DataEvent() end, ["Push"] = function(self) Send("PU",{db.profile.lists,db.profile.persons,db.profile.changes}) end, ["PU"] = function(self,packet,sender,isloop) if isloop then return end db.profile.lists,db.profile.persons,db.profile.changes = unpack(packet) CreateWorkingStateFromChanges(db.profile.changes) if changeListener then changeListener:DataEvent() end end, } local function OnCommReceived(prefix, message, distribution, sender) print("Received on", distribution) local success,packet = s:Deserialize(message) local isloop = _G.UnitName("player") == sender print("received",message) Comm[packet[1]](Comm,packet[2],sender,isloop) end function InitializeComm() commlib:RegisterComm("BSKADDON",OnCommReceived) end function DeinitializeComm() end