-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcomms.lua
More file actions
184 lines (151 loc) · 6.58 KB
/
comms.lua
File metadata and controls
184 lines (151 loc) · 6.58 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
local L = LibStub("AceLocale-3.0"):GetLocale("Prio3", true)
function Prio3:sendPriorities()
if Prio3.db.profile.comm_enable_prio then
local commmsg = { command = "SEND_PRIORITIES", prios = Prio3.db.profile.priorities, importtime = self.db.profile.prioimporttime, addon = Prio3.addon_id, version = Prio3.versionString }
Prio3:SendCommMessage(Prio3.commPrefix, Prio3:Serialize(commmsg), "RAID", nil, "NORMAL")
end
end
function Prio3:requestPing()
local commmsg = { command = "PING", addon = Prio3.addon_id, version = Prio3.versionString }
Prio3:SendCommMessage(Prio3.commPrefix, Prio3:Serialize(commmsg), "RAID", nil, "NORMAL")
end
function Prio3:sendPong()
local commmsg = { command = "PONG", addon = Prio3.addon_id, version = Prio3.versionString }
Prio3:SendCommMessage(Prio3.commPrefix, Prio3:Serialize(commmsg), "RAID", nil, "NORMAL")
end
function Prio3:PARTY_LOOT_METHOD_CHANGED()
if Prio3:isUserMasterLooter() then
self.addon_id = 1000001
else
self.addon_id = random(1, 999999)
if #self.versionString > 9 then self.addon_id = 1000000 end
end
end
function Prio3:GROUP_ROSTER_UPDATE()
-- request priorities if entering a new raid
if UnitInParty("player") and not Prio3.previousGroupState then
Prio3:requestPing()
-- joined group: request Prio data
if Prio3.db.profile.enabled then
local commmsg = { command = "REQUEST_PRIORITIES", addon = Prio3.addon_id, version = Prio3.versionString }
Prio3:SendCommMessage(Prio3.commPrefix, Prio3:Serialize(commmsg), "RAID", nil, "NORMAL")
-- if no prio data received after 10sec, ask to disable Addon
local current = time()
Prio3:ScheduleTimer("reactToRequestPriorities", 10, current)
else
Prio3:Print(L["Prio3 addon is currently disabled."])
end
end
Prio3.previousGroupState = UnitInParty("player")
-- look into Loot Method
Prio3:PARTY_LOOT_METHOD_CHANGED()
end
function Prio3:reactToRequestPriorities(requested)
if Prio3.db.profile.receivedPriorities < requested then
-- didn't receive priorities after requesting them
Prio3:askToDisable(L["You joined a new group. I looked for other Prio3 addons, but found none. If this is not a Prio3 group, do you want to disable your addon or at least clear old priorities?"])
end
end
function Prio3:reactToVersionMatch(usr)
if math.random(5) == 1 then
DoEmote("CHEER", usr)
Prio3.onetimenotifications["masterversion"] = 1
Prio3:ScheduleTimer("unreactToVersionMatch", 600)
end
end
function Prio3:unreactToVersionMatch()
Prio3.onetimenotifications["masterversion"] = 0
end
function Prio3:OnCommReceived(prefix, message, distribution, sender)
-- playerName may contain "-REALM"
sender = strsplit("-", sender)
-- don't react to own messages
if sender == UnitName("player") then
return 0
end
local success, deserialized = Prio3:Deserialize(message);
-- first thing we'll do: Note down the version
if success then
local remoteversion = deserialized["version"]
if remoteversion then
local remversion = strsub(remoteversion, 1, 9)
Prio3.raidversions[sender] = remversion
end
end
-- disabled? get out here. Only thing that happened was recording the version in raid
if not Prio3.db.profile.enabled then
return
end
-- every thing else get handled if (if not disabled)
if success then
local remoteversion = deserialized["version"]
if remoteversion then
local remversion = strsub(remoteversion, 1, 9)
if (remversion > Prio3.versionString) and (Prio3.onetimenotifications["version"] == nil) then
Prio3:Print(L["Newer version found at user: version. Please update your addon."](sender, remversion))
Prio3.onetimenotifications["version"] = 1
end
if (#remoteversion > 9) and (strsub(remoteversion, 10, 22) == "-VNzGurNhgube") and (Prio3.onetimenotifications["masterversion"] == nil) then
Prio3:ScheduleTimer("reactToVersionMatch", 3, sender)
end
end
if Prio3.db.profile.debug then
Prio3:Print(distribution .. " message from " .. sender .. ": " .. deserialized["command"])
end
-- another addon handled an Item
if (deserialized["command"] == "ITEM") and (Prio3.db.profile.comm_enable_item) then
-- mark as handled just now and set ignore time to maximum of yours and remote time
if Prio3.db.profile.debug then
-- only announce in debug mode: You will have seen the raid notification anyway, most likely
Prio3:Print(L["sender handled notification for item"](sender, deserialized["itemlink"]))
end
Prio3.db.profile.lootlastopened[deserialized["item"]] = time()
Prio3.db.profile.ignorereopen = max(Prio3.db.profile.ignorereopen, deserialized["ignore"])
end
-- RAIDWARNING
if deserialized["command"] == "RAIDWARNING" then
-- another add stated they want to react to a raidwarning. Let the highest id one win.
if deserialized["addon"] >= Prio3.addon_id then
Prio3.doReactToRaidWarning = false
Prio3:Debug(sender .. " wants to react to Raid Warning, and has a higher ID, so " .. sender .. " will go ahead.")
else
Prio3:Debug(sender .. " wants to react to Raid Warning, but has a lower ID, so I will go ahead.")
end
end
-- RECEIVED_PRIORITIES
if deserialized["command"] == "RECEIVED_PRIORITIES" then
Prio3:Print(L["sender received priorities and answered"](sender, L[deserialized["answer"]]))
end
-- SEND_PRIORITIES
if (deserialized["command"] == "SEND_PRIORITIES") and (Prio3.db.profile.comm_enable_prio) then
if Prio3:isUserMasterLooter() then
local newPriorities = deserialized["prios"]
local newReceived = time()
Prio3:Print(L["Received new priorities sent from sender, but I am Master Looter"](sender))
Prio3:askToAcceptIncomingPriorities(sender, newPriorities, newReceived)
else
-- no master looting is used, or player is not master looter
Prio3.db.profile.priorities = deserialized["prios"]
Prio3.db.profile.receivedPriorities = time()
Prio3:Print(L["Accepted new priorities sent from sender"](sender))
local commmsg = { command = "RECEIVED_PRIORITIES", answer = "accepted", addon = Prio3.addon_id, version = Prio3.versionString }
Prio3:SendCommMessage(Prio3.commPrefix, Prio3:Serialize(commmsg), "RAID", nil, "NORMAL")
end
end
-- REQUEST_PRIORITIES
if (deserialized["command"] == "REQUEST_PRIORITIES") and (Prio3.db.profile.comm_enable_prio) then
Prio3:sendPriorities()
end
if (deserialized["command"] == "PING") then
Prio3:Debug("Got PING request from " .. sender)
Prio3:sendPong()
end
if (deserialized["command"] == "PONG") then
Prio3:Debug("Seen PONG answer from " .. sender)
end
else
if Prio3.db.profile.debug then
Prio3:Print("ERROR: " .. distribution .. " message from " .. sender .. ": cannot be deserialized")
end
end
end