-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathinit.lua
More file actions
657 lines (539 loc) · 23.5 KB
/
init.lua
File metadata and controls
657 lines (539 loc) · 23.5 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
-- rgmercs
-- Copyright (C) 2025 Derple (derple@ntsj.com)
-- SPDX-License-Identifier: GPL-3.0-or-later
-- This file is part of rgmercs. See the `LICENSE` file in the repository root for license terms.
-- For the full license text, see https://www.gnu.org/licenses/gpl-3.0.txt
local mq = require('mq')
local ImGui = require('ImGui')
-- Preload these incase any modules need them.
local PackageMan = require('mq.PackageMan')
local sqllite3 = PackageMan.Require('lsqlite3')
if not sqllite3 then
error("Failed to load lsqlite3. Please ensure it is installed and in the correct directory.")
end
local lfs = PackageMan.Require('luafilesystem', 'lfs')
if not lfs then
error("Failed to load luafilesystem. Please ensure it is installed and in the correct directory.")
end
local Config = require('utils.config')
Config:LoadSettings()
local Logger = require("utils.logger")
Logger.set_log_level(Config:GetSetting('LogLevel'))
Logger.set_toast_level(Config:GetSetting('ToastLevel') - 1) -- adjust for the "None" entry.
Logger.set_log_to_file(Config:GetSetting('LogToFile'))
Logger.set_log_timestamps_to_console(Config:GetSetting('LogTimeStampsToConsole'))
Logger.set_debug_tracer_enabled(Config:GetSetting('EnableLogTracer'))
if Config:GetSetting('LogFilter') ~= "" then
Logger.set_log_filter(Config:GetSetting('LogFilter'))
end
local Binds = require('utils.binds')
require('utils.event_handlers')
local Set = require('mq.set')
local Casting = require("utils.casting")
local ClassLoader = require('utils.classloader')
local Combat = require("utils.combat")
local Comms = require("utils.comms")
local Core = require("utils.core")
local Events = require("utils.events")
local Globals = require("utils.globals")
local Movement = require("utils.movement")
local Targeting = require("utils.targeting")
local Ui = require("utils.ui")
-- Initialize class-based modules
local Modules = require("utils.modules")
Modules:load(Globals.Constants.LootModuleTypes[Config:GetSetting('LootModuleType')])
-- pass through to avoid include loop
Globals.Modules = Modules
Globals.Logger = Logger
Globals.Comms = Comms
Globals.Config = Config
require('utils.datatypes')
-- ImGui Variables
local openGUI = true
local notifyZoning = true
Globals.CurrentState = "Downtime"
local initPctComplete = 0
local initMsg = "Initializing RGMercs..."
-- UI --
local ConsoleUI = require("ui.console")
local HudUI = require("ui.hud")
local LoaderUI = require("ui.loader")
local OptionsUI = require("ui.options")
local SimpleUI = require("ui.simple")
local StandardUI = require("ui.standard")
local TargetUI = require("ui.target")
local function Alive()
return mq.TLO.NearestSpawn('pc')() ~= nil
end
local function GetTheme()
local classTheme = Config:GetSetting('DisableClassTheme') and {} or (Modules:ExecModule("Class", "GetTheme") or {})
local userTheme = Config:GetSetting('UserTheme') or {}
if #classTheme == 0 or (Config:GetSetting('UserThemeOverrideClassTheme') and #userTheme > 0) then
return userTheme
end
return classTheme
end
local function RGMercsGUI()
local theme = GetTheme()
local themeColorPop = 0
local themeStylePop = 0
if mq.TLO.MacroQuest.GameState() == "CHARSELECT" then
openGUI = false
return
end
ImGui.SetNextWindowSize(ImVec2(500, 600), ImGuiCond.FirstUseEver)
if openGUI and Alive() and Config:SettingsLoaded() then
ImGui.PushFont(ImGui.GetFont(), ImGui.GetFontSize() * (1 + (Config:GetSetting('FontScale') / 100)))
if initPctComplete < 100 or not LoaderUI:IsDone() then
LoaderUI:RenderLoader(initPctComplete, initMsg)
else
if theme ~= nil then
for _, t in pairs(theme) do
if t.color then
local colorId = Ui.GetImGuiColorId(t.element)
if type(colorId) ~= 'number' then
colorId = tonumber(colorId) or 0
end
ImGui.PushStyleColor(colorId, t.color.r or t.color.x,
t.color.g or t.color.y,
t.color.b or t.color
.z, t.color.a or t.color.w)
themeColorPop = themeColorPop + 1
elseif t.value then
local elementId = Ui.GetImGuiStyleId(t.element)
if type(t.value) == 'number' then
ImGui.PushStyleVar(elementId, t.value)
else
ImGui.PushStyleVar(elementId, t.value.x, t.value.y)
end
themeStylePop = themeStylePop + 1
end
end
end
local imGuiStyle = ImGui.GetStyle()
ImGui.PushStyleVar(ImGuiStyleVar.Alpha, Config:GetMainOpacity()) -- Main window opacity.
ImGui.PushStyleVar(ImGuiStyleVar.ScrollbarRounding, Config:GetSetting('ScrollBarRounding'))
ImGui.PushStyleVar(ImGuiStyleVar.FrameRounding, Config:GetSetting('FrameEdgeRounding'))
local flags = bit32.bor(ImGuiWindowFlags.NoFocusOnAppearing)
if Config:GetSetting('PopoutWindowsLockWithMain') and Config:GetSetting('MainWindowLocked') then
flags = bit32.bor(flags, ImGuiWindowFlags.NoMove, ImGuiWindowFlags.NoResize)
end
if Config:GetSetting('PopOutForceTarget') then
local openFT, showFT = ImGui.Begin(
Ui.GetWindowTitle("Force Target"),
Config:GetSetting('PopOutForceTarget'), flags)
if showFT then
Ui.RenderForceTargetList()
end
ImGui.End()
if not openFT then
Config:SetSetting('PopOutForceTarget', false)
showFT = false
end
end
if Config:GetSetting('PopOutMercsStatus') then
local openMS, showMS = ImGui.Begin(Ui.GetWindowTitle("Mercs Status"),
Config:GetSetting('PopOutMercsStatus'), flags)
if showMS then
Ui.RenderMercsStatus()
end
ImGui.End()
if not openMS then
Config:SetSetting('PopOutMercsStatus', false)
showMS = false
end
end
if Config:GetSetting('PopOutConsole') then
local openConsole, showConsole = ImGui.Begin(Ui.GetWindowTitle("Debug Console"),
Config:GetSetting('PopOutConsole'), flags)
if showConsole then
ConsoleUI:DrawConsole()
end
ImGui.End()
if not openConsole then
Config:SetSetting('PopOutConsole', false)
showConsole = false
end
end
if Config:GetSetting('ShowTargetWindow') then
TargetUI:RenderWindow(flags)
end
Ui.RenderModulesPopped(flags)
if Config:GetSetting("AlwaysShowMiniButton") or Globals.Minimized then
HudUI:RenderToggleHud()
end
local flashingWarning = Globals.PauseMain and Targeting.GetXTHaterCount(false) > 0 and Config:GetSetting('WarnCombatPaused')
if flashingWarning then
if Globals.GetTimeSeconds() % 3 == 0 then
Comms.PopUpColor(15, 1, "RGMercs Warning: You have aggro while paused!")
end
ImGui.PushStyleColor(ImGuiCol.WindowBg, Globals.GetAlternatingColor(ImVec4(0.7, 0.1, 0.1, Config:GetMainOpacity()), ImVec4(0.3, 0.1, 0.1, Config:GetMainOpacity())))
end
if Config:GetSetting('FullUI') then
openGUI = StandardUI:RenderMainWindow(imGuiStyle, openGUI, flags)
else
openGUI = SimpleUI:RenderMainWindow(imGuiStyle, openGUI, flags)
end
if flashingWarning then
ImGui.PopStyleColor()
end
Ui.RenderAAOverlay()
if Config:GetSetting('EnableOptionsUI') then
local openOptionsUI = OptionsUI:RenderMainWindow(imGuiStyle, true, flags)
if not openOptionsUI then
Config:SetSetting('EnableOptionsUI', false)
end
end
ImGui.PopStyleVar(3)
if themeColorPop > 0 then
ImGui.PopStyleColor(themeColorPop)
end
if themeStylePop > 0 then
ImGui.PopStyleVar(themeStylePop)
end
end
ImGui.PopFont()
end
end
mq.imgui.init('RGMercsUI', RGMercsGUI)
-- End UI --
local unloadedPlugins = {}
local function RGInit(...)
Core.CheckPlugins({
"MQ2Rez",
"MQ2AdvPath",
"MQ2MoveUtils",
"MQ2Nav",
"MQ2DanNet", })
unloadedPlugins = Core.UnCheckPlugins({ "MQ2Melee", "MQ2Twist", })
Core.CheckSpawnMasterVersion()
if mq.TLO.Plugin("MQ2Mono").IsLoaded() then
Logger.log_warning("\ar MQ2Mono detected! \aw Pausing E3N to avoid conflicts.")
mq.cmd("/e3p on")
end
initPctComplete = 0
initMsg = "Initializing RGMercs..."
local args = { ..., }
-- check mini argument before loading other modules so it minimizes as soon as possible.
if args and #args > 0 then
Logger.log_debug("Arguments passed to RGMercs: %s", table.concat(args, ", "))
for _, v in ipairs(args) do
if v == "mini" then
Globals.Minimized = true
break
end
if v == "paused" then
Globals.PauseMain = true
break
end
if v == "reset_config_type" or v == "reset_class_config_type" or v == "reset_class_config" then
Config:SetSetting('ClassConfigDir', '')
Logger.log_info("ClassConfigDir reset to empty by startup argument.")
break
end
if v == "reset_to_default" then
Config.Db:deleteCharacter(Globals.CurServer, Globals.CurLoadedChar)
Logger.log_info("All settings for %s on %s wiped from DB — defaults will load on startup.", Globals.CurLoadedChar, Globals.CurServer)
break
end
end
end
initPctComplete = 10
initMsg = "Scanning for Configurations..."
Core.ScanConfigDirs()
if Config:GetSetting("RunSelfTestsOnStartup") then
initPctComplete = 15
initMsg = "Running Self Tests..."
Config.UnitTestsPass = require('utils.unit_tests').RunAll()
end
initPctComplete = 20
initMsg = "Initializing Modules..."
-- complex objects are passed by reference so we can just use these without having to pass them back in for saving.
Modules:ExecAll("Init")
Globals.SubmodulesLoaded = true
initPctComplete = 30
initMsg = "Updating Command Handlers..."
Config:UpdateCommandHandlers()
initPctComplete = 40
initMsg = "Setting Assist..."
Combat.SetMainAssist()
Ui.GetAssistWarningString()
local assistString = Globals.MainAssist:len() > 0 and string.format("set to %s.", Globals.MainAssist) or string.format("unset!")
if Config.TempSettings.AssistWarning then
Comms.PopUp("RGMercs " .. Config.TempSettings.AssistWarning .. "\nYour assist is currently " .. assistString)
else
Comms.PopUp("Welcome to RGMercs!\nYour assist is currently set to %s.", Globals.MainAssist)
end
if Core.IAmMA() then
Logger.log_info("This PC has assigned itself as the MA! If this is not intentional, please check your assist setup.")
end
initPctComplete = 50
initMsg = "We deleted the thing that used to be here..."
initPctComplete = 60
initMsg = "Setting up MQ2DanNet..."
if mq.TLO.Plugin("MQ2DanNet")() then
Core.DoCmd("/squelch /dnet commandecho off")
end
-- Don't pass this through the DoStickCmd system so our timing isn't affected.
Core.DoCmd("/squelch /stick set breakontarget on")
initPctComplete = 70
initMsg = "Closing down Macro..."
if (mq.TLO.Macro.Name() or ""):find("RGMERC") then
Core.DoCmd("/macro end")
end
initMsg = "Pausing the CWTN Plugin..."
Core.DoCmd("/squelch /docommand /%s pause on", mq.TLO.Me.Class.ShortName())
initPctComplete = 80
initMsg = "Clearing Cursor..."
if mq.TLO.Cursor() and mq.TLO.Cursor.ID() > 0 then
Logger.log_info("Sending Item(%s) on Cursor to Bag", mq.TLO.Cursor())
Core.DoCmd("/autoinventory")
end
printf("\aw****************************")
printf("\aw\awWelcome to \ag%s", Config._AppName)
printf("\aw\awVersion \ag%s \aw(\at%s\aw)", Config._version, Config._subVersion)
printf("\aw\awBy \ag%s", Config._author)
printf("\aw****************************")
-- keep these for easy editing/addition later
printf("\agRGMercs! Where even fun has an option and a command attached.")
printf("\awPlease visit us on the RG forums for the most recent news and updates.")
printf("\awFAQs, Commands and Settings are searchable from the options panel!")
-- store initial positioning data.
initPctComplete = 90
initMsg = "Storing Initial Positioning Data..."
Movement:StoreLastMove()
initPctComplete = 100
initMsg = "Done!"
HudUI:LoadAllOptions()
end
local function Main()
Logger.log_super_verbose("Starting Main loop.")
-- always do this and do it first
Config:FlushDB()
Config.Db:updateTelemetryGraphs()
Comms.HeartbeatWatchdog()
if mq.TLO.Zone.ID() ~= Globals.CurZoneId or mq.TLO.Me.Instance() ~= Globals.CurInstanceId then
if notifyZoning then
Modules:ExecAll("OnZone")
notifyZoning = false
Config.TempSettings.NoLevZone = false
Globals.ForceCombatID = 0
Globals.IgnoredTargetIDs = Set.new({})
Globals.LastCachedBuffUpdate = {}
Globals.AutoTargetID = 0
Globals.AutoTargetIsNamed = false
Globals.AggroTargetID = 0
Globals.SetForcedTargetId(0)
end
mq.delay(100)
Globals.CurZoneId = mq.TLO.Zone.ID()
Globals.CurInstanceId = mq.TLO.Me.Instance()
Logger.log_super_verbose("Completed Main loop.")
return
end
Core.UpdateBuffs()
Events.DoEvents()
Config:ValidatePeers()
notifyZoning = true
if mq.TLO.Me.NumGems() ~= Casting.UseGem then
-- sometimes this can get out of sync.
Casting.UseGem = mq.TLO.Me.NumGems()
end
if Globals.PauseMain then
mq.delay(100)
mq.doevents()
if Config:GetSetting('RunMovePaused') then
Modules:ExecModule("Movement", "GiveTime")
end
Modules:ExecModule("Drag", "GiveTime")
Modules:ExecModule("Debug", "GiveTime")
Modules:ExecModule("Clickies", "ValidateClickies")
return
end
if Targeting.GetXTHaterCount(false) > 0 then
if Globals.CurrentState == "Downtime" and mq.TLO.Me.Sitting() then
-- if switching into combat state stand up.
mq.TLO.Me.Stand()
end
Globals.CurrentState = "Combat"
if Config:GetSetting('FaceTarget') and not Targeting.FacingTarget() and mq.TLO.Target.ID() ~= mq.TLO.Me.ID() and not mq.TLO.Me.Moving() then
Core.DoCmd("/squelch /face fast")
end
if Config:GetSetting('DoMed') == 3 then
Casting.AutoMed()
end
else
if Globals.CurrentState ~= "Downtime" then
Logger.log_debug("Switching to Downtime state.")
-- clear the cache during state transition.
Targeting.ClearSafeTargetCache()
Targeting.ForceBurnTargetID = 0
Globals.LastPulledID = 0
Globals.AutoTargetID = 0
Globals.IgnoredTargetIDs = Set.new({})
Globals.LastBurnCheck = false
Modules:ExecModule("Pull", "SetLastPullOrCombatEndedTimer")
end
Globals.CurrentState = "Downtime"
if Config:GetSetting('DoMed') ~= 1 then
Casting.AutoMed()
end
end
if mq.TLO.MacroQuest.GameState() ~= "INGAME" then return end
if Globals.CurLoadedChar ~= mq.TLO.Me.DisplayName() then
Config:LoadSettings()
Modules:ExecAll("LoadSettings")
end
if Globals.CurLoadedClass ~= mq.TLO.Me.Class.ShortName() then
ClassLoader.changeLoadedClass()
end
Movement:StoreLastMove()
if mq.TLO.Me.Hovering() then Events.HandleDeath() end
Combat.SetMainAssist()
Ui.GetAssistWarningString()
if not Globals.BackOffFlag then
-- This will find a valid target and set it to : Globals.AutoTargetID
Combat.FindBestAutoTarget(Combat.OkToEngagePreValidateId)
-- finds the AggroTarget for a tank mode character
if Core.IsTanking() and Config:GetSetting('TankAggroScan') then
Combat.TankAggroScan()
end
end
if Combat.OkToEngage(Globals.AutoTargetID) then
Combat.EngageTarget(Globals.AutoTargetID)
else
if Globals.CurrentState == "Combat" then
local targetId = Targeting.GetTargetID()
local ignored = Globals.IgnoredTargetIDs:contains(targetId) -- don't target something in our ignore list
local pullTarget = Config:GetSetting('DoPull') and targetId == Globals.LastPulledID -- don't clear your pull target while its traveling to you
local assistHater = Core.IAmMA() and Targeting.IsSpawnXTHater(targetId) -- don't clear a targeted hater as MA unless it is ignored
if ignored or (not pullTarget and not assistHater) then
Logger.log_debug("\ayClearing Target because we are not OkToEngage() and we are in combat!")
Targeting.ClearTarget()
end
elseif mq.TLO.Me.Combat() and (Config:GetSetting('AutoAttackSafetyCheck') or not mq.TLO.Target()) then
Logger.log_debug("\ayTurning off attack because we don't have a target or we are not OkToEngage the current target!")
Core.DoCmd("/attack off")
end
end
-- Handles state for when we're in combat
if Globals.CurrentState == "Combat" then
if ((Globals.GetTimeSeconds() - Globals.LastPetCmd) > 2) then
Globals.LastPetCmd = Globals.GetTimeSeconds()
if Config:GetSetting('DoPetCommands') and mq.TLO.Pet.ID() > 0 and Targeting.GetTargetPctHPs(Targeting.GetAutoTarget()) <= Config:GetSetting('PetEngagePct') then
Combat.PetAttack(Globals.AutoTargetID, true)
end
end
if Config:GetSetting('DoMercenary') then
local merc = mq.TLO.Me.Mercenary
if merc() and merc.ID() then
if Combat.MercEngage() then
local class = merc.Class.ShortName():lower()
local stanceGroups = {
war = Globals.Constants.TankMercStances,
clr = Globals.Constants.HealerMercStances,
rog = Globals.Constants.MeleeMercStances,
wiz = Globals.Constants.CasterMercStances,
}
local stances = stanceGroups[class]
if stances and merc.Stance() then
local desiredStance = stances[Config:GetSetting("MercStance")]
if desiredStance then
if merc.Stance():lower() ~= desiredStance then
Core.DoCmd("/squelch /stance %s", desiredStance)
end
else
local fallbackStance = stances[1]
if merc.Stance():lower() ~= fallbackStance then
Core.DoCmd("/squelch /stance %s", fallbackStance)
end
end
end
Combat.MercAssist()
else
if merc.Class.ShortName():lower() ~= "clr" and merc.Stance():lower() ~= "passive" then
Core.DoCmd("/squelch /stance passive")
end
end
end
end
end
if Combat.ShouldDoCamp() then
if Config:GetSetting('DoMercenary') and mq.TLO.Me.Mercenary.ID() and (mq.TLO.Me.Mercenary.Class.ShortName() or "none"):lower() ~= "clr" and mq.TLO.Me.Mercenary.Stance():lower() ~= "passive" then
Core.DoCmd("/squelch /stance passive")
end
end
if Globals.Constants.ModRodUse[Config:GetSetting('ModRodUse')] == "Anytime" or (Globals.Constants.ModRodUse[Config:GetSetting('ModRodUse')] == "Combat" and Globals.CurrentState == "Combat") then
Casting.ClickModRod()
end
if not Combat.ValidCombatTarget(Globals.AutoTargetID) then
Globals.AutoTargetID = 0
end
-- Revive our mercenary if they're dead and we're using a mercenary
if Config:GetSetting('DoMercenary') then
if mq.TLO.Me.Mercenary.State():lower() == "dead" then
if mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_SuspendButton").Text():lower() == "revive" then
mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_SuspendButton").LeftMouseUp()
mq.delay(1000, function() return (mq.TLO.Me.Mercenary.State() or "dead"):lower() ~= "dead" end)
end
else
if mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_AssistModeCheckbox").Checked() then
mq.TLO.Window("MMGW_ManageWnd").Child("MMGW_AssistModeCheckbox").LeftMouseUp()
end
end
end
Modules:ExecAll("GiveTime")
mq.doevents()
Logger.log_super_verbose("Completed Main loop.")
mq.delay(10)
end
-- Global Messaging callback
---@diagnostic disable-next-line: unused-local
local script_actor = Comms.Actors.register('RGMercs', function(message)
local msg = message()
if msg.Script ~= Comms.ScriptName then
return
end
Logger.log_super_verbose("\ayGot Event from(\am%s\ay) module(\at%s\ay) event(\at%s\ay)", msg.From,
msg.Module,
msg.Event)
-- This is a core event so handle it here.
if msg.Event == "Heartbeat" then
--Logger.log_debug("Received Heartbeat from \am%s\aw: \ag%s", msg.From, Strings.TableToString(msg.Data))
if Config:GetSetting('HeartbeatAnnounceGroup') and msg.Data.Forced then
Comms.HandleAnnounce(
Comms.FormatChatEvent("Heartbeat", msg.From, string.format("AutoTarget: %d, ForceTarget: %d", msg.Data.AutoTargetID, msg.Data.ForceTargetID)),
true, false, true)
end
Comms.UpdatePeerHeartbeat(msg.From, msg.Data)
return
end
if msg.Event == "DoCmd" then
--Logger.log_debug("Received Heartbeat from \am%s\aw: \ag%s", msg.From, Strings.TableToString(msg.Data))
Logger.log_debug("Received Command from \am%s\aw: \ag%s", msg.From, msg.Data.cmd or "nil")
Core.DoCmd(msg.Data.cmd)
return
end
if msg.Module == "Config" then
if msg.Event and Config[msg.Event] then
Config[msg.Event](Config, msg.Data)
end
return
end
-- all other handlers
if Modules:GetModule(msg.Module) then
Modules:ExecModule(msg.Module, msg.Event, msg.Data)
return
end
end)
-- Binds
mq.bind("/rglua", Binds.MainHandler)
RGInit(...)
while openGUI do
Main()
mq.doevents()
mq.delay(10)
end
Core.CheckPlugins(unloadedPlugins, true)
Modules:ExecAll("Shutdown")
Config:Shutdown()