Mercurial > wow > breuesk
comparison Comm.lua @ 72:9e5b0a2368ad
Big progress towards GUI usefulness and communication between clients
author | John@Yosemite-PC |
---|---|
date | Sat, 07 Apr 2012 13:35:57 -0400 |
parents | |
children | 22b37c800bc4 |
comparison
equal
deleted
inserted
replaced
71:d5e2dfe0c269 | 72:9e5b0a2368ad |
---|---|
1 local bsk=bsk | |
2 local _G=_G | |
3 local table=table | |
4 local pairs=pairs | |
5 local setmetatable=setmetatable | |
6 local ipairs=ipairs | |
7 local unpack=unpack | |
8 local string=string | |
9 local sformat=string.format | |
10 local tostring=tostring | |
11 local type=type | |
12 local getn=getn | |
13 | |
14 local commlib = LibStub("AceComm-3.0") or _G.error("Couldn't load up AceComm") | |
15 local s = LibStub("AceSerializer-3.0") or _G.error("Couldn't load up AceSerializer") | |
16 | |
17 setfenv(1,bsk) | |
18 | |
19 local function BuildPacket(handler,message) | |
20 local p = {handler,message} | |
21 local str = s:Serialize({handler,message}) | |
22 print("sending",str) | |
23 return p,str | |
24 end | |
25 | |
26 local function SendMessage(str) | |
27 --commlib:SendCommMessage("BSKADDON",str,"GUILD") | |
28 commlib:SendCommMessage("BSKADDON",str,"RAID") | |
29 end | |
30 | |
31 local function Send(handler,message) | |
32 local p,str = BuildPacket(handler,message) | |
33 SendMessage(str) | |
34 end | |
35 | |
36 -- todo: ActivateList and AddReserve -> state | |
37 Comm = | |
38 { | |
39 ["SS"] = function(self,packet,sender,isloop) | |
40 print("isloop",isloop) | |
41 if not isloop then DispatchState(packet) end | |
42 end, | |
43 ["SendStateChange"] = function(self,...) | |
44 local p,str = BuildPacket("SS",{...}) | |
45 DispatchState(p[2]) | |
46 SendMessage(str) | |
47 end, | |
48 ["AR"] = function(self,packet,sender,isloop) | |
49 if isloop then return end | |
50 PersonList:AddReserve(packet) | |
51 changeListener:DataEvent() | |
52 end, | |
53 ["AddReserve"] = function(self,packet) | |
54 if changeListener then | |
55 changeListener:DataEvent(change) | |
56 end | |
57 Send("AR",packet) | |
58 end, | |
59 ["SendChange"] = function(self,change) | |
60 if changeListener then | |
61 changeListener:DataEvent(change) | |
62 end | |
63 Send("CC",change) | |
64 end, | |
65 ["CC"] = function(self,change,sender,isloop) | |
66 if isloop then return end | |
67 ProcessChange(change) | |
68 changeListener:DataEvent() | |
69 end, | |
70 ["Push"] = function(self) | |
71 Send("PU",{db.profile.lists,db.profile.persons,db.profile.changes}) | |
72 end, | |
73 ["PU"] = function(self,packet,sender,isloop) | |
74 if isloop then return end | |
75 db.profile.lists,db.profile.persons,db.profile.changes = unpack(packet) | |
76 CreateWorkingStateFromChanges(db.profile.changes) | |
77 if changeListener then | |
78 changeListener:DataEvent() | |
79 end | |
80 end, | |
81 } | |
82 | |
83 local function OnCommReceived(prefix, message, distribution, sender) | |
84 print("Received on", distribution) | |
85 local success,packet = s:Deserialize(message) | |
86 local isloop = _G.UnitName("player") == sender | |
87 | |
88 print("received",message) | |
89 | |
90 Comm[packet[1]](Comm,packet[2],sender,isloop) | |
91 end | |
92 | |
93 function InitializeComm() | |
94 commlib:RegisterComm("BSKADDON",OnCommReceived) | |
95 end | |
96 | |
97 function DeinitializeComm() | |
98 | |
99 end |