-
Notifications
You must be signed in to change notification settings - Fork 1
/
Communication.lua
45 lines (33 loc) · 1.38 KB
/
Communication.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
local _, Namespace = ...
Namespace.Communication = {}
local AceSerializer = Namespace.Libs.AceSerializer
local LibCompress = Namespace.Libs.LibCompress
local Encoder = LibCompress:GetAddonEncodeTable()
local GroupType = Namespace.Utils.GroupType
local GetRealUnitName = Namespace.Utils.GetRealUnitName
local Channel = {
Raid = 'RAID',
Party = 'PARTY',
Instance = 'INSTANCE_CHAT',
Whisper = 'WHISPER',
Say = 'SAY',
}
Namespace.Communication.Channel = Channel
function Namespace.Communication.PackData(data)
if not data.sender then data.sender = GetRealUnitName('player') end
return Encoder:Encode(LibCompress:CompressHuffman(AceSerializer:Serialize(data)))
end
function Namespace.Communication.UnpackData(raw)
local decompressed = LibCompress:Decompress(Encoder:Decode(raw))
if not decompressed then return end
local success, data = AceSerializer:Deserialize(decompressed)
if not success then return end
return data
end
function Namespace.Communication.GetMessageDestination()
local currentType = Namespace.Utils.GetGroupType()
if currentType == GroupType.InstanceRaid or currentType == GroupType.InstanceParty then return Channel.Instance, nil end
if currentType == GroupType.Raid then return Channel.Raid, nil end
if currentType == GroupType.Party then return Channel.Party, nil end
return Channel.Whisper, GetRealUnitName('player')
end