-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathServer.lua
4110 lines (3707 loc) · 178 KB
/
Server.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
LootReserve = LootReserve or { };
LootReserve.Server =
{
CurrentSession = nil,
NewSessionSettings =
{
LootCategories = { },
MaxReservesPerPlayer = 1,
Multireserve = 1,
Duration = 300,
ChatFallback = true,
Equip = true,
Blind = false,
Lock = false,
ImportedMembers = { },
},
Settings =
{
ChatAsRaidWarning = {
true,
false,
false,
true,
true,
true,
true,
true,
false,
false,
false,
},
ChatAnnounceWinToGuild = false,
ChatAnnounceWinToGuildThreshold = 3,
ChatReservesList = true,
ChatReservesListLimit = 5,
ChatUpdates = true,
ReservesSorting = LootReserve.Constants.ReservesSorting.BySource,
UseGlobalProfile = false,
RollUseTiered = true,
Phases = LootReserve:Deepcopy(LootReserve.Constants.DefaultPhases),
RollUsePhases = false,
RollPhases = LootReserve:Deepcopy(LootReserve.Constants.DefaultRollPhases),
RollAdvanceOnExpire = true,
RollLimitDuration = false,
RollDuration = 30,
RollFinishOnExpire = false,
Disenchanters = { },
RollDisenchant = false,
RollDisenchanters = { },
RollFinishOnAllReservingRolled = true,
RollFinishOnRaidRoll = false,
RollSkipNotContested = true,
RollHistoryDisplayLimit = 10,
RollHistoryKeepLimit = 1000,
RollHistoryHideEmpty = true,
RollHistoryHideNotOwed = false,
RollMasterLoot = true,
AcceptAllRollFormats = false,
AcceptRollsAfterTimerEnded = true,
AllowMultipleRollsOnReserves = true,
WinnerReservesRemoval = LootReserve.Constants.WinnerReservesRemoval.Smart,
ItemConditions = { },
CollapsedExpansions = { },
RecentLootBlacklist = { },
MaxRecentLoot = 30,
MinimumLootQuality = 3,
RemoveRecentLootAfterRolling = true,
UseUnitFrames = false,
Use24HourTime = true,
ShowReopenHint = true,
},
RequestedRoll = nil,
RollHistory = { },
RecentLoot = { },
LootedCorpses = { },
AddonUsers = { },
GuildMembers = { },
LootEdit = { },
MembersEdit = { },
Import = { },
Export = {
PendingRollsExportTextUpdate = nil,
},
PendingMasterLoot = nil,
RecentTradeAttempt = nil,
RecentLootAttempts = nil,
TradeAcceptState = { false, false };
OwedRolls = { },
ExtraRollRequestNag = { },
SentMessages = { },
ReservableIDs = { },
ReservableRewardIDs = { },
LootTrackingRegistered = false,
GuildMemberTrackingRegistered = false,
DurationUpdateRegistered = false,
RollDurationUpdateRegistered = false,
RollMatcherRegistered = false,
ChatTrackingRegistered = false,
ChatFallbackRegistered = false,
BasicChatListeningRegistered = false,
SessionEventsRegistered = false,
StartupAwaitingAuthority = false,
StartupAwaitingAuthorityRegistered = false,
MasterLootListUpdateRegistered = false,
RollHistoryDisplayLimit = 0,
PendingReserveListUpdate = nil,
PendingRollListUpdate = nil,
PendingMembersEditUpdate = nil,
PendingLootEditUpdate = nil,
PendingLootEditTextUpdate = false,
PendingInputOptionsUpdate = false,
PendingReservesListUpdate = nil,
PendingRecentLootAttemptsWipe = nil,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_FORCED_CANCEL_RESERVE"] =
{
text = "Are you sure you want to remove %s's reserve for item %s?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserve.Server:CancelReserve(self.data.Player, self.data.Item:GetID(), 1, false, true);
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_FORCED_CANCEL_ROLL"] =
{
text = "Are you sure you want to delete %s's roll for item %s?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserve.Server:DeleteRoll(self.data.Player, self.data.RollNumber, self.data.Item);
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_CUSTOM_ROLL_RESERVED_ITEM"] =
{
text = "Are you sure you want to roll among all players?|n|n%s has been reserved by:|n%s.",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
self.data.Frame:SetItem(nil);
local phases = LootReserve.Server.Settings.RollUsePhases and #LootReserve.Server.Settings.RollPhases > 0 and LootReserve.Server.Settings.RollPhases or nil;
if self.data.Phase then
phases = LootReserve:Deepcopy(LootReserve.Server.Settings.RollPhases)
for i = 2, self.data.Phase do
table.remove(phases, 1)
end
end
LootReserve.Server:RequestCustomRoll(self.data.Item,
LootReserve.Server.Settings.RollLimitDuration and LootReserve.Server.Settings.RollDuration or nil,
phases,
LootReserve.Server.Settings.RollUseTiered or nil);
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_DISENCHANT_RESERVED_ITEM"] =
{
text = "Are you sure you want to send to disenchanter?|n|n%s has been reserved by:|n%s.",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
self.data.Frame:SetItem(nil);
LootReserve.Server:RecordDisenchant(self.data.Item, self.data.Disenchanter, true);
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_ROLL_RESERVED_ITEM_AGAIN"] =
{
text = "Are you sure you want to roll %s among reserving players?|n|nIt has already been won by %s.",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
if self.data.Frame then
self.data.Frame:SetItem(nil);
end
local tokenID;
if LootReserve.Server.ReservableRewardIDs[self.data.Item:GetID()] then
tokenID = LootReserve.Data:GetToken(self.data.Item:GetID());
end
if LootReserve.Server.CurrentSession and LootReserve.Server.CurrentSession.ItemReserves[tokenID or self.data.Item:GetID()] then
LootReserve.Server:RequestRoll(self.data.Item);
end
end,
};
StaticPopupDialogs["LOOTRESERVE_ACCEPT_ALL_ROLL_FORMATS_ENABLE"] =
{
text = "|cffff0000WARNING|r|nThis option causes LootReserve to accept any roll.|n|nA player could do|n|cffff0000/roll 100 100|r|nand LootReserve will consider it valid.|n|nYou'll see a player's full rolls in the Recent Chat tracker next to their name in the Rolls tab.|n|nDo you want to enable this option?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserve.Server.Settings.AcceptAllRollFormats = true;
CloseMenus();
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_GLOBAL_PROFILE_ENABLE"] =
{
text = "By enabling global profile you acknowledge that all the mess you can create (by e.g. swapping between characters who are in different raid groups) will be on your conscience.|n|nDo you want to enable global profile?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserveGlobalSave.Server.GlobalProfile = LootReserveCharacterSave.Server;
LootReserve.Server.Settings.UseGlobalProfile = true;
LootReserve.Server:Load();
CloseMenus();
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_GLOBAL_PROFILE_DISABLE"] =
{
text = "Disabling global profile will revert you back to using sessions stored on your other characters before you turned global profile on. Your current character will adopt the current session.|n|nDo you want to disable global profile?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserveCharacterSave.Server = LootReserveGlobalSave.Server.GlobalProfile;
LootReserveGlobalSave.Server.GlobalProfile = nil;
LootReserve.Server.Settings.UseGlobalProfile = false;
CloseMenus();
LootReserve.Server:Load();
LootReserve.Server:Startup();
LootReserve.Server:UpdateReserveList();
LootReserve.Server:UpdateRollList();
end,
};
StaticPopupDialogs["LOOTRESERVE_NEW_PHASE_NAME"] =
{
text = "Name the new stage:",
button1 = ACCEPT,
button2 = CANCEL,
hasEditBox = true,
maxLetters = 50,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
local name = LootReserve:StringTrim(self.editBox:GetText():gsub("[,|]", ""));
if #name > 0 and not LootReserve:Contains(LootReserve.Server.Settings.Phases, name) then
table.insert(LootReserve.Server.Settings.Phases, name);
end
end,
EditBoxOnEnterPressed = function(self)
StaticPopupDialogs["LOOTRESERVE_NEW_PHASE_NAME"].OnAccept(self:GetParent());
self:GetParent():Hide();
end,
EditBoxOnEscapePressed = function(self)
self:GetParent():Hide();
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_ADD_TO_RECENT_LOOT_BLACKLIST"] =
{
text = "Are you sure you want to add %s to the Recent Loot Blacklist?\n\nIt won't show up in Recent Loot until you clear the Blacklist.",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self, data)
LootReserve.Server.Settings.RecentLootBlacklist[data.item:GetID()] = time();
while LootReserve:TableRemove(LootReserve.Server.RecentLoot, data.item) do end
CloseMenus();
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_CLEAR_RECENT_LOOT_BLACKLIST"] =
{
text = "Are you sure you want to clear the Recent Loot Blacklist?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
wipe(LootReserve.Server.Settings.RecentLootBlacklist);
CloseMenus();
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_CLEAR_RECENT_LOOT"] =
{
text = "Are you sure you want to clear the Recent Loot?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
wipe(LootReserve.Server.RecentLoot);
CloseMenus();
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_RESET_PHASES"] =
{
text = "Are you sure you want to reset stages to default?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserve.Server.Settings.Phases = LootReserve:Deepcopy(LootReserve.Constants.DefaultPhases);
LootReserve.Server.Settings.RollPhases = LootReserve:Deepcopy(LootReserve.Constants.DefaultRollPhases);
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_RESET_DISENCHANTERS"] =
{
text = "Are you sure you want to clear the list of disenchanters?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserve.Server.Settings.RollDisenchanters = { };
LootReserve.Server.Settings.Disenchanters = { };
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_CLEAR_HISTORY"] =
{
text = "Are you sure you want to clear all %d roll%s?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
table.wipe(LootReserve.Server.RollHistory);
table.wipe(LootReserve.Server.OwedRolls);
LootReserve.Server:UpdateRollList();
end,
};
StaticPopupDialogs["LOOTRESERVE_CONFIRM_ANNOUNCE_BLIND_RESERVES"] =
{
text = "Blind reserves in effect. Are you sure you want to publicly announce all reserves?",
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
LootReserve.Server:SendReservesList(nil, nil, true);
end,
};
StaticPopupDialogs["LOOTRESERVE_RELOAD_UI"] =
{
text = "%s",
button1 = "Reload",
button2 = CANCEL,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
OnAccept = function(self)
ReloadUI();
end,
};
local function stringStartsWith(str, start)
return str:sub(1, #start) == start;
end
function LootReserve.Server:CanBeServer()
return not IsInGroup() or UnitIsGroupLeader("player") or IsMasterLooter();
end
function LootReserve.Server:GetChatChannel(announcement)
if IsInRaid() then
return announcement and self.Settings.ChatAsRaidWarning[announcement] and (UnitIsGroupLeader("player") or UnitIsGroupAssistant("player")) and "RAID_WARNING" or "RAID";
elseif IsInGroup() then
return "PARTY";
else
return "WHISPER", LootReserve:Me();
end
end
function LootReserve.Server:HasRelevantRecentChat(roll, player)
local chat = roll.Chat;
local players = roll.Players;
if not chat or not chat[player] then return false; end
if not players or not players[player] then return false; end
local alreadyRolledTiers = { };
local chatRollCount = 0;
for _, str in ipairs(chat[player]) do
local time, channel, text = strsplit("|", str, 3);
if channel ~= "SYSTEM" then
return true;
end
local tier = text:match("%(1%-(%d+)%)");
if not tier then
return true;
end
if roll.Tiered then
if alreadyRolledTiers[tier] then
return true;
end
elseif tier ~= "100" then
return true;
end
alreadyRolledTiers[tier] = true;
chatRollCount = chatRollCount + 1;
end
return #players[player] < chatRollCount;
end
function LootReserve.Server:IsAddonUser(player)
return LootReserve:IsMe(player) or self.AddonUsers[player] and self.AddonUsers[player] >= LootReserve.MinAllowedVersion and true or false;
end
function LootReserve.Server:SetAddonUser(player, version)
if not self.AddonUsers[player] or self.AddonUsers[player] ~= version and version ~= "" then
self.AddonUsers[player] = version;
self:UpdateAddonUsers();
end
end
local function GetSavedItemConditionsSingle(category)
if not category then return { }; end
local container = LootReserve.Server.Settings.ItemConditions[category];
if not container then
container = { };
LootReserve.Server.Settings.ItemConditions[category] = container;
end
return container;
end
local function GetSavedItemConditions(categories)
if not categories then return { }; end
local container = { };
local itemIDs = { };
for _, category in ipairs(categories) do
for itemID, conditions in pairs(GetSavedItemConditionsSingle(category)) do
itemIDs[itemID] = true;
container[itemID] = container[itemID] or { };
container[itemID].ClassMask = bit.bor(container[itemID].ClassMask or 0, conditions.ClassMask or 0);
container[itemID].Custom = container[itemID].Custom or conditions.Custom or nil;
container[itemID].Hidden = container[itemID].Hidden or conditions.Hidden or nil;
container[itemID].Limit = (container[itemID].Limit or 0) + (conditions.Limit or 0);
if container[itemID].ClassMask == 0 then
container[itemID].ClassMask = nil;
end
if container[itemID].Limit == 0 then
container[itemID].Limit = nil;
end
-- container[itemID] = conditions;
end
end
-- explicitly check if item is bosshidden in each category
for itemID in pairs(itemIDs) do
local conditions = container[itemID];
local bossHidden = true;
for _, category in ipairs(categories) do
local conditions = LootReserve.Server.Settings.ItemConditions[category];
if not conditions or not conditions.BossHidden then
bossHidden = nil;
break;
end
end
conditions.BossHidden = bossHidden;
if not next(conditions) then
container[itemID] = nil;
end
end
return container;
end
function LootReserve.Server:GetNewSessionItemConditions()
if #self.NewSessionSettings.LootCategories == 1 then
return GetSavedItemConditionsSingle(self.NewSessionSettings.LootCategories[1]);
else
return GetSavedItemConditions(self.NewSessionSettings.LootCategories);
end
end
function LootReserve.Server:GetAllItemConditions()
local categories = { };
for category in pairs(LootReserve.Data.Categories) do
if category > 0 then
table.insert(categories, category);
end
end
return GetSavedItemConditions(categories);
end
function LootReserve.Server:Load()
LootReserveCharacterSave.Server = LootReserveCharacterSave.Server or { };
LootReserveGlobalSave.Server = LootReserveGlobalSave.Server or { };
-- Copy data from saved variables into runtime tables
-- Don't outright replace tables, as new versions of the addon could've added more fields that would be missing in the saved data
local function loadInto(to, from, field)
if from and to and field then
if from[field] then
for k, v in pairs(from[field]) do
to[field] = to[field] or { };
to[field][k] = v;
empty = false;
end
end
from[field] = to[field];
end
end
local versionGlobal = LootReserveGlobalSave.Server.Version and LootReserveGlobalSave.Server.Version or "0"
loadInto(self, LootReserveGlobalSave.Server, "NewSessionSettings");
loadInto(self, LootReserveGlobalSave.Server, "Settings");
if self.Settings.UseGlobalProfile then
LootReserveGlobalSave.Server.GlobalProfile = LootReserveGlobalSave.Server.GlobalProfile or { };
self.SaveProfile = LootReserveGlobalSave.Server.GlobalProfile;
else
self.SaveProfile = LootReserveCharacterSave.Server;
end
local versionSave = self.SaveProfile.Version and self.SaveProfile.Version or "0"
loadInto(self, self.SaveProfile, "CurrentSession");
loadInto(self, self.SaveProfile, "RequestedRoll");
loadInto(self, self.SaveProfile, "RollHistory");
loadInto(self, self.SaveProfile, "RecentLoot");
for name, key in pairs(LootReserve.Constants.ChatAnnouncement) do
if self.Settings.ChatAsRaidWarning[key] == nil then
self.Settings.ChatAsRaidWarning[key] = true;
end
end
-- 2021-08-28: Convert active session LootCategory to LootCategories
-- Date is late because the check was added late
if versionSave < "2022-05-21" then
if self.CurrentSession and not self.CurrentSession.Settings.LootCategories then
self.CurrentSession.Settings.LootCategories = {self.CurrentSession.Settings.LootCategory};
self.NewSessionSettings.LootCategories = {self.CurrentSession.Settings.LootCategory};
end
end
-- 2021-02-12: Upgrade item conditions
if versionGlobal < "2021-02-12" then
if self.NewSessionSettings.ItemConditions then
for itemID, conditions in pairs(self.NewSessionSettings.ItemConditions) do
local category = conditions.Custom;
conditions.Custom = conditions.Custom and true or nil;
if category then
self.Settings.ItemConditions[category] = self.Settings.ItemConditions[category] or { };
self.Settings.ItemConditions[category][itemID] = LootReserve:Deepcopy(conditions);
end
for _, category in ipairs(LootReserve.Data:GetItemCategories(itemID)) do
self.Settings.ItemConditions[category] = self.Settings.ItemConditions[category] or { };
self.Settings.ItemConditions[category][itemID] = LootReserve:Deepcopy(conditions);
end
end
self.NewSessionSettings.ItemConditions = nil;
end
end
if versionSave < "2021-02-12" then
if self.CurrentSession then
if not self.CurrentSession.ItemConditions then
self.CurrentSession.ItemConditions = { };
end
if self.CurrentSession.Settings.ItemConditions then
for itemID, conditions in pairs(self.CurrentSession.Settings.ItemConditions) do
local category = conditions.Custom;
conditions.Custom = conditions.Custom and true or nil;
if LootReserve:Contains(self.CurrentSession.Settings.LootCategories, category) or LootReserve.Data:IsItemInCategories(item, self.CurrentSession.Settings.LootCategories) then
self.CurrentSession.ItemConditions[itemID] = LootReserve:Deepcopy(conditions);
end
end
self.CurrentSession.Settings.ItemConditions = nil;
end
end
end
-- 2021-06-17: Upgrade roll history to support multiple rolls from the same player
if versionSave < "2021-06-17" then
for _, rollTable in ipairs({self.RollHistory, {self.RequestedRoll}}) do
for _, roll in ipairs(rollTable or { }) do
local needsUpgrade = false;
for player, rolls in pairs(roll.Players) do
if type(rolls) == "number" then
needsUpgrade = true;
break;
end
end
if needsUpgrade then
local players = { };
for player, rolls in LootReserve:Ordered(roll.Players) do
players[player] = players[player] or { };
if type(rolls) == "number" then
table.insert(players[player], rolls);
elseif type(rolls) == "table" then
for _, roll in ipairs(rolls) do
table.insert(players[player], roll);
end
end
end
roll.Players = players;
end
end
end
end
-- 2021-09-01: Prune unneeded historical data
if versionSave < "2021-09-01" then
if #self.RollHistory > 0 then
if self.RollHistory[#self.RollHistory].Duration then
for _, roll in ipairs(self.RollHistory) do
roll.Duration = nil;
roll.MaxDuration = nil;
if roll.Phases then
roll.Phases = {roll.Phases[1]};
end
end
end
end
end
-- 2021-09-20: Add self.CurrentSession.Members[player].ReservesDelta and update self.CurrentSession.Settings.MultiReserve
-- 2021-09-20: Prune deprecated settings
-- 2021-09-20: Prune old chat history
if versionSave < "2021-09-20" then
if self.CurrentSession then
for _, member in pairs(self.CurrentSession.Members) do
member.ReservesDelta = member.ReservesDelta or 0;
end
if not self.CurrentSession.Settings.Multireserve then
self.CurrentSession.Settings.MultiReserve = 1;
end
end
self.Settings.ChatThrottle = nil;
self.Settings.KeepUnlootedRecentLoot = nil;
self.Settings.MasterLooting = nil;
self.Settings.HighlightSameItemWinners = nil;
for _, rollTable in ipairs({self.RollHistory, {self.RequestedRoll}}) do
for _, entry in ipairs(rollTable or { }) do
for player, lines in pairs(entry.Chat or { }) do
for i = #lines, LootReserve.Constants.MAX_CHAT_STORAGE + 1, -1 do
lines[i] = nil;
end
end
end
end
end
-- 2022-06-16: Delete irrelevant chat
if versionSave < "2022-06-16" then
for _, roll in ipairs(self.RollHistory) do
local toRemove = { };
if roll.Chat then
for player, chat in pairs(roll.Chat) do
if self:HasRelevantRecentChat(roll, player) then
local text = chat[1]
if text:match("Tie for |cff%x%x%x%x%x%x|Hitem:%d+[:%d%-]+|h%[.+%]|h|r between players .+%. All rolled %d+%. Please /roll again") then
table.remove(chat, 1);
end
text = chat[1]
if text:match(".+ %- roll on reserved |cff%x%x%x%x%x%x|Hitem:%d+[:%d%-]+|h%[.+%]|h|r")
or text:match("Roll.* on |cff%x%x%x%x%x%x|Hitem:%d+[:%d%-]+|h%[.+%]|h|r") then
table.remove(chat, 1);
end
end
if not self:HasRelevantRecentChat(roll, player) then
table.insert(toRemove, player);
end
end
for _, player in ipairs(toRemove) do
roll.Chat[player] = nil;
end
if not next(roll.Chat) then
roll.Chat = nil;
end
end
end
end
-- 2022-10-30: Add RollBonus field
if versionSave < "2022-10-30" then
if self.CurrentSession and self.CurrentSession.Members then
for member, memberData in pairs(self.CurrentSession.Members) do
if not memberData.RollBonus then
memberData.RollBonus = { }; -- metatable added in next block
end
end
end
end
-- 2023-06-20: Remove illegal characters in phases
if versionSave < "2023-06-20" then
for _, t in ipairs({LootReserve.Server.Settings.RollPhases, LootReserve.Server.Settings.Phases}) do
for i, phase in ipairs(t) do
t[i] = phase:gsub("[,|]", "");
end
end
end
-- 2024-03-09: Delete LootCategory key in LootReserve.Server.NewSessionSettings
if versionSave < "2024-03-09" then
LootReserve.Server.NewSessionSettings.LootCategory = nil;
end
-- Create RollBonus metatables
if self.CurrentSession then
for _, member in pairs(self.CurrentSession.Members) do
member.RollBonus = setmetatable(member.RollBonus, { __index = function() return 0 end })
end
end
-- Create Item objects
for _, roll in ipairs(self.RollHistory) do
roll.Item = LootReserve.ItemCache:Item(roll.Item);
-- Populate list of items that have not been distributed
if roll.Owed then
table.insert(self.OwedRolls, roll);
end
end
if self.RequestedRoll then
self.RequestedRoll.Item = LootReserve.ItemCache:Item(self.RequestedRoll.Item);
end
if self.CurrentSession then
for _, member in pairs(self.CurrentSession.Members) do
if member.WonRolls then
for i, won in ipairs(member.WonRolls) do
won.Item = LootReserve.ItemCache:Item(won.Item);
end
end
end
end
for i, item in ipairs(self.RecentLoot) do
self.RecentLoot[i] = LootReserve.ItemCache:Item(item);
end
-- Verify that all the required fields are present in the session
if self.CurrentSession then
for _, field in ipairs({ "Settings", "StartTime", "Duration", "DurationEndTimestamp", "Members", "WonItems", "ItemReserves", "LootTracking" }) do
if self.CurrentSession and self.CurrentSession[field] == nil then
self.CurrentSession = nil;
self.SaveProfile.CurrentSession = nil;
break;
end
end
end
-- Verify that all loot categories actually exist. deselect categories and/or terminate session otherwise
if self.CurrentSession then
for _, category in ipairs(self.CurrentSession.Settings.LootCategories or {}) do
if not LootReserve.Data.Categories[category] or LootReserve.Data.Categories[category].Expansion > LootReserve:GetCurrentExpansion() then
self.CurrentSession = nil;
self.SaveProfile.CurrentSession = nil;
break;
end
end
end
do
local newLootCategories = { };
for _, category in ipairs(self.NewSessionSettings.LootCategories or {}) do
if LootReserve.Data.Categories[category] and LootReserve.Data.Categories[category].Expansion <= LootReserve:GetCurrentExpansion() then
table.insert(newLootCategories, category);
end
end
self.NewSessionSettings.LootCategories = newLootCategories;
end
-- Warn player if a stale session or roll exists
if self.CurrentSession and self.CurrentSession.LogoutTime and time() > self.CurrentSession.LogoutTime + 1*15*60 then
if self.CurrentSession.AcceptingReserves then
LootReserve:ShowError("You logged out with an active session.|nYou can stop and reset the session in the Host window.")
else
LootReserve:ShowError("You logged out with an active session.|nYou can reset the session in the Host window.")
end
end
if self.RequestedRoll and time() > self.RequestedRoll.StartTime + 1*15*60 then
LootReserve:ShowError("You logged out with an active roll.|nYou can end the roll in the Host window.")
self.Window:Show();
PanelTemplates_SetTab(self.Window, 3);
self:SetWindowTab(3);
end
-- Rearm the duration timer, to make it expire at about the same time (second precision) as it would've otherwise if the server didn't log out/reload UI
-- Unless the timer would've expired during that time, in which case set it to a dummy 1 second to allow the code to finish reserves properly upon expiration
if self.CurrentSession and self.CurrentSession.AcceptingReserves and self.CurrentSession.Duration ~= 0 then
self.CurrentSession.Duration = math.max(1, self.CurrentSession.DurationEndTimestamp - time());
end
-- Same for current roll
if self.RequestedRoll and self.RequestedRoll.MaxDuration and self.RequestedRoll.Duration ~= 0 then
self.RequestedRoll.Duration = math.max(1, self.RequestedRoll.StartTime + self.RequestedRoll.MaxDuration - time());
end
self.SaveProfile.Version = LootReserve.Version;
-- Update the UI according to loaded settings
self:LoadNewSessionSettings();
self.LootEdit:UpdateCategories();
end
function LootReserve.Server:Startup()
-- Hook roll handlers if needed
if self.RequestedRoll then
self:PrepareRequestRoll();
end
if self.CurrentSession and not LootReserve.Client.SessionServer then
if self:CanBeServer() then
-- Hook handlers
self:PrepareSession();
-- Inform other players about ongoing session
LootReserve.Comm:BroadcastSessionInfo();
else
-- If we have a session but no authority to be a server - wait until we have RL/ML role and restart the server again
self.StartupAwaitingAuthority = true;
self:UpdateServerAuthority();
if not self.StartupAwaitingAuthorityRegistered then
self.StartupAwaitingAuthorityRegistered = true;
LootReserve:RegisterEvent("GROUP_ROSTER_UPDATE", function()
if self.StartupAwaitingAuthority and self.CurrentSession and not LootReserve.Client.SessionServer and self:CanBeServer() then
self.StartupAwaitingAuthority = false;
self:Startup();
end
end);
end
end
-- Update UI
if self.CurrentSession.AcceptingReserves then
self:SessionStarted();
else
self:SessionStopped();
end
self:UpdateReserveList();
self.Window:Show();
-- Immediately after logging in retrieving raid member names might not work (names not yet cached?)
-- so update the UI a little bit later, otherwise reserving players will show up as "(not in raid)"
-- until the next group roster change
C_Timer.After(5, function()
self:UpdateReserveList();
self:UpdateRollList();
end);
end
-- Prepare dropdown lists for displaying item tooltips
local OnTooltipEnter = function(self)
if type(self.tooltipOnButton) == "string" and self.tooltipOnButton:find("item:%d+") then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
GameTooltip:SetHyperlink(self.tooltipOnButton);
GameTooltip:Show();
end
end
-- Hook all existing dropdown buttons
local list, index = 1, 1
while _G["L_DropDownList"..list] do
while _G["L_DropDownList"..list.."Button"..index] do
_G["L_DropDownList"..list.."Button"..index]:HookScript("OnEnter", OnTooltipEnter)
index = index + 1
end
list = list + 1
end
-- Hook all future dropdown buttons
hooksecurefunc("CreateFrame", function(frameType, name, _, template, _, ...)
if frameType == "Button" and name and type(name) == "string" and name:find("L_DropDownList%d+Button%d+") and template == "L_UIDropDownMenuButtonTemplate" then
_G[name]:HookScript("OnEnter", OnTooltipEnter)
end
end)
-- Show reserves even if no longer the server, just a failsafe
self:UpdateReserveList();
-- Hook events to record recent loot and track looters
self:PrepareLootTracking();
self:PrepareGuildTracking();
end
function LootReserve.Server:HasAlreadyWon(player, item)
local won = self.CurrentSession and self.CurrentSession.Members[player] and self.CurrentSession.Members[player].WonRolls;
if won then
local item = LootReserve.Data:GetToken(item) or item;
for i, roll in ipairs(won) do
if roll.Item:GetID() == item then
return true;
end
end
end
return false;
end
function LootReserve.Server:UpdateTradeFrameAutoButton(accepting)
if not TradeFrame:IsShown() then
return;
end
local target = LootReserve:Player(UnitNameUnmodified("npc"));
local itemsToInsert = { };
local slotsFree = 6;
local relevantSlots = 0;
-- Add all "recent" owed items to the list
for _, roll in ipairs(self.OwedRolls) do
if roll.Winners[1] == target then
table.insert(itemsToInsert, roll.Item);
end
end
-- Remove items which are currently being traded
local offsets = { };
if accepting then
self.RecentTradeAttempt = { target = target };
end
for i = 1, 6 do
local name, texture, quantity, quality, isUsable, enchant = GetTradePlayerItemInfo(i);
local link = GetTradePlayerItemLink(i);
if link then
local item = LootReserve.ItemCache:Item(link);
if not offsets[item] then
offsets[item] = -1;
end
offsets[item] = offsets[item] + 1;
if accepting then
self.RecentTradeAttempt[i] = {item = item, quantity = quantity};
end
if LootReserve:TableRemove(itemsToInsert, item) then
relevantSlots = relevantSlots + 1;
end
slotsFree = slotsFree - 1;
end
end
-- Remove items which aren't found in bags
for i = #itemsToInsert, 1, -1 do
local item = itemsToInsert[i]
if not offsets[item] then
offsets[item] = -1;
end
offsets[item] = offsets[item] + 1;
if LootReserve:GetTradeableItemCount(item) - offsets[item] < 1 then
table.remove(itemsToInsert, i);
end
end
if relevantSlots > 0 and (slotsFree == 0 or #itemsToInsert == 0) then
LootReserveTradeFrameAutoButton:Show();
LootReserveTradeFrameAutoButton:SetEnabled(not self.TradeAcceptState[1]);
LootReserveTradeFrameAutoButton:SetText("|TInterface\\AddOns\\LootReserve\\Assets\\Textures\\IconDice:16:16:0:0|t Trade");
LootReserveTradeFrameAutoButton.ItemsToInsert = nil;
elseif #itemsToInsert > 0 then
LootReserveTradeFrameAutoButton:Show();
LootReserveTradeFrameAutoButton:SetEnabled(slotsFree ~= 0);
LootReserveTradeFrameAutoButton:SetText(format("|TInterface\\AddOns\\LootReserve\\Assets\\Textures\\IconDice:16:16:0:0|t Insert %s%d |4item:items;", #itemsToInsert > slotsFree and format("%d / ", slotsFree) or "", #itemsToInsert));
LootReserveTradeFrameAutoButton.ItemsToInsert = itemsToInsert;
else
LootReserveTradeFrameAutoButton:Hide();
end
end
function LootReserve.Server:AddRecentLoot(item, skipChecks)
if self.Settings.RecentLootBlacklist[item:GetID()] or LootReserve.Data.RecentLootBlacklist[item:GetID()] then return; end
if not item:IsCached() then
if item:Exists() then
item:OnCache(function() self:AddRecentLoot(item) end);