-
Notifications
You must be signed in to change notification settings - Fork 6
/
LogTracker.lua
executable file
·2850 lines (2754 loc) · 105 KB
/
LogTracker.lua
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local _, L = ...;
local addonPrefixCompressed = "LTSC";
local dbVersion = 1;
local syncVersion = 3;
local syncInterval = 5; -- 5 seconds
local syncHistoryCount = 50; -- Keep up to 50 players in the "recently updated" list for sync between logins
local syncHistoryLimit = 1000; -- Do not sync more than 1000 players to new peers
local syncPeerGreeting = 120; -- 2 minutes (interval to greet potential peers on guild/raid/group/yell)
local syncPeerUpdates = 1800; -- 30 minutes (interval to check available peers)
local syncPeerOnlineCheck = 3600; -- 60 minutes (check if peers are online if there is nothing to do)
local syncBatchPlayers = 20; -- Sync up to 20 players per batch
local syncRequestFactor = 100; -- Number of players used for calculating the request delay
local syncRequestDelay = 10; -- 10 seconds
local playerUpdateInterval = 3600; -- 1 hours
local playerLogsInterval = 86400; -- 1 day
local playerAgeLimit = 86400 * 21; -- 3 weeks
local peerAgeLimit = 86400 * 7; -- 1 week
local appQueueUpdateInterval = 10; -- 10 seconds
-- Libraries
local Comm = LibStub:GetLibrary("AceComm-3.0")
local LibDeflate = LibStub:GetLibrary("LibDeflate");
local LibSerialize = LibStub:GetLibrary("LibSerialize");
LogTracker = CreateFrame("Frame", "LogTracker", UIParent);
function LogTracker:Init()
self.defaults = {
debug = false,
chatExtension = true,
tooltipExtension = true,
lfgExtension = true,
slashExtension = true,
hide10Player = false,
hide25Player = false,
disableShift = false,
syncSend = true,
syncReceive = true,
appImportCount = 0,
appPriorityOnly = false
};
self.syncStatus = {
guild = 0,
guildVersion = syncVersion,
party = 0,
partyVersion = syncVersion,
raid = 0,
raidVersion = syncVersion,
whisper = 0,
offsetStart = 0,
timer = GetTime(),
peers = {},
peersUpdate = GetTime(),
peersChannel = {
guild = GetTime() + random(1, 10),
party = GetTime() + random(1, 10),
raid = GetTime() + random(1, 10),
yell = GetTime() + random(1, 10),
whisper = {}
},
players = {},
requests = {},
requestsLogs = {},
requestsSent = {},
requestsLock = {},
requestsLockLogs = {},
requestsTimer = GetTime(),
messages = {},
messageLength = 0
};
self.appSyncStatusTime = time();
self.versionNoticeSent = false;
self.achievementTime = nil;
self.achievementGuid = nil;
self.achievementUnit = nil;
self.achievementDetails = {
name = nil, level = nil, faction = nil
};
self.activityDetails = {
-- Naxxramas 10-man
[841] = {
zone = 1015,
size = 10,
encounters = { 101107, 101108, 101109, 101110, 101111, 101112, 101113, 101114, 101115, 101116, 101117, 101118, 101119, 101120, 101121 }
},
-- The Obsidian Sanctum 10-man
[1101] = {
zone = 1015,
size = 10,
encounters = { 742 }
},
-- The Eye of Eternity 10-man
[1102] = {
zone = 1015,
size = 10,
encounters = { 734 }
},
-- Vault of Archavon 10-man
[1095] = {
zone = 1016,
size = 10,
encounters = { 772 }
},
-- Ulduar 10-man
[1106] = {
zone = 1017,
size = 10,
encounters = { 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757 },
achivements = {
[744] = { -- 744 2856 Flame Leviathan
killCount = 2856, hardmodes = {
{ id = 2913, difficulty = 1, label = "1T" },
{ id = 2914, difficulty = 2, label = "2T" },
{ id = 2915, difficulty = 3, label = "3T" },
{ id = 3056, difficulty = 4, label = "4T" }
}
},
[745] = { -- 745 2858 Ignis the Furnace Master
killCount = 2858, hardmodes = {}
},
[746] = { -- 746 2857 Razorscale
killCount = 2857, hardmodes = {}
},
[747] = { -- 747 2859 XT-002 Deconstructor
killCount = 2859, hardmodes = {
{ id = 3058, difficulty = 4, label = "Hard" }
}
},
[748] = { -- 748 2860 The Assembly of Iron
killCount = 2860, hardmodes = {
{ id = 2940, difficulty = 0, label = "Easy" },
{ id = 2939, difficulty = 2, label = "Med" },
{ id = 2941, difficulty = 4, label = "Hard" }
}
},
[749] = { -- 749 2861 Kologarn
killCount = 2861, hardmodes = {}
},
[750] = { -- 750 2868 Auriaya
killCount = 2868, hardmodes = {}
},
[751] = { -- 751 2862 Hodir
killCount = 2862, hardmodes = {
{ id = 3182, difficulty = 4, label = "Hard" }
}
},
[752] = { -- 752 2863 Thorim
killCount = 2863, hardmodes = {
{ id = 3176, difficulty = 4, label = "Hard" }
}
},
[753] = { -- 753 2864 Freya
killCount = 2864, hardmodes = {
{ id = 3177, difficulty = 2, label = "1E" },
{ id = 3178, difficulty = 3, label = "2E" },
{ id = 3179, difficulty = 4, label = "3E" }
}
},
[754] = { -- 754 2865 Mimiron
killCount = 2865, hardmodes = {
{ id = 3180, difficulty = 4, label = "Hard" }
}
},
[755] = { -- 755 2866 General Vezax
killCount = 2866, hardmodes = {
{ id = 3181, difficulty = 4, label = "Hard" }
}
},
[756] = { -- 756 2869 Yogg-Saron
killCount = 2869, hardmodes = {
{ id = 3157, difficulty = 1, label = "3L" },
{ id = 3141, difficulty = 2, label = "2L" },
{ id = 3158, difficulty = 3, label = "1L" },
{ id = 3159, difficulty = 4, label = "0L" }
}
},
[757] = { -- 757 2867 Algalon the Observer
killCount = 2867, hardmodes = {}
}
}
},
-- Naxxramas 25-man
[1098] = {
zone = 1015,
size = 25,
encounters = { 101107, 101108, 101109, 101110, 101111, 101112, 101113, 101114, 101115, 101116, 101117, 101118, 101119, 101120, 101121 }
},
-- The Obsidian Sanctum 25-man
[1097] = {
zone = 1015,
size = 25,
encounters = { 742 }
},
-- The Eye of Eternity 25-man
[1094] = {
zone = 1015,
size = 25,
encounters = { 734 }
},
-- Vault of Archavon 25-man
[1096] = {
zone = 1016,
size = 25,
encounters = { 772 }
},
-- Ulduar 25-man
[1107] = {
zone = 1017,
size = 25,
encounters = { 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757 },
achivements = {
[744] = { -- 744 2872 Flame Leviathan
killCount = 2872, hardmodes = {
{ id = 2918, difficulty = 1, label = "1T" },
{ id = 2916, difficulty = 2, label = "2T" },
{ id = 2917, difficulty = 3, label = "3T" },
{ id = 3057, difficulty = 4, label = "4T" }
}
},
[745] = { -- 745 2874 Ignis the Furnace Master
killCount = 2874, hardmodes = {}
},
[746] = { -- 746 2873 Razorscale
killCount = 2873, hardmodes = {}
},
[747] = { -- 747 2884 XT-002 Deconstructor
killCount = 2884, hardmodes = {
{ id = 3059, difficulty = 4, label = "Hard" }
}
},
[748] = { -- 748 2885 The Assembly of Iron
killCount = 2885, hardmodes = {
{ id = 2943, difficulty = 0, label = "Easy" },
{ id = 2942, difficulty = 2, label = "Med" },
{ id = 2944, difficulty = 4, label = "Hard" }
}
},
[749] = { -- 749 2875 Kologarn
killCount = 2875, hardmodes = {}
},
[750] = { -- 750 2882 Auriaya
killCount = 2882, hardmodes = {}
},
[751] = { -- 751 3256 Hodir
killCount = 3256, hardmodes = {
{ id = 3184, difficulty = 4, label = "Hard" }
}
},
[752] = { -- 752 3257 Thorim
killCount = 3257, hardmodes = {
{ id = 3183, difficulty = 4, label = "Hard" }
}
},
[753] = { -- 753 3258 Freya
killCount = 3258, hardmodes = {
{ id = 3185, difficulty = 2, label = "1E" },
{ id = 3186, difficulty = 3, label = "2E" },
{ id = 3187, difficulty = 4, label = "3E" }
}
},
[754] = { -- 754 2879 Mimiron
killCount = 2879, hardmodes = {
{ id = 3189, difficulty = 4, label = "Hard" }
}
},
[755] = { -- 755 2880 General Vezax
killCount = 2880, hardmodes = {
{ id = 3188, difficulty = 4, label = "Hard" }
}
},
[756] = { -- 756 2883 Yogg-Saron
killCount = 2883, hardmodes = {
{ id = 3161, difficulty = 1, label = "3L" },
{ id = 3162, difficulty = 2, label = "2L" },
{ id = 3163, difficulty = 3, label = "1L" },
{ id = 3164, difficulty = 4, label = "0L" }
}
},
[757] = { -- 757 2881 Algalon the Observer
killCount = 2881, hardmodes = {}
}
}
},
};
self.db = CopyTable(self.defaults);
self:SetScript("OnEvent", self.OnEvent);
self:RegisterEvent("ADDON_LOADED");
self:RegisterEvent("PLAYER_LOGOUT");
self:RegisterEvent("CHAT_MSG_SYSTEM");
self:RegisterEvent("CHAT_MSG_CHANNEL");
self:RegisterEvent("MODIFIER_STATE_CHANGED");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("PLAYER_TARGET_CHANGED");
self:RegisterEvent("INSPECT_ACHIEVEMENT_READY");
self:RegisterEvent("NAME_PLATE_UNIT_ADDED");
self:RegisterEvent("GUILD_ROSTER_UPDATE");
self:RegisterEvent("GROUP_ROSTER_UPDATE");
self:RegisterEvent("RAID_ROSTER_UPDATE");
self:RegisterEvent("FRIENDLIST_UPDATE");
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT");
self:RegisterEvent("LFG_LIST_SEARCH_RESULT_UPDATED");
Comm:RegisterComm(addonPrefixCompressed, function(...)
LogTracker:OnCommMessage(...);
end);
GameTooltip:HookScript("OnTooltipSetUnit", function(tooltip, ...)
LogTracker:OnTooltipSetUnit(tooltip, ...);
end);
GameTooltip:HookScript("OnShow", function(tooltip, ...)
LogTracker:OnTooltipShow(tooltip, ...);
end);
end
function LogTracker:InitLogsFrame()
local urlRegion = "";
local urlRegionId = GetCurrentRegion();
if (urlRegionId == 1) then
urlRegion = "us";
elseif (urlRegionId == 2) then
urlRegion = "kr";
elseif (urlRegionId == 3) then
urlRegion = "eu";
elseif (urlRegionId == 4) then
urlRegion = "tw";
elseif (urlRegionId == 5) then
urlRegion = "ch";
end
local urlBase = "https://classic.warcraftlogs.com/character/" .. urlRegion .. "/" .. strlower(GetRealmName()) .. "/";
self.warcraftlogsFrame = CreateFrame("Frame", nil, UIParent, "DialogBorderTemplate");
self.warcraftlogsFrame:ClearAllPoints();
self.warcraftlogsFrame:SetPoint("TOPLEFT", 50, -50);
self.warcraftlogsFrame:SetSize(160, 124);
self.warcraftlogsFrame:Hide();
self.warcraftlogsFrame.Title = self.warcraftlogsFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal");
self.warcraftlogsFrame.Title:ClearAllPoints();
self.warcraftlogsFrame.Title:SetPoint("TOPLEFT", 18, -15);
self.warcraftlogsFrame.Title:SetText("WarcraftLogs");
self.warcraftlogsFrame.Title:SetTextColor(1, 1, 1);
self.warcraftlogsFrame.CharacterLabel = self.warcraftlogsFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal");
self.warcraftlogsFrame.CharacterLabel:ClearAllPoints();
self.warcraftlogsFrame.CharacterLabel:SetPoint("TOPLEFT", 18, -35);
self.warcraftlogsFrame.CharacterLabel:SetText("Character");
self.warcraftlogsFrame.CharacterLabel:SetJustifyH("LEFT");
self.warcraftlogsFrame.CharacterDropdown = CreateFrame("Button", nil, self.warcraftlogsFrame, "UIDropDownMenuTemplate");
self.warcraftlogsFrame.CharacterDropdown:ClearAllPoints();
self.warcraftlogsFrame.CharacterDropdown:SetPoint("TOPLEFT", -4, -46);
self.warcraftlogsFrame.CharacterDropdown:SetPoint("TOPRIGHT", -18, -46);
self.warcraftlogsFrame.CharacterDropdown:SetScript("OnClick", function()
ToggleDropDownMenu(1, nil, self.warcraftlogsFrame.CharacterDropdown, self.warcraftlogsFrame.CharacterDropdown, 0, 0);
end);
self.warcraftlogsFrame.CharacterDropdown.values = {};
self.warcraftlogsFrame.CharacterName = self.warcraftlogsFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal");
self.warcraftlogsFrame.CharacterName:ClearAllPoints();
self.warcraftlogsFrame.CharacterName:SetPoint("TOPLEFT", 18, -54);
self.warcraftlogsFrame.CharacterName:SetText("TODO");
self.warcraftlogsFrame.CharacterName:SetJustifyH("LEFT");
self.warcraftlogsFrame.UrlLabel = self.warcraftlogsFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal");
self.warcraftlogsFrame.UrlLabel:ClearAllPoints();
self.warcraftlogsFrame.UrlLabel:SetPoint("TOPLEFT", 18, -75);
self.warcraftlogsFrame.UrlLabel:SetText("Profile URL");
self.warcraftlogsFrame.UrlLabel:SetJustifyH("LEFT");
self.warcraftlogsFrame.Url = CreateFrame("EditBox", nil, self.warcraftlogsFrame, "InputBoxTemplate");
self.warcraftlogsFrame.Url:ClearAllPoints();
self.warcraftlogsFrame.Url:SetAutoFocus(false);
self.warcraftlogsFrame.Url:SetPoint("TOPLEFT", 20, -88);
self.warcraftlogsFrame.Url:SetPoint("TOPRIGHT", -14, -88);
self.warcraftlogsFrame.Url:SetHeight(20);
self.warcraftlogsFrame.Url:SetText("TODO");
local characterDropdownClick = function(dropdown)
UIDropDownMenu_SetSelectedValue(dropdown.owner, dropdown.value);
self.warcraftlogsFrame.Url:SetText(urlBase .. strlower(dropdown.value));
end
local characterDropdownInit = function(dropdown)
for i = 1, #dropdown.values do
local info = UIDropDownMenu_CreateInfo();
info.text = dropdown.values[i].text;
info.value = dropdown.values[i].value;
info.owner = dropdown;
info.checked = UIDropDownMenu_GetSelectedValue(dropdown) == info.value;
info.func = characterDropdownClick;
UIDropDownMenu_AddButton(info);
if (info.checked) then
UIDropDownMenu_SetSelectedValue(dropdown, info.value);
end
end
end
UIDropDownMenu_Initialize(self.warcraftlogsFrame.CharacterDropdown, characterDropdownInit);
UIDropDownMenu_JustifyText(self.warcraftlogsFrame.CharacterDropdown, "LEFT");
LFGBrowseFrame:HookScript("OnShow", function()
self.warcraftlogsFrame:SetPoint("TOPLEFT", LFGBrowseFrame, "TOPRIGHT", -30, -10);
end);
LFGBrowseFrame:HookScript("OnHide", function()
self.warcraftlogsFrame:Hide();
end);
-- Show due app updates
if self.db.appImportCount > 0 then
if not self.appSyncStatus then
self.appSyncStatus = LFGBrowseFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmallLeft");
self.appSyncStatus:SetPoint("TOPLEFT", LFGBrowseFrame, "TOPLEFT", 74, -50);
self.appSyncStatus:SetText("");
self.appSyncStatus:Show();
end
if not self.appSyncHelp then
self.appSyncHelp = LFGBrowseFrame:CreateFontString(nil, "ARTWORK", "GameFontNormalSmallLeft");
self.appSyncHelp:SetPoint("TOPLEFT", LFGBrowseFrame, "TOPLEFT", 54, -72);
self.appSyncHelp:SetText("|cffa0a0a0Do a /reload to start updating / import results|r");
self.appSyncHelp:Show();
end
self:UpdateAppQueue();
end
-- Show logs within the group finder
hooksecurefunc("LFGBrowseSearchEntry_Update", function(frame)
if not frame.Logs then
frame.Logs = frame:CreateFontString(nil, "ARTWORK", "GameFontNormal");
frame.Logs:SetPoint("TOPLEFT", frame, "TOPRIGHT", -28, -13)
end
local searchResultInfo = C_LFGList.GetSearchResultInfo(frame.resultID);
local isSolo = searchResultInfo.numMembers == 1;
if isSolo then
local logTargets = self:GetGroupFinderLogTargets(searchResultInfo);
local playerData, playerName, playerRealm = self:GetPlayerData(searchResultInfo.leaderName, nil, nil, nil, true);
if playerData then
frame.Logs:SetText(self:GetPlayerOverallPerformance(playerData, logTargets));
else
frame.Logs:SetText(self:GetColoredText("muted", "--"));
end
frame.Logs:Show();
else
frame.Logs:Hide();
end
end);
hooksecurefunc("LFGBrowseSearchEntry_OnClick", function(lfg, button)
local searchResultInfo = C_LFGList.GetSearchResultInfo(lfg.resultID);
local numMembers = searchResultInfo.numMembers;
if (numMembers > 1) then
-- Group
local selectedValue = nil;
wipe(self.warcraftlogsFrame.CharacterDropdown.values);
for i = 1, numMembers do
local name, role, classFileName, className, level, isLeader = C_LFGList.GetSearchResultMemberInfo(lfg.resultID, i);
if name then
local classColor = RAID_CLASS_COLORS[classFileName];
tinsert(self.warcraftlogsFrame.CharacterDropdown.values, {
text = "|cff" .. string.format("%02x%02x%02x", classColor.r * 255, classColor.g * 255, classColor.b * 255) .. name .. "|r",
value = name
});
if isLeader then
selectedValue = name;
end
end
end
self.warcraftlogsFrame.CharacterName:Hide();
self.warcraftlogsFrame.CharacterDropdown:Show();
UIDropDownMenu_Initialize(self.warcraftlogsFrame.CharacterDropdown, characterDropdownInit);
if selectedValue then
UIDropDownMenu_SetSelectedValue(self.warcraftlogsFrame.CharacterDropdown, selectedValue);
self.warcraftlogsFrame.Url:SetText(urlBase .. strlower(selectedValue));
end
self.warcraftlogsFrame:Show();
elseif (numMembers == 1) then
-- Player
local name, role, classFileName, className, level, areaName, soloRoleTank, soloRoleHealer, soloRoleDPS = C_LFGList
.GetSearchResultLeaderInfo(lfg.resultID);
local classColor = RAID_CLASS_COLORS[classFileName];
self.warcraftlogsFrame.CharacterName:SetTextColor(classColor.r, classColor.g, classColor.b);
self.warcraftlogsFrame.CharacterName:SetText(name);
self.warcraftlogsFrame.CharacterName:Show();
self.warcraftlogsFrame.Url:SetText(urlBase .. strlower(name));
self.warcraftlogsFrame.CharacterDropdown:Hide();
self.warcraftlogsFrame:Show();
else
self.warcraftlogsFrame:Hide();
end
end);
end
function LogTracker:InitOptions()
self.optionsPanel = CreateFrame("Frame");
self.optionsPanel.name = "LogTracker";
InterfaceOptions_AddCategory(self.optionsPanel);
-- --------------------------------------------------- --
-- GENERAL --
-- --------------------------------------------------- --
self.optionsGroupGeneral = CreateFrame("Frame", "LogTracker_Options_GroupGeneral", self.optionsPanel, "OptionsBoxTemplate");
self.optionsGroupGeneral:SetPoint("TOPLEFT", 10, -20);
self.optionsGroupGeneral:SetSize(600, 130);
self.optionsGroupGeneralTitle = _G["LogTracker_Options_GroupGeneralTitle"];
self.optionsGroupGeneralTitle:SetText(L["OPTION_GROUP_GENERAL"]);
-- Chat integration
self.optionCheckChat = CreateFrame("CheckButton", nil, self.optionsGroupGeneral, "InterfaceOptionsCheckButtonTemplate");
self.optionCheckChat:SetPoint("TOPLEFT", 10, -10);
self.optionCheckChat.Text:SetText(L["OPTION_CHAT"]);
self.optionCheckChat:SetScript("OnClick", function()
self.db.chatExtension = self.optionCheckChat:GetChecked();
end)
self.optionCheckChat:SetChecked(self.db.chatExtension);
-- Player tooltip integration
self.optionCheckTooltip = CreateFrame("CheckButton", nil, self.optionsGroupGeneral, "InterfaceOptionsCheckButtonTemplate");
self.optionCheckTooltip:SetPoint("TOPLEFT", 10, -30);
self.optionCheckTooltip.Text:SetText(L["OPTION_TOOLTIP"]);
self.optionCheckTooltip:SetScript("OnClick", function()
self.db.tooltipExtension = self.optionCheckTooltip:GetChecked();
end)
self.optionCheckTooltip:SetChecked(self.db.tooltipExtension);
-- LFLG integration
self.optionCheckLFG = CreateFrame("CheckButton", nil, self.optionsGroupGeneral, "InterfaceOptionsCheckButtonTemplate");
self.optionCheckLFG:SetPoint("TOPLEFT", 10, -50);
self.optionCheckLFG.Text:SetText(L["OPTION_LFG"]);
self.optionCheckLFG:SetScript("OnClick", function(_, value)
self.db.lfgExtension = self.optionCheckLFG:GetChecked();
end)
self.optionCheckLFG:SetChecked(self.db.lfgExtension);
-- Slash command
self.optionCheckSlash = CreateFrame("CheckButton", nil, self.optionsGroupGeneral, "InterfaceOptionsCheckButtonTemplate");
self.optionCheckSlash:SetPoint("TOPLEFT", 10, -70);
self.optionCheckSlash.Text:SetText(L["OPTION_SLASH_CMD"]);
self.optionCheckSlash:SetScript("OnClick", function(_, value)
self.db.slashExtension = self.optionCheckSlash:GetChecked();
end)
self.optionCheckSlash:SetChecked(self.db.slashExtension);
-- Debug output
self.optionShowDebug = CreateFrame("CheckButton", nil, self.optionsGroupGeneral, "InterfaceOptionsCheckButtonTemplate");
self.optionShowDebug:SetPoint("TOPLEFT", 10, -90);
self.optionShowDebug.Text:SetText(L["OPTION_SHOW_DEBUG"]);
self.optionShowDebug:SetScript("OnClick", function(_, value)
self.db.debug = self.optionShowDebug:GetChecked();
end)
self.optionShowDebug:SetChecked(self.db.debug);
-- --------------------------------------------------- --
-- TOOLTIP --
-- --------------------------------------------------- --
self.optionsGroupTooltip = CreateFrame("Frame", "LogTracker_Options_GroupTooltip", self.optionsPanel, "OptionsBoxTemplate");
self.optionsGroupTooltip:SetPoint("TOPLEFT", 10, -170);
self.optionsGroupTooltip:SetSize(290, 80);
self.optionsGroupTooltipTitle = _G["LogTracker_Options_GroupTooltipTitle"];
self.optionsGroupTooltipTitle:SetText(L["OPTION_GROUP_TOOLTIP"]);
-- Show 10 player logs
self.optionHide10Player = CreateFrame("CheckButton", nil, self.optionsGroupTooltip, "InterfaceOptionsCheckButtonTemplate");
self.optionHide10Player:SetPoint("TOPLEFT", 10, -10);
self.optionHide10Player.Text:SetText(L["OPTION_HIDE_10_PLAYER"]);
self.optionHide10Player:SetScript("OnClick", function(_, value)
self.db.hide10Player = self.optionHide10Player:GetChecked();
end)
self.optionHide10Player:SetChecked(self.db.hide10Player);
-- Show 25 player logs
self.optionHide25Player = CreateFrame("CheckButton", nil, self.optionsGroupTooltip, "InterfaceOptionsCheckButtonTemplate");
self.optionHide25Player:SetPoint("TOPLEFT", 10, -30);
self.optionHide25Player.Text:SetText(L["OPTION_HIDE_25_PLAYER"]);
self.optionHide25Player:SetScript("OnClick", function(_, value)
self.db.hide25Player = self.optionHide25Player:GetChecked();
end)
self.optionHide25Player:SetChecked(self.db.hide25Player);
-- Disable extended tooltips
self.optionDisableShift = CreateFrame("CheckButton", nil, self.optionsGroupTooltip, "InterfaceOptionsCheckButtonTemplate");
self.optionDisableShift:SetPoint("TOPLEFT", 10, -50);
self.optionDisableShift.Text:SetText(L["OPTION_DISABLE_SHIFT"]);
self.optionDisableShift:SetScript("OnClick", function(_, value)
self.db.disableShift = self.optionDisableShift:GetChecked();
end)
self.optionDisableShift:SetChecked(self.db.disableShift);
-- --------------------------------------------------- --
-- SYNC --
-- --------------------------------------------------- --
self.optionsGroupSync = CreateFrame("Frame", "LogTracker_Options_GroupSync", self.optionsPanel, "OptionsBoxTemplate");
self.optionsGroupSync:SetPoint("TOPLEFT", 310, -170);
self.optionsGroupSync:SetSize(290, 80);
self.optionsGroupSyncTitle = _G["LogTracker_Options_GroupSyncTitle"];
self.optionsGroupSyncTitle:SetText(L["OPTION_GROUP_SYNC"]);
-- Send player data to other clients
self.optionSyncSend = CreateFrame("CheckButton", nil, self.optionsGroupSync, "InterfaceOptionsCheckButtonTemplate");
self.optionSyncSend:SetPoint("TOPLEFT", 10, -10);
self.optionSyncSend.Text:SetText(L["OPTION_SYNC_SEND"]);
self.optionSyncSend:SetScript("OnClick", function(_, value)
self.db.syncSend = self.optionSyncSend:GetChecked();
end)
self.optionSyncSend:SetChecked(self.db.syncSend);
-- Receive player data from other clients
self.optionSyncReceive = CreateFrame("CheckButton", nil, self.optionsGroupSync, "InterfaceOptionsCheckButtonTemplate");
self.optionSyncReceive:SetPoint("TOPLEFT", 10, -30);
self.optionSyncReceive.Text:SetText(L["OPTION_SYNC_RECEIVE"]);
self.optionSyncReceive:SetScript("OnClick", function(_, value)
self.db.syncReceive = self.optionSyncReceive:GetChecked();
end)
self.optionSyncReceive:SetChecked(self.db.syncReceive);
-- --------------------------------------------------- --
-- APP --
-- --------------------------------------------------- --
self.optionsGroupApp = CreateFrame("Frame", "LogTracker_Options_GroupApp", self.optionsPanel, "OptionsBoxTemplate");
self.optionsGroupApp:SetPoint("TOPLEFT", 10, -270);
self.optionsGroupApp:SetSize(600, 280);
self.optionsGroupAppTitle = _G["LogTracker_Options_GroupAppTitle"];
self.optionsGroupAppTitle:SetText(L["OPTION_GROUP_APP"]);
-- Only update prioritized players
self.optionAppPriorityOnly = CreateFrame("CheckButton", nil, self.optionsGroupApp, "InterfaceOptionsCheckButtonTemplate");
self.optionAppPriorityOnly:SetPoint("TOPLEFT", 10, -10);
self.optionAppPriorityOnly.Text:SetText(L["OPTION_APP_PRIORITY_ONLY"]);
self.optionAppPriorityOnly:SetScript("OnClick", function(_, value)
self.db.appPriorityOnly = self.optionAppPriorityOnly:GetChecked();
end)
self.optionAppPriorityOnly:SetChecked(self.db.appPriorityOnly or false);
end
function LogTracker:LogOutput(...)
print("|cffff0000LT|r", ...);
end
function LogTracker:LogDebug(...)
if self.db and self.db.debug then
print("|cffff0000LT|r", "|cffffff00Debug|r", ...);
end
end
function LogTracker:StringifyData(data, glueOuter, glueInner)
glueOuter = glueOuter or "|";
glueInner = glueInner or ",";
local dataStr = {};
for _, values in ipairs(data) do
tinsert(dataStr, strjoin(glueInner, unpack(values)));
end
return strjoin(glueOuter, unpack(dataStr));
end
function LogTracker:UnstringifyData(dataStr, glueOuter, glueInner)
glueOuter = glueOuter or "|";
glueInner = glueInner or ",";
local data = {};
local dataRaw = { strsplit(glueOuter, dataStr) };
for _, valuesStr in ipairs(dataRaw) do
tinsert(data, { strsplit(glueInner, valuesStr) });
end
return data;
end
function LogTracker:SendCommMessage(action, data, type, target, prio)
local message = action.."#"..LibDeflate:EncodeForPrint(LibDeflate:CompressDeflate(LibSerialize:Serialize(data)));
--self:LogDebug("SendCommMessage", action, type, target);
Comm:SendCommMessage(addonPrefixCompressed, message, type, target, prio or "NORMAL");
end
function LogTracker:InsertPlayerData(data, name, requireLogs)
local realmName = GetRealmName();
local playerData = self.db.playerData[realmName][name];
if playerData and (playerData.class > 0) and (playerData.lastUpdateLogs or not requireLogs) then
tinsert(data, {
name = name, level = playerData.level, faction = playerData.faction, class = playerData.class,
lastUpdate = playerData.lastUpdate, lastUpdateLogs = playerData.lastUpdateLogs or playerData.lastUpdate,
encounters = playerData.encounters, logs = playerData.logs
});
return true;
end
return false;
end
function LogTracker:AddPlayerInfoToTooltip(targetName)
local playerData, playerName, playerRealm = self:GetPlayerData(targetName, nil, nil, nil, true);
if playerData then
self:SetPlayerInfoTooltip(playerData, playerName, playerRealm);
end
end
function LogTracker:OnSlashCommand(arguments)
if not self.db.slashExtension then
return;
end
--self:LogOutput("OnSlashCommand", arguments);
local playerData, playerName, playerRealm = self:GetPlayerData(arguments);
if playerData then
self:SendSystemChatLine(L["CHAT_PLAYER_DETAILS"] .. " |Hplayer:" .. playerName .. "-" .. playerRealm .. "|h" .. playerName .. "|h");
self:SendPlayerInfoToChat(playerData, playerName, playerRealm, true);
else
self:SendSystemChatLine(L["CHAT_PLAYER_NOT_FOUND"] .. " |Hplayer:" .. playerName .. "-" .. playerRealm .. "|h" .. playerName .. "|h");
end
end
function LogTracker:OnEvent(event, ...)
if (event == "ADDON_LOADED") then
self:OnAddonLoaded(...);
elseif (event == "PLAYER_LOGOUT") then
self:OnPlayerLogout(...);
elseif (event == "CHAT_MSG_SYSTEM") then
self:OnChatMsgSystem(...);
elseif (event == "CHAT_MSG_CHANNEL") then
self:OnChatMsgChannel(...);
elseif (event == "INSPECT_ACHIEVEMENT_READY") then
self:OnInspectAchievements(...);
elseif (event == "PLAYER_TARGET_CHANGED") then
self:OnTargetChanged(...);
elseif (event == "UPDATE_MOUSEOVER_UNIT") then
self:OnMouseoverUnit(...);
elseif (event == "NAME_PLATE_UNIT_ADDED") then
self:OnNameplateUnitAdded(...);
elseif (event == "MODIFIER_STATE_CHANGED") then
self:OnModifierStateChanged(...);
elseif (event == "GUILD_ROSTER_UPDATE") then
self:OnGuildRosterUpdate(...);
elseif (event == "GROUP_ROSTER_UPDATE") then
self:OnGroupRosterUpdate(...);
elseif (event == "RAID_ROSTER_UPDATE") then
self:OnRaidRosterUpdate(...);
elseif (event == "FRIENDLIST_UPDATE") then
self:OnFriendlistUpdate(...);
elseif (event == "LFG_LIST_SEARCH_RESULT_UPDATED") then
self:OnLfgListSearchResultUpdated(...);
elseif (event == "PLAYER_ENTERING_WORLD") then
self:OnPlayerEnteringWorld(...);
else
self:LogDebug("OnEvent", event, ...);
end
end
function LogTracker:OnPlayerEnteringWorld()
-- Workaround for misaligned tooltip
if TacoTipConfig and not TacoTipConfig.show_guild_name then
print(self:GetColoredText("error", L["TACOTIP_GUILD_NAME_WARNING"]));
end
-- Update self
self:CompareAchievements("player", 30);
-- Greet peers
if IsInGuild() then
self:SyncSendHello("GUILD");
end
if IsInRaid() then
self:SyncSendHello("RAID");
elseif IsInGroup() then
self:SyncSendHello("PARTY");
end
-- Hook into Group finder frame
LogTracker:InitLogsFrame();
-- Hook into Group finder tooltip
if LFGBrowseSearchEntryTooltip then
hooksecurefunc("LFGBrowseSearchEntryTooltip_UpdateAndShow", function(tooltip, ...)
LogTracker:OnTooltipShow(tooltip, ...);
end);
end
-- Cleanup peer status
self:CleanupPeerStatus();
-- Sync timer
if not self.syncTimer then
self.syncTimer = C_Timer.NewTicker(1, function()
LogTracker:SyncCheck();
end);
end
-- WCL Notice
self:LogOutput("Log ratings (if shown) are owned by and obtained from warcraftlogs.com. Please consider supporting them!");
end
function LogTracker:OnAddonLoaded(addonName)
if (addonName ~= "LogTracker") then
return;
end
LogTrackerDB = LogTrackerDB or self.db;
self.db = LogTrackerDB;
self.db.version = self.db.version or 0;
if self.db.version < dbVersion then
self.db.playerData = {};
self.db.syncHistory = {};
self.db.version = dbVersion;
else
self.db.playerData = self.db.playerData or {};
end
if self.db.syncSend == nil then
self.db.syncSend = self.defaults.syncSend;
end
if self.db.syncReceive == nil then
self.db.syncReceive = self.defaults.syncReceive;
end
if self.db.syncHistory then
self.syncStatus.players = { unpack(self.db.syncHistory) };
else
self.db.syncHistory = {};
end
if not self.db.syncPeers then
self.db.syncPeers = {};
end
if self.db.appImportCount == nil then
self.db.appImportCount = 0;
end
self:LogDebug("Init");
-- Init options panel
self:InitOptions();
-- Register slash command
if self.db.slashExtension then
SLASH_LOGTRACKER1, SLASH_LOGTRACKER2 = '/lt', '/logtracker';
SlashCmdList.LOGTRACKER = function(...)
LogTracker:OnSlashCommand(...);
end
end
-- Filter system messages
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", function(...)
return LogTracker:OnChatMsgSystemFilter(...);
end);
-- Cleanup player data
self:CleanupPlayerData();
self:CleanupPeerData();
-- Import app data
self:ImportAppData();
end
function LogTracker:OnPlayerLogout()
local realmName = GetRealmName();
-- Store history slice
wipe(self.db.syncHistory);
local last = #(self.syncStatus.players);
local first = max(0, last - syncHistoryCount) + 1;
for i = first, last do
tinsert(self.db.syncHistory, self.syncStatus.players[i]);
end
self:LogDebug("SyncPeers", "Updated persistent sync history.");
-- Adjust history for online peers, so they will be checked after reload/relog
for name, peer in pairs(self.syncStatus.peers) do
if peer.isWhisper and peer.isOnline then
self.db.syncPeers[realmName][name].lastUpdate = time() - syncPeerOnlineCheck;
end
end
end
function LogTracker:OnCommMessage(prefix, message, distribution, sender)
if not self.db.syncSend and not self.db.syncReceive then
return;
end
if prefix ~= addonPrefixCompressed then
return;
end
local split_pos = strfind(message, "#");
if not split_pos then
self:LogDebug("OnCommMessage", "Invalid message received.");
return;
end
local message_type = strsub(message, 1, split_pos-1);
local message_data_raw = strsub(message, split_pos+1);
local message_data = LibDeflate:DecodeForPrint(message_data_raw);
if not message_data then
self:LogDebug("OnCommMessage", "Error decoding message data.");
return;
end
message_data = LibDeflate:DecompressDeflate(message_data);
if not message_data then
self:LogDebug("OnCommMessage", "Error decompressing message data.");
return;
end
local success, message_data_obj = LibSerialize:Deserialize(message_data);
if not success then
self:LogDebug("OnCommMessage", "Error deserializing message data.");
return;
end
self:OnCommMessageDecoded(message_type, message_data_obj, distribution, sender);
end
function LogTracker:OnCommMessageDecoded(message_type, message_data, distribution, sender)
local realmName = GetRealmName();
local syncName = strsplit("-", sender);
local peer = self:GetSyncPeer(syncName, false, false, 2);
if peer == nil then
return;
end
if message_type == "hi" then
if message_data.versionAddon then
local myAddonMajor, myAddonMinor, myAddonPatch = strsplit(".", GetAddOnMetadata("LogTracker", "version"));
local peerAddonMajor, peerAddonMinor, peerAddonPatch = strsplit(".", message_data.versionAddon);
local myAddonNumeric = tonumber(myAddonMajor) * 10000 + tonumber(myAddonMinor) * 100 + tonumber(myAddonPatch);
local peerAddonNumeric = tonumber(peerAddonMajor) * 10000 + tonumber(peerAddonMinor) * 100 + tonumber(peerAddonPatch);
if (myAddonNumeric < peerAddonNumeric) and not self.versionNoticeSent then
self.versionNoticeSent = true;
self:LogOutput("There is a new version of LogTracker available! (" .. message_data.versionAddon .. ")");
end
peer.versionAddon = message_data.versionAddon;
end
peer.version = message_data.version or peer.version;
if message_data.peers then
for _, name in ipairs(message_data.peers) do
self:OnPlayerOnline(name);
-- Add/update peer history
if not self.db.syncPeers[realmName] then
self.db.syncPeers[realmName] = {};
end
if not self.db.syncPeers[realmName][name] then
self.db.syncPeers[realmName][name] = { lastUpdate = time() - syncPeerOnlineCheck };
end
end
end
if peer.version > syncVersion and not self.versionNoticeSent then
self.versionNoticeSent = true;
self:LogOutput("There is a new version of LogTracker available! Data updates may be limited until you update.");
end
elseif message_type == "pl" then
if not self.db.syncReceive then
return;
end
peer.version = message_data.version or peer.version;
for i, playerDataRcv in ipairs(message_data.players) do
local playerData = self.db.playerData[realmName][playerDataRcv.name];
local updated = false;
peer.receivedOverall = peer.receivedOverall + 1;
if not playerData then
playerData = { encounters = {}, lastUpdate = 0 };
end
if (playerDataRcv.lastUpdate < time()) then
if (playerData.lastUpdate < playerDataRcv.lastUpdate) then
playerData.syncFrom = syncName;
playerData.level = playerDataRcv.level;
playerData.class = playerDataRcv.class;
playerData.faction = playerDataRcv.faction;
playerData.lastUpdate = playerDataRcv.lastUpdate;
playerData.encounters = playerDataRcv.encounters;
updated = true;
end
if not playerData.lastUpdateLogs or (playerData.lastUpdateLogs < playerDataRcv.lastUpdateLogs) then
playerData.syncFromLogs = syncName;
playerData.lastUpdateLogs = playerDataRcv.lastUpdateLogs;
playerData.logs = playerDataRcv.logs;
updated = true;
end
end
if updated then
peer.receivedUpdates = peer.receivedUpdates + 1;
self.db.playerData[realmName][playerDataRcv.name] = playerData;
-- Update tooltip if target is active
local unitName, unitId = GameTooltip:GetUnit();
if unitId and unitName and (unitName == playerDataRcv.name) then
self:LogDebug("Received data for active tooltip, updating... (Sync from "..syncName..")");
GameTooltip:SetUnit(unitId);
end
end
end
elseif message_type == "rq" then
if not self.db.syncSend then
return;
end
peer.version = message_data.version or peer.version;
-- Request for player data
local amount = self:SyncSendByNames(message_data.names, distribution, sender);
self:LogDebug("Sync v2 Request (base) from", syncName, "(Sent " .. amount .. " / " .. #message_data.names .. " players)");
--self:LogDebug("Sync Request (base)", unpack(message_data.names));
elseif message_type == "rqL" then
if not self.db.syncSend then
return;
end
peer.version = message_data.version or peer.version;
-- Request for player logs
local amount = self:SyncSendByNames(message_data.names, distribution, sender, true);
self:LogDebug("Sync v2 Request (logs) from", syncName, "(Sent " .. amount .. " / " .. #message_data.names .. " players)");
--self:LogDebug("Sync Request (logs)", unpack(message_data.names));
elseif message_type == "rqC" then
if not self.db.syncSend then
return;
end
peer.version = message_data.version or peer.version;
local amountSent = 0;
local amountRequested = 0;
if #message_data.names_base > 0 then
amountSent = amountSent + self:SyncSendByNames(message_data.names_base, distribution, sender);
amountRequested = amountRequested + #message_data.names_base;
end
if #message_data.names_logs > 0 then
amountSent = amountSent + self:SyncSendByNames(message_data.names_logs, distribution, sender, true);
amountRequested = amountRequested + #message_data.names_logs;
end
self:LogDebug("Sync v3 Request from", syncName, "(Sent " .. amountSent .. " / " .. amountRequested .. " players)");
end
peer.chatReported = false;
peer.lastUpdate = GetTime();
peer.isOnline = true;
if distribution == "GUILD" then
peer.isGuild = true;
elseif distribution == "PARTY" then
peer.isParty = true;
elseif distribution == "RAID" then
peer.isRaid = true;
end
end
function LogTracker:OnChatMsgSystem(text)
if not self.db.chatExtension then
return;
end
local _, _, name, linkText = string.find(text, "|Hplayer:([^:]*)|h%[([^%[%]]*)%]?|h");
if name then
local playerData, playerName, playerRealm = self:GetPlayerData(name);
if playerData then
self:SendPlayerInfoToChat(playerData, playerName, playerRealm);
end
end
end
function LogTracker:OnChatMsgSystemFilter(_, _, text)
local offlineName = strmatch(text, gsub(ERR_CHAT_PLAYER_NOT_FOUND_S, "%%s", "(.+)"));
if offlineName then
local peer = self:GetSyncPeer(offlineName, true, true);
if peer then
peer.isOnline = false;
return true;
end
end
return false;
end
function LogTracker:OnChatMsgChannel(text, sender)
local playerName = strsplit("-", sender);
self:OnPlayerOnline(playerName);
end