CC_snippets/centralLoggingSystem/loggerClient.lua

33 lines
924 B
Lua
Raw Permalink Normal View History

2023-09-09 01:14:08 +02:00
local loggerClient = {}
settings.define("logger.AES.key", {
description = "AES key used for encryption",
type = "number"
})
settings.define("logger.modemSide", {
description = "The side of the modem (for pocket computers this is 'back')",
type = "string"
})
settings.define("logger.channel", {
description = "The channel used",
type = "number"
})
local AES = require("/AES")
local key = settings.get("logger.AES.key") or error("No AES Key set")
local modemSide = settings.get("logger.modemSide") or error("No modem found")
local channel = settings.get("logger.channel") or error("No channel set")
local modem = peripheral.wrap(modemSide)
function loggerClient.log(sender, message)
local message = textutils.serialize({sender = sender, message = message})
local encrypted = AES.ECB_256(AES.encrypt, key, message)
modem.transmit(channel, channel, encrypted)
end
return loggerClient