2025-09-25 19:22:17 +02:00
|
|
|
import whisky
|
2025-10-01 21:57:26 +02:00
|
|
|
import times, tables, json, base64
|
2025-10-03 12:44:28 +02:00
|
|
|
import ../../common/[types, utils, serialize, event]
|
2025-09-27 13:54:12 +02:00
|
|
|
export sendHeartbeat, recvEvent
|
2025-09-25 19:22:17 +02:00
|
|
|
|
|
|
|
|
#[
|
|
|
|
|
Client -> Server
|
|
|
|
|
]#
|
2025-10-01 21:57:26 +02:00
|
|
|
proc sendPublicKey*(connection: WsConnection, publicKey: Key) =
|
|
|
|
|
let event = Event(
|
|
|
|
|
eventType: CLIENT_KEY_EXCHANGE,
|
|
|
|
|
timestamp: now().toTime().toUnix(),
|
|
|
|
|
data: %*{
|
|
|
|
|
"publicKey": encode(Bytes.toString(publicKey))
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
|
|
|
|
|
|
|
|
|
proc sendStartListener*(connection: WsConnection, listener: UIListener) =
|
2025-09-27 13:54:12 +02:00
|
|
|
let event = Event(
|
|
|
|
|
eventType: CLIENT_LISTENER_START,
|
|
|
|
|
timestamp: now().toTime().toUnix(),
|
|
|
|
|
data: %listener
|
|
|
|
|
)
|
2025-10-01 21:57:26 +02:00
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
2025-09-25 19:22:17 +02:00
|
|
|
|
2025-10-01 21:57:26 +02:00
|
|
|
proc sendStopListener*(connection: WsConnection, listenerId: string) =
|
2025-09-27 13:54:12 +02:00
|
|
|
let event = Event(
|
|
|
|
|
eventType: CLIENT_LISTENER_STOP,
|
|
|
|
|
timestamp: now().toTime().toUnix(),
|
|
|
|
|
data: %*{
|
|
|
|
|
"listenerId": listenerId
|
|
|
|
|
}
|
|
|
|
|
)
|
2025-10-01 21:57:26 +02:00
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
2025-09-25 19:22:17 +02:00
|
|
|
|
2025-10-01 21:57:26 +02:00
|
|
|
proc sendAgentBuild*(connection: WsConnection, buildInformation: AgentBuildInformation) =
|
2025-09-27 15:18:45 +02:00
|
|
|
let event = Event(
|
|
|
|
|
eventType: CLIENT_AGENT_BUILD,
|
|
|
|
|
timestamp: now().toTime().toUnix(),
|
2025-10-23 11:14:26 +02:00
|
|
|
data: %buildInformation
|
2025-09-27 15:18:45 +02:00
|
|
|
)
|
2025-10-01 21:57:26 +02:00
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
2025-09-27 15:18:45 +02:00
|
|
|
|
2025-10-02 13:51:04 +02:00
|
|
|
proc sendAgentTask*(connection: WsConnection, agentId: string, command: string, task: Task) =
|
2025-09-27 17:45:52 +02:00
|
|
|
let event = Event(
|
2025-09-30 10:04:29 +02:00
|
|
|
eventType: CLIENT_AGENT_TASK,
|
2025-09-27 17:45:52 +02:00
|
|
|
timestamp: now().toTime().toUnix(),
|
|
|
|
|
data: %*{
|
|
|
|
|
"agentId": agentId,
|
2025-10-02 13:51:04 +02:00
|
|
|
"command": command,
|
2025-09-30 10:04:29 +02:00
|
|
|
"task": task
|
2025-09-27 17:45:52 +02:00
|
|
|
}
|
|
|
|
|
)
|
2025-10-01 21:57:26 +02:00
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
2025-10-09 16:25:05 +02:00
|
|
|
|
2025-10-27 15:17:56 +01:00
|
|
|
proc sendAgentRemove*(connection: WsConnection, agentId: string) =
|
|
|
|
|
let event = Event(
|
|
|
|
|
eventType: CLIENT_AGENT_REMOVE,
|
|
|
|
|
timestamp: now().toTime().toUnix(),
|
|
|
|
|
data: %*{
|
|
|
|
|
"agentId": agentId
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
|
|
|
|
|
2025-10-09 16:25:05 +02:00
|
|
|
proc sendRemoveLoot*(connection: WsConnection, lootId: string) =
|
|
|
|
|
let event = Event(
|
|
|
|
|
eventType: CLIENT_LOOT_REMOVE,
|
|
|
|
|
timestamp: now().toTime().toUnix(),
|
|
|
|
|
data: %*{
|
|
|
|
|
"lootId": lootId
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
|
|
|
|
|
2025-10-14 22:04:04 +02:00
|
|
|
proc sendGetLoot*(connection: WsConnection, lootId: string) =
|
2025-10-09 16:25:05 +02:00
|
|
|
let event = Event(
|
2025-10-14 22:04:04 +02:00
|
|
|
eventType: CLIENT_LOOT_GET,
|
2025-10-09 16:25:05 +02:00
|
|
|
timestamp: now().toTime().toUnix(),
|
|
|
|
|
data: %*{
|
|
|
|
|
"lootId": lootId
|
|
|
|
|
}
|
|
|
|
|
)
|
2025-10-27 15:17:56 +01:00
|
|
|
connection.ws.sendEvent(event, connection.sessionKey)
|
|
|
|
|
|