2025-09-22 21:53:13 +02:00
|
|
|
import whisky
|
|
|
|
|
import tables, strutils
|
2025-09-05 10:49:27 +02:00
|
|
|
import ./utils/appImGui
|
2025-09-10 18:25:15 +02:00
|
|
|
import ./views/[dockspace, sessions, listeners, eventlog, console]
|
2025-09-22 21:53:13 +02:00
|
|
|
import ../common/[types, utils]
|
|
|
|
|
import ./websocket
|
2025-09-02 12:48:46 +02:00
|
|
|
|
2025-09-05 10:49:27 +02:00
|
|
|
proc main() =
|
|
|
|
|
var app = createApp(1024, 800, imnodes = true, title = "Conquest", docking = true)
|
|
|
|
|
defer: app.destroyApp()
|
2025-09-02 12:48:46 +02:00
|
|
|
|
2025-09-05 19:39:24 +02:00
|
|
|
var
|
|
|
|
|
views: Table[string, ptr bool]
|
|
|
|
|
showConquest = true
|
2025-09-07 17:18:50 +02:00
|
|
|
showSessionsTable = true
|
|
|
|
|
showSessionsGraph = false
|
2025-09-11 12:03:02 +02:00
|
|
|
showListeners = true
|
2025-09-06 14:12:51 +02:00
|
|
|
showEventlog = true
|
2025-09-10 18:25:15 +02:00
|
|
|
consoles: Table[string, ConsoleComponent]
|
2025-09-11 12:03:02 +02:00
|
|
|
|
|
|
|
|
var
|
|
|
|
|
dockTop: ImGuiID = 0
|
|
|
|
|
dockBottom: ImGuiID = 0
|
|
|
|
|
dockTopLeft: ImGuiID = 0
|
|
|
|
|
dockTopRight: ImGuiID = 0
|
|
|
|
|
|
2025-09-07 17:18:50 +02:00
|
|
|
views["Sessions [Table View]"] = addr showSessionsTable
|
|
|
|
|
views["Sessions [Graph View]"] = addr showSessionsGraph
|
2025-09-06 14:12:51 +02:00
|
|
|
views["Listeners"] = addr showListeners
|
|
|
|
|
views["Eventlog"] = addr showEventlog
|
2025-09-02 12:48:46 +02:00
|
|
|
|
2025-09-09 22:55:43 +02:00
|
|
|
# Create components
|
|
|
|
|
var
|
|
|
|
|
dockspace = Dockspace()
|
2025-09-10 18:25:15 +02:00
|
|
|
sessionsTable = SessionsTable("Sessions [Table View]", addr consoles)
|
2025-09-09 22:55:43 +02:00
|
|
|
listenersTable = ListenersTable("Listeners")
|
|
|
|
|
eventlog = Eventlog("Eventlog")
|
|
|
|
|
|
2025-09-05 10:49:27 +02:00
|
|
|
let io = igGetIO()
|
2025-09-02 12:48:46 +02:00
|
|
|
|
2025-09-22 21:53:13 +02:00
|
|
|
# Initiate WebSocket connection
|
|
|
|
|
let ws = newWebSocket("ws://localhost:12345")
|
|
|
|
|
defer: ws.close()
|
|
|
|
|
|
2025-09-05 10:49:27 +02:00
|
|
|
# main loop
|
|
|
|
|
while not app.handle.windowShouldClose:
|
|
|
|
|
pollEvents()
|
|
|
|
|
|
2025-09-05 19:39:24 +02:00
|
|
|
# Reduce rendering activity when window is minimized
|
2025-09-05 10:49:27 +02:00
|
|
|
if app.isIconifySleep():
|
|
|
|
|
continue
|
|
|
|
|
newFrame()
|
|
|
|
|
|
2025-09-22 21:53:13 +02:00
|
|
|
#[
|
|
|
|
|
WebSocket communication with the team server
|
|
|
|
|
]#
|
|
|
|
|
# Continuously send heartbeat messages
|
|
|
|
|
ws.sendHeartbeat()
|
|
|
|
|
|
|
|
|
|
# Receive and parse websocket response message
|
|
|
|
|
let message = ws.receiveMessage().get()
|
|
|
|
|
case message.getMessageType()
|
|
|
|
|
of CLIENT_EVENT_LOG:
|
|
|
|
|
message.receiveEventlogItem(addr eventlog)
|
2025-09-23 15:51:57 +02:00
|
|
|
else: discard
|
2025-09-22 21:53:13 +02:00
|
|
|
|
|
|
|
|
|
2025-09-09 22:55:43 +02:00
|
|
|
# Draw/update UI components/views
|
2025-09-11 12:03:02 +02:00
|
|
|
dockspace.draw(addr showConquest, views, addr dockTop, addr dockBottom, addr dockTopLeft, addr dockTopRight)
|
2025-09-09 22:55:43 +02:00
|
|
|
if showSessionsTable: sessionsTable.draw(addr showSessionsTable)
|
2025-09-22 21:53:13 +02:00
|
|
|
if showListeners: listenersTable.draw(addr showListeners, ws)
|
2025-09-09 22:55:43 +02:00
|
|
|
if showEventlog: eventlog.draw(addr showEventlog)
|
2025-09-02 12:48:46 +02:00
|
|
|
|
2025-09-10 18:25:15 +02:00
|
|
|
# Show console windows
|
|
|
|
|
var newConsoleTable: Table[string, ConsoleComponent]
|
|
|
|
|
for agentId, console in consoles.mpairs():
|
2025-09-11 12:03:02 +02:00
|
|
|
if console.showConsole:
|
|
|
|
|
# Ensure that new console windows are docked to the bottom panel by default
|
|
|
|
|
igSetNextWindowDockID(dockBottom, ImGuiCond_FirstUseEver.int32)
|
2025-09-22 21:53:13 +02:00
|
|
|
console.draw(ws)
|
2025-09-10 18:25:15 +02:00
|
|
|
newConsoleTable[agentId] = console
|
|
|
|
|
|
|
|
|
|
# Update the consoles table with only those sessions that have not been closed yet
|
|
|
|
|
# This is done to ensure that closed console windows can be opened again
|
|
|
|
|
consoles = newConsoleTable
|
|
|
|
|
|
2025-09-02 12:48:46 +02:00
|
|
|
igShowDemoWindow(nil)
|
|
|
|
|
|
|
|
|
|
# render
|
2025-09-05 10:49:27 +02:00
|
|
|
app.render()
|
2025-09-02 12:48:46 +02:00
|
|
|
|
2025-09-05 10:49:27 +02:00
|
|
|
if not showConquest:
|
|
|
|
|
app.handle.setWindowShouldClose(true)
|
2025-09-02 12:48:46 +02:00
|
|
|
|
|
|
|
|
when isMainModule:
|
2025-09-05 10:49:27 +02:00
|
|
|
main()
|