vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Guild Event Manager by Kiki of European Cho'gall (Alliance)
3 Queues module (broadcast/build)
4 ]]
5  
6 --------------- Local variables ---------------
7 local _GEM_QUE_immediateQueue = {};
8 local _GEM_QUE_delayedQueue = {};
9 local _GEM_QUE_cmdQueue = {};
10 local _GEM_MaxBcastRow = 2;
11 local _GEM_MinimalTimeBeforeSend = 2;
12 local _GEM_RejoinTooSoon = 60; -- 60 sec delay
13  
14 --------------- Internal functions ---------------
15  
16 local function _GEM_QUE_CheckForBroadcast(queue)
17 local curr_count = 0;
18 if(queue == 1) -- Immediate EVENT queue
19 then
20 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Start immediate EVENT queue");
21 for ev_id,event in _GEM_QUE_immediateQueue
22 do
23 curr_count = curr_count + 1;
24 if(curr_count > _GEM_MaxBcastRow or GEM_YouAreDrunk) -- Check for reschedule later
25 then
26 GEMSystem_Schedule(1,_GEM_QUE_CheckForBroadcast,1);
27 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Queue continue in 1sec");
28 return;
29 end
30 GEM_COM_BroadcastEvent(event);
31 _GEM_QUE_immediateQueue[ev_id] = nil;
32 end
33 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Complete");
34 elseif(queue == 2) -- Delayed EVENT queue
35 then
36 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Start delayed EVENT queue");
37 for ev_id,event in _GEM_QUE_delayedQueue
38 do
39 curr_count = curr_count + 1;
40 if(curr_count > _GEM_MaxBcastRow or GEM_YouAreDrunk) -- Check for reschedule later
41 then
42 GEMSystem_Schedule(2,_GEM_QUE_CheckForBroadcast,2);
43 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Queue continue in 2sec");
44 return;
45 end
46 GEM_COM_BroadcastEvent(event);
47 _GEM_QUE_delayedQueue[ev_id] = nil;
48 end
49 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Complete");
50 elseif(queue == 3) -- Delayed CMD queue
51 then
52 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Start delayed CMD queue");
53 for ev_id,cmdstab in _GEM_QUE_cmdQueue
54 do
55 while(table.getn(cmdstab) > 0)
56 do
57 curr_count = curr_count + 1;
58 if(curr_count > _GEM_MaxBcastRow or GEM_YouAreDrunk) -- Check for reschedule later
59 then
60 GEMSystem_Schedule(2,_GEM_QUE_CheckForBroadcast,3);
61 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Queue continue in 2sec");
62 return;
63 end
64 local cmd_id = _GEM_QUE_cmdQueue[ev_id][table.getn(_GEM_QUE_cmdQueue[ev_id])]; -- Get cmd_id value from queue
65 table.remove(_GEM_QUE_cmdQueue[ev_id]); -- Immediately remove cmd_id from queue
66 if(not GEM_CMD_IsCommandAcked(ev_id,cmd_id)) -- Still not acked, send it
67 then
68 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Broadcasting cmdID "..cmd_id.." from eventID "..ev_id);
69 GEM_COM_BroadcastCommand(ev_id,cmd_id);
70 end
71 end
72 _GEM_QUE_cmdQueue[ev_id] = nil;
73 end
74 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_CheckForBroadcast : Complete");
75 end
76 end
77  
78 local function _GEM_QUE_BuildCommandsQueue(channel,forcesend)
79 -- Acks queues
80 for ev_id,cmdstab in GEM_Events.realms[GEM_Realm].commands
81 do
82 GEM_CheckCommandHasChannel(cmdstab);
83 if(cmdstab.channel == channel)
84 then
85 for cmd_id,tab in cmdstab.cmds
86 do
87 if(not GEM_CMD_IsCommandAcked(ev_id,cmd_id))
88 then
89 if(forcesend or GEM_IsMyReroll(tab.params[5])) -- Forced send, or if it is a command from me
90 then
91 if(_GEM_QUE_cmdQueue[ev_id] == nil)
92 then
93 _GEM_QUE_cmdQueue[ev_id] = {};
94 end
95 tinsert(_GEM_QUE_cmdQueue[ev_id],cmd_id);
96 GEM_ChatDebug(GEM_DEBUG_QUEUES,"_GEM_QUE_BuildCommandsQueue : "..channel.." : Added cmdID "..cmd_id.." to ACK queue for eventID "..ev_id);
97 end
98 end
99 end
100 end
101 end
102 end
103  
104  
105 --------------- Exported functions ---------------
106  
107 function GEM_QUE_RemoveEventFromQueue(ev_id)
108 _GEM_QUE_immediateQueue[ev_id] = nil;
109 _GEM_QUE_delayedQueue[ev_id] = nil;
110 end
111  
112 function GEM_QUE_RemoveCommandFromQueue(ev_id,cmd_id)
113 local cmdstab = _GEM_QUE_cmdQueue[ev_id];
114  
115 if(cmdstab == nil)
116 then
117 return;
118 end
119 for pos,cmd in cmdstab
120 do
121 if(cmd == cmd_id)
122 then
123 GEM_ChatDebug(GEM_DEBUG_QUEUES,"GEM_QUE_RemoveCommandFromQueue : Removed cmdID "..cmd_id.." from cmdQueue");
124 table.remove(cmdstab,pos);
125 return;
126 end
127 end
128 end
129  
130 --[[
131 function GEM_QUE_RemoveCommands
132 Remove all commands for this event.
133 ev_id : String -- EventID for commands to remove from ACK list
134 ]]
135 function GEM_QUE_RemoveCommands(ev_id)
136 -- Cancel delayed queue
137 _GEM_QUE_cmdQueue[ev_id] = {};
138 end
139  
140 --[[
141 Builds broadcast queues.
142 player : String -- Player who joined the channel
143 ]]
144 function GEM_QUE_BuildBroadcastQueues(channel,player)
145 -- Check for player's last leave
146 local last_leave = GEM_PLAY_GetLastLeave(channel,player);
147 local tim = time();
148  
149 if((last_leave + _GEM_RejoinTooSoon) > tim)
150 then
151 GEM_ChatDebug(GEM_DEBUG_QUEUES,"GEM_QUE_BuildBroadcastQueues : "..channel.." : Player "..tostring(player).." rejoining too soon the channel. Don't broadcast");
152 return;
153 end
154  
155 -- Check for expired events
156 GEM_EVT_CheckExpiredEvents();
157  
158 -- Events queues
159 for ev_id,event in GEM_Events.realms[GEM_Realm].events
160 do
161 GEM_CheckEventHasChannel(event);
162 if(event.channel == channel)
163 then
164 if(GEM_IsMyReroll(event.leader)) -- My event -> Immediate queue
165 then
166 _GEM_QUE_immediateQueue[ev_id] = event;
167 GEM_ChatDebug(GEM_DEBUG_QUEUES,"GEM_QUE_BuildBroadcastQueues : "..channel.." : Added EventID "..ev_id.." to immediate queue");
168 elseif(event.leader ~= player) -- Player is not the leader -> Delayed queue
169 then
170 _GEM_QUE_delayedQueue[ev_id] = event;
171 GEM_ChatDebug(GEM_DEBUG_QUEUES,"GEM_QUE_BuildBroadcastQueues : "..channel.." : Added EventID "..ev_id.." to delayed queue");
172 end
173 end
174 end
175  
176 -- Check for expired commands
177 GEM_CMD_CheckExpiredCommands();
178  
179 -- Build commands
180 _GEM_QUE_BuildCommandsQueue(channel,true);
181  
182 -- Send Immediate queue
183 GEMSystem_Schedule(_GEM_MinimalTimeBeforeSend,_GEM_QUE_CheckForBroadcast,1); -- 1 = Immediate EVENT queue
184 GEM_ChatDebug(GEM_DEBUG_QUEUES,"Scheduled 'delayed_queue' in "..GEM_Events.my_bcast_offset.."sec");
185 GEMSystem_Schedule(_GEM_MinimalTimeBeforeSend+GEM_Events.my_bcast_offset,_GEM_QUE_CheckForBroadcast,2); -- 2 = Delayed EVENT queue
186 GEMSystem_Schedule(_GEM_MinimalTimeBeforeSend+GEM_Events.my_bcast_offset+1,_GEM_QUE_CheckForBroadcast,3); -- 3 = ACK EVENT queue
187 end
188  
189 --[[
190 function GEM_QUE_BroadcastMyEvents(channel)
191 for ev_id,event in GEM_Events.realms[GEM_Realm].events
192 do
193 GEM_CheckEventHasChannel(event);
194 if(event.channel == channel)
195 then
196 if(GEM_IsMyReroll(event.leader)) -- My event -> Immediate queue
197 then
198 GEM_ChatDebug(GEM_DEBUG_QUEUES,"GEM_QUE_BroadcastMyEvents : "..channel.." : Adding my EventID "..ev_id.." to immediate broadcast queue");
199 _GEM_QUE_immediateQueue[ev_id] = event;
200 end
201 end
202 end
203  
204 _GEM_QUE_BuildCommandsQueue(channel,false);
205  
206 GEMSystem_Schedule(_GEM_MinimalTimeBeforeSend,_GEM_QUE_CheckForBroadcast,1); -- 1 = Immediate EVENT queue
207 GEMSystem_Schedule(_GEM_MinimalTimeBeforeSend+GEM_Events.my_bcast_offset+1,_GEM_QUE_CheckForBroadcast,3); -- 3 = ACK EVENT queue
208 end
209 ]]