adds client library

This commit is contained in:
Finn Dane 2023-09-09 01:14:08 +02:00
parent 6e5244ed45
commit f240662e40
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,32 @@
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

View File

@ -11,6 +11,18 @@ Logs data sent to it by various computers and prints it on printed pieces of pap
7. Choose a channel number and set the channel by changing the `channel` variable. 7. Choose a channel number and set the channel by changing the `channel` variable.
# Client Setup # Client Setup
1. download `loggerClient.lua` and put it on your computer.
2. attach a modem to the computer and note what side it is on.
3. set the settings `logger.AES.key`, `logger.modemSide` and `logger.channel`.
4. download the AES dependency and put it in the root directory.
5. use `require` to include to use this library.
## Example
```lua
local logger = require("/loggerClient")
logger.log("testLogger", "this is a test log")
```
# Dependencies # Dependencies
- [Lua_AES](https://github.com/idiomic/Lua_AES) - [Lua_AES](https://github.com/idiomic/Lua_AES)