vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Guild Event Manager by Kiki of European Cho'gall (Alliance) |
||
3 | Commands module (handle) |
||
4 | ]] |
||
5 | |||
6 | |||
7 | --------------- Shared variables --------------- |
||
8 | |||
9 | |||
10 | --------------- Local variables --------------- |
||
11 | local _GEM_CMD_CloseEventSends = {}; |
||
12 | local _GEM_CMD_AutoAckCorrespondance = {}; |
||
13 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSCRIBE] = {}; |
||
14 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSCRIBE][GEM_CMD_CMD_SUBSCRIBE] = 1; |
||
15 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSCRIBE][GEM_CMD_CMD_UNSUBSCRIBE] = 1; |
||
16 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_UNSUBSCRIBE] = {}; |
||
17 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_UNSUBSCRIBE][GEM_CMD_CMD_SUBSCRIBE] = 1; |
||
18 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_UNSUBSCRIBE][GEM_CMD_CMD_UNSUBSCRIBE] = 1; |
||
19 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_TITULAR] = {}; |
||
20 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_TITULAR][GEM_CMD_CMD_TITULAR] = 1; |
||
21 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_TITULAR][GEM_CMD_CMD_SUBSTITUTE] = 1; |
||
22 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_TITULAR][GEM_CMD_CMD_REPLACEMENT] = 1; |
||
23 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_TITULAR][GEM_CMD_CMD_KICK] = 1; |
||
24 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_TITULAR][GEM_CMD_CMD_BAN] = 1; |
||
25 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSTITUTE] = {}; |
||
26 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSTITUTE][GEM_CMD_CMD_TITULAR] = 1; |
||
27 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSTITUTE][GEM_CMD_CMD_SUBSTITUTE] = 1; |
||
28 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSTITUTE][GEM_CMD_CMD_REPLACEMENT] = 1; |
||
29 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSTITUTE][GEM_CMD_CMD_KICK] = 1; |
||
30 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_SUBSTITUTE][GEM_CMD_CMD_BAN] = 1; |
||
31 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_REPLACEMENT] = {}; |
||
32 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_REPLACEMENT][GEM_CMD_CMD_TITULAR] = 1; |
||
33 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_REPLACEMENT][GEM_CMD_CMD_SUBSTITUTE] = 1; |
||
34 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_REPLACEMENT][GEM_CMD_CMD_REPLACEMENT] = 1; |
||
35 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_REPLACEMENT][GEM_CMD_CMD_KICK] = 1; |
||
36 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_REPLACEMENT][GEM_CMD_CMD_BAN] = 1; |
||
37 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_KICK] = {}; |
||
38 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_KICK][GEM_CMD_CMD_TITULAR] = 1; |
||
39 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_KICK][GEM_CMD_CMD_SUBSTITUTE] = 1; |
||
40 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_KICK][GEM_CMD_CMD_REPLACEMENT] = 1; |
||
41 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_KICK][GEM_CMD_CMD_KICK] = 1; |
||
42 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_KICK][GEM_CMD_CMD_BAN] = 1; |
||
43 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_BAN] = {}; |
||
44 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_BAN][GEM_CMD_CMD_TITULAR] = 1; |
||
45 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_BAN][GEM_CMD_CMD_SUBSTITUTE] = 1; |
||
46 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_BAN][GEM_CMD_CMD_REPLACEMENT] = 1; |
||
47 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_BAN][GEM_CMD_CMD_KICK] = 1; |
||
48 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_BAN][GEM_CMD_CMD_BAN] = 1; |
||
49 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_UNBAN] = {}; |
||
50 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_UNBAN][GEM_CMD_CMD_KICK] = 1; |
||
51 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_UNBAN][GEM_CMD_CMD_UNBAN] = 1; |
||
52 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_ASSISTANT] = {}; |
||
53 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_ASSISTANT][GEM_CMD_CMD_UNSUBSCRIBE] = 1; |
||
54 | _GEM_CMD_AutoAckCorrespondance[GEM_CMD_CMD_ASSISTANT][GEM_CMD_CMD_ASSISTANT] = 1; |
||
55 | |||
56 | |||
57 | --------------- Internal functions --------------- |
||
58 | |||
59 | --[[ |
||
60 | function _GEM_CMD_CheckExpiredCommand |
||
61 | Checks if the Event has expired yet (well 10h after) |
||
62 | ev_id : String -- EventID |
||
63 | ev_date : Integer -- Event's date |
||
64 | -- |
||
65 | Returns True if the event has expired. False otherwise |
||
66 | ]] |
||
67 | local function _GEM_CMD_CheckExpiredCommand(ev_id,ev_date) |
||
68 | if(ev_id == nil or ev_date == nil) |
||
69 | then |
||
70 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_CMD_CheckExpiredCommand : ev_id or ev_date is nil. Set as expired !"); |
||
71 | return true; |
||
72 | end |
||
73 | local tim = time(); |
||
74 | if((ev_date + GEM_ExpirationTime) < (tim-GEM_GetOffsetTime(ev_id))) |
||
75 | then |
||
76 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_CMD_CheckExpiredCommand : Command expired for Event "..ev_id.." ! ("..date("%c",ev_date).."--"..date("%c",tim)..")"); |
||
77 | GEM_EVT_ClearEvent(ev_id,"Expired command",true); |
||
78 | return true; |
||
79 | end |
||
80 | return false; |
||
81 | end |
||
82 | |||
83 | local function _GEM_CMD_AckCommand(ev_id,cmd_id) |
||
84 | GEM_Events.realms[GEM_Realm].commands[ev_id].cmds[cmd_id].acked = 1; |
||
85 | end |
||
86 | |||
87 | --[[ |
||
88 | _GEM_CMD_CheckCommandForward : |
||
89 | Params[1] = leader (STRING) -- Leader of the event |
||
90 | Params[2] = ev_date (INT) -- Date of the event |
||
91 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
92 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
93 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
94 | Returns true if command must be processed, false if it has been forwarded to the new leader |
||
95 | ]] |
||
96 | local function _GEM_CMD_CheckCommandForward(channel,cmd,from,stamp,ev_id,params) |
||
97 | local forwarder = GEM_Events.realms[GEM_Realm].forward[ev_id]; |
||
98 | -- Check if we have a forwarder set |
||
99 | if(forwarder ~= nil) |
||
100 | then |
||
101 | if(cmd == GEM_CMD_CMD_SUBSCRIBE or cmd == GEM_CMD_CMD_UNSUBSCRIBE) -- For leader commands, we must forward |
||
102 | then |
||
103 | -- Build new params |
||
104 | local new_params = {}; |
||
105 | for i=1,table.getn(params) do table.insert(new_params,params[i]); end; |
||
106 | new_params[1] = forwarder; |
||
107 | new_params[4] = forwarder; |
||
108 | |||
109 | if(new_params[3] == "1") -- A ACK |
||
110 | then |
||
111 | GEM_ChatWarning("_GEM_CMD_CheckCommandForward : Params[3] is acked. Must creat new_params entierely"); |
||
112 | new_params[3] = "0"; |
||
113 | end |
||
114 | |||
115 | -- Store new command |
||
116 | local cmd_id = forwarder.."-"..params[5].."-"..stamp.."-"..cmd; |
||
117 | GEM_CMD_CreateCommandId(ev_id,cmd_id,cmd,stamp,new_params); |
||
118 | |||
119 | -- Send the forwarded message |
||
120 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_CMD_CheckCommandForward : Forwarding "..from.."'s cmd "..cmd.." from "..params[1].." to "..forwarder); |
||
121 | GEM_COM_SendForwardCommand(channel,cmd,ev_id,stamp,new_params); |
||
122 | return false; |
||
123 | end |
||
124 | end |
||
125 | return true; |
||
126 | end |
||
127 | |||
128 | function _GEM_CMD_PurgeMultipleCommands_Sorting(a,b) |
||
129 | if(a.stamp < b.stamp) |
||
130 | then |
||
131 | return true; |
||
132 | else |
||
133 | return false; |
||
134 | end |
||
135 | end |
||
136 | |||
137 | local function _GEM_CMD_PurgeMultipleCommands(ev_id,cmd_id,from) |
||
138 | local thiscmd = GEM_Events.realms[GEM_Realm].commands[ev_id].cmds[cmd_id].cmd; |
||
139 | local thisautoack = _GEM_CMD_AutoAckCorrespondance[thiscmd]; |
||
140 | |||
141 | -- First, sort cmds by stamp |
||
142 | local cmds = {}; |
||
143 | for cmdid,cmdtab in GEM_Events.realms[GEM_Realm].commands[ev_id].cmds |
||
144 | do |
||
145 | if(from == cmdtab.params[5]) -- This cmd is from 'from' too, add it to the list |
||
146 | then |
||
147 | table.insert(cmds,{ id=cmdid, cmd=cmdtab.cmd, stamp=cmdtab.stamp, acked=cmdtab.acked }); |
||
148 | end |
||
149 | end |
||
150 | table.sort(cmds,_GEM_CMD_PurgeMultipleCommands_Sorting); |
||
151 | |||
152 | -- Now check for auto acked cmds |
||
153 | for i,cmd in cmds |
||
154 | do |
||
155 | if(cmd.id == cmd_id) -- Found our cmd, stop parsing |
||
156 | then |
||
157 | break; |
||
158 | end |
||
159 | if(thisautoack[cmd.cmd]) -- This older command must be auto-acked |
||
160 | then |
||
161 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"_GEM_CMD_PurgeMultipleCommands : Auto acking CmdId "..cmd.id.." because of "..cmd_id); |
||
162 | _GEM_CMD_AckCommand(ev_id,cmd.id); |
||
163 | end |
||
164 | end |
||
165 | end |
||
166 | |||
167 | local function _GEM_CMD_IsTooSoonCmd(ev_id,cmd_id) |
||
168 | if(ev_id == nil or cmd_id == nil) |
||
169 | then |
||
170 | GEM_ChatWarning("_GEM_CMD_IsTooSoonCmd : ev_id or cmd_id is nil : "..tostring(ev_id).." : "..tostring(cmd_id)); |
||
171 | return true; |
||
172 | end |
||
173 | if(GEM_Events.realms[GEM_Realm].commands[ev_id].cmds[cmd_id].LastSend and GEM_Events.realms[GEM_Realm].commands[ev_id].cmds[cmd_id].LastSend > GEM_COM_LastJoinerTime) -- Sending too soon ? |
||
174 | then |
||
175 | return true; |
||
176 | end |
||
177 | return false; |
||
178 | end |
||
179 | |||
180 | --------------- Exported functions --------------- |
||
181 | |||
182 | function GEM_CMD_IsCommandAcked(ev_id,cmd_id) |
||
183 | return GEM_Events.realms[GEM_Realm].commands[ev_id].cmds[cmd_id].acked == 1; |
||
184 | end |
||
185 | |||
186 | function GEM_CMD_CreateCommands(channel,ev_id,leader,ev_date) |
||
187 | local s_cmd = {} |
||
188 | |||
189 | s_cmd.cmds = {}; |
||
190 | s_cmd.channel = channel; |
||
191 | s_cmd.leader = leader; |
||
192 | s_cmd.ev_date = ev_date; |
||
193 | GEM_Events.realms[GEM_Realm].commands[ev_id] = s_cmd; |
||
194 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"GEM_CMD_CreateCommands : Creating cmds for eventID "..ev_id); |
||
195 | end |
||
196 | |||
197 | function GEM_CMD_CreateCommandId(ev_id,cmd_id,cmd,stamp,params) |
||
198 | local s_cmd = {}; |
||
199 | |||
200 | s_cmd.cmd = cmd; |
||
201 | s_cmd.stamp = stamp; |
||
202 | s_cmd.acked = 0; |
||
203 | s_cmd.params = params; |
||
204 | GEM_Events.realms[GEM_Realm].commands[ev_id].cmds[cmd_id] = s_cmd; |
||
205 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"GEM_CMD_CreateCommandId : Creating a new cmdID "..cmd_id.." for eventID "..ev_id); |
||
206 | _GEM_CMD_PurgeMultipleCommands(ev_id,cmd_id,params[5]); |
||
207 | end |
||
208 | |||
209 | function GEM_CMD_GetCommands(ev_id) |
||
210 | return GEM_Events.realms[GEM_Realm].commands[ev_id]; |
||
211 | end |
||
212 | |||
213 | --[[ |
||
214 | GEM_CMD_ReceivedCommand : |
||
215 | Params[1] = leader (STRING) -- Leader of the event |
||
216 | Params[2] = ev_date (INT) -- Date of the event |
||
217 | Params[3] = ack (STRING) -- 1 or 0, if the packet is an ack to the command or not |
||
218 | Params[4] = pl_dest (STRING) -- Name of player the command is destinated to |
||
219 | Params[5] = pl_src (STRING) -- Name of player the command is originating from |
||
220 | ]] |
||
221 | function GEM_CMD_ReceivedCommand(channel,cmd,from,stamp,ev_id,params) |
||
222 | local cmd_id = params[4].."-"..params[5].."-"..stamp.."-"..cmd; |
||
223 | local ev_date = tonumber(params[2]); |
||
224 | local must_process = false; |
||
225 | |||
226 | -- First check if command is not expired |
||
227 | if(_GEM_CMD_CheckExpiredCommand(ev_id,ev_date)) |
||
228 | then |
||
229 | return must_process; |
||
230 | end |
||
231 | |||
232 | -- Check for unknown event if I'm leader |
||
233 | if(GEM_IsMyReroll(params[1]) and GEM_Events.realms[GEM_Realm].events[ev_id] == nil) -- Unknown event |
||
234 | then |
||
235 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"GEM_CMD_ReceivedCommand : I'm leader of EventID "..ev_id..", but I don't know it."); |
||
236 | end |
||
237 | |||
238 | -- Create the CMD struct for this ev_id, if it does not exist |
||
239 | if(GEM_Events.realms[GEM_Realm].commands[ev_id] == nil) |
||
240 | then |
||
241 | GEM_CMD_CreateCommands(channel,ev_id,params[1],ev_date); |
||
242 | end |
||
243 | |||
244 | -- Then check if commandID exists |
||
245 | if(GEM_Events.realms[GEM_Realm].commands[ev_id].cmds[cmd_id] == nil) |
||
246 | then |
||
247 | GEM_CMD_CreateCommandId(ev_id,cmd_id,cmd,stamp,params); |
||
248 | end |
||
249 | |||
250 | GEM_QUE_RemoveCommandFromQueue(ev_id,cmd_id); -- Remove from queue. It will be resent if needed |
||
251 | if(params[3] == "1") -- A ACK |
||
252 | then |
||
253 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"GEM_CMD_ReceivedCommand : Received an ACK from "..from.." for cmdID : "..cmd_id); |
||
254 | _GEM_CMD_AckCommand(ev_id,cmd_id); |
||
255 | else -- A command (not a ACK) |
||
256 | -- Check if I already have a ACK for this |
||
257 | if(GEM_CMD_IsCommandAcked(ev_id,cmd_id)) -- I have a ACK |
||
258 | then |
||
259 | if(not _GEM_CMD_IsTooSoonCmd(ev_id,cmd_id)) |
||
260 | then |
||
261 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"GEM_CMD_ReceivedCommand : I already have a ACK for cmdID "..cmd_id..". Broadcasting my ACK"); |
||
262 | GEM_COM_SendAckCommand(ev_id,cmd_id); -- Broadcast the ACK |
||
263 | end |
||
264 | elseif(GEM_IsMyReroll(params[4])) -- This command is for me, ACK it |
||
265 | then |
||
266 | GEM_ChatDebug(GEM_DEBUG_COMMANDS,"GEM_CMD_ReceivedCommand : Got cmdID "..cmd_id.." for me. Broadcasting ACK"); |
||
267 | _GEM_CMD_AckCommand(ev_id,cmd_id); |
||
268 | GEM_COM_SendAckCommand(ev_id,cmd_id); -- Broadcast the ACK |
||
269 | must_process = _GEM_CMD_CheckCommandForward(channel,cmd,from,stamp,ev_id,params); |
||
270 | end |
||
271 | end |
||
272 | |||
273 | return must_process; |
||
274 | end |
||
275 | |||
276 | |||
277 | --[[ |
||
278 | function GEM_CMD_CheckExpiredCommands |
||
279 | Checks all commands, for expired ones |
||
280 | ]] |
||
281 | function GEM_CMD_CheckExpiredCommands() |
||
282 | for ev_id,cmdtab in GEM_Events.realms[GEM_Realm].commands |
||
283 | do |
||
284 | _GEM_CMD_CheckExpiredCommand(ev_id,cmdtab.ev_date); |
||
285 | end |
||
286 | end |
||
287 |