forked from mikepauer/Carbonite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NxCom.lua
1879 lines (1363 loc) · 43.5 KB
/
NxCom.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
---------------------------------------------------------------------------------------
-- Carbonite - Addon for World of Warcraft(tm)
-- Copyright 2007-2012 Carbon Based Creations, LLC
--
-- NxCom - Communication code
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-- Warning: "\" in send data can lead to invalid escape codes (ok, since only escaped if in literal string?)
-- Bytes 35 (#) + 57 == 92 (\)
--
-- Byte 124 == |. Must be |c or creates invalid escape code. Not in addon channel, only chat
-- Byte 128 or higher == invalid UTF-8 error. Not in addon channel, only chat
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-- Com
---------------------------------------------------------------------------------------
local L = LibStub("AceLocale-3.0"):GetLocale("Carbonite")
NxCOMOPTS_VERSION = .01
NxComOpts = {
Version = 0
}
NxComOptsDefaults = {
Version = NxCOMOPTS_VERSION,
}
function Nx.Com:Init()
if NxComOpts.Version < NxCOMOPTS_VERSION then
if NxComOpts.Version ~= 0 then
Nx.prt (L["Com options reset (%f, %f)"], NxComOpts.Version, NxComOptsDefaults.Version)
end
NxComOpts = NxComOptsDefaults
end
--
self.Created = false
self.Data = {}
self.Data.Rcv = {}
self.Data.Send = {}
self.Name = "Crb"
self.ChanALetter = Nx.Free and "Y" or Nx.Ads and "M" or "B" -- Global letter. Z is used by zone channel
self.SendRate = 1
self.SendQNames = { ["Chan"] = 1, ["Guild"] = 2, ["Friend"] = 3, ["Zone"] = 4 }
local sq = {}
self.SendQ = sq
sq[1] = {} -- Channel
sq[2] = {} -- Guild
sq[3] = {} -- Friends
sq[4] = {} -- Zone
self.SendQMode = 1
self.PalsInfo = {} -- Friends and guildy info (position)
self.PalsSendQ = {}
self.PalNames = {}
self.MemberNames = {} -- Names in party or raid
self.Friends = {}
self.Punks = {}
self.ZPInfo = {} -- Zone player info (position)
self.ZStatus = {} -- Zones status. Indexed with map id
self.ZMonitor = {} -- Zones to monitor
self.SendChanQ = {}
self.PosSendNext = -2
self.SendZSkip = 1
self.TypeColors = { "|cff80ff80", "|cffff4040", "|cffffff40", "|cffffffe0", "|cffc0c0ff" }
self.ClassNames = {
[0] = "?",
L["Druid"], L["Hunter"], L["Mage"], L["Paladin"], L["Priest"],
L["Rogue"], L["Shaman"], L["Warlock"], L["Warrior"], L["Deathknight"], L["Monk"]
}
for k, v in ipairs (self.ClassNames) do
self.ClassNames[v] = k
self.ClassNames[strupper (v)] = k -- All caps version
end
self.Created = true -- Used???
self.List.Opened = false
self.List.Sorted = {}
-- self.List:Open()
--[[
for n = 1, 25 do
Nx.Timer:Start (L["ComTest"]..n, 1 + n * .1, self, self.OnTestTimer)
end
--]]
self.SentBytes = 0 -- Debugging
self.SentBytesSec = 0
self.SentBytesTime = GetTime()
ComBytesSec = Nx:ScheduleTimer(self.OnBytesSecTimer,1,self)
hooksecurefunc ("SendChatMessage", self.SendChatHook)
Nx:RegisterComm(self.Name,Nx.Com.OnChat_msg_addon)
end
---------------------------------------------------------------------------------------
function Nx.Com:Test (a1, a2)
self:SendSecG ("? }a", "") -- Ask for it
--[[
local start = tonumber (a1) or 1
local num = tonumber (a2) or 8
local s = ""
for n = start, start+19 do
Nx.prt ("%d", n)
s = format ("%d |d%c", n, n)
self:SendChatMessageFixed (s, "CHANNEL", num)
self:SendChatMessageFixed (s, "PARTY")
-- Nx:SendCommMessage (self.Name, format ("%d |%c \%c", n, n, n), "PARTY")
end
--]]
end
---------------------------------------------------------------------------------------
--
---------------------------------------------------------------------------------------
function Nx.Com:OnTestTimer (name)
self:SendPals ("!"..name)
if random() < .5 then
-- local i = random (1, 80)
-- self:OnPlayer_level_up (i)
end
return .1 + random() * 5 --15
end
---------------------------------------------------------------------------------------
--
---------------------------------------------------------------------------------------
function Nx.Com:OnBytesSecTimer (name)
local tm = GetTime()
self.SentBytesSec = self.SentBytes / (tm - self.SentBytesTime)
self.SentBytes = 0
self.SentBytesTime = tm
return 1
end
---------------------------------------------------------------------------------------
-- On com event
---------------------------------------------------------------------------------------
function Nx.Com:OnEvent (event)
local self = Nx.Com
-- Nx.prt ("Com Event: %s", event)
if event == "PLAYER_LOGIN" then
local playername, realmname = UnitFullName("player")
self.PlyrName = playername .. "-" .. realmname
self.PlyrMapId = Nx.Map:GetRealMapId()
self.PlyrX = 0
self.PlyrY = 0
local _, tCls = UnitClass ("player") -- Non localized uppercase version
self.PlyrClassI = self.ClassNames[tCls] or 0
self.List:AddInfo ("", "PLAYER_LOGIN")
self.SendTime = GetTime()
self.SendPosTime = GetTime()
self.SendChanTime = GetTime()
self:LeaveChan ("A")
self:LeaveChan ("Z")
-- Nx.Timer:Start ("ComLogin", 3 + random() * 1, self, self.OnLoginTimer)
ComLogin = Nx:ScheduleTimer(self.OnLoginTimer,random(10,15),self)
-- Nx.prt ("Com PLAYER_LOGIN")
if IsInGuild() then
GuildRoster()
end
ShowFriends()
Nx.Com.Initialized = true
elseif event == "ZONE_CHANGED_NEW_AREA" then
self.List:AddInfo ("", "ZONE_CHANGED_NEW_AREA")
if Nx.TimeLeft(ComLogin) == 0 then
self:UpdateChannels()
end
elseif event == "PLAYER_LEAVINGWORLD" then
self:LeaveChan ("A")
self:LeaveChan ("Z")
end
self.List:Update()
end
function Nx.Com:OnLoginTimer()
local redeploy = 0
if UnitOnTaxi ("player") then -- Detect login on taxi, which will not join channels until you land
local id = GetChannelName (1) -- Detect if reload
if id ~= 1 then
self.WasOnTaxi = true
redeploy = 1
end
end
if self.WasOnTaxi then
self.WasOnTaxi = nil
redeploy = 3
end
if GetChannelName(1) ~= 1 then
redeploy = 3
end
if redeploy > 0 then
ComLogin = Nx:ScheduleTimer(self.OnLoginTimer,redeploy,self)
return
end
if IsControlKeyDown() and IsAltKeyDown() then
Nx.prt (L["Disabling com functions!"])
Nx.db.profile.Comm.Global = false
Nx.db.profile.Comm.Zone = false
end
local need = 2
if not Nx.db.profile.Comm.Global then
need = 1
end
if not Nx.db.profile.Comm.Zone then
need = need - 1
end
local free = max (10 - self:GetChanCount(), 0)
if need > free then
Nx.prt ("|cffff9f5f" .. L["Need"] .. " %d " .. L["chat channel(s)!"], need - free)
Nx.prt ("|cffff9f5f" .. L["This will disable some communication features"])
Nx.prt ("|cffff9f5f" .. L["You may free channels using the chat tab"])
end
-- Should not find any since we left all zone channels a few seconds ago
self:ScanChans()
self:UpdateChannels()
self:JoinChan ("A") -- Addon
-- self:JoinChan ("Z") -- Zone
-- self:SendA (format ("TEST"))
end
function Nx.Com:OnLeaveATimer()
-- Nx.prt ("Com OnLeaveATimer")
self:LeaveChan ("A")
end
---------------------------------------------------------------------------------------
-- We leveled
---------------------------------------------------------------------------------------
function Nx.Com:OnPlayer_level_up (event, arg1)
if arg1 >= 1 then -- Level #
self:SendPals (format ("L%s", strchar (35 + arg1)))
end
end
---------------------------------------------------------------------------------------
-- Friends list changed. Build list of connected non guild friends
---------------------------------------------------------------------------------------
function Nx.Com:OnFriendguild_update()
local self = Nx.Com
-- Nx.prt ("OnFriendguild_update")
local gNames = {}
local gNum = GetNumGuildMembers()
for n = 1, gNum do
local name, _, _, _, _, _, _, _, online = GetGuildRosterInfo (n)
if online then
gNames [name] = true
end
end
self.Friends = {}
local i = 1
for n = 1, GetNumFriends() do
local name, lvl, class, area, con, status = GetFriendInfo (n)
if con then
if not gNames[name] then
-- Nx.prt ("Add friend %s", name)
self.Friends[i] = name
i = i + 1
end
end
end
for k, v in ipairs (self.Friends) do
gNames[v] = false
end
self.PalNames = gNames
end
---------------------------------------------------------------------------------------
-- On com event
---------------------------------------------------------------------------------------
function Nx.Com:OnChatEvent (event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
local self = Nx.Com
-- Nx.prt ("ComChatEvent: %s %s", event, arg9)
if strsub (arg9, 1, 3) == self.Name then
if event == "CHAT_MSG_CHANNEL_JOIN" then
self.List:AddInfo ("CJ:"..arg9, format ("%s", arg2))
elseif event == "CHAT_MSG_CHANNEL_NOTICE" then
self.List:AddInfo ("CN:"..arg9, format ("%s", arg1))
local nameRoot = Nx.Split ("I", arg9) -- Drop I and #
if arg1 == "YOU_JOINED" then
local typ = strupper (strsub (arg9, 4, 4))
if typ == self.ChanALetter then
self.ChanAName = arg9
-- Nx.prt ("Join %s", arg9)
Nx:CancelTimer(ComA)
elseif typ == "Z" then
local mapId = tonumber (strsub (nameRoot, 5))
if mapId then
local zs = self.ZStatus[mapId] or {}
zs.ChanName = arg9
self.ZStatus[mapId] = zs
Nx:CancelTimer("ComZ" .. mapId)
self:UpdateChannels()
end
-- Nx.prt ("Join %s", arg9)
end
elseif arg1 == "YOU_LEFT" then
local typ = strupper (strsub (arg9, 4, 4))
if typ == "Z" then
local mapId = tonumber (strsub (nameRoot, 5))
if mapId then
local zs = self.ZStatus[mapId] or {}
zs.ChanName = nil
self.ZStatus[mapId] = zs
end
end
end
elseif event == "CHAT_MSG_CHANNEL_LEAVE" then
self.List:AddInfo ("CL:"..arg9, format ("%s", arg2))
end
self.List:Update()
end
end
---------------------------------------------------------------------------------------
-- On channel message event
---------------------------------------------------------------------------------------
function Nx.Com:OnChat_msg_channel (event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
local self = Nx.Com
if strsub (arg9, 1, 3) == self.Name then
local name = arg2
if name ~= self.PlyrName then
local msg = self:RestoreChars (arg1)
-- self.List:AddInfo ("C:"..arg9, format ("(%s) %s", name, msg))
-- self.List:Update()
local id = strbyte (msg)
if id == 83 then -- S (status) Check 1st for performance
if not self.PalsInfo[name] then -- Not a pal we have?
if #msg >= 16 then
local pl = self.ZPInfo[name]
if not pl then
pl = {}
self.ZPInfo[name] = pl
end
self:ParsePlyrStatus (name, pl, msg)
end
end
elseif id == 86 then -- V (Version and registered name)
end
end
end
end
---------------------------------------------------------------------------------------
-- On addon message event
---------------------------------------------------------------------------------------
function Nx.Com:OnChat_msg_addon (args, distribution, target)
local self = Nx.Com
-- Nx.prt ("ComChatAddonEvent: %s %s %s", args, distribution, target)
local name = target
-- if 1 then
if name ~= self.PlyrName then -- Ignore myself
-- self.List:AddInfo ("A:"..arg1, format ("(%s %s) %s", name, arg3, arg2))
local data = { Nx.Split ("\t", args) }
for k, msg in ipairs (data) do
local id = strbyte (msg)
if id == 83 then -- S (status) Check 1st for performance
if self.PalNames[name] ~= nil then
if #msg >= 16 then
local pal = self.PalsInfo[name]
if not pal then
pal = {}
self.PalsInfo[name] = pal
end
self:ParsePlyrStatus (name, pal, msg)
end
end
elseif id == 76 then -- L (Level)
if Nx.db.profile.Comm.LvlUpShow then
local s = format ("%s " .. L["reached level"] .." %d!", name, strbyte (msg, 2) - 35)
Nx.prt (s)
Nx.UEvents:AddInfo (s)
end
elseif id == 81 then -- Q (Quest)
if Nx.Quest then
Nx.Quest:OnMsgQuest (name, msg)
end
elseif id == 86 then -- V (Version and registered name)
end
end
end
end
---------------------------------------------------------------------------------------
-- Parse a player status message
---------------------------------------------------------------------------------------
function Nx.Com:ParsePlyrStatus (name, info, msg)
-- Flags
-- 1 combat
-- 2 target data
-- 4 quest data
-- 8 punks data
local flags = strbyte (msg, 2) - 35
info.F = flags
info.Quest = nil
-- Player info
local mapId = tonumber (strsub (msg, 3, 6), 16) -- Map id
local winfo = Nx.Map.MapWorldInfo[mapId]
if not winfo then
info.T = 0 -- Cause it to die
-- Nx.prt ("Die %s", mapId)
return
end
info.T = GetTime()
info.MId = mapId
info.EntryMId = mapId
if winfo.EntryMId then
info.EntryMId = winfo.EntryMId
end
if not msg or #msg < 7 then
return
end
info.X = tonumber (strsub (msg, 7, 9), 16) / 0xfff * 100
info.Y = (tonumber (strsub (msg, 10, 13), 16) or 0) / 0xfff * 100 -- Includes dungeon level offset (dzzz)
info.Health = (strbyte (msg, 14) - 48) / 20 * 100
info.Lvl = strbyte (msg, 15) - 35
info.Cls = self.ClassNames[strbyte (msg, 16) - 35] or "?"
-- Nx.prt ("%s %d %d", name, info.X, info.Y)
-- if not self.ClassNames[strbyte (msg, 16) - 35] then
-- Nx.prt ("com cls? %s", strbyte (msg, 16) - 35)
-- end
info.Tip = format ("%s %s%%\n %s %s", name, info.Health, info.Lvl, info.Cls)
-- Nx.prtVar ("Cominfo", info)
local off = 17
-- Target data
if bit.band (flags, 2) > 0 then
-- Type, level, class, health, name len, name
info.TType = strbyte (msg, 17) - 35
local col = self.TypeColors[info.TType] or "" -- User had a nil
info.TLvl = strbyte (msg, 18) - 35
info.TCls = self.ClassNames[strbyte (msg, 19) - 35] or "?"
-- if not self.ClassNames[strbyte (msg, 19) - 35] then
-- Nx.prt ("com tcls? %s", strbyte (msg, 19) - 35)
-- end
info.TH = (strbyte (msg, 20) - 35) / 20 * 100
local len = strbyte (msg, 21) - 35
info.TName = strsub (msg, 22, 22 + len - 1)
local lvl = info.TLvl
if lvl < 0 then
lvl = "??"
end
info.TStr = format ("\n%s%s %s %s %d%%", col, info.TName, lvl, info.TCls, info.TH)
off = 22 + len
else
info.TType = nil
info.TStr = nil
end
-- Quest tracking data
if bit.band (flags, 4) > 0 then
Nx.qTEMPinfo = info
Nx.qTEMPmsg = strsub(msg,off)
Nx.qTEMPname = name
if Nx.qTEMPinfo and Nx.qTEMPmsg and Nx.qTEMPname then
-- Nx:SendCommMessage("carbmodule","QUEST_DECODE","WHISPER",UnitName("player"),"BULK")
Nx.ModQAction = "QUEST_DECODE"
end
if not Nx.qTEMPmsg or #Nx.qTEMPmsg > 7 then
local tmp = (strbyte(Nx.qTEMPmsg,7) - 35)
off = off + (7 + tmp * 2)
else
off = off
end
end
-- Punks data
if bit.band (flags, 8) > 0 then
Nx.pTEMPinfo = info
Nx.pTEMPname = name
Nx.pTEMPmsg = strsub(msg,off+1)
if Nx.pTEMPinfo and Nx.pTEMPname and Nx.pTEMPmsg then
Nx.ModPAction = "PUNK_DECODE"
-- Nx:SendCommMessage("carbmodule","PUNK_DECODE","WHISPER",UnitName("player"),"BULK")
end
end
end
---------------------------------------------------------------------------------------
-- Parse Cartographer LibGuildPositions
---------------------------------------------------------------------------------------
function Nx.Com:ParseLGP (name, msg)
if strbyte (msg) == 0x50 then -- P (position)
local x, x2, y, y2, len = strbyte (msg, 2, 6)
if len and len > 1 then
x = ((x - 1) * 255 + x2 - 1) / (255 ^ 2) * 100
y = ((y - 1) * 255 + y2 - 1) / (255 ^ 2) * 100
local zoneName = strsub (msg, 7, 5 + len) -- Len is +1 real length
-- Nx.prt ("%s %s %s", zoneName, x, y)
local mapId = Nx.MapOverlayToMapId[strlower (zoneName)]
-- Nx.prt ("mapId %s", mapId or "nil")
if mapId then
local info = self.PalsInfo[name]
if not info then
info = {}
self.PalsInfo[name] = info
end
info.T = GetTime()
info.MId = mapId
info.EntryMId = mapId
info.X = x
info.Y = y
info.F = 0
info.Tip = name
end
end
end
end
---------------------------------------------------------------------------------------
-- Update channels
---------------------------------------------------------------------------------------
function Nx.Com:UpdateChannels()
ComUC = Nx:ScheduleTimer(self.UpdateChannelsTimer,0,self)
end
function Nx.Com:UpdateChannelsTimer()
if Nx:TimeLeft(ComLogin) > 0 then
return 0
end
local curMapId = Nx.Map:GetRealMapId()
if UnitIsAFK ("player") or not Nx.db.profile.Comm.Zone then -- No current zone channel?
curMapId = nil
else
if Nx.Map:IsNormalMap (curMapId) then
local zs = self.ZStatus[curMapId] or {}
zs.Join = true
self.ZStatus[curMapId] = zs
end
end
-- Monitor
for mapId, mode in pairs (self.ZMonitor) do
if mode == 0 then
self.ZMonitor[mapId] = 1
local zs = self.ZStatus[mapId] or {}
zs.Join = true
self.ZStatus[mapId] = zs
elseif mode == -1 then
self.ZMonitor[mapId] = nil
end
end
-- Update status (join or leave channels)
for mapId, status in pairs (self.ZStatus) do
if status.ChanName then
if curMapId ~= mapId and not self.ZMonitor[mapId] then
status.Leave = true
end
end
if status.Leave then
status.Leave = false
Nx:CancelTimer ("ComZ")
if status.ChanName then
LeaveChannelByName (status.ChanName)
end
end
if status.Join then
status.Join = false
if not status.ChanName then
if Nx:TimeLeft(ComZ) == 0 then
-- Nx.prt ("Com Status Join %s", mapId)
ComZ = Nx:ScheduleTimer(self.OnJoinChanZTimer,2,self)
timer = {}
timer.UMapId = mapId
timer.UTryCnt = 0
end
end
end
end
end
---------------------------------------------------------------------------------------
-- Join a channel
---------------------------------------------------------------------------------------
function Nx.Com:JoinChan (chanId)
if chanId == "A" then -- Addon channel (global)
if Nx.db.profile.Comm.Global then
self.ChanAName = nil
self.TryA = 0
ComA = Nx:ScheduleTimer(self.OnJoinChanATimer, 0, self)
end
elseif chanId == "Z" then -- Our zone
if Nx.db.profile.Comm.Zone then
local mapId = Nx.Map:GetRealMapId()
if Nx.Map:IsNormalMap (mapId) then
ComZ = Nx:ScheduleTimer(self.OnJoinChanZTimer,2,self)
timer = {}
timer.UMapId = mapId
timer.UTryCnt = 0
end
end
else
Nx.prt (L["JoinChan Err %s"], chanId)
end
end
function Nx.Com:OnJoinChanATimer()
self.List:AddInfo ("", "OnJoinChanATimer")
if self:GetChanCount() >= 10 then
return 10
end
-- if self.TryA > 0 then
-- Nx.prt ("Trying A%d", self.TryA + 1)
-- end
self.TryA = self.TryA + 1
JoinChannelByName (self.Name .. self.ChanALetter .. self.TryA)
return 3
end
function Nx.Com:OnJoinChanZTimer ()
name = "ComZ" .. timer.UMapId
self.List:AddInfo ("", "OnJoinChanZTimer " .. name)
if self:GetChanCount() >= 10 then
return 5
end
-- if self.TryZ > 0 then
-- Nx.prt ("Trying Z%d", self.TryZ + 1)
-- end
timer.UTryCnt = timer.UTryCnt + 1
local name = format ("%sZ%dI%d", self.Name, timer.UMapId, timer.UTryCnt)
if self:InChan (name) then
return
end
Nx.Com:LeaveChan("Z")
JoinChannelByName (name)
return 3
end
---------------------------------------------------------------------------------------
-- Count channels being used
---------------------------------------------------------------------------------------
function Nx.Com:GetChanCount()
local chanCnt = 0
for n = 1, GetNumDisplayChannels() do
local chname, header, collapsed, chanNumber, plCnt, active, category, voiceEnabled, voiceActive = GetChannelDisplayInfo (n)
if not header then
chanCnt = chanCnt + 1
end
end
return chanCnt
end
---------------------------------------------------------------------------------------
-- Leave a channel
---------------------------------------------------------------------------------------
function Nx.Com:LeaveChan (chanId)
if chanId == "A" then
self.ChanAName = nil
self:LeaveChans (self.ChanALetter)
elseif chanId == "Z" then
self:LeaveChans (chanId)
end
end
---------------------------------------------------------------------------------------
-- Leave a type of channel
---------------------------------------------------------------------------------------
function Nx.Com:LeaveChans (typeName)
for n = 1, 10 do
local id, name = GetChannelName (n)
if id > 0 and name then
-- Nx.prt ("Leave Chan N %d %s", id, name)
local name3 = strsub (name, 1, 3)
if name3 == self.Name then
local typ = strupper (strsub (name, 4, 4))
if typ == typeName then
if typ == "Z" then
local nameRoot = Nx.Split ("I", name) -- Drop I and #
local id = tonumber (strsub (nameRoot, 5))
-- Nx.prtVar ("Com leave id", id)
if not self.ZMonitor[id] then -- Not monitored?
LeaveChannelByName (name)
end
else
LeaveChannelByName (name)
end
end
end
end
end
end
---------------------------------------------------------------------------------------
-- Scan channels and add missing to status
---------------------------------------------------------------------------------------
function Nx.Com:ScanChans()
-- Nx.prt ("Com scan")
local baseName = self.Name .. "Z"
for n = 1, 10 do
local id, name = GetChannelName (n)
if id > 0 and name then
-- Nx.prt ("Com scan %s", name)
local name4 = strsub (name, 1, 4)
if name4 == baseName then
local nameRoot = Nx.Split ("I", name) -- Drop I and #
local mapId = tonumber (strsub (nameRoot, 5))
if mapId then
local zs = self.ZStatus[mapId] or {}
zs.ChanName = name
self.ZStatus[mapId] = zs
end
end
end
end
end
---------------------------------------------------------------------------------------
-- Check if in a type of channel
---------------------------------------------------------------------------------------
function Nx.Com:InChanType (typeName)
for n = 1, 10 do
local _, name = GetChannelName (n)
if name then
local name3 = strsub (name, 1, 3)
if name3 == self.Name then
local typ = strsub (name, 4, 4)
if typ == typeName then
return true
end
end
end
end
end
---------------------------------------------------------------------------------------
-- Check if in a named channel
---------------------------------------------------------------------------------------
function Nx.Com:InChan (chanName)
for n = 1, 10 do
local _, name = GetChannelName (n)
if chanName == name then
return true
end
end
end
---------------------------------------------------------------------------------------
-- Set send pals mask. Called by options init. Don't do stuff needing com init
---------------------------------------------------------------------------------------
function Nx.Com:SetSendPalsMask (mask)
self.SendPMask = mask
end
---------------------------------------------------------------------------------------
-- Send message to pals
---------------------------------------------------------------------------------------
function Nx.Com:SendPals (msg)
assert (msg)
self.PalsSendQ[#self.PalsSendQ + 1] = msg
end
---------------------------------------------------------------------------------------
-- Send a secure message to the global addon named channel
---------------------------------------------------------------------------------------
function Nx.Com:SendSecG (pre, msg)
-- Nx.prt ("Send G")