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 | Events module (handle) |
||
4 | ]] |
||
5 | |||
6 | |||
7 | --------------- Shared variables --------------- |
||
8 | GEM_ExpirationTime = 60*60*1; -- 1 hour |
||
9 | GEM_ExpirationTimeSelf = 60*60*10; -- 10 hours |
||
10 | |||
11 | --------------- Local variables --------------- |
||
12 | |||
13 | --------------- Internal functions --------------- |
||
14 | |||
15 | local function _GEM_EVT_CheckMySubscription(ev_id) |
||
16 | if(GEM_Events.realms[GEM_Realm].subscribed[ev_id] == nil) -- I never subscribed |
||
17 | then |
||
18 | -- Check titulars list |
||
19 | for i,tab in GEM_Events.realms[GEM_Realm].events[ev_id].titulars do |
||
20 | if(GEM_IsMyReroll(tab.name)) |
||
21 | then |
||
22 | local infos = GEM_Events.realms[GEM_Realm].my_names[tab.name]; |
||
23 | if(infos ~= nil) |
||
24 | then |
||
25 | GEM_EVT_SubscribeMyself(ev_id,tab.name,infos.guild,infos.level,infos.class,"",0,"1"); |
||
26 | end |
||
27 | return; |
||
28 | end |
||
29 | end |
||
30 | |||
31 | -- Check substitutes list |
||
32 | for i,tab in GEM_Events.realms[GEM_Realm].events[ev_id].substitutes do |
||
33 | if(GEM_IsMyReroll(tab.name)) |
||
34 | then |
||
35 | local infos = GEM_Events.realms[GEM_Realm].my_names[tab.name]; |
||
36 | if(infos ~= nil) |
||
37 | then |
||
38 | GEM_EVT_SubscribeMyself(ev_id,tab.name,infos.guild,infos.level,infos.class,"",0,"2"); |
||
39 | end |
||
40 | return; |
||
41 | end |
||
42 | end |
||
43 | |||
44 | -- Check replacements list |
||
45 | for i,tab in GEM_Events.realms[GEM_Realm].events[ev_id].replacements do |
||
46 | if(GEM_IsMyReroll(tab.name)) |
||
47 | then |
||
48 | local infos = GEM_Events.realms[GEM_Realm].my_names[tab.name]; |
||
49 | if(infos ~= nil) |
||
50 | then |
||
51 | GEM_EVT_SubscribeMyself(ev_id,tab.name,infos.guild,infos.level,infos.class,"",1,"3"); |
||
52 | end |
||
53 | return; |
||
54 | end |
||
55 | end |
||
56 | end |
||
57 | end |
||
58 | |||
59 | |||
60 | --------------- Exported functions --------------- |
||
61 | |||
62 | function GEM_EVT_SubscribeMyself(ev_id,name,guild,level,class,comment,forcesub,state) |
||
63 | GEM_Events.realms[GEM_Realm].kicked[ev_id] = nil; -- Unkick me if I was |
||
64 | GEM_Events.realms[GEM_Realm].subscribed[ev_id] = {}; |
||
65 | GEM_Events.realms[GEM_Realm].subscribed[ev_id].state = state; |
||
66 | GEM_Events.realms[GEM_Realm].subscribed[ev_id].comment = comment; |
||
67 | GEM_Events.realms[GEM_Realm].subscribed[ev_id].forcesub = forcesub; |
||
68 | GEM_Events.realms[GEM_Realm].subscribed[ev_id].name = name; |
||
69 | GEM_Events.realms[GEM_Realm].subscribed[ev_id].class = class; |
||
70 | GEM_Events.realms[GEM_Realm].subscribed[ev_id].guild = guild; |
||
71 | GEM_Events.realms[GEM_Realm].subscribed[ev_id].level = level; |
||
72 | end |
||
73 | |||
74 | function GEM_GetOffsetTime(ev_id) |
||
75 | if(GEM_Events.realms[GEM_Realm].events[ev_id] == nil) |
||
76 | then |
||
77 | return 0; |
||
78 | end |
||
79 | return GEM_Events.realms[GEM_Realm].events[ev_id].offset_time; |
||
80 | end |
||
81 | |||
82 | function GEM_SetOffsetStamp(ev_id,leader_stamp) |
||
83 | GEM_Events.realms[GEM_Realm].events[ev_id].offset_time = time() - leader_stamp; |
||
84 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"I have an offset of "..GEM_Events.realms[GEM_Realm].events[ev_id].offset_time.." sec from Leader"); |
||
85 | end |
||
86 | |||
87 | function GEM_EVT_AddEvent(channel,ev_id,creat_time,leader,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,titulars,substitutes,replacements,sorttype,closed_comment) |
||
88 | if(GEM_Events.realms[GEM_Realm].events[ev_id] ~= nil) then GEM_ChatDebug(GEM_DEBUG_EVENTS,"Already have an Event with that ID ("..ev_id..")"); return GEM_Events.realms[GEM_Realm].events[ev_id]; end; |
||
89 | local event = {}; |
||
90 | event.channel = channel; |
||
91 | event.id = ev_id; |
||
92 | event.update_time = creat_time; |
||
93 | event.offset_time = 0; |
||
94 | event.leader = leader; |
||
95 | event.ev_date = ev_date; |
||
96 | event.ev_place = ev_place; |
||
97 | event.ev_comment = ev_comment; |
||
98 | event.max_count = max_count; |
||
99 | event.min_lvl = min_lvl; |
||
100 | event.max_lvl = max_lvl; |
||
101 | event.classes = classes; |
||
102 | event.titular_count = table.getn(titulars); |
||
103 | event.titulars = titulars; |
||
104 | event.substitutes = substitutes; |
||
105 | event.replacements = replacements; |
||
106 | event.sorttype = sorttype; |
||
107 | if(closed_comment and closed_comment ~= "") |
||
108 | then |
||
109 | event.closed_comment = closed_comment; |
||
110 | end |
||
111 | event.players = {}; -- Leader side only |
||
112 | event.banned = {}; -- Leader side only |
||
113 | event.assistants = {}; -- Leader side only |
||
114 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_AddEvent : EventId "..ev_id.." Leader="..leader.." Date="..date("%c",ev_date).." ("..ev_date..") Place="..ev_place); |
||
115 | GEM_Events.realms[GEM_Realm].events[ev_id] = event; |
||
116 | return event; |
||
117 | end |
||
118 | |||
119 | -- Returns true if event updated, false otherwise |
||
120 | function GEM_EVT_UpdateEvent(channel,ev_id,update_time,leader,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,titulars,substitutes,replacements,sorttype,closed_comment) |
||
121 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
122 | local tim = time(); |
||
123 | |||
124 | if(GEM_IsMyReroll(leader)) -- If I'm the leader of this event |
||
125 | then |
||
126 | if(event and update_time == event.update_time) -- Someone just sent the event, cancel the send |
||
127 | then |
||
128 | GEM_QUE_RemoveEventFromQueue(ev_id); |
||
129 | end |
||
130 | if(event == nil) |
||
131 | then |
||
132 | if(GEM_Events.realms[GEM_Realm].my_closed_events[ev_id] == nil) -- Never heard of this event |
||
133 | then |
||
134 | if((ev_date + GEM_ExpirationTime) > tim) |
||
135 | then |
||
136 | GEM_ChatPrint("WARNING : I'm supposed to be the leader of '"..ev_id.."' but I don't know it. Auto-closing event. This happen if you crashed the game, after creating the event. You can try to 'Recover' the event."); |
||
137 | event = GEM_EVT_AddEvent(channel,ev_id,update_time,leader,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,titulars,substitutes,replacements,sorttype,"Leader lost the event (crashed)"); |
||
138 | event.crashed = 1; |
||
139 | GEM_COM_NotifyEventUpdate(ev_id); |
||
140 | GEM_NotifyGUI(GEM_NOTIFY_NEW_EVENT,ev_id); |
||
141 | else |
||
142 | GEM_ChatDebug(GEM_DEBUG_WARNING,"GEM_EVT_UpdateEvent : I'm supposed to be the leader of '"..ev_id.."', it's expired, ignoring."); |
||
143 | end |
||
144 | else -- I deleted this event |
||
145 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_UpdateEvent : Event "..ev_id.." was deleted ! Resending deleted event notification."); |
||
146 | event = GEM_EVT_AddEvent(channel,ev_id,update_time,leader,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,titulars,substitutes,replacements,sorttype,"Event was deleted"); |
||
147 | event.ev_date = time() - GEM_ExpirationTimeSelf * 2; |
||
148 | event.update_time = time(); |
||
149 | GEM_COM_BroadcastEvent(event); -- Force brodcast (or it will be deleted before update) |
||
150 | GEM_Events.realms[GEM_Realm].events[ev_id] = nil; |
||
151 | end |
||
152 | end |
||
153 | return false; -- Return, not interested in an update of my own event |
||
154 | end |
||
155 | |||
156 | if((ev_date + GEM_ExpirationTime) < (tim-GEM_GetOffsetTime(ev_id))) |
||
157 | then |
||
158 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_UpdateEvent : Event "..ev_id.." expired ! ev_date="..date("%c",ev_date).." ("..ev_date..")"); |
||
159 | GEM_EVT_ClearEvent(ev_id,"Expired",true); |
||
160 | return false; |
||
161 | end |
||
162 | |||
163 | if(event == nil) -- Never seen this event, create it |
||
164 | then |
||
165 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_UpdateEvent : EventID not found ("..ev_id..") : Creating"); |
||
166 | event = GEM_EVT_AddEvent(channel,ev_id,update_time,leader,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,titulars,substitutes,replacements,sorttype,closed_comment); |
||
167 | _GEM_EVT_CheckMySubscription(ev_id); |
||
168 | event.update_time = update_time; |
||
169 | GEM_NotifyGUI(GEM_NOTIFY_NEW_EVENT,ev_id); |
||
170 | return true; |
||
171 | end |
||
172 | |||
173 | if(update_time > event.update_time) -- New update, destroy and re-create it |
||
174 | then |
||
175 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_UpdateEvent : Found an update for EventID "..ev_id); |
||
176 | GEM_Events.realms[GEM_Realm].events[ev_id] = nil; |
||
177 | event = GEM_EVT_AddEvent(channel,ev_id,update_time,leader,ev_date,ev_place,ev_comment,max_count,min_lvl,max_lvl,classes,titulars,substitutes,replacements,sorttype,closed_comment); |
||
178 | _GEM_EVT_CheckMySubscription(ev_id); |
||
179 | event.update_time = update_time; |
||
180 | GEM_QUE_RemoveEventFromQueue(ev_id); |
||
181 | GEM_NotifyGUI(GEM_NOTIFY_EVENT_UPDATE,ev_id); |
||
182 | elseif(update_time == event.update_time) -- Someone just sent the event, cancel the send |
||
183 | then |
||
184 | GEM_QUE_RemoveEventFromQueue(ev_id); |
||
185 | else -- Old event |
||
186 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_UpdateEvent : Found an old update for EventID "..ev_id); |
||
187 | end |
||
188 | return true; |
||
189 | end |
||
190 | |||
191 | |||
192 | --[[ |
||
193 | function GEM_EVT_CloseEvent |
||
194 | Close an event (called by leader only). |
||
195 | ev_id : String -- EventID to be closed |
||
196 | reason : String -- Reason of the close |
||
197 | ]] |
||
198 | function GEM_EVT_CloseEvent(ev_id,reason) |
||
199 | if(reason == nil or reason == "") |
||
200 | then |
||
201 | reason = GEM_TEXT_NO_REASON; |
||
202 | end |
||
203 | GEM_EVT_ClearEvent(ev_id,reason,false); |
||
204 | GEM_Events.realms[GEM_Realm].my_closed_events[ev_id] = 1; |
||
205 | GEM_Events.realms[GEM_Realm].events[ev_id].crashed = nil; -- Un-crash it |
||
206 | GEM_COM_NotifyEventUpdate(ev_id); -- Notify an update |
||
207 | end |
||
208 | |||
209 | --[[ |
||
210 | function GEM_EVT_UnCloseEvent |
||
211 | Unclose a closed event (called by leader only). |
||
212 | ev_id : String -- EventID to be unclosed |
||
213 | ]] |
||
214 | function GEM_EVT_UnCloseEvent(ev_id) |
||
215 | GEM_Events.realms[GEM_Realm].events[ev_id].closed_comment = nil; |
||
216 | GEM_Events.realms[GEM_Realm].my_closed_events[ev_id] = nil; |
||
217 | GEM_COM_NotifyEventUpdate(ev_id); -- Notify an update |
||
218 | end |
||
219 | |||
220 | |||
221 | --[[ |
||
222 | function GEM_EVT_ClearEvent |
||
223 | Remove all infos about this event. |
||
224 | ev_id : String -- EventID to be removed |
||
225 | comment : String -- Comment for close event |
||
226 | purge : Boolean -- If event must be completly purged |
||
227 | ]] |
||
228 | function GEM_EVT_ClearEvent(ev_id,comment,purge) |
||
229 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
230 | -- Remove from NewEvents |
||
231 | if(GEM_IsNewEvent(ev_id)) |
||
232 | then |
||
233 | GEM_RemoveNewEvent(ev_id); |
||
234 | end |
||
235 | -- Set close comment |
||
236 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_ClearEvent : Clearing Event "..ev_id.." : "..comment); |
||
237 | if(event) |
||
238 | then |
||
239 | event.closed_comment = comment; |
||
240 | end |
||
241 | if(purge) |
||
242 | then |
||
243 | -- Remove the event |
||
244 | GEM_ChatDebug(GEM_DEBUG_EVENTS,"GEM_EVT_ClearEvent : Purging Event "..ev_id.." : "..comment); |
||
245 | GEM_Events.realms[GEM_Realm].events[ev_id] = nil; |
||
246 | -- Clear all related infos |
||
247 | GEM_Events.realms[GEM_Realm].commands[ev_id] = nil; -- Remove commands |
||
248 | GEM_Events.realms[GEM_Realm].subscribed[ev_id] = nil; -- Remove my subscriptions |
||
249 | GEM_Events.realms[GEM_Realm].kicked[ev_id] = nil; -- Remove kicks |
||
250 | GEM_Events.realms[GEM_Realm].banned[ev_id] = nil; -- Remove bans |
||
251 | GEM_Events.realms[GEM_Realm].forward[ev_id] = nil; -- Remove bans |
||
252 | GEM_Events.realms[GEM_Realm].assistant[ev_id] = nil; -- Remove assistant |
||
253 | -- DON'T REMOVE FROM IGNORE LIST !!! |
||
254 | end |
||
255 | -- Clear queues |
||
256 | GEM_QUE_RemoveCommands(ev_id); |
||
257 | -- Notify GUI |
||
258 | GEM_NotifyGUI(GEM_NOTIFY_CLOSE_EVENT,ev_id); |
||
259 | end |
||
260 | |||
261 | function GEM_EVT_SetBanned(ev_id,pl_name,reason) |
||
262 | if(GEM_Events.realms[GEM_Realm].events[ev_id] ~= nil) |
||
263 | then |
||
264 | GEM_Events.realms[GEM_Realm].events[ev_id].banned[pl_name] = reason; |
||
265 | end |
||
266 | end |
||
267 | |||
268 | function GEM_EVT_SetUnBanned(ev_id,pl_name) |
||
269 | if(GEM_Events.realms[GEM_Realm].events[ev_id] ~= nil) |
||
270 | then |
||
271 | GEM_Events.realms[GEM_Realm].events[ev_id].banned[pl_name] = nil; |
||
272 | end |
||
273 | end |
||
274 | |||
275 | function GEM_EVT_IsBanned(ev_id,pl_name) |
||
276 | if(GEM_Events.realms[GEM_Realm].events[ev_id] == nil) |
||
277 | then |
||
278 | return false; |
||
279 | end |
||
280 | return GEM_Events.realms[GEM_Realm].events[ev_id].banned[pl_name] ~= nil; |
||
281 | end |
||
282 | |||
283 | --[[ |
||
284 | function GEM_EVT_CheckExpiredEvent |
||
285 | Checks if the Event has expired yet (well 10h after) |
||
286 | ev_id : String -- EventID |
||
287 | -- |
||
288 | Returns True if the event has expired. False otherwise |
||
289 | ]] |
||
290 | function GEM_EVT_CheckExpiredEvent(ev_id) |
||
291 | local event = GEM_Events.realms[GEM_Realm].events[ev_id]; |
||
292 | |||
293 | if(event) |
||
294 | then |
||
295 | local tim = time(); |
||
296 | if(event.ev_date == nil) |
||
297 | then |
||
298 | return true; |
||
299 | end |
||
300 | local expire_time = GEM_ExpirationTime; |
||
301 | if(GEM_IsMyReroll(event.leader)) |
||
302 | then |
||
303 | expire_time = GEM_ExpirationTimeSelf; |
||
304 | end |
||
305 | if((event.ev_date + expire_time) < (tim-GEM_GetOffsetTime(ev_id))) |
||
306 | then |
||
307 | GEM_EVT_ClearEvent(ev_id,"Expired",true); |
||
308 | end |
||
309 | end |
||
310 | return false; |
||
311 | end |
||
312 | |||
313 | --[[ |
||
314 | function GEM_EVT_CheckExpiredEvents |
||
315 | Checks all events, for expired ones |
||
316 | ]] |
||
317 | function GEM_EVT_CheckExpiredEvents() |
||
318 | for ev_id,event in GEM_Events.realms[GEM_Realm].events |
||
319 | do |
||
320 | GEM_EVT_CheckExpiredEvent(ev_id); |
||
321 | end |
||
322 | end |
||
323 |