Repository navigation
Expand file tree
/
Copy pathGuild-View-Extended-Sync.lua
More file actions
1873 lines (1762 loc) · 91.7 KB
/
Copy pathGuild-View-Extended-Sync.lua
File metadata and controls
1873 lines (1762 loc) · 91.7 KB
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
---------------------------------------------------------------------------
-- Guild-View-Extended: Berufe
-- WoW 3.3.5a: versionierte, anfragebasierte Snapshot-Synchronisierung ueber
-- SendAddonMessage. Keine Retail-APIs, keine Server- oder HTTP-Anfragen.
---------------------------------------------------------------------------
local GVE = _G.GVE
if not GVE then return end
local Sync = {}
GVE.Sync = Sync
local PREFIX = "GVEX4"
local PROTOCOL = 4
local STORAGE_SCHEMA = 2
local CHUNK_BYTES = 175
local MAX_CHUNKS = 256
local MAX_BYTES = MAX_CHUNKS * CHUNK_BYTES
local CACHE_TTL = 30 * 24 * 60 * 60
local REQUEST_TIMEOUT = 15
local REQUEST_COOLDOWN = 10
local AUTO_REQUEST_INTERVAL = 1.0
local AUTO_REQUEST_RETRY = 300
local SEND_INTERVAL = 0.09
local MAX_CACHED_PLAYERS = 300
local MAX_QUEUE_BEFORE_BUSY = 80
local ABSOLUTE_TRANSFER_TIMEOUT = 60
local L = GetLocale() == "deDE" and {
members="Mitglieder", tab="Berufe", search="Spieler oder Beruf suchen ...",
professions="Berufe", request="Daten anfragen",
capture="Jetzt erfassen", noSelection="Wähle links einen Spieler aus.",
noData="Noch keine Daten synchronisiert.", noProfessions="Keine passenden Berufe.", fresh="vor %s synchronisiert",
pending="Anfrage gesendet ...", offline="Spieler ist offline – gespeicherte Daten",
timeout="Keine Antwort. Spieler offline oder Addon nicht verfügbar.",
denied="Freigabe wurde vom Spieler deaktiviert.", empty="Der Spieler hat diese Daten noch nicht erfasst.",
busy="Der Spieler überträgt gerade andere Daten. Bitte später erneut versuchen.",
help="Berufe werden als vollständige, anklickbare 3.3.5a-Berufslinks gespeichert – so wie beim Posten aus dem Zauberbuch in den Chat.",
footerShort="Berufslinks aus der letzten Synchronisierung",
clickToOpen="Klicken, um den verlinkten Beruf zu öffnen.",
shareP="Eigene Berufe teilen", captured="Lokaler Snapshot aktualisiert.", players="%d Spieler",
professionSearch="Berufe durchsuchen ...", professionCount="%d Berufe",
current="aktuell", stale="veraltet", never="keine Daten",
sec="Sek.", min="Min.", hour="Std.", day="Tage",
openProfession="Kein vollständiger Berufslink gefunden. Öffne dein Zauberbuch oder deinen eigenen Beruf und versuche es erneut.",
syncNow="Jetzt synchronisieren", syncSent="Gildenweite Synchronisierung gestartet: eigene Berufe verteilt und aktuelle Daten angefragt.",
staleReply="Antwort erhalten, aber der Snapshot des Spielers ist weiterhin veraltet.",
lastCaptured="zuletzt erfasst vor %s",
synchronized="%d synchronisierte Spieler", categoryPlayers="%d Spieler",
tooBig="Die Berufsdaten sind für die Synchronisierung zu groß.",
notSynchronized="Noch nicht synchronisiert",
columnPlayer="Beruf / Spieler", columnLink="Berufslink", columnSkill="Skill",
columnAge="Aktualität", columnStatus="Status", allPlayers="Alle Spieler",
onlineOnly="Online", offlineOnly="Offline", allData="Alle Daten",
currentOnly="Aktuell", staleOnly="Veraltet", openAll="Alle öffnen",
closeAll="Alle schließen", onlineCount="%d Spieler · %d online",
syncActive="Automatische Synchronisierung aktiv", offlineCache="Offline · Cache",
noResults="Keine passenden Spieler oder Berufe.", requestShort="Anfragen",
relayedCurrent="über %s · aktuell", relayedStale="über %s · veraltet",
} or {
members="Members", tab="Professions", search="Search player or profession ...",
professions="Professions", request="Request data",
capture="Capture now", noSelection="Select a player on the left.",
noData="No synchronized data yet.", noProfessions="No matching professions.", fresh="synchronized %s ago",
pending="Request sent ...", offline="Player is offline – showing cached data",
timeout="No response. Player may be offline or not use the addon.",
denied="Sharing was disabled by the player.", empty="The player has not captured this data yet.",
busy="The player is transferring other data. Please try again later.",
help="Professions are stored as complete, clickable 3.3.5a trade links – just like posting them from the spellbook into chat.",
footerShort="Profession links from the latest synchronization",
clickToOpen="Click to open the linked profession.",
shareP="Share my professions", captured="Local snapshot updated.", players="%d players",
professionSearch="Search professions ...", professionCount="%d professions",
current="current", stale="stale", never="no data",
sec="sec", min="min", hour="hr", day="days",
openProfession="No complete profession link was found. Open your spellbook or your own profession and try again.",
syncNow="Sync guild now", syncSent="Guild synchronization started: shared your professions and requested current data.",
staleReply="Response received, but the player's snapshot is still outdated.",
lastCaptured="last captured %s ago",
synchronized="%d synchronized players", categoryPlayers="%d players",
tooBig="The profession data is too large to synchronize.",
notSynchronized="Not synchronized",
columnPlayer="Profession / player", columnLink="Profession link", columnSkill="Skill",
columnAge="Last update", columnStatus="Status", allPlayers="All players",
onlineOnly="Online", offlineOnly="Offline", allData="All data",
currentOnly="Current", staleOnly="Stale", openAll="Expand all",
closeAll="Collapse all", onlineCount="%d players · %d online",
syncActive="Automatic synchronization active", offlineCache="Offline · cache",
noResults="No matching players or professions.", requestShort="Request",
relayedCurrent="via %s · current", relayedStale="via %s · stale",
}
local function CleanName(value)
if type(value) ~= "string" then return nil end
local name = value:gsub("[\r\n]", ""):gsub("%-.*$", "")
name = name:gsub("^%s+", ""):gsub("%s+$", "")
if name == "" then return nil end
return name
end
local function KeyName(value)
local name = CleanName(value)
return name and (GVE.CaseFoldName and GVE:CaseFoldName(name) or name:lower()) or nil
end
local function Fold(value)
return GVE.CaseFoldName and GVE:CaseFoldName(value) or tostring(value or ""):lower()
end
local function SafeText(value, maxLength)
if type(value) ~= "string" or #value > maxLength or value:find("%c") or value:find("|", 1, true) then return nil end
return value
end
local function IsInteger(value, minimum, maximum)
return value and value == math.floor(value) and value >= minimum and value <= maximum
end
local function ParseTradeLink(value)
if type(value) ~= "string" or #value < 10 or #value > 12000 or value:find("%c") then return nil end
local hyperlink, label = value:match("^|c%x%x%x%x%x%x%x%x|H([^|]+)|h%[([^|%[%]]+)%]|h|r$")
if not hyperlink or not label then return nil end
-- 3.3.5a-Serverimplementierungen nutzen auch sehr kurze Character-IDs und eine
-- Custom-6-bit-Bitmap mit Zeichen wie "{". Das komplette letzte Feld
-- bleibt deshalb opak; Pipes und Steuerzeichen sind oben ausgeschlossen.
local spellID, skill, maxSkill, ownerGUID, tradeData = hyperlink:match("^trade:(%d+):(%d+):(%d+):([%x]+):([^|%c]*)$")
spellID, skill, maxSkill = tonumber(spellID), tonumber(skill), tonumber(maxSkill)
if not IsInteger(spellID, 1, 10000000) or not IsInteger(skill, 0, 1000) or not IsInteger(maxSkill, 0, 1000) then return nil end
if #ownerGUID < 1 or #ownerGUID > 32 or #tradeData > 10000 then return nil end
return value, label, skill, maxSkill, spellID
end
local function SafeTradeLink(value)
return ParseTradeLink(value)
end
local function DebugLog(message)
if type(GVE.AddLog) == "function" then
GVE:AddLog("Berufe: "..tostring(message))
end
end
local function DebugLink(value)
if type(value) ~= "string" then return tostring(value) end
local visible = value:gsub("|", "<PIPE>")
visible = visible:gsub("[%c]", function(character)
return format("<%02X>", string.byte(character))
end)
return "("..#value.." Bytes) "..visible
end
local function OpenTradeLink(link)
local safe = SafeTradeLink(link)
local hyperlink = safe and safe:match("|H([^|]+)|h")
if hyperlink and type(SetItemRef) == "function" then
pcall(SetItemRef, hyperlink, safe, "LeftButton")
end
end
local function Encode(value)
return tostring(value or ""):gsub("([^%w%-%_%.])", function(c)
return format("%%%02X", string.byte(c))
end)
end
local function Decode(value)
if type(value) ~= "string" then return "" end
return (value:gsub("%%(%x%x)", function(hex)
return string.char(tonumber(hex, 16))
end))
end
local function Split(value, sep)
local out, start = {}, 1
if value == "" then return out end
while true do
local a, b = value:find(sep, start, true)
if not a then
out[#out + 1] = value:sub(start)
break
end
out[#out + 1] = value:sub(start, a - 1)
start = b + 1
end
return out
end
local function AgeText(stamp)
local seconds = math.max(0, time() - (tonumber(stamp) or 0))
if seconds < 60 then return seconds.." "..L.sec end
if seconds < 3600 then return math.floor(seconds / 60).." "..L.min end
if seconds < 86400 then return math.floor(seconds / 3600).." "..L.hour end
return math.floor(seconds / 86400).." "..L.day
end
local function IsOwn(name)
local player = UnitName("player")
return player and KeyName(player) == KeyName(name)
end
local function MakeBackdrop(frame, r, g, b, a)
frame:SetBackdrop({
bgFile="Interface\\ChatFrame\\ChatFrameBackground",
edgeFile="Interface\\Tooltips\\UI-Tooltip-Border",
tile=true, tileSize=16, edgeSize=12,
insets={left=3,right=3,top=3,bottom=3},
})
frame:SetBackdropColor(r, g, b, a)
end
local function MakeCheck(parent, text)
local cb = CreateFrame("CheckButton", nil, parent)
cb:SetSize(16, 16)
cb:SetNormalTexture("Interface\\Buttons\\UI-CheckBox-Up")
cb:SetCheckedTexture("Interface\\Buttons\\UI-CheckBox-Check")
cb:SetHighlightTexture("Interface\\Buttons\\UI-CheckBox-Highlight", "ADD")
cb.text = cb:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
cb.text:SetPoint("LEFT", cb, "RIGHT", 3, 0)
cb.text:SetText(text)
return cb
end
-- Ruhige, flache UI-Bausteine. Sie verwenden nur Texturen, Backdrops und
-- FontObjects aus dem 3.3.5a-Client und vermeiden die roten Standardknöpfe.
local UI_COLOR = {
panel = {0.018, 0.027, 0.047, 1.00},
section = {0.028, 0.043, 0.071, 0.96},
field = {0.012, 0.020, 0.035, 0.98},
border = {0.16, 0.25, 0.34, 0.72},
borderFocus = {0.20, 0.667, 1.00, 1.00},
accent = {0.08, 0.45, 0.68, 0.95},
accentSoft = {0.082, 0.114, 0.165, 1.00}, -- #151d2a
hover = {0.153, 0.204, 0.278, 1.00}, -- #273447
selected = {0.075, 0.204, 0.302, 1.00}, -- #13344d
good = {0.282, 0.835, 0.592, 1.00},
warn = {0.894, 0.722, 0.302, 1.00},
error = {0.86, 0.38, 0.38, 1.00},
rowA = {0.025, 0.039, 0.061, 0.74},
rowB = {0.035, 0.053, 0.080, 0.74},
text = {0.89, 0.94, 0.98},
muted = {0.51, 0.61, 0.69},
}
local function SetTextureColor(texture, color)
texture:SetTexture(color[1], color[2], color[3], color[4])
end
local function MakeFlatPanel(frame, color)
frame:SetBackdrop({
bgFile="Interface\\ChatFrame\\ChatFrameBackground",
edgeFile="Interface\\ChatFrame\\ChatFrameBackground",
tile=true, tileSize=16, edgeSize=1,
insets={left=1,right=1,top=1,bottom=1},
})
frame:SetBackdropColor(color[1], color[2], color[3], color[4])
frame:SetBackdropBorderColor(UI_COLOR.border[1], UI_COLOR.border[2], UI_COLOR.border[3], UI_COLOR.border[4])
end
local function PaintFlatButton(button)
local color
if button.flatSelected then color = UI_COLOR.selected
elseif button.flatDisabled then color = UI_COLOR.field
elseif button.flatHover then color = UI_COLOR.hover
elseif button.flatAccent then color = UI_COLOR.accentSoft
else color = UI_COLOR.accentSoft end
button:SetBackdropColor(color[1], color[2], color[3], color[4])
local textColor = button.flatDisabled and not button.flatSelected and UI_COLOR.muted or UI_COLOR.text
button.label:SetTextColor(textColor[1], textColor[2], textColor[3])
if button.flatSelected or (button.flatHover and not button.flatDisabled) then
button:SetBackdropBorderColor(UI_COLOR.borderFocus[1], UI_COLOR.borderFocus[2], UI_COLOR.borderFocus[3], UI_COLOR.borderFocus[4])
else
button:SetBackdropBorderColor(UI_COLOR.border[1], UI_COLOR.border[2], UI_COLOR.border[3], UI_COLOR.border[4])
end
end
local function MakeFlatButton(parent, width, height, text, accent)
local button = CreateFrame("Button", nil, parent)
button:SetSize(width, height)
MakeFlatPanel(button, accent and UI_COLOR.accentSoft or UI_COLOR.section)
button.flatAccent = accent and true or nil
button.label = button:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
button.label:SetPoint("CENTER")
button.label:SetText(text or "")
button.SetText = function(self, value) self.label:SetText(value or "") end
button.GetText = function(self) return self.label:GetText() end
button:SetScript("OnEnter", function(self) self.flatHover = true; PaintFlatButton(self) end)
button:SetScript("OnLeave", function(self) self.flatHover = nil; PaintFlatButton(self) end)
button:SetScript("OnDisable", function(self) self.flatDisabled = true; PaintFlatButton(self) end)
button:SetScript("OnEnable", function(self) self.flatDisabled = nil; PaintFlatButton(self) end)
PaintFlatButton(button)
return button
end
local function SetFlatSelected(button, selected)
if not button then return end
button.flatSelected = selected and true or nil
if button.selectionIndicator then
if selected then button.selectionIndicator:Show() else button.selectionIndicator:Hide() end
end
PaintFlatButton(button)
end
local function MakeFlatSearch(parent, width, height)
local box = CreateFrame("EditBox", nil, parent)
box:SetSize(width, height)
box:SetAutoFocus(false)
box:SetFontObject(ChatFontNormal)
box:SetTextInsets(9, 8, 0, 0)
MakeFlatPanel(box, UI_COLOR.field)
box:SetScript("OnEditFocusGained", function(self)
self:SetBackdropBorderColor(UI_COLOR.borderFocus[1], UI_COLOR.borderFocus[2], UI_COLOR.borderFocus[3], UI_COLOR.borderFocus[4])
end)
box:SetScript("OnEditFocusLost", function(self)
self:SetBackdropBorderColor(UI_COLOR.border[1], UI_COLOR.border[2], UI_COLOR.border[3], UI_COLOR.border[4])
end)
return box
end
local function PaintPlayerRow(row, alternate)
local color
if row.rowSelected then color = UI_COLOR.selected
elseif row.rowHover then color = UI_COLOR.hover
elseif alternate then color = UI_COLOR.rowB
else color = UI_COLOR.rowA end
SetTextureColor(row.bg, color)
if row.selectionBar then
if row.rowSelected then row.selectionBar:Show() else row.selectionBar:Hide() end
end
end
function Sync:InitDB()
if type(GVESyncData) ~= "table" then
GVESyncData = {schema=PROTOCOL, storageSchema=STORAGE_SCHEMA, guilds={}, settings={}}
end
local db = GVESyncData
local previousSchema = tonumber(db.schema) or 0
if previousSchema > PROTOCOL then
-- Daten einer neueren, unbekannten Version niemals als v4 umdeuten.
-- Nur die harmlosen Freigabeeinstellungen koennen uebernommen werden.
db = {schema=PROTOCOL, storageSchema=STORAGE_SCHEMA, guilds={}, settings=type(db.settings) == "table" and db.settings or {}}
GVESyncData = db
previousSchema = PROTOCOL
end
-- Alte Berufslinks bleiben erhalten. Nicht mehr verwendete Bank- und
-- Rezeptindexdaten werden bei der Migration ersatzlos entfernt.
db.schema = PROTOCOL
db.settings = type(db.settings) == "table" and db.settings or {}
if db.settings.shareProfessions == nil then db.settings.shareProfessions = true end
db.settings.shareReagents = nil
-- One-time cleanup after removal of guild maps/name markers. Release
-- forced engine plate visibility without changing other addon profiles.
for _, entry in ipairs({{"guildFriendlyPrevious", "nameplateShowFriends"},
{"guildEnemyPrevious", "nameplateShowEnemies"}}) do
local saved = tonumber(db.settings[entry[1]])
if (saved == 0 or saved == 1) and type(GetCVar) == "function"
and type(SetCVar) == "function" and GetCVar(entry[2]) == "1" then
SetCVar(entry[2], tostring(saved))
end
db.settings[entry[1]] = nil
end
for _, key in ipairs({"guildMapEnabled", "guildNearbyEnabled", "guildMarkerStyle", "guildMarkerRevision"}) do
db.settings[key] = nil
end
local function MigrateSnapshot(snapshot)
if type(snapshot) ~= "table" then return end
snapshot.reagents = nil
if type(snapshot.professions) ~= "table" then snapshot.professions = nil return end
local migrated, oldestAt = {}, nil
for professionName, profession in pairs(snapshot.professions) do
if type(profession) == "table" then
local tradeLink, linkLabel, skill, maxSkill = ParseTradeLink(profession.tradeLink)
local capturedAt = tonumber(profession.capturedAt) or tonumber(snapshot.professionsCapturedAt)
or tonumber(snapshot.receivedAt) or time()
if tradeLink and SafeText(professionName, 128) and Fold(linkLabel) == Fold(professionName) then
if not IsInteger(capturedAt, 1, time() + 3600) then capturedAt = time() end
migrated[linkLabel] = {
name=linkLabel, skill=skill, maxSkill=maxSkill,
capturedAt=capturedAt, tradeLink=tradeLink,
}
oldestAt = not oldestAt and capturedAt or math.min(oldestAt, capturedAt)
end
end
end
snapshot.professions = next(migrated) and migrated or nil
snapshot.professionsCapturedAt = oldestAt
snapshot.relayFrom = CleanName(snapshot.relayFrom)
snapshot.directSource = snapshot.relayFrom and false or true
end
local guildName = GetGuildInfo("player")
if (not guildName or guildName == "") and type(IsInGuild) == "function" and IsInGuild() then
-- Direkt bei PLAYER_LOGIN kann der Gildenname noch ungeladen sein.
-- Niemals deshalb einen gueltigen gespeicherten Guild-Scope leeren.
self.db = db
self.guildData = self.guildData or {players={}, ownByCharacter={}}
self.own = self.own or {}
self.waitingForGuild = true
return false
end
guildName = guildName or ""
self.waitingForGuild = nil
local guildKey = (GetRealmName() or "").."\031"..guildName
-- Bis Version 1.3 lagen nur die Daten der zuletzt angemeldeten Gilde an
-- der Wurzel der SavedVariables. Verschiebe sie einmalig in den damals
-- gespeicherten Gildenbereich. So bleiben sie auch erhalten, wenn der
-- naechste Charakter in einer anderen Gilde oder gildenlos ist.
db.guilds = type(db.guilds) == "table" and db.guilds or {}
if type(db.players) == "table" or type(db.ownByCharacter) == "table" or type(db.own) == "table" then
local legacyGuildKey = type(db.guildKey) == "string" and db.guildKey or guildKey
local legacyGuild = type(db.guilds[legacyGuildKey]) == "table" and db.guilds[legacyGuildKey] or {}
legacyGuild.players = type(legacyGuild.players) == "table" and legacyGuild.players or {}
legacyGuild.ownByCharacter = type(legacyGuild.ownByCharacter) == "table" and legacyGuild.ownByCharacter or {}
for key, snapshot in pairs(type(db.players) == "table" and db.players or {}) do
if legacyGuild.players[key] == nil then legacyGuild.players[key] = snapshot end
end
for key, snapshot in pairs(type(db.ownByCharacter) == "table" and db.ownByCharacter or {}) do
if legacyGuild.ownByCharacter[key] == nil then legacyGuild.ownByCharacter[key] = snapshot end
end
if type(db.own) == "table" and legacyGuildKey == guildKey then
local legacyCharacterKey = guildKey.."\031"..(UnitName("player") or "Unknown")
if legacyGuild.ownByCharacter[legacyCharacterKey] == nil then
legacyGuild.ownByCharacter[legacyCharacterKey] = db.own
end
end
db.guilds[legacyGuildKey] = legacyGuild
db.players, db.ownByCharacter, db.own, db.guildKey = nil, nil, nil, nil
end
db.storageSchema = STORAGE_SCHEMA
local guildData = type(db.guilds[guildKey]) == "table" and db.guilds[guildKey] or {}
guildData.players = type(guildData.players) == "table" and guildData.players or {}
guildData.ownByCharacter = type(guildData.ownByCharacter) == "table" and guildData.ownByCharacter or {}
db.guilds[guildKey] = guildData
-- Alle gespeicherten Gildenbereiche migrieren, nicht nur die gerade
-- aktive Gilde. Dadurch bleibt auch ein spaeter wieder besuchter Cache
-- gueltig und wird nicht beim Charakterwechsel verworfen.
for _, storedGuild in pairs(db.guilds) do
if type(storedGuild) == "table" then
storedGuild.players = type(storedGuild.players) == "table" and storedGuild.players or {}
storedGuild.ownByCharacter = type(storedGuild.ownByCharacter) == "table" and storedGuild.ownByCharacter or {}
for _, snapshot in pairs(storedGuild.ownByCharacter) do MigrateSnapshot(snapshot) end
for _, snapshot in pairs(storedGuild.players) do MigrateSnapshot(snapshot) end
end
end
local characterKey = guildKey.."\031"..(UnitName("player") or "Unknown")
if self.activeGuildKey ~= guildKey or self.activeCharacterKey ~= characterKey then
if self.sendQueue then wipe(self.sendQueue) end
if self.pending then wipe(self.pending) end
if self.receiving then wipe(self.receiving) end
if self.cooldowns then wipe(self.cooldowns) end
if self.incomingCooldown then wipe(self.incomingCooldown) end
if self.viewMessages then wipe(self.viewMessages) end
if self.autoQueue then wipe(self.autoQueue) end
if self.autoQueued then wipe(self.autoQueued) end
if self.autoLastRequest then wipe(self.autoLastRequest) end
if self.relayCatalogPending then wipe(self.relayCatalogPending) end
if self.relayCatalogCooldown then wipe(self.relayCatalogCooldown) end
if self.relayQueue then wipe(self.relayQueue) end
if self.relayQueued then wipe(self.relayQueued) end
if self.relayPending then wipe(self.relayPending) end
if self.relayReceiving then wipe(self.relayReceiving) end
if self.relayOwnerPending then wipe(self.relayOwnerPending) end
if self.relayIncomingCooldown then wipe(self.relayIncomingCooldown) end
end
self.activeGuildKey = guildKey
self.activeCharacterKey = characterKey
if type(guildData.ownByCharacter[characterKey]) ~= "table" then
guildData.ownByCharacter[characterKey] = {}
end
self.own = guildData.ownByCharacter[characterKey]
local cutoff = time() - CACHE_TTL
for key, entry in pairs(guildData.players) do
if type(entry) ~= "table" or (tonumber(entry.receivedAt) or 0) < cutoff then
guildData.players[key] = nil
end
end
self.db = db
self.guildData = guildData
return true
end
function Sync:IsGuildMember(name)
local key = KeyName(name)
if not key then return false end
for _, member in ipairs(GVE:GetMembers() or {}) do
if KeyName(member.name) == key then return true end
end
return false
end
function Sync:GetMember(name)
local key = KeyName(name)
for _, member in ipairs(GVE:GetMembers() or {}) do
if KeyName(member.name) == key then return member end
end
end
function Sync:GetOwnCharacterSnapshot(name)
local wanted = KeyName(name)
if not wanted or not self.guildData or type(self.guildData.ownByCharacter) ~= "table" then return nil end
for characterKey, snapshot in pairs(self.guildData.ownByCharacter) do
local characterName = type(characterKey) == "string" and characterKey:match("([^\031]+)$")
if characterName and KeyName(characterName) == wanted and type(snapshot) == "table" then
return snapshot, characterName
end
end
end
function Sync:GetPlayerData(name)
if IsOwn(name) then return self.own end
local cached = self.guildData.players[KeyName(name) or ""]
local ownAlt = self:GetOwnCharacterSnapshot(name)
if ownAlt and (not cached
or (tonumber(ownAlt.professionsCapturedAt) or 0) >= (tonumber(cached.professionsCapturedAt) or 0)) then
return ownAlt
end
return cached
end
function Sync:GetShareableSnapshot(name)
local ownerKey = KeyName(name)
if not ownerKey then return nil end
local cached = self.guildData.players[ownerKey]
local ownAlt = self:GetOwnCharacterSnapshot(name)
if ownAlt and (not cached
or (tonumber(ownAlt.professionsCapturedAt) or 0) >= (tonumber(cached.professionsCapturedAt) or 0)) then
return ownAlt
end
return cached
end
---------------------------------------------------------------------------
-- Lokale Erfassung
---------------------------------------------------------------------------
function Sync:CaptureProfession(showMessage, refreshTimestamp)
if type(self.own) ~= "table" then return false end
local capturedAt, professions, candidateCount = time(), {}, 0
local function AddLink(value, source, logMissing)
if type(value) ~= "string" or value == "" then
if showMessage and logMissing then DebugLog(source.." liefert keinen Link") end
return false
end
candidateCount = candidateCount + 1
local tradeLink, name, skill, maxSkill = ParseTradeLink(value)
if tradeLink then
professions[name] = {name=name, skill=skill, maxSkill=maxSkill, capturedAt=capturedAt, tradeLink=tradeLink}
if showMessage then DebugLog(source.." akzeptiert: "..DebugLink(tradeLink)) end
return true
end
if showMessage and (logMissing or value:find("|Htrade:", 1, true)) then
DebugLog(source.." abgelehnt: "..DebugLink(value))
end
return false
end
if showMessage then
DebugLog("Capture gestartet; GetNumSpellTabs="..type(GetNumSpellTabs)
..", GetSpellTabInfo="..type(GetSpellTabInfo)
..", GetSpellLink="..type(GetSpellLink)
..", GetTradeSkillListLink="..type(GetTradeSkillListLink))
end
-- In 3.3.5a entspricht der zweite Rueckgabewert exakt dem Link, den der
-- Client beim Shift-Klick des Berufs aus dem Zauberbuch in den Chat setzt.
if type(GetNumSpellTabs) == "function" and type(GetSpellTabInfo) == "function" and type(GetSpellLink) == "function" then
local tabCount = math.min(tonumber(GetNumSpellTabs()) or 0, 64)
if showMessage then DebugLog("Zauberbuch-Tabs: "..tabCount) end
for tab = 1, tabCount do
local tabName, _, offset, spellCount = GetSpellTabInfo(tab)
offset, spellCount = tonumber(offset) or 0, math.min(tonumber(spellCount) or 0, 5000)
if showMessage then
DebugLog("Tab "..tab.." ("..tostring(tabName).."): Offset "..offset..", Einträge "..spellCount)
end
for slot = offset + 1, offset + spellCount do
local spellLink, tradeLink = GetSpellLink(slot, BOOKTYPE_SPELL or "spell")
local accepted = AddLink(tradeLink, "GetSpellLink Slot "..slot.." Rückgabewert 2", false)
-- Einige 3.3.5a-Serverimplementierungen geben den Trade-Link
-- abweichend als ersten Wert zurück. Der strikte Parser stellt
-- sicher, dass gewöhnliche Zauberlinks nicht übernommen werden.
if not accepted and type(spellLink) == "string" and spellLink:find("|Htrade:", 1, true) then
AddLink(spellLink, "GetSpellLink Slot "..slot.." Rückgabewert 1", true)
end
end
end
elseif showMessage then
DebugLog("Zauberbuch-APIs sind nicht vollständig verfügbar")
end
-- Fallback fuer Clients, die den Berufslink erst bei geoeffnetem eigenem
-- TradeSkill-Fenster materialisieren. Fremde/verlinkte Fenster ablehnen.
local ownTradeSkill = not (type(IsTradeSkillLinked) == "function" and IsTradeSkillLinked())
local tradeSkillVisible = not TradeSkillFrame or TradeSkillFrame:IsShown()
if showMessage then
DebugLog("Berufefenster-Fallback: eigen="..tostring(ownTradeSkill)
..", sichtbar="..tostring(tradeSkillVisible))
end
if ownTradeSkill and type(GetTradeSkillListLink) == "function" and tradeSkillVisible then
AddLink(GetTradeSkillListLink(), "GetTradeSkillListLink", true)
end
if not next(professions) then
if showMessage then DebugLog("Capture beendet: 0 Berufe aus "..candidateCount.." Link-Kandidaten") end
if showMessage then DEFAULT_CHAT_FRAME:AddMessage("|cff33aaff[GuildView]|r "..L.openProfession) end
return false
end
local unchanged = true
local previous = self.own.professions
if type(previous) ~= "table" then
unchanged = false
else
for name, profession in pairs(professions) do
if type(previous[name]) ~= "table" or previous[name].tradeLink ~= profession.tradeLink then
unchanged = false
break
end
end
if unchanged then
for name in pairs(previous) do
if not professions[name] then unchanged = false break end
end
end
end
if unchanged then
if refreshTimestamp then
-- Eine direkte Datenanfrage bestaetigt, dass diese Links gerade
-- erneut im eigenen Zauberbuch gefunden wurden. Deshalb bekommt
-- auch ein inhaltlich unveraenderter Snapshot einen frischen
-- Synchronisierungszeitpunkt.
for _, profession in pairs(previous) do profession.capturedAt = capturedAt end
self.own.professionsCapturedAt = capturedAt
self.own.receivedAt = capturedAt
end
if showMessage then
local count = 0
for _ in pairs(previous) do count = count + 1 end
DebugLog("Capture beendet: "..count.." Berufe unverändert")
DEFAULT_CHAT_FRAME:AddMessage("|cff33aaff[GuildView]|r "..L.captured)
end
self:RefreshUI()
return true
end
self.own.professions = professions
local oldestAt
for _, profession in pairs(self.own.professions) do
oldestAt = not oldestAt and profession.capturedAt or math.min(oldestAt, profession.capturedAt)
end
self.own.professionsCapturedAt = oldestAt or time()
self.own.receivedAt = time()
if showMessage then
local count = 0
for _ in pairs(self.own.professions) do count = count + 1 end
DebugLog("Capture beendet: "..count.." Berufe gespeichert")
end
if showMessage then DEFAULT_CHAT_FRAME:AddMessage("|cff33aaff[GuildView]|r "..L.captured) end
self:RefreshUI()
if type(self.Announce) == "function" then self:Announce("U") end
return true
end
---------------------------------------------------------------------------
-- Kompaktes, defensiv begrenztes Austauschformat
---------------------------------------------------------------------------
function Sync:SerializeProfessions(snapshot)
local sections, professionKeys, professionCount = {}, {}, 0
local names = {}
for name in pairs(snapshot.professions or {}) do names[#names + 1] = name end
table.sort(names, function(a, b) return Fold(a) < Fold(b) end)
for _, name in ipairs(names) do
local profession = snapshot.professions[name]
local tradeLink = type(profession) == "table" and SafeTradeLink(profession.tradeLink)
if tradeLink then
local safeName = SafeText(name, 128)
local skill = tonumber(profession.skill)
local maxSkill = tonumber(profession.maxSkill)
local capturedAt = tonumber(profession.capturedAt)
local _, linkLabel, linkSkill, linkMaxSkill = ParseTradeLink(tradeLink)
if not safeName or not IsInteger(skill, 0, 1000) or not IsInteger(maxSkill, 0, 1000)
or not IsInteger(capturedAt, 1, time() + 3600) or Fold(linkLabel) ~= Fold(safeName)
or linkSkill ~= skill or linkMaxSkill ~= maxSkill then return nil, "INVALID" end
local professionKey = Fold(safeName)
if professionKeys[professionKey] then return nil, "INVALID" end
professionKeys[professionKey] = true
professionCount = professionCount + 1
if professionCount > 16 then return nil, "TOOBIG" end
sections[#sections + 1] = Encode(safeName).."~"..skill.."~"..maxSkill.."~"..capturedAt.."~"..Encode(tradeLink)
end
end
local payload = table.concat(sections, "^")
if #payload > MAX_BYTES then return nil, "TOOBIG" end
return payload
end
function Sync:DeserializeProfessions(payload, capturedAt)
if type(payload) ~= "string" or payload == "" then return nil end
local professions, professionKeys, professionCount, oldestAt = {}, {}, 0, nil
for _, section in ipairs(Split(payload, "^")) do
local fields = Split(section, "~")
if #fields ~= 5 then return nil end
local name = SafeText(Decode(fields[1] or ""), 128)
local skill, maxSkill, professionCapturedAt = tonumber(fields[2]), tonumber(fields[3]), tonumber(fields[4])
local professionKey = name and Fold(name)
if not name or name == "" or not IsInteger(skill, 0, 1000) or not IsInteger(maxSkill, 0, 1000) or not IsInteger(professionCapturedAt, 1, time() + 3600) or professionKeys[professionKey] then return nil end
professionCount = professionCount + 1
if professionCount > 16 then return nil end
local tradeLink, linkLabel, linkSkill, linkMaxSkill = ParseTradeLink(Decode(fields[5] or ""))
if not tradeLink or Fold(linkLabel) ~= Fold(name) or linkSkill ~= skill or linkMaxSkill ~= maxSkill then return nil end
professionKeys[professionKey] = true
professions[name] = {name=name, skill=skill, maxSkill=maxSkill, capturedAt=professionCapturedAt, tradeLink=tradeLink}
oldestAt = not oldestAt and professionCapturedAt or math.min(oldestAt, professionCapturedAt)
end
return {professions=professions, professionsCapturedAt=oldestAt or capturedAt}
end
function Sync:QueueMessage(message, target, channel)
if #self.sendQueue >= MAX_CHUNKS * 2 then return end
self.sendQueue[#self.sendQueue + 1] = {message=message, target=target, channel=channel or "WHISPER"}
end
function Sync:QueueControlMessage(message, target, channel)
if #self.sendQueue >= MAX_CHUNKS * 2 then return false end
table.insert(self.sendQueue, 1, {message=message, target=target, channel=channel or "WHISPER"})
return true
end
local function NewRequestID()
return tostring(math.floor(GetTime() * 1000) % 10000000)..tostring(math.random(100, 999))
end
function Sync:PruneCachedPlayers()
local cached = {}
for key, value in pairs(self.guildData.players) do
cached[#cached + 1] = {key=key, receivedAt=tonumber(value.receivedAt) or 0}
end
table.sort(cached, function(a, b) return a.receivedAt < b.receivedAt end)
while #cached > MAX_CACHED_PLAYERS do
self.guildData.players[cached[1].key] = nil
table.remove(cached, 1)
end
end
function Sync:RequestRelayCatalog(peer, force)
local clean, key = CleanName(peer), KeyName(peer)
local member = clean and self:GetMember(clean)
if not clean or not key or IsOwn(clean) or not member or not member.online then return false end
local now = GetTime()
if self.relayCatalogPending[key] then return false end
if not force and self.relayCatalogCooldown[key]
and now - self.relayCatalogCooldown[key] < AUTO_REQUEST_RETRY then return false end
local requestID = NewRequestID()
self.relayCatalogPending[key] = {requestID=requestID, deadline=now + REQUEST_TIMEOUT}
self.relayCatalogCooldown[key] = now
if self:QueueControlMessage("C|"..requestID, clean) then return true end
self.relayCatalogPending[key] = nil
return false
end
function Sync:SendRelayCatalog(target, requestID)
local catalogByOwner = {}
local function AddCatalogEntry(owner, entry)
owner = CleanName(owner)
local ownerKey = KeyName(owner)
local stamp = type(entry) == "table" and tonumber(entry.professionsCapturedAt)
if owner and ownerKey and stamp and entry.professions and self:IsGuildMember(owner)
and IsInteger(stamp, 1, time() + 3600) then
local previous = catalogByOwner[ownerKey]
if not previous or stamp > previous.stamp then
catalogByOwner[ownerKey] = {owner=owner, stamp=stamp}
end
end
end
for _, entry in pairs(self.guildData.players or {}) do
-- Auch weitergeleitete Snapshots duerfen erneut angeboten werden.
-- Empfaenger akzeptieren sie nur bei strikt neuerem Besitzer-Zeitstempel;
-- dadurch laufen identische Daten nicht im Kreis.
AddCatalogEntry(type(entry) == "table" and entry.displayName, entry)
end
-- Accountweite SavedVariables erlauben es, auch eigene derzeit offline
-- Twinks mit ihrem letzten selbst erfassten Stand anzubieten.
if self.db.settings.shareProfessions then
for characterKey, entry in pairs(self.guildData.ownByCharacter or {}) do
local owner = type(characterKey) == "string" and characterKey:match("([^\031]+)$")
if not IsOwn(owner) then AddCatalogEntry(owner, entry) end
end
end
local catalog = {}
for _, value in pairs(catalogByOwner) do catalog[#catalog + 1] = value end
table.sort(catalog, function(a, b) return KeyName(a.owner) < KeyName(b.owner) end)
for _, value in ipairs(catalog) do
self:QueueMessage("V|"..requestID.."|"..Encode(value.owner).."|"..value.stamp, target)
end
self:QueueMessage("K|"..requestID, target)
DebugLog("Relay-Katalog an "..target..": "..#catalog.." neueste Snapshots")
end
function Sync:QueueRelayCandidate(peer, owner, advertisedAt)
local cleanPeer, cleanOwner = CleanName(peer), CleanName(owner)
local peerKey, ownerKey = KeyName(cleanPeer), KeyName(cleanOwner)
local stamp = tonumber(advertisedAt)
if not cleanPeer or not cleanOwner or not peerKey or not ownerKey
or peerKey == ownerKey or IsOwn(cleanOwner) or not self:IsGuildMember(cleanOwner)
or not IsInteger(stamp, 1, time() + 3600) then return false end
-- Vergleiche gegen den besten lokal bekannten Stand. Dazu gehoeren auch
-- eigene, derzeit offline gespielte Charaktere aus den SavedVariables.
local cached = self:GetPlayerData(cleanOwner)
if cached and (tonumber(cached.professionsCapturedAt) or 0) >= stamp then return false end
if self.relayOwnerPending[ownerKey] then return false end
local queued = self.relayQueued[ownerKey]
if queued then
if stamp > queued.stamp then queued.peer, queued.stamp = cleanPeer, stamp end
return true
end
local candidate = {peer=cleanPeer, owner=cleanOwner, ownerKey=ownerKey, stamp=stamp}
self.relayQueued[ownerKey] = candidate
self.relayQueue[#self.relayQueue + 1] = candidate
return true
end
function Sync:RequestRelayedSnapshot(candidate)
if type(candidate) ~= "table" then return false end
local cached = self:GetPlayerData(candidate.owner)
if cached and (tonumber(cached.professionsCapturedAt) or 0) >= candidate.stamp then return false end
local requestID = NewRequestID()
local peerKey = KeyName(candidate.peer)
local transferKey = peerKey.."|"..requestID
self.relayPending[transferKey] = {
requestID=requestID, peer=candidate.peer, owner=candidate.owner,
ownerKey=candidate.ownerKey, advertisedAt=candidate.stamp,
started=GetTime(), deadline=GetTime() + ABSOLUTE_TRANSFER_TIMEOUT,
}
self.relayOwnerPending[candidate.ownerKey] = transferKey
SendAddonMessage(PREFIX, "R|"..requestID.."|"..Encode(candidate.owner), "WHISPER", candidate.peer)
return true
end
function Sync:SendRelayedSnapshot(target, requestID, owner)
local entry = self:GetShareableSnapshot(owner)
local ownAlt = self:GetOwnCharacterSnapshot(owner)
if entry == ownAlt and not self.db.settings.shareProfessions then return false end
if not entry or not entry.professions or not self:IsGuildMember(owner) then return false end
local payload = self:SerializeProfessions(entry)
if not payload or payload == "" or #payload > MAX_BYTES then return false end
local chunks = math.ceil(#payload / CHUNK_BYTES)
if chunks < 1 or chunks > MAX_CHUNKS or #self.sendQueue + chunks + 2 > MAX_CHUNKS * 2 then return false end
local capturedAt = tonumber(entry.professionsCapturedAt)
if not IsInteger(capturedAt, 1, time() + 3600) then return false end
self:QueueMessage("RB|"..requestID.."|"..Encode(owner).."|"..capturedAt.."|"..chunks, target)
for index = 1, chunks do
self:QueueMessage("RD|"..requestID.."|"..index.."|"..payload:sub((index - 1) * CHUNK_BYTES + 1, index * CHUNK_BYTES), target)
end
self:QueueMessage("RE|"..requestID, target)
DebugLog("Relay-Snapshot "..owner.." an "..target.." gesendet")
return true
end
function Sync:Announce(command, target)
if not target and type(IsInGuild) == "function" and not IsInGuild() then return false end
if command ~= "H" then
if not self.db or not self.db.settings.shareProfessions
or not self.own or not self.own.professions then return false end
end
local stamp = self.own and tonumber(self.own.professionsCapturedAt) or 0
local message = command.."|"..math.max(0, math.floor(stamp or 0))
if target then return self:QueueControlMessage(message, target, "WHISPER") end
self:QueueMessage(message, nil, "GUILD")
return true
end
function Sync:QueueAutoRequest(name, advertisedAt, force)
local clean, stamp = CleanName(name), tonumber(advertisedAt)
local key = KeyName(clean)
local minimumStamp = force and 0 or 1
if not clean or not key or IsOwn(clean) or not IsInteger(stamp, minimumStamp, time() + 3600) then return false end
local member = self:GetMember(clean)
if not member then return false end
local cached = self:GetPlayerData(clean)
if not force and cached and cached.professions and (tonumber(cached.professionsCapturedAt) or 0) >= stamp then return false end
local now = GetTime()
if self.pending[key] or self.autoQueued[key]
or not force and self.autoLastRequest[key] and now - self.autoLastRequest[key] < AUTO_REQUEST_RETRY then return false end
if force then
-- Der manuelle Knopf ist eine ausdrueckliche Benutzeraktion und darf
-- deshalb einen alten automatischen Retry-/Cooldown-Zeitpunkt umgehen.
self.autoLastRequest[key] = nil
self.cooldowns[key] = nil
end
self.autoQueued[key] = true
self.autoQueue[#self.autoQueue + 1] = {name=clean, key=key, force=force and true or false}
return true
end
function Sync:ManualBroadcastSync()
if not self.db then return false end
-- Eigene Links unmittelbar neu einlesen. Auch wenn sie unveraendert sind,
-- wird danach U gesendet: Der Benutzer hat den Push bewusst angefordert.
local captured = self:CaptureProfession(false, true)
if captured and self.own and self.own.professions then
if self.db.settings.shareProfessions then self:Announce("U") end
end
-- H ist der kompatible, gildenweite Discovery-Broadcast. Auch aeltere
-- Addon-Releases mit demselben Protokoll kennen ihn und antworten per A.
-- Antworten in diesem kurzen Fenster werden absichtlich erneut abgefragt,
-- selbst wenn der lokale Cache denselben Zeitstempel meldet.
self.forceDiscoveryUntil = GetTime() + REQUEST_TIMEOUT
-- Bereits bekannte Online-Mitglieder werden sofort eingeplant. Der
-- Guild-Broadcast bleibt zusaetzlich aktiv, damit auch gerade erst
-- entdeckte kompatible Clients antworten koennen.
wipe(self.autoQueue)
wipe(self.autoQueued)
wipe(self.relayQueue)
wipe(self.relayQueued)
local directRequests = 0
for _, member in ipairs(GVE:GetMembers() or {}) do
if member.online and not IsOwn(member.name) then
local memberKey = KeyName(member.name)
if memberKey then
self.pending[memberKey] = nil
self.receiving[memberKey] = nil
self.viewMessages[memberKey] = nil
self.relayCatalogPending[memberKey] = nil
end
if self:QueueAutoRequest(member.name, 0, true) then directRequests = directRequests + 1 end
self:RequestRelayCatalog(member.name, true)
end
end
self:Announce("H")
DebugLog("Manuelle Gildensynchronisierung: "..directRequests.." direkte Online-Anfragen + Guild-Broadcast")
if DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.AddMessage then
DEFAULT_CHAT_FRAME:AddMessage("|cff33aaff[GuildView]|r "..L.syncSent)
end
return true
end
function Sync:SendSnapshot(target, requestID)
if not self.db.settings.shareProfessions then
self:QueueControlMessage("N|"..requestID.."|DENIED", target)
return
end
if #self.sendQueue > MAX_QUEUE_BEFORE_BUSY then
self:QueueControlMessage("N|"..requestID.."|BUSY", target)
return
end
local payload, payloadError
if self.own.professions then payload, payloadError = self:SerializeProfessions(self.own) end
local capturedAt = self.own.professionsCapturedAt
if payloadError then
self:QueueControlMessage("N|"..requestID.."|TOOBIG", target)
return
end
if not payload or payload == "" then
self:QueueControlMessage("N|"..requestID.."|EMPTY", target)
return
end
if #payload > MAX_BYTES then
self:QueueControlMessage("N|"..requestID.."|TOOBIG", target)
return
end
local chunks = math.ceil(#payload / CHUNK_BYTES)
if chunks < 1 then chunks = 1 end
if chunks > MAX_CHUNKS then
self:QueueControlMessage("N|"..requestID.."|TOOBIG", target)
return
end
if #self.sendQueue + chunks + 2 > MAX_CHUNKS * 2 then
self:QueueControlMessage("N|"..requestID.."|BUSY", target)
return
end
DebugLog("Sende Berufs-Snapshot an "..tostring(target)..": "..chunks.." Teil(e), Zeitstempel "..tostring(capturedAt))
self:QueueMessage("B|"..requestID.."|"..(tonumber(capturedAt) or time()).."|"..chunks, target)
for index = 1, chunks do
local part = payload:sub((index - 1) * CHUNK_BYTES + 1, index * CHUNK_BYTES)
self:QueueMessage("D|"..requestID.."|"..index.."|"..part, target)
end
self:QueueMessage("E|"..requestID, target)
end
function Sync:Request(name, automatic, force)
local clean = CleanName(name)
local key = KeyName(clean)
if not clean or not key or not self:IsGuildMember(clean) then return end
if IsOwn(clean) then
self:CaptureProfession(true)
return
end
local now = GetTime()
if self.pending[key] then return false end
if not force and self.cooldowns[key] and now - self.cooldowns[key] < REQUEST_COOLDOWN then return end
self.cooldowns[key] = now
if automatic then self.autoLastRequest[key] = now end
local requestID = NewRequestID()
self.pending[key] = {
started=now, lastActivity=now, deadline=now + ABSOLUTE_TRANSFER_TIMEOUT,
requestID=requestID, requireFresh=force and true or false,