vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | ---------------------------------------------------------------------------------- |
2 | -- |
||
3 | -- GuildAds.lua |
||
4 | -- |
||
5 | -- Author: Alexandre Flament |
||
6 | -- URL : http://guildads.sourceforge.net |
||
7 | -- Licence: GPL version 2 (General Public License) |
||
8 | -- |
||
9 | -- GuildAds allows multiple independant players to create a channel for chatting, |
||
10 | -- exchange object and event organisation. |
||
11 | -- |
||
12 | |||
13 | --------------------------------------------------------------------------------- |
||
14 | -- |
||
15 | -- Constants |
||
16 | -- |
||
17 | --------------------------------------------------------------------------------- |
||
18 | GUILDADS_VERSION = 103.2; |
||
19 | |||
20 | GUILDADS_MAX_CHANNEL_JOIN_ATTEMPTS = 5; -- Wait 8 seconds more if no channel are joined |
||
21 | |||
22 | GUILDADS_DEBUG = false; |
||
23 | |||
24 | ---------------------------------------------------------------------------------- |
||
25 | -- |
||
26 | -- Global variables / file scope variables |
||
27 | -- |
||
28 | --------------------------------------------------------------------------------- |
||
29 | local g_GuildAdsInitialized; --- Is GuildAds initialized? |
||
30 | |||
31 | local g_playerName = "Noname"; |
||
32 | local g_realmName = "None"; |
||
33 | local g_ChatChannel = "GuildAdsGlobal"; |
||
34 | local g_ChatPassword = nil; |
||
35 | local g_JoinChannelAttempts = 0; |
||
36 | |||
37 | -- CHAT_MSG_CHANNEL_JOIN, g_HasJoined[player] = true |
||
38 | -- GuildAds_OnOnline(player, true), si g_HasJoined[player] |
||
39 | -- alors on affiche le message de connexion |
||
40 | local g_HasJoined = {}; |
||
41 | |||
42 | local g_showPlayerVersion = false; |
||
43 | |||
44 | ---------------------------------------------------------------------------------- |
||
45 | -- |
||
46 | -- Print a debug string to the chat frame |
||
47 | -- msg - message to print |
||
48 | -- |
||
49 | --------------------------------------------------------------------------------- |
||
50 | local function DEBUG_MSG(msg) |
||
51 | if (GUILDADS_DEBUG) then |
||
52 | ChatFrame1:AddMessage(msg, 1.0, 1.0, 0.5); |
||
53 | end |
||
54 | end |
||
55 | |||
56 | function NoNil(param) |
||
57 | if (param == nil) then |
||
58 | return "<nil>"; |
||
59 | else |
||
60 | return param |
||
61 | end |
||
62 | end |
||
63 | |||
64 | ---------------------------------------------------------------------------------- |
||
65 | -- |
||
66 | -- GetVersionAsString |
||
67 | -- |
||
68 | --------------------------------------------------------------------------------- |
||
69 | function GuildAds_GetVersionAsString() |
||
70 | local addThis; |
||
71 | local major = floor(GUILDADS_VERSION); |
||
72 | local minor = floor((GUILDADS_VERSION - major)*10 + 0.5); |
||
73 | if minor>0 then |
||
74 | local minorToString = { |
||
75 | [1] = "Alpha", |
||
76 | [2] = "Beta", |
||
77 | [3] = "Beta 2", |
||
78 | [4] = "Beta 3", |
||
79 | [5] = "Beta 4", |
||
80 | [6] = "Beta 5", |
||
81 | [7] = "RC 1", |
||
82 | [8] = "RC 2", |
||
83 | [9] = "RC 3" |
||
84 | } |
||
85 | addThis = " "..minorToString[minor]; |
||
86 | else |
||
87 | addThis = ""; |
||
88 | end |
||
89 | return string.format("%0.2f", major/100)..addThis; |
||
90 | end |
||
91 | |||
92 | -------------------------------------------------------------------------------- |
||
93 | -- |
||
94 | -- Init |
||
95 | -- |
||
96 | -------------------------------------------------------------------------------- |
||
97 | function GuildAds_InitVariablesLoaded() |
||
98 | DEBUG_MSG("[GuildAds_InitVariablesLoaded]"); |
||
99 | |||
100 | local backupAccountId; |
||
101 | |||
102 | -- Init player and realm Name |
||
103 | g_playerName = UnitName("player"); |
||
104 | g_realmName = GetCVar("realmName"); |
||
105 | |||
106 | -- Add GuildAds to myAddOns addons list |
||
107 | if(myAddOnsFrame) then |
||
108 | myAddOnsList.GuildAds = { |
||
109 | name = "GuildAds", |
||
110 | version = GuildAds_GetVersionAsString(), |
||
111 | category = MYADDONS_CATEGORY_GUILD, |
||
112 | author = "Zarkan", |
||
113 | email = "guildads@gmail.com", |
||
114 | website = "http://guildads.sf.net", |
||
115 | frame = "GuildAdsFrame", |
||
116 | optionsframe = "GuildAdsConfigFrame" |
||
117 | }; |
||
118 | end |
||
119 | |||
120 | -- On reset, backup accountId |
||
121 | if GuildAds and GuildAds.Version=="reset" then |
||
122 | backupAccountId = GuildAds.AccountId; |
||
123 | end |
||
124 | |||
125 | -- Reset channel data for old version |
||
126 | if GuildAds and GuildAds.Version == "20050729" then |
||
127 | -- for each GuildAds.Data[realmName].Global[channel] |
||
128 | for realmName, data in pairs(GuildAds.Data) do |
||
129 | for channelName, ads in pairs(data.Global) do |
||
130 | data.Global[channelName] = nil; |
||
131 | end |
||
132 | end |
||
133 | -- to avoid reset |
||
134 | GuildAds.Version = GUILDADS_VERSION_STORAGE; |
||
135 | end |
||
136 | |||
137 | -- If this is the first time that GuildAds is use with this version |
||
138 | if ( (GuildAds == nil) or (GuildAds["Version"] ~= GUILDADS_VERSION_STORAGE) ) then |
||
139 | if (GuildAds) then |
||
140 | ChatFrame1:AddMessage("GuildAds: Reset", 1.0, 0.0, 0.0); |
||
141 | end |
||
142 | GuildAds = {}; |
||
143 | GuildAds.Version = GUILDADS_VERSION_STORAGE; |
||
144 | GuildAds.Data = {}; |
||
145 | GuildAds.Config = { |
||
146 | MinimapRadiusOffset = 77; |
||
147 | MinimapArcOffset = 296; |
||
148 | PublishMyAds = true; |
||
149 | ShowMyAds = true; |
||
150 | ShowOfflinePlayer = true; |
||
151 | Filters = { |
||
152 | [GUILDADS_MSG_TYPE_ANNONCE] = { }; |
||
153 | [GUILDADS_MSG_TYPE_REQUEST] = { |
||
154 | everything = true; |
||
155 | }; |
||
156 | [GUILDADS_MSG_TYPE_AVAILABLE] = { |
||
157 | everything = true; |
||
158 | }; |
||
159 | [GUILDADS_MSG_TYPE_SKILL] = { |
||
160 | [4] = true, [5] = true, [6] = true, |
||
161 | [7] = true, [8] = true, [9] = true, |
||
162 | [13] = true |
||
163 | }; |
||
164 | [GUILDADS_MSG_TYPE_EVENT] = {}; |
||
165 | }; |
||
166 | Mine = {}; |
||
167 | } |
||
168 | |||
169 | for id, _ in GUILDADS_CLASSES do |
||
170 | GuildAds.Config.Filters[GUILDADS_MSG_TYPE_ANNONCE][id] = true; |
||
171 | end |
||
172 | |||
173 | if (backupAccountId) then |
||
174 | GuildAds.AccountId = backupAccountId; |
||
175 | end |
||
176 | |||
177 | DEBUG_MSG("First time for this client"); |
||
178 | end |
||
179 | |||
180 | -- Call GAC_InitVariablesLoaded |
||
181 | GAC_InitVariablesLoaded(); |
||
182 | |||
183 | -- Call GuildAds_Init in 8 seconds or after Clcore init |
||
184 | if clcore_AfterInit then |
||
185 | clcore_AfterInit(GuildAds_ChatLocCallBack); |
||
186 | else |
||
187 | GuildAdsSystem.Reinit = false; |
||
188 | GuildAdsSystem.InitTimer = 8; |
||
189 | end |
||
190 | end |
||
191 | |||
192 | function GuildAds_ChatLocCallBack(flag) |
||
193 | if flag=="INIT" then |
||
194 | GuildAds_Init(); |
||
195 | end |
||
196 | end |
||
197 | |||
198 | function GuildAds_Init() |
||
199 | DEBUG_MSG("[GuildAds_Init] begin"); |
||
200 | |||
201 | -- already init ? |
||
202 | if g_GuildAdsInitialized then |
||
203 | return; |
||
204 | end |
||
205 | |||
206 | -- does general channels exists ? if not delayed init |
||
207 | local firstChannelNumber = GetChannelList(); |
||
208 | if (firstChannelNumber == nil) then |
||
209 | DEBUG_MSG("[GuildAds_Init] delay - channels"); |
||
210 | g_JoinChannelAttempts = g_JoinChannelAttempts +1; |
||
211 | if (g_JoinChannelAttempts <= GUILDADS_MAX_CHANNEL_JOIN_ATTEMPTS) then |
||
212 | GuildAdsSystem.InitTimer = 2; |
||
213 | return; |
||
214 | end |
||
215 | end |
||
216 | |||
217 | -- Init du channel |
||
218 | g_ChatChannel = GuildAdsConfig_GetChannelName(); |
||
219 | g_ChatPassword = GuildAdsConfig_GetChannelPassword(); |
||
220 | |||
221 | -- GuildAdsStorage : init |
||
222 | GAS_Init(g_playerName, g_ChatChannel); |
||
223 | |||
224 | -- Register plugins |
||
225 | GuildAdsPlugin_RegisterPlugins(); |
||
226 | |||
227 | -- GuildAdsComm : init |
||
228 | GAC_Init(g_playerName, g_ChatChannel, g_ChatPassword); |
||
229 | |||
230 | -- Init Plugin |
||
231 | DEBUG_MSG("[GuildAdsPlugin_OnInit] begin"); |
||
232 | GuildAdsPlugin_OnInit(); |
||
233 | DEBUG_MSG("[GuildAdsPlugin_OnInit] end"); |
||
234 | |||
235 | -- Init first step done |
||
236 | g_GuildAdsInitialized = true; |
||
237 | |||
238 | -- Init GuildAdsFrame |
||
239 | DEBUG_MSG("[GuildAdsFrame_Init] begin"); |
||
240 | GuildAdsFrame_Init(); |
||
241 | DEBUG_MSG("[GuildAdsFrame_Init] end"); |
||
242 | |||
243 | DEBUG_MSG("[GuildAds_Init] end"); |
||
244 | end |
||
245 | |||
246 | function GuildAds_Reinit() |
||
247 | DEBUG_MSG("[GuildAds_Reinit]"); |
||
248 | GAC_SendRemoveAll(nil); |
||
249 | |||
250 | GuildAdsSystem.Reinit = true; |
||
251 | GuildAdsSystem.InitTimer = 2; |
||
252 | end |
||
253 | |||
254 | function GuildAds_ReinitSecond() |
||
255 | DEBUG_MSG("[GuildAds_ReinitSecond]"); |
||
256 | g_GuildAdsInitialized = false; |
||
257 | |||
258 | -- Reinit du channel |
||
259 | g_ChatChannel = GuildAdsConfig_GetChannelName(); |
||
260 | g_ChatPassword = GuildAdsConfig_GetChannelPassword(); |
||
261 | |||
262 | -- Reinit GuildAdsStorage |
||
263 | GAS_Init(g_playerName, g_ChatChannel); |
||
264 | |||
265 | -- Reinit UI |
||
266 | GuildAdsFrame_OnChannelChange(); |
||
267 | |||
268 | -- Reinit GuildAdsComm |
||
269 | GAC_Reinit(g_ChatChannel, g_ChatPassword); |
||
270 | |||
271 | g_GuildAdsInitialized = true; |
||
272 | end |
||
273 | |||
274 | function GuildAds_OnEvent(event) |
||
275 | if (event == "PLAYER_LEVEL_UP") then |
||
276 | GuildAdsSystem.SendAnnonceTimer = 10; |
||
277 | |||
278 | elseif (event == "CHAT_MSG_SKILL") then |
||
279 | -- Toutes les compétences sont envoyées. |
||
280 | -- Lors de l'apprentissage d'une armes contre un mob la compétence monte vite. |
||
281 | -- --> MAJ au maxi toutes les minutes, pour éviter le flood. |
||
282 | GuildAdsSystem.SendSkillsTimer = 60; |
||
283 | |||
284 | elseif (event == "CHARACTER_POINTS_CHANGED") then |
||
285 | GuildAdsSystem.SendSkillsTimer = 60; |
||
286 | |||
287 | elseif (event == "PLAYER_GUILD_UPDATE") then |
||
288 | -- Changement de guilde ? |
||
289 | if g_GuildAdsInitialized and GuildAdsConfig_GetChannelName() ~= g_ChatChannel then |
||
290 | GuildAds_ReinitSecond(); |
||
291 | end |
||
292 | |||
293 | elseif (event == "CHAT_MSG_CHANNEL_JOIN") and (arg9 == g_ChatChannel) then |
||
294 | -- Un joueur vient d'arrive sur le channel |
||
295 | g_HasJoined[arg2] = GAS_currentTime(); |
||
296 | |||
297 | elseif (event == "CHAT_MSG_CHANNEL_LEAVE") and (arg9 == g_ChatChannel) then |
||
298 | -- Un joueur vient de quitter le channel |
||
299 | -- Mise à jour du statut online |
||
300 | GAS_SetOnlineStatus(arg2, false); |
||
301 | |||
302 | elseif (event == "VARIABLES_LOADED") then |
||
303 | GuildAds_InitVariablesLoaded(); |
||
304 | |||
305 | end |
||
306 | end |
||
307 | |||
308 | --------------------------------------------------------------------------------- |
||
309 | -- |
||
310 | -- Called by WOW for each frame |
||
311 | -- |
||
312 | --------------------------------------------------------------------------------- |
||
313 | function GuildAds_OnUpdate(elapsed) |
||
314 | |||
315 | if (this.InitTimer) then |
||
316 | this.InitTimer = this.InitTimer - elapsed; |
||
317 | if (this.InitTimer <= 0) then |
||
318 | this.InitTimer = nil; |
||
319 | if (this.Reinit) then |
||
320 | GuildAds_ReinitSecond(); |
||
321 | else |
||
322 | GuildAds_Init(); |
||
323 | end |
||
324 | end |
||
325 | else |
||
326 | if (this.SendAnnonceTimer) then |
||
327 | this.SendAnnonceTimer = this.SendAnnonceTimer - elapsed; |
||
328 | if (this.SendAnnonceTimer <=0) then |
||
329 | this.SendAnnonceTimer = nil; |
||
330 | GAC_SendAnnonce(nil); |
||
331 | end |
||
332 | end |
||
333 | |||
334 | if (this.SendSkillsTimer) then |
||
335 | this.SendSkillsTimer = this.SendSkillsTimer - elapsed; |
||
336 | if (this.SendSkillsTimer <= 0) then |
||
337 | this.SendSkillsTimer = nil; |
||
338 | GAC_SendSkills(nil); |
||
339 | end |
||
340 | end |
||
341 | |||
342 | if (this.SynchronizeOfflinesTimer) then |
||
343 | this.SynchronizeOfflinesTimer = this.SynchronizeOfflinesTimer - elapsed; |
||
344 | if (this.SynchronizeOfflinesTimer <= 0) then |
||
345 | this.SynchronizeOfflinesTimer = nil; |
||
346 | if (this.SynchronizeOfflinesTimerEnd) then |
||
347 | GAC_SynchronizeOfflinesEnd(); |
||
348 | else |
||
349 | GAC_SynchronizeOfflines(this.SynchronizeOfflinesCount); |
||
350 | end |
||
351 | end |
||
352 | end |
||
353 | end |
||
354 | end |
||
355 | |||
356 | --------------------------------------------------------------------------------- |
||
357 | -- |
||
358 | -- Called by WoW when this add-on is loaded. Register for events we are interested in. |
||
359 | -- |
||
360 | --------------------------------------------------------------------------------- |
||
361 | function GuildAds_OnLoad() |
||
362 | DEBUG_MSG("[GuildAds_OnLoad]"); |
||
363 | |||
364 | -- |
||
365 | this:RegisterEvent("VARIABLES_LOADED"); |
||
366 | |||
367 | this:RegisterEvent("PLAYER_LEVEL_UP"); |
||
368 | |||
369 | this:RegisterEvent("CHAT_MSG_SKILL"); |
||
370 | this:RegisterEvent("CHARACTER_POINTS_CHANGED"); |
||
371 | |||
372 | this:RegisterEvent("CHAT_MSG_CHANNEL_JOIN"); |
||
373 | this:RegisterEvent("CHAT_MSG_CHANNEL_LEAVE"); |
||
374 | |||
375 | this:RegisterEvent("PLAYER_GUILD_UPDATE"); |
||
376 | |||
377 | -- Start uninitialized |
||
378 | g_GuildAdsInitialized = false; |
||
379 | |||
380 | -- Slash commands |
||
381 | SLASH_GUILDADS1 = "/guildads"; |
||
382 | SlashCmdList["GUILDADS"] = GuildAds_SlashHandler; |
||
383 | end |
||
384 | |||
385 | ---------------------------------------------------------------------------------- |
||
386 | -- |
||
387 | -- Return non-nil if playerName has joined the GuildAds channel after the current one |
||
388 | -- |
||
389 | --------------------------------------------------------------------------------- |
||
390 | function GuildAds_HasJoined(playerName) |
||
391 | return g_HasJoined[playerName]; |
||
392 | end |
||
393 | |||
394 | function GuildAds_ResetHasJoined(playerName) |
||
395 | g_HasJoined[playerName] = nil; |
||
396 | end |
||
397 | |||
398 | ---------------------------------------------------------------------------------- |
||
399 | -- |
||
400 | -- Called by /guildads |
||
401 | -- |
||
402 | --------------------------------------------------------------------------------- |
||
403 | function GuildAds_ShowPlayerVersion() |
||
404 | return g_showPlayerVersion; |
||
405 | end |
||
406 | |||
407 | function GuildAds_SlashHandler(msg) |
||
408 | iStart, iEnd, command = string.find(msg, "(%w+)( ?)"); |
||
409 | if (iEnd) then |
||
410 | param = string.sub(msg, iEnd+1) |
||
411 | else |
||
412 | param = ""; |
||
413 | end |
||
414 | |||
415 | if (msg == "") then |
||
416 | if (g_GuildAdsInitialized) then |
||
417 | GuildAds_Toggle(); |
||
418 | else |
||
419 | ChatFrame1:AddMessage("GuildAds is not initialized."); |
||
420 | end |
||
421 | elseif (command == "debuginfo") then |
||
422 | GuildAds_Debuginfo(); |
||
423 | elseif (command == "reset") then |
||
424 | g_GuildAdsInitialized = false; |
||
425 | GuildAds.Version = "reset"; |
||
426 | ReloadUI(); |
||
427 | elseif (command == "hardreset") then |
||
428 | g_GuildAdsInitialized = false; |
||
429 | GuildAds = nil; |
||
430 | ReloadUI(); |
||
431 | elseif (command == "debug") then |
||
432 | GUILDADS_DEBUG = true; |
||
433 | GUILDADSSTORAGE_DEBUG = true; |
||
434 | GUILDADSCOMM_DEBUG = true; |
||
435 | elseif (command == "nodebug") then |
||
436 | GUILDADS_DEBUG = false; |
||
437 | GUILDADSSTORAGE_DEBUG = false; |
||
438 | GUILDADSCOMM_DEBUG = false; |
||
439 | elseif (command == "config") then |
||
440 | if (g_GuildAdsInitialized) then |
||
441 | GuildAdsConfigFrame:Show(); |
||
442 | else |
||
443 | ChatFrame1:AddMessage("GuildAds is not initialized."); |
||
444 | end |
||
445 | elseif (command == "angle") then |
||
446 | if (param=="") then |
||
447 | ChatFrame1:AddMessage(GuildAds.Config.MinimapArcOffset); |
||
448 | else |
||
449 | GuildAds.Config.MinimapArcOffset = tonumber(param)+0; |
||
450 | GuildAdsMinimapButton_Update(); |
||
451 | end |
||
452 | elseif (command == "showVersions") then |
||
453 | if g_showPlayerVersion then |
||
454 | ChatFrame1:AddMessage("show versions: no"); |
||
455 | g_showPlayerVersion = false; |
||
456 | else |
||
457 | ChatFrame1:AddMessage("show versions: yes"); |
||
458 | g_showPlayerVersion = true; |
||
459 | end |
||
460 | elseif (command == "ignore") then |
||
461 | if param=="" then |
||
462 | ChatFrame1:AddMessage(IGNORE_LIST); |
||
463 | for playerName, when in GAS_ProfileIgnoreList() do |
||
464 | ChatFrame1:AddMessage(string.format("|Hplayer %s|h[%s]|h "..GUILDADS_SINCE, playerName, playerName, GAS_timeToString(when))); |
||
465 | end |
||
466 | else |
||
467 | if GAS_ProfileIsIgnored(param) then |
||
468 | ChatFrame1:AddMessage(string.format(ERR_IGNORE_REMOVED_S, param)); |
||
469 | GAS_ProfileIgnore(param, false); |
||
470 | else |
||
471 | ChatFrame1:AddMessage(string.format(ERR_IGNORE_ADDED_S, param)); |
||
472 | GAS_ProfileIgnore(param, true); |
||
473 | end |
||
474 | end |
||
475 | end |
||
476 | end |
||
477 | |||
478 | function GuildAds_Debuginfo() |
||
479 | ChatFrame1:AddMessage("Version: "..GUILDADS_VERSION.."("..NoNil(GuildAds.Version)..")"); |
||
480 | if (g_GuildAdsInitialized) then |
||
481 | ChatFrame1:AddMessage("GuildAdsInitialized: true"); |
||
482 | else |
||
483 | ChatFrame1:AddMessage("GuildAdsInitialized: false"); |
||
484 | end |
||
485 | ChatFrame1:AddMessage("PlayerName: "..NoNil(g_playerName)); |
||
486 | ChatFrame1:AddMessage("Realm: "..NoNil(g_realmName)); |
||
487 | ChatFrame1:AddMessage("AccountId: "..NoNil(GAS_GetAccountId())); |
||
488 | ChatFrame1:AddMessage("Channel: "..NoNil(g_ChatChannel)); |
||
489 | ChatFrame1:AddMessage("JoinChannelAttemps: "..g_JoinChannelAttempts); |
||
490 | end |
||
491 | |||
492 | ---------------------------------------------------------------------------------- |
||
493 | -- |
||
494 | -- Toggle hidden status of want ads |
||
495 | -- |
||
496 | --------------------------------------------------------------------------------- |
||
497 | function GuildAds_Toggle() |
||
498 | if (g_GuildAdsInitialized) then |
||
499 | if ( GuildAdsFrame:IsVisible() ) then |
||
500 | GuildAdsFrame:Hide(); |
||
501 | else |
||
502 | GuildAdsFrame:Show(); |
||
503 | end |
||
504 | end |
||
505 | end |
||
506 | |||
507 | ---------------------------------------------------------------------------------- |
||
508 | -- |
||
509 | -- Toggle advertise on and off |
||
510 | -- |
||
511 | --------------------------------------------------------------------------------- |
||
512 | function GuildAds_SetPublishMyAds(state) |
||
513 | if (state) then |
||
514 | -- Broadcast all my ads |
||
515 | GAC_SendAllAdsType(nil, nil); |
||
516 | else |
||
517 | -- Broadcast a message to remove all my ads |
||
518 | GAC_SendRemoveAll(nil); |
||
519 | end |
||
520 | GuildAds.Config.PublishMyAds = state; |
||
521 | end |