forked from kahluamods/konfersk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKKonferSK.lua
2049 lines (1715 loc) · 55.8 KB
/
KKonferSK.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
--[[
KahLua KonferSK - a suicide kings loot distribution addon.
WWW: http://kahluamod.com/ksk
Git: https://github.com/kahluamods/konfersk
IRC: #KahLua on irc.freenode.net
E-mail: [email protected]
Please refer to the file LICENSE.txt for the Apache License, Version 2.0.
Copyright 2008-2021 James Kean Johnston. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
]]
local MAJOR= "KKonferSK"
local MINOR = tonumber("@revision@")
local MINOR = 1 -- @debug-delete@
local K,KM = LibStub:GetLibrary("KKore")
local H = LibStub:GetLibrary("KKoreHash")
local KUI = LibStub:GetLibrary("KKoreUI")
local KRP = LibStub:GetLibrary("KKoreParty")
local KLD = LibStub:GetLibrary("KKoreLoot")
local KK = LibStub:GetLibrary("KKoreKonfer")
local DB = LibStub:GetLibrary("AceDB-3.0")
local ZL = LibStub:GetLibrary("LibDeflate")
local LS = LibStub:GetLibrary("LibSerialize")
if (not K) then
error("KSK: could not find KahLua Kore.", 2)
end
if (tonumber(KM) < 5) then
error("KSK: outdated KahLua Kore. Please update all KahLua addons.")
end
if (not H) then
error("KSK: could not find Kore Hash library.", 2)
end
if (not DB) then
error("KSK: could not find Kore Database library.", 2)
end
if (not KUI) then
error("KSK: could not find Kore UI library.", 2)
end
if (not KRP) then
error("KSK: could not find Kore Raid/Party library.", 2)
end
if (not KK) then
error("KSK: could not find Kore Konfer library.", 2)
end
if (not KLD) then
error("KSK: could not find Kore Loot Distribution library.", 2)
end
if (not ZL) then
error("KSK: could not find LibDeflate library.", 2)
end
if (not LS) then
error("KSK: could not find LibSerialize library.", 2)
end
local L = LibStub("AceLocale-3.0"):GetLocale(MAJOR, false)
-- Local aliases for global or Lua library functions
local _G = _G
local tinsert = table.insert
local tonumber = tonumber
local strfmt = string.format
local strsub = string.sub
local strlower = string.lower
local match = string.match
local pairs, ipairs, type = pairs, ipairs, type
local printf = K.printf
local LOOT_METHOD_UNKNOWN = KRP.LOOT_METHOD_UNKNWON
local LOOT_METHOD_FREEFORALL = KRP.LOOT_METHOD_FREEFORALL
local LOOT_METHOD_GROUP = KRP.LOOT_METHOD_GROUP
local LOOT_METHOD_PERSONAL = KRP.LOOT_METHOD_PERSONAL
local LOOT_METHOD_MASTER = KRP.LOOT_METHOD_MASTER
ksk = K:NewAddon(nil, MAJOR, MINOR, L["Suicide Kings loot distribution system."], L["MODNAME"], L["CMDNAME"] )
if (not ksk) then
error("KahLua KonferSK: addon creation failed.", 2)
end
ksk.KUI = KUI
ksk.L = L
ksk.KRP = KRP
ksk.KLD = KLD
ksk.H = H
ksk.DB = DB
ksk.KK = KK
ksk.ZL = ZL
ksk.LS = LS
ksk.CHAT_MSG_PREFIX = "KSKC"
ksk.addon_handle = "kskc"
local MakeFrame = KUI.MakeFrame
-- We will be using both KKoreParty and KKoreLoot.
KRP:RegisterAddon(ksk.addon_handle)
KLD:RegisterAddon(ksk.addon_handle)
KK:RegisterAddon(ksk.addon_handle)
-------------------------------------------------------------------------------
--
-- KSK "global" variables. All variables, whether they can be nil or not, that
-- can possibly be set in the ksk namespace, must be listed here, along with
-- their default value. A description of what the variable controls and which
-- user interface element is affected by the variable must accompany each such
-- global variable. This includes variables used in other files. They must all
-- be declared and described here.
--
-------------------------------------------------------------------------------
-- The version number of this release of KSK. This is set by the prep script
-- when it sets MINOR above. For debug / development releases this is always
-- set to 1. This is used in the version check code as well as the mod info
-- display and mod registration.
ksk.version = MINOR
-- The KSK "protocol" version number. This is used in every addon message
-- that KSK sends. As a general principle someone with a version of the mod
-- that has a higher protocol version number should be able to decode messages
-- from a lower version protocol, but so far we have made no attempt to code
-- this backwards compatibility into each protocol message. So at the moment
-- these protocol versions must match exactly in order for two KSK mods to
-- talk to each other.
-- 1 - internal only (version check)
-- 2 - initial protocol
-- 3 - dates now in UTC seconds since epoch for history
-- 4 - OROLL now has extra param for allowing offspec rolls
-- 5 - resurect guild config and rank priorities
-- 6 - alt tethered now a list option not global
-- 7/8 - can't remember
-- 9 - after rework and LZ/LS changes
ksk.protocol = 9
-- The format and "shape" of the KSK stored variables database. As various new
-- features have been added or bugs fixed, this changes. The code in the file
-- KSK-Utility.lua (ksk:UpdateDatabaseVersion()) will update older databases
-- dating all the way back to version 1. Once a database version has been
-- upgraded it cannot be reverted.
ksk.dbversion = 6
-- Whether or not KSK has been fully initialised. This can take a while as
-- certain bits of information are not immediately available on login.
-- None of the event handlers or callback functions except those participating
-- in actual initialisation should execute if this is false.
ksk.initialised = false
-- Maximum number of disenchanters that can be defined in a config
ksk.MAX_DENCHERS = 3
-- Constants used to define the various UI tabs and sub-tabs. These should
-- never be changed by code.
ksk.LISTS_TAB = 1
ksk.LISTS_MEMBERS_PAGE = 1
ksk.LISTS_CONFIG_PAGE = 2
ksk.LOOT_TAB = 2
ksk.LOOT_ASSIGN_PAGE = 1
ksk.LOOT_ITEMS_PAGE = 2
ksk.LOOT_HISTORY_PAGE = 3
ksk.USERS_TAB = 3
ksk.SYNC_TAB = 4
ksk.CONFIG_TAB = 5
ksk.CONFIG_LOOT_PAGE = 1
ksk.CONFIG_ROLLS_PAGE = 2
ksk.CONFIG_ADMIN_PAGE = 3
ksk.NON_ADMIN_THRESHOLD = ksk.USERS_TAB
ksk.NON_ADMIN_CONFIG_THRESHOLD = ksk.CONFIG_ROLLS_PAGE
-- Constants used too define the index into each table element for the loot
-- history.
ksk.HIST_WHEN = 1
ksk.HIST_WHAT = 2
ksk.HIST_WHO = 3
ksk.HIST_HOW = 4
ksk.HIST_POS = 5
-- Table of users currently in the group. This is indexed by KSK uid and
-- contains the full player name. This in turn can be used to access
-- KRP.players, also indexed by the full name, which contains the detailed
-- info about the raid / party member. The uid index used is for the actual
-- character in the raid. If the character is an alt, it will be the alt's
-- uid that is used and any code will need to check for that if it is
-- important.
ksk.users = nil
-- Table of disenchanters currently available.
ksk.denchers = nil
-- Handle to the return value from database initialisation. This is set early
-- on in the initialisation process. No code other than that initialisation
-- code should ever touch this.
ksk.db = nil
-- The faction and realm database. This is the root of all stored configuration
-- variables and is set during initialisation. This is a convenience alias for
-- ksk.db.factionrealm.
ksk.frdb = nil
-- Convenience alias for ksk.db.factionrealm.configs
ksk.configs = nil
-- The ID of the currently selected configuration or nil if none (rare).
ksk.currentid = nil
-- The config database for the currently selected configuration or nil if no
-- config is currently active. This is a convenience alias for
-- ksk.db.factionrealm.configs[ksk.currentid].
ksk.cfg = nil
-- The number of raiders currently in the raid group that are missing from the
-- users list, and the actual list of such missing players. Each entry in the
-- missing table is itself a table with the members "name" and "class", where
-- "name" is the full player-realm name of the player and class is the KKore
-- class number (for example K.CLASS_DRUID) of the missing player. These are
-- set to 0 and nil respectively when not in a raid.
ksk.nmissing = 0
ksk.missing = {}
-- Cached session data. This is a table, with one entry per defined config in
-- the config file, and stores convenience data frequently accessed from each
-- config. Typically these are computed values and therefore not stored in the
-- actual database that is saved each time the user logs out. The table is
-- indexed by config id.
ksk.csdata = {}
-- The sorted list of lists. This is almost never nil, even if the config has
-- no defined lists (it will just be an empty table). When not empty it
-- contains the sorted list of lists for the current config. It is refreshed
-- when the lists UI is refreshed by ksk:RefreshListsUI().
ksk.sortedlists = nil
-- Set to true if the main KSK window was automatically opened.
ksk.autoshown = nil
-- The default values for a new configuration.
ksk.defaults = {
auto_bid = true,
silent_bid = false,
tooltips = true,
announce_where = 0,
def_list = "0",
def_rank = 0,
auto_loot = true,
boe_to_ml = true, -- Assign BoE items to Master-Looter
disenchant = true, -- Assign to disenchanter
use_decay = false,
chat_filter = true, -- Enable chat message filter
history = true, -- Record loot history
roll_timeout = 10,
roll_extend = 5,
try_roll = false,
bid_threshold = 0,
disenchant_below = false,
offspec_rolls = true,
suicide_rolls = false,
ann_bidchanges = true,
ann_winners_raid = true,
ann_winners_guild = true,
ann_bid_progress = true,
ann_bid_usage = true,
ann_roll_usage = true,
ann_countdown = true,
ann_roll_ties = true,
ann_cancel = true,
ann_no_bids = true,
ann_missing = true,
hide_absent = false,
use_ranks = false,
rank_prio = {},
denchers = {},
}
-- The main UI window handle, which is a KUI frame.
ksk.mainwin = nil
-- The global popup window. There can only be one popup window active at a
-- time and if that window is currently up, this will be the frame for it.
-- Otherwise it is nil.
ksk.popupwindow = nil
-- The global quickframe cache. Each UI panel should maintain its own
-- quickframe cache. This is only for the very top level UI frames.
ksk.qf = {}
-------------------------------------------------------------------------------
local admin_hooks_registered = nil
local ml_hooks_registered = nil
local chat_filters_installed = nil
local sentoloot = nil
local ucolor = K.ucolor
local ecolor = K.ecolor
local icolor = K.icolor
local function debug(lvl,...)
K.debug(L["MODNAME"], lvl, ...)
end
local function err(msg, ...)
local str = L["MODTITLE"] .. " " .. L["error: "] .. strfmt(msg, ...)
printf(ecolor, "%s", str)
end
local function info(msg, ...)
local str = L["MODTITLE"] .. ": " .. strfmt(msg, ...)
printf(icolor, "%s", str)
end
ksk.debug = debug
ksk.err = err
ksk.info = info
ksk.white = K.white
ksk.red = K.red
ksk.green = K.green
ksk.yellow = K.yellow
ksk.class = KRP.ClassString
ksk.shortclass = KRP.ShortClassString
ksk.aclass = KRP.AlwaysClassString
ksk.shortaclass = KRP.ShortAlwaysClassString
local white = K.white
local class = KRP.ClassString
-- cfg is known to be valid before this is called
local function get_my_ids(self, cfg)
local uid = self:FindUser(K.player.name, cfg)
if (not uid) then
return nil, nil
end
local ia, main = self:UserIsAlt(uid, nil, cfg)
if (ia) then
return uid, main
else
return uid, uid
end
end
local function extract_cmd(msg)
local lm = strlower(msg)
lm = lm:gsub("^%s*", "")
lm = lm:gsub("%s*$", "")
if ((lm == L["WHISPERCMD_BID"]) or
(lm == L["WHISPERCMD_RETRACT"]) or
(lm == L["WHISPERCMD_SUICIDE"]) or
(lm == L["WHISPERCMD_SUICIDE_ALTERNATE"]) or
(lm == L["WHISPERCMD_STANDBY"]) or
(lm == L["WHISPERCMD_HELP"]) or
(lm == "bid") or (lm == "retract") or (lm == "suicide") or
(lm == "position") or (lm == "standby") or (lm == "help")) then
return lm
end
end
local function whisper_filter(self, evt, msg, ...)
if (extract_cmd(msg)) then
return true
end
end
local titlematch = "^" .. L["MODTITLE"] .. ": "
local abbrevmatch = "^" .. L["MODABBREV"] .. ": "
local function reply_filter(self, evt, msg, snd, ...)
local sender = K.CanonicalName(snd, nil)
if (strmatch(msg, titlematch)) then
if (evt == "CHAT_MSG_WHISPER_INFORM") then
return true
elseif (sender == K.player.name) then
return true
end
end
if (strmatch(msg, abbrevmatch)) then
if (evt == "CHAT_MSG_WHISPER_INFORM") then
return true
elseif (sender == K.player.name) then
return true
end
end
end
local function chat_msg_whisper(evt, msg, snd, ...)
local sender = K.CanonicalName(snd, nil)
local cmd = extract_cmd(msg)
if (cmd) then
if (cmd == "bid" or cmd == L["WHISPERCMD_BID"]) then
return ksk:NewBidder(sender)
elseif (cmd == "retract" or cmd == L["WHISPERCMD_RETRACT"]) then
return ksk:RetractBidder(sender)
elseif (cmd == "suicide" or cmd == L["WHISPERCMD_SUICIDE"] or cmd == L["WHISPERCMD_SUICIDE_ALTERNATE"]) then
local uid = ksk:FindUser(sender)
if (not uid) then
ksk:SendWhisper(strfmt(L["%s: you are not on any roll lists (yet)."], L["MODABBREV"]), sender)
return
end
local sentheader = false
local ndone = 0
for k,v in pairs(ksk.sortedlists) do
local lp = ksk.cfg.lists[v.id]
local apos, rpos = get_user_pos(uid, lp)
if (apos) then
ndone = ndone + 1
if (not sentheader) then
ksk:SendWhisper(strfmt(L["LISTPOSMSG"], L["MODABBREV"], ksk.cfg.name, L["MODTITLE"]), sender)
sentheader = true
end
if (ksk.users) then
ksk:SendWhisper(strfmt(L["%s: %s - #%d (#%d in raid)"], L["MODABBREV"], lp.name, apos, rpos), sender)
else
ksk:SendWhisper(strfmt("%s: %s - #%d", L["MODABBREV"], lp.name, apos), sender)
end
end
end
if (ndone > 0) then
ksk:SendWhisper(strfmt(L["%s: (End of list)"], L["MODABBREV"]), sender)
else
ksk:SendWhisper(strfmt(L["%s: you are not on any roll lists (yet)."], L["MODABBREV"]), sender)
end
elseif (cmd == "help" or cmd == L["WHISPERCMD_HELP"]) then
ksk:SendWhisper(strfmt(L["HELPMSG1"], L["MODABBREV"], L["MODTITLE"], L["MODABBREV"]), sender)
ksk:SendWhisper(strfmt(L["HELPMSG2"], L["MODABBREV"], L["WHISPERCMD_BID"]), sender)
ksk:SendWhisper(strfmt(L["HELPMSG3"], L["MODABBREV"], L["WHISPERCMD_RETRACT"]), sender)
ksk:SendWhisper(strfmt(L["HELPMSG4"], L["MODABBREV"], L["WHISPERCMD_SUICIDE"]), sender)
ksk:SendWhisper(strfmt(L["HELPMSG5"], L["MODABBREV"], L["WHISPERCMD_STANDBY"]), sender)
end
end
end
--
-- Fired whenever our admin status for the currently selected config changes,
-- or when we refresh due to a config change or other events. This registers
-- messages that only an admin cares about.
--
local function config_admin(self)
local onoff = self.csdata[self.currentid].is_admin ~= nil and true or false
if (onoff and admin_hooks_registered ~= true) then
admin_hooks_registered = true
self:RegisterEvent("CHAT_MSG_WHISPER", chat_msg_whisper)
elseif (not onoff and admin_hooks_registered == true) then
admin_hooks_registered = false
self:UnregisterEvent("CHAT_MSG_WHISPER")
end
local ef = nil
if (onoff) then
if (chat_filters_installed ~= true) then
if (self.cfg.settings.chat_filter) then
chat_filters_installed = true
ef = ChatFrame_AddMessageEventFilter
end
end
end
if (not onoff or not self.cfg.settings.chat_filter) then
if (chat_filters_installed) then
chat_filters_installed = nil
ef = ChatFrame_RemoveMessageEventFilter
end
end
if (ef) then
ef("CHAT_MSG_WHISPER", whisper_filter)
ef("CHAT_MSG_WHISPER_INFORM", reply_filter)
ef("CHAT_MSG_RAID", reply_filter)
ef("CHAT_MSG_GUILD", reply_filter)
ef("CHAT_MSG_RAID_LEADER", reply_filter)
end
end
function ksk:UpdateUserSecurity(conf)
local conf = conf or self.currentid
if (not conf or not self.frdb or not self.frdb.configs
or not self.frdb.configs[conf] or not self.csdata
or not self.csdata[conf]) then
return false
end
local csd = self.csdata[conf]
local cfg = self.frdb.configs[conf]
csd.myuid, csd.mymainid = get_my_ids(self, conf)
csd.is_admin = nil
if (csd.myuid) then
if (cfg.owner == csd.myuid or cfg.owner == csd.mymainid) then
csd.is_admin = 2
elseif (self:UserIsCoadmin(csd.myuid, conf)) then
csd.is_admin = 1
elseif (self:UserIsCoadmin(csd.mymainid, conf)) then
csd.is_admin = 1
end
end
if (self.initialised and conf == self.currentid) then
config_admin(self)
end
return true
end
function ksk:AmIML()
if (KRP.is_ml and self.csdata[self.currentid].is_admin) then
return true
end
return false
end
function ksk:IsAdmin(uid, cfg)
local cfg = cfg or self.currentid
if (not cfg or not self.frdb.configs or not self.frdb.configs[cfg]) then
return nil, nil
end
local uid = uid or self:FindUser(K.player.name, cfg)
if (not uid) then
return nil, nil
end
if (self.frdb.configs[cfg].owner == uid) then
return 2, uid
end
if (self:UserIsCoadmin(uid, cfg)) then
return 1, uid
end
local isalt, main = self:UserIsAlt(uid, nil, cfg)
if (isalt) then
if (self.configs[cfg].owner == main) then
return 2, main
end
if (self:UserIsCoadmin(main, cfg)) then
return 1, main
end
end
return nil, nil
end
local ts_datebase = nil
local ts_evtcount = 0
local function check_config()
if (ksk.frdb.tempcfg) then
info(strfmt(L["no active configuration. Either create one with %s or wait for a guild admin to broadcast the guild list."], white(strfmt("/%s %s", L["CMDNAME"], L["CMD_CREATECONFIG"]))))
return true
end
return false
end
local function ksk_version()
printf (ucolor, L["%s<%s>%s %s (version %d) - %s"],
"|cffff2222", K.KAHLUA, "|r", L["MODTITLE"], MINOR,
L["Suicide Kings loot distribution system."])
end
local function ksk_versioncheck()
ksk:VersionCheck()
end
local function ksk_usage()
ksk_version()
printf(ucolor, L["Usage: "] .. white(strfmt(L["/%s [command [arg [arg...]]]"], L["CMDNAME"])))
printf(ucolor, white(strfmt("/%s [%s]", L["CMDNAME"], L["CMD_LISTS"])))
printf(ucolor, L[" Open the list management window."])
printf(ucolor, white(strfmt("/%s %s", L["CMDNAME"], L["CMD_USERS"])))
printf(ucolor, L[" Opens the user list management window."])
printf(ucolor, white(strfmt("/%s %s [%s | %s]", L["CMDNAME"], L["CMD_LOOT"], L["SUBCMD_ASSIGN"], L["SUBCMD_ITEMS"])))
printf(ucolor, L[" Opens the loot management window."])
printf(ucolor, white(strfmt("/%s %s", L["CMDNAME"], L["CMD_SYNC"])))
printf(ucolor, L[" Opens the sync manager window."])
printf(ucolor, white(strfmt("/%s %s", L["CMDNAME"], L["CMD_SUSPEND"])))
printf(ucolor, strfmt(L[" Suspend %s (no auto-open on loot, no missing member warnings etc)."], L["MODTITLE"]))
printf(ucolor, white(strfmt("/%s %s", L["CMDNAME"], L["CMD_RESUME"])))
printf(ucolor, strfmt(L[" Resume normal %s operations."], L["MODTITLE"]))
printf(ucolor, white(strfmt("/%s %s [%s | %s]", L["CMDNAME"], L["CMD_CONFIG"], L["SUBCMD_LOOT"], L["SUBCMD_ADMIN"])))
printf(ucolor, L[" Set up various options and manage configurations."])
printf(ucolor, white(strfmt(L["/%s %s name"], L["CMDNAME"], L["CMD_SELECTCONFIG"])))
printf(ucolor, L[" Selects the specified configuration as the current one."])
printf(ucolor, white(strfmt(L["/%s %s name"], L["CMDNAME"], L["CMD_CREATECONFIG"])))
printf(ucolor, L[" Create the specified configuration."])
printf(ucolor, white(strfmt(L["/%s %s name"], L["CMDNAME"], L["CMD_DELETECONFIG"])))
printf(ucolor, L[" Delete the specified configuration."])
printf(ucolor, white(strfmt(L["/%s %s oldname newname"], L["CMDNAME"], L["CMD_COPYCONFIG"])))
printf(ucolor, L[" Copies the specified configuration to a new one, with options."])
printf(ucolor, white(strfmt(L["/%s %s oldname newname"], L["CMDNAME"], L["CMD_RENAMECONFIG"])))
printf(ucolor, L[" Renames the specified configuration."])
-- User list management commands
printf(ucolor, white(strfmt(L["/%s %s name class"], L["CMDNAME"], L["CMD_CREATEUSER"])))
printf(ucolor,L[" Adds a new user to the users list."])
printf(ucolor, white(strfmt(L["/%s %s name"], L["CMDNAME"], L["CMD_DELETEUSER"])))
printf(ucolor,L[" Removes a user from the users list."])
printf(ucolor, white(strfmt(L["/%s %s oldname newname"], L["CMDNAME"], L["CMD_RENAMEUSER"])))
printf(ucolor,L[" Renames a user after a paid name change."])
printf(ucolor,white(strfmt(L["/%s %s [itemid | itemlink]"], L["CMDNAME"], L["CMD_ADDITEM"])))
printf(ucolor,L[" Adds a new item to the item list."])
printf(ucolor,white(strfmt(L["/%s %s [itemid | itemlink]"], L["CMDNAME"], L["CMD_ADDLOOT"])))
printf(ucolor,L[" Adds a new item to the loot list."])
end
local function common_verify_input(input, cmd, exist, bypass, tbl, nexmsg, exmsg)
if (not bypass and ksk:CheckPerm()) then
return true
end
local found = false
local nname, pos
local retid = 0
local kcmd = L["CMDNAME"]
if (not input or input == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s name"], kcmd, cmd)))
return true
end
nname, pos = K.GetArgs(input)
if (not nname or nname == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s name"], kcmd, cmd)))
return true
end
if (pos ~= 1e9) then
err(L["Usage: "] .. white(strfmt(L["/%s %s name"], kcmd, cmd)))
return true
end
if (type(tbl) == "string" and tbl == "special") then
return false, nname
end
local low = strlower(nname)
if (tbl) then
for k,v in pairs(tbl) do
if (strlower(v.name) == low) then
found = true
retid = k
end
end
end
if (exist) then
if (not found) then
err(nexmsg, white(nname))
return true
end
else
if (found) then
err(exmsg, white(nname))
return true
end
end
return false, nname, found, retid
end
local function common_verify_input2(input, cmd, exist, bypass, tbl, nexmsg, exmsg)
if (not bypass and ksk:CheckPerm()) then
return true
end
if (not tbl) then
return true
end
local oldname, newname, pos
local found = 0
local retid = 0
local kcmd = L["CMDNAME"]
if (not input or input == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s oldname newname"], kcmd, cmd)))
return true
end
oldname, newname, pos = K.GetArgs(input, 2)
if (not oldname or oldname == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s oldname newname"], kcmd, cmd)))
return true
end
if (not newname or newname == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s oldname newname"], kcmd, cmd)))
return true
end
if (pos ~= 1e9) then
err(L["Usage: "] .. white(strfmt(L["/%s %s oldname newname"], kcmd, cmd)))
return true
end
if (oldname == newname) then
return true
end
if (type(tbl) == "string" and tbl == "special") then
return false, oldname, newname
end
local lnew = strlower(newname)
local lold = strlower(oldname)
if (tbl) then
for k,v in pairs(tbl) do
if (strlower(v.name) == lnew) then
found = k
end
if (strlower(v.name) == lold) then
retid = k
end
end
end
if (retid == 0) then
err(nexmsg, white(oldname))
return true
end
if (not exist) then
if (found ~= 0) then
err(exmsg, white(newname))
return true
end
end
return false, oldname, newname, retid, found
end
local function ksk_createconfig(input)
local cmd = L["CMD_CREATECONFIG"]
local rv, nname, _, cfgid = common_verify_input(input, cmd, false, true,
ksk.configs, nil,
L["configuration %q already exists. Try again."])
if (rv) then
return true
end
return ksk:CreateNewConfig(nname, false)
end
local function ksk_selectconfig(input)
local cmd = L["CMD_SELECTCONFIG"]
local rv, nname, _, cfgid = common_verify_input(input, cmd, true, false,
ksk.configs,
L["configuration %q does not exist. Try again."], nil)
if (rv) then
return true
end
ksk:SetDefaultConfig(cfgid)
return false
end
local function ksk_deleteconfig(input)
local cmd = L["CMD_DELETECONFIG"]
local rv, nname, _, cfgid = common_verify_input(input, cmd, true, true,
ksk.configs,
L["configuration %q does not exist. Try again."], nil)
if (rv) then
return true
end
ksk:DeleteConfig(cfgid)
return false
end
local function ksk_renameconfig(input)
local cmd = L["CMD_RENAMECONFIG"]
local rv, _, newname, cfgid, _ = common_verify_input2(input, cmd, true,
false, ksk.configs,
L["configuration %q does not exist. Try again."],
L["configuration %q already exists. Try again."])
if (rv) then
return true
end
return ksk:RenameConfig(cfgid, newname)
end
local function ksk_copyconfig(input)
local cmd = L["CMD_COPYCONFIG"]
local rv, _, newname, cfgid, newid = common_verify_input2(input, cmd, true,
false, ksk.configs,
L["configuration %q does not exist. Try again."],
L["configuration %q already exists. Try again."])
if (rv) then
return true
end
return ksk:CopyConfigSpace(cfgid, newname, newid)
end
local function ksk_createuser(input)
if (ksk:CheckPerm()) then
return true
end
local kcmd = L["CMDNAME"]
local cmd = L["CMD_CREATEUSER"]
local nname, nclass, pos
local classid = nil
if (not input or input == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s name class"], kcmd, cmd)))
return true
end
nname, nclass, pos = K.GetArgs(input, 2)
if (not nname or nname == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s name class"], kcmd, cmd)))
return true
end
if (not nclass or nclass == "") then
err(L["Usage: "] .. white(strfmt(L["/%s %s name class"], kcmd, cmd)))
return true
end
if (pos ~= 1e9) then
err(L["Usage: "] .. white(strfmt(L["/%s %s name class"], kcmd, cmd)))
return true
end
local lclass = strlower(nclass)
for k,v in pairs(K.IndexClass) do
if (v.l == lclass) then
classid = k
end
end
if (not classid) then
err(L["invalid class %q specified. Valid classes are:"], white(lclass))
for k,v in pairs(K.IndexClass) do
if (v.l) then
printf(" |cffffffff%s|r", v.l)
end
end
return true
end
if (not ksk:CreateNewUser(nname, classid)) then
return true
end
return false
end
local function ksk_deleteuser(input)
local cmd = L["CMD_DELETEUSER"]
local rv, nname, _, userid = common_verify_input(input, cmd, true, false,
ksk.cfg.users, L["user %q does not exist. Try again."], nil)
if (rv) then
return true
end
if (not ksk:DeleteUserCmd(userid)) then
return true
end
return false
end
local function ksk_renameuser(input)
if (not ksk.cfg.users) then
return false
end
local cmd = L["CMD_RENAMEUSER"]
local rv, _, newname, userid, found = common_verify_input2(input, cmd, true,
false, ksk.cfg.users,
L["user %q does not exist. Try again."],
L["user %q already exists. Try again."])
if (rv) then
return true
end
return ksk:RenameUser(userid, newname)
end
local function ksk_config(input)
if (ksk:CheckPerm()) then
return true
end
local tab = ksk.CONFIG_TAB
local subpanel = ksk.CONFIG_LOOT_PAGE
if (input == L["SUBCMD_LOOT"] or input == "" or not input) then
subpanel = ksk.CONFIG_LOOT_PAGE
elseif (input == L["SUBCMD_ROLLS"]) then
subpanel = ksk.CONFIG_ROLLS_PAGE
elseif (input == L["SUBCMD_ADMIN"]) then
subpanel = ksk.CONFIG_ADMIN_PAGE
elseif (input == L["CMD_LISTS"]) then
tab = ksk.LISTS_TAB
subpanel = ksk.LISTS_CONFIG_PAGE
else
printf(ucolor,L["Usage: "] .. white(strfmt("/%s %s [%s | %s | %s | %s]", L["CMDNAME"], L["CMD_CONFIG"], L["SUBCMD_LOOT"], L["SUBCMD_ROLLS"], L["SUBCMD_ADMIN"], L["CMD_LISTS"])))
printf(ucolor,L[" %s - set up loot related options"], white(L["SUBCMD_LOOT"]))
printf(ucolor,L[" %s - set up roll related options"], white(L["SUBCMD_ROLL"]))
printf(ucolor,L[" %s - set up config spaces and permissions options"], white(L["SUBCMD_ADMIN"]))
printf(ucolor,L[" %s - configure lists and list options"], white(L["CMD_LISTS"]))
return
end
ksk.mainwin:Show()
ksk.mainwin:SetTab(tab, subpanel)
end
local function ksk_main()
ksk.mainwin:Show()
if (ksk.bossloot) then
ksk.mainwin:SetTab(ksk.LOOT_TAB, ksk.LOOT_ASSIGN_PAGE)
else
ksk.mainwin:SetTab(ksk.LISTS_TAB, ksk.LISTS_MEMBERS_PAGE)
end
end
local function ksk_users()
if (ksk:CheckPerm()) then
return true
end
ksk.mainwin:Show()
ksk.mainwin:SetTab(ksk.USERS_TAB, nil)
end
local function ksk_importgusers()
if (ksk:CheckPerm()) then
return true
end
ksk:ImportGuildUsers(ksk.mainwin:IsShown())
end
local function ksk_show()
ksk.mainwin:Show()
end
local function ksk_createlist(input)
local cmd = L["CMD_CREATELIST"]
local rv, nname, _, listid = common_verify_input(input, cmd, false, false,
ksk.cfg.lists, nil,
L["roll list %q already exists. Try again."])
if (rv) then
return true
end
return ksk:CreateNewList(nname, ksk.currentid)
end
local function ksk_selectlist(input)
local cmd = L["CMD_SELECTLIST"]
local rv, nname, _, listid = common_verify_input(input, cmd, true, false,
ksk.cfg.lists,
L["roll list %q does not exist. Try again."], nil)
if (rv) then
return true
end