mirror of
https://github.com/AR2000AR/openComputers_codes.git
synced 2025-09-04 12:45:58 +02:00
format all files
This commit is contained in:
@@ -8,16 +8,16 @@ local component = require("component")
|
||||
local term = require("term")
|
||||
local computer = require("computer")
|
||||
|
||||
local transposer = component.transposer
|
||||
local gpu = component.gpu
|
||||
local disk_drive = component.disk_drive
|
||||
local data = component.data
|
||||
local transposer = component.transposer
|
||||
local gpu = component.gpu
|
||||
local disk_drive = component.disk_drive
|
||||
local data = component.data
|
||||
|
||||
local CONFIG_PATH = "/etc/bank/accountMaker/"
|
||||
local CONFIG_FILE = CONFIG_PATH .. "config.cfg"
|
||||
local OUT_PATH = "/var/bank/accountMaker/"
|
||||
local ACCOUNT_FILE = OUT_PATH .. "accounts.csv"
|
||||
local ERROR_FILE = OUT_PATH .. "operr.csv"
|
||||
local CONFIG_PATH = "/etc/bank/accountMaker/"
|
||||
local CONFIG_FILE = CONFIG_PATH .. "config.cfg"
|
||||
local OUT_PATH = "/var/bank/accountMaker/"
|
||||
local ACCOUNT_FILE = OUT_PATH .. "accounts.csv"
|
||||
local ERROR_FILE = OUT_PATH .. "operr.csv"
|
||||
|
||||
local config = {}
|
||||
local knownAccounts = {}
|
||||
@@ -51,7 +51,7 @@ local function saveConfig()
|
||||
cFile:close()
|
||||
if (config.masterAccountCBdata) then
|
||||
---@type cardData
|
||||
config.masterAccountCBdata = serialization.unserialize(data.decode64(config.masterAccountCBdata--[[@as string]] ))
|
||||
config.masterAccountCBdata = serialization.unserialize(data.decode64(config.masterAccountCBdata --[[@as string]]))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -127,7 +127,7 @@ local function makeCard(playerName)
|
||||
if (status == 0) then --ok
|
||||
addToKnonwPlayer(playerName, acUUID)
|
||||
if (config.masterAccountCreditPerAccount ~= 0) then
|
||||
status = bank.editAccount(config.masterAccountCBdata--[[@as cardData]] , config.masterAccountCreditPerAccount)
|
||||
status = bank.editAccount(config.masterAccountCBdata --[[@as cardData]], config.masterAccountCreditPerAccount)
|
||||
if (status ~= 0) then
|
||||
local file = io.open(ERROR_FILE, "a")
|
||||
assert(file, "Can't fail here")
|
||||
@@ -287,7 +287,10 @@ local old_res_x, old_res_y = gpu.getResolution()
|
||||
gpu.setResolution(26, 13)
|
||||
|
||||
--listen for ctrl+c (interrupted)
|
||||
event.listen("interrupted", function() run = false; return false end)
|
||||
event.listen("interrupted", function()
|
||||
run = false;
|
||||
return false
|
||||
end)
|
||||
--MAIN LOOP====================================================================
|
||||
while (run) do
|
||||
term.clear()
|
||||
|
@@ -57,8 +57,11 @@ local function loadRecipe(recipePatern, sideStorage, sideRobot)
|
||||
local itemSlot = findStack(item, sideStorage)
|
||||
if (itemSlot == 0) then
|
||||
emptyCrafter(sideStorage, sideRobot)
|
||||
if (itemDamage) then return string.format("%s/%d", itemID, itemDamage)
|
||||
else return itemID end
|
||||
if (itemDamage) then
|
||||
return string.format("%s/%d", itemID, itemDamage)
|
||||
else
|
||||
return itemID
|
||||
end
|
||||
end --not enough ressources
|
||||
transposer.transferItem(sideStorage, sideRobot, 1, itemSlot, craftingGrid[i]) --put
|
||||
end
|
||||
@@ -90,7 +93,7 @@ local function craftItem(recipes, labels, itemName, sideStorage, sideRobot)
|
||||
local loadedName = loaded:match("^[^/]+")
|
||||
local loadedDamage = tonumber(loaded:match("%d+$"))
|
||||
if (recipes[loadedName]) then
|
||||
if (not loadedDamage) then
|
||||
if (not loadedDamage) then
|
||||
for k, r in pairs(recipes[loadedName]) do
|
||||
---@diagnostic disable-next-line: cast-local-type
|
||||
craftable = craftItem(recipes, labels, string.format("%s/%d", loadedName, k), sideStorage, sideRobot)
|
||||
@@ -158,8 +161,11 @@ local sideStorage = 2
|
||||
for i = 0, 5 do
|
||||
local name = transposer.getInventoryName(i)
|
||||
if (name) then
|
||||
if (name == "opencomputers:robot") then sideRobot = i
|
||||
else sideStorage = i end
|
||||
if (name == "opencomputers:robot") then
|
||||
sideRobot = i
|
||||
else
|
||||
sideStorage = i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -202,7 +208,6 @@ local run = true
|
||||
local pageNumber = 1
|
||||
local maxPage = 1
|
||||
while run do
|
||||
|
||||
term.clear()
|
||||
if (pageNumber > maxPage) then pageNumber = maxPage end
|
||||
if (pageNumber < 1) then pageNumber = 1 end
|
||||
@@ -222,7 +227,8 @@ while run do
|
||||
|
||||
io.write("<id>|<new>|<refreshLabels> :")
|
||||
local userInput = io.read()
|
||||
if (userInput == false) then run = false
|
||||
if (userInput == false) then
|
||||
run = false
|
||||
elseif (userInput:match("^p%d$")) then
|
||||
---@diagnostic disable-next-line: cast-local-type
|
||||
pageNumber = tonumber(userInput:match("%d"))
|
||||
@@ -234,13 +240,19 @@ while run do
|
||||
if (recipes[itemName] and recipes[itemName][itemDamage]) then
|
||||
io.write("[item count] (default 1) :")
|
||||
local count = io.read()
|
||||
if (count == false) then goto END_CRAFT
|
||||
elseif (not tonumber(count)) then count = 1 end
|
||||
if (count == false) then
|
||||
goto END_CRAFT
|
||||
elseif (not tonumber(count)) then
|
||||
count = 1
|
||||
end
|
||||
local crafted = 0
|
||||
for i = 1, count do
|
||||
local craftedItem = craftItem(recipes, labels, recipesNames[userInput], sideStorage, sideRobot)
|
||||
if (craftedItem == true) then crafted = crafted + 1
|
||||
else print("Missing " .. (labels[craftedItem] or craftedItem)) end
|
||||
if (craftedItem == true) then
|
||||
crafted = crafted + 1
|
||||
else
|
||||
print("Missing " .. (labels[craftedItem] or craftedItem))
|
||||
end
|
||||
end
|
||||
print(string.format("Crafted %d/%d %s", crafted, count, labels[recipesNames[userInput]] or recipesNames[userInput]))
|
||||
end
|
||||
@@ -265,8 +277,11 @@ while run do
|
||||
save = io.read()
|
||||
end
|
||||
until (save == false or save:match("^[yYnN]$"))
|
||||
if (save == false) then goto END_NEW
|
||||
elseif (save == "y" or save == "Y") then itemInf = string.format("%s/%d", item.name, item.damage) end
|
||||
if (save == false) then
|
||||
goto END_NEW
|
||||
elseif (save == "y" or save == "Y") then
|
||||
itemInf = string.format("%s/%d", item.name, item.damage)
|
||||
end
|
||||
end
|
||||
table.insert(newPatern, itemInf)
|
||||
end
|
||||
@@ -316,7 +331,8 @@ while run do
|
||||
end
|
||||
end
|
||||
lFile:close()
|
||||
elseif (userInput == "exit" or userInput:match("^[eq]$")) then run = false
|
||||
elseif (userInput == "exit" or userInput:match("^[eq]$")) then
|
||||
run = false
|
||||
end
|
||||
end
|
||||
term.clear()
|
||||
|
@@ -1,58 +1,58 @@
|
||||
---@diagnostic disable: cast-local-type
|
||||
local libCB = require("libCB")
|
||||
local bank = require("bank_api")
|
||||
local shell = require("shell")
|
||||
local sides = require("sides")
|
||||
local coin = require("libCoin")
|
||||
local gui = require("libGUI")
|
||||
local event = require("event")
|
||||
local os = require("os")
|
||||
local component = require("component")
|
||||
local gpu = component.gpu
|
||||
local transposer = component.transposer
|
||||
local disk_drive = component.disk_drive
|
||||
local proxy = component.proxy
|
||||
local beep = component.computer.beep
|
||||
local libCB = require("libCB")
|
||||
local bank = require("bank_api")
|
||||
local shell = require("shell")
|
||||
local sides = require("sides")
|
||||
local coin = require("libCoin")
|
||||
local gui = require("libGUI")
|
||||
local event = require("event")
|
||||
local os = require("os")
|
||||
local component = require("component")
|
||||
local gpu = component.gpu
|
||||
local transposer = component.transposer
|
||||
local disk_drive = component.disk_drive
|
||||
local proxy = component.proxy
|
||||
local beep = component.computer.beep
|
||||
|
||||
local STORAGE = 0
|
||||
local EXTERIOR = 0
|
||||
local STORAGE = 0
|
||||
local EXTERIOR = 0
|
||||
|
||||
local MODE_IDLE = 0
|
||||
local MODE_PIN = 1
|
||||
local MODE_MENU = 2
|
||||
local MODE_WITHDRAW = 3
|
||||
local MODE_DEPOSIT = 4
|
||||
local MODE_STATS = 5
|
||||
local MODE_CLOSING = -1
|
||||
local mode = MODE_IDLE
|
||||
local CARD_IN_READER = false
|
||||
local MODE_IDLE = 0
|
||||
local MODE_PIN = 1
|
||||
local MODE_MENU = 2
|
||||
local MODE_WITHDRAW = 3
|
||||
local MODE_DEPOSIT = 4
|
||||
local MODE_STATS = 5
|
||||
local MODE_CLOSING = -1
|
||||
local mode = MODE_IDLE
|
||||
local CARD_IN_READER = false
|
||||
|
||||
local BUTTON_NAME_WITHDRAW = "bw"
|
||||
local BUTTON_NAME_DEPOSIT = "bd"
|
||||
local BUTTON_NAME_EJECT = "be"
|
||||
local BUTTON_NAME_WITHDRAW = "bw"
|
||||
local BUTTON_NAME_DEPOSIT = "bd"
|
||||
local BUTTON_NAME_EJECT = "be"
|
||||
|
||||
local main_screen = nil
|
||||
local card_wait = nil
|
||||
local keypad = nil
|
||||
local error_popup = nil
|
||||
local success_popup = nil
|
||||
local main_menu = nil
|
||||
local sold_text = nil
|
||||
local bin_text = nil
|
||||
local main_screen = nil
|
||||
local card_wait = nil
|
||||
local keypad = nil
|
||||
local error_popup = nil
|
||||
local success_popup = nil
|
||||
local main_menu = nil
|
||||
local sold_text = nil
|
||||
local bin_text = nil
|
||||
|
||||
local event_touch, event_drive, event_eject, event_magData = nil, nil, nil, nil
|
||||
|
||||
local old_res_x, old_res_y = nil, nil
|
||||
local old_res_x, old_res_y = nil, nil
|
||||
|
||||
---@type Component
|
||||
local drive = nil
|
||||
local drive = nil
|
||||
---@type cardData
|
||||
local cbData = nil
|
||||
local cbData = nil
|
||||
---@type encryptedCardData
|
||||
local encryptedData = nil
|
||||
local solde = 0
|
||||
local encryptedData = nil
|
||||
local solde = 0
|
||||
-- =============================================================================
|
||||
local eject = disk_drive.eject
|
||||
local eject = disk_drive.eject
|
||||
|
||||
local function endSession()
|
||||
mode = MODE_IDLE
|
||||
@@ -112,7 +112,7 @@ local function makeTransaction(amount)
|
||||
endSession()
|
||||
else
|
||||
local coinGiven, b, s, g, p = 0, 0, 0, 0, 0
|
||||
if (mode == MODE_WITHDRAW) then
|
||||
if (mode == MODE_WITHDRAW) then
|
||||
if (solde < amount) then
|
||||
error_popup:show("Insufisant balance.", true)
|
||||
amount = 0
|
||||
@@ -185,7 +185,7 @@ end
|
||||
|
||||
local function showNumericalKeypad()
|
||||
keypad:clearInput()
|
||||
keypad:setMaxInputLen(-1)
|
||||
keypad:setMaxInputLen( -1)
|
||||
keypad:setVisible(true)
|
||||
keypad:enable(true)
|
||||
keypad:hideInput(false)
|
||||
@@ -195,7 +195,7 @@ end
|
||||
-- =============================================================================
|
||||
local function buttonEventHandler(buttonName)
|
||||
if (mode == MODE_MENU) then
|
||||
if (buttonName == BUTTON_NAME_EJECT) then
|
||||
if (buttonName == BUTTON_NAME_EJECT) then
|
||||
endSession()
|
||||
elseif (buttonName == BUTTON_NAME_DEPOSIT) then
|
||||
mode = MODE_DEPOSIT
|
||||
|
@@ -1,11 +1,11 @@
|
||||
local gui = require("libGUI")
|
||||
local event = require("event")
|
||||
local bank_api = require("bank_api")
|
||||
local libCB = require("libCB")
|
||||
local os = require("os")
|
||||
local component = require("component")
|
||||
local gui = require("libGUI")
|
||||
local event = require("event")
|
||||
local bank_api = require("bank_api")
|
||||
local libCB = require("libCB")
|
||||
local os = require("os")
|
||||
local component = require("component")
|
||||
|
||||
local gpu = component.gpu
|
||||
local gpu = component.gpu
|
||||
|
||||
local MODE_CLOSING = -1
|
||||
local MODE_IDLE = 0
|
||||
@@ -21,25 +21,25 @@ local B_NAME_MAGCARD = "mg"
|
||||
local IMG_PATH = "/usr/share/bank_client/"
|
||||
local mode = MODE_IDLE
|
||||
|
||||
local touchListenerId = nil
|
||||
local driveListenerId = nil
|
||||
local intListenerId = nil
|
||||
local magDataListenerId = nil
|
||||
local touchListenerId = nil
|
||||
local driveListenerId = nil
|
||||
local intListenerId = nil
|
||||
local magDataListenerId = nil
|
||||
|
||||
local resX, resY = nil, nil
|
||||
local resX, resY = nil, nil
|
||||
|
||||
local screen = gui.Screen()
|
||||
local backgroundScreen = gui.Screen()
|
||||
local mainInterfaceScreen = gui.Screen()
|
||||
local newAccountScreen = gui.Screen()
|
||||
local viewAccountScreen = gui.Screen()
|
||||
local diskWaitPopup = gui.Screen()
|
||||
local cardSupportPopup = gui.Screen()
|
||||
local keypad = nil
|
||||
local statusBar = nil
|
||||
local acUUIDText = nil
|
||||
local soldeText = nil
|
||||
local pinText = nil
|
||||
local screen = gui.Screen()
|
||||
local backgroundScreen = gui.Screen()
|
||||
local mainInterfaceScreen = gui.Screen()
|
||||
local newAccountScreen = gui.Screen()
|
||||
local viewAccountScreen = gui.Screen()
|
||||
local diskWaitPopup = gui.Screen()
|
||||
local cardSupportPopup = gui.Screen()
|
||||
local keypad = nil
|
||||
local statusBar = nil
|
||||
local acUUIDText = nil
|
||||
local soldeText = nil
|
||||
local pinText = nil
|
||||
|
||||
local function closeClient(...)
|
||||
event.cancel(touchListenerId)
|
||||
@@ -124,12 +124,14 @@ local function voirCompte(pin, rawData)
|
||||
soldeText:setText("Solde : " .. solde)
|
||||
viewAccountScreen:setVisible(true)
|
||||
end
|
||||
else voirCompte(nil, rawData) end
|
||||
else
|
||||
voirCompte(nil, rawData)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function buttonEventHandler(buttonName)
|
||||
if (buttonName == B_NAME_POPUP_CLOSE) then
|
||||
if (buttonName == B_NAME_POPUP_CLOSE) then
|
||||
closePopup(diskWaitPopup)
|
||||
closePopup(cardSupportPopup)
|
||||
printStatus("cancel")
|
||||
@@ -145,8 +147,8 @@ local function buttonEventHandler(buttonName)
|
||||
closePopup(cardSupportPopup)
|
||||
mode = MODE_IDLE
|
||||
end
|
||||
if (mode == MODE_IDLE) then
|
||||
if (buttonName == B_NAME_VIEW_ACCOUNT) then
|
||||
if (mode == MODE_IDLE) then
|
||||
if (buttonName == B_NAME_VIEW_ACCOUNT) then
|
||||
mode = MODE_VIEW_ACCOUNT
|
||||
printStatus("entering view account mode")
|
||||
openPopup(diskWaitPopup)
|
||||
@@ -157,7 +159,7 @@ local function buttonEventHandler(buttonName)
|
||||
openPopup(cardSupportPopup)
|
||||
end
|
||||
elseif (mode == MODE_CREATE_ACCOUNT_1) then
|
||||
if (buttonName == B_NAME_FLOPPY) then
|
||||
if (buttonName == B_NAME_FLOPPY) then
|
||||
mode = MODE_CREATE_ACCOUNT_2
|
||||
openPopup(diskWaitPopup)
|
||||
closePopup(cardSupportPopup)
|
||||
@@ -172,7 +174,7 @@ end
|
||||
|
||||
local function diskEventHandler(eName, cAddr, cType)
|
||||
if (cType == "drive") then
|
||||
if (mode == MODE_VIEW_ACCOUNT) then
|
||||
if (mode == MODE_VIEW_ACCOUNT) then
|
||||
printStatus("Card inserted")
|
||||
voirCompte(nil, component.proxy(cAddr))
|
||||
elseif (mode == MODE_CREATE_ACCOUNT_2) then
|
||||
@@ -190,7 +192,6 @@ local function magDataEventHandler(eName, eAddr)
|
||||
end
|
||||
|
||||
local function init()
|
||||
|
||||
resX, resY = gpu.getResolution()
|
||||
gpu.setResolution(80, 25)
|
||||
|
||||
|
@@ -75,7 +75,7 @@ end
|
||||
local function writeAccount(accountUUID, solde)
|
||||
print("-> writeAccount")
|
||||
local account = {solde = solde, uuid = accountUUID}
|
||||
account.sig = dataCard.encode64(dataCard.ecdsa(solde .. accountUUID, getKey(false))--[[@as string]] ) --encode sig to make saving it easier
|
||||
account.sig = dataCard.encode64(dataCard.ecdsa(solde .. accountUUID, getKey(false)) --[[@as string]]) --encode sig to make saving it easier
|
||||
local fileContent = serialization.serialize(account) --convert the table into a string
|
||||
fileContent = dataCard.encrypt(fileContent, getAES(), AES_IV) --encrypt the data
|
||||
fileContent = dataCard.encode64(fileContent) --encode the encrypted data to make saving and reading it easier
|
||||
@@ -115,7 +115,7 @@ end
|
||||
|
||||
local args, opts = shell.parse(...)
|
||||
if (args[3]) then assert(tonumber(args[3]) ~= nil, "not a number") end
|
||||
if (args[1] == "get") then
|
||||
if (args[1] == "get") then
|
||||
local ac = loadAccount(args[2])
|
||||
if (type(ac) == "number") then
|
||||
print("err:" .. ac)
|
||||
@@ -139,7 +139,7 @@ elseif (args[1] == 'test') then
|
||||
assert(clearData, "Error when loading the account data")
|
||||
local b, c
|
||||
b = dataCard.ecdsa(clearData.solde .. args[2], getKey(true), dataCard.decode64(clearData.sig))
|
||||
c = dataCard.encode64(dataCard.ecdsa(clearData.solde .. args[2], getKey(false))--[[@as string]] )
|
||||
c = dataCard.encode64(dataCard.ecdsa(clearData.solde .. args[2], getKey(false)) --[[@as string]])
|
||||
print(b)
|
||||
print("saved: " .. clearData.sig)
|
||||
print("calc : " .. c)
|
||||
|
@@ -114,7 +114,7 @@ end
|
||||
local function writeAccount(accountUUID, solde)
|
||||
log("-> writeAccount")
|
||||
local account = {solde = solde, uuid = accountUUID}
|
||||
account.sig = dataCard.encode64(dataCard.ecdsa(solde .. accountUUID, getKey(false))--[[@as string]] ) --encode sig to make saving it easier
|
||||
account.sig = dataCard.encode64(dataCard.ecdsa(solde .. accountUUID, getKey(false)) --[[@as string]]) --encode sig to make saving it easier
|
||||
local fileContent = serialization.serialize(account) --convert the table into a string
|
||||
fileContent = dataCard.encrypt(fileContent, getAES(), AES_IV) --encrypt the data
|
||||
fileContent = dataCard.encode64(fileContent) --encode the encrypted data to make saving and reading it easier
|
||||
@@ -154,7 +154,7 @@ local function handlerMakeTransaction(address, from, to, amount)
|
||||
sendMsg(address, PROTOCOLE_ERROR_RECEIVING_ACCOUNT, PROTOCOLE_MAKE_TRANSACTION)
|
||||
else
|
||||
---@diagnostic disable-next-line:param-type-mismatch
|
||||
if (editAccount(fromAccount.uuid, (-1 * math.abs(amount))) and editAccount(toAccount.uuid, (math.abs(amount)))) then
|
||||
if (editAccount(fromAccount.uuid, ( -1 * math.abs(amount))) and editAccount(toAccount.uuid, (math.abs(amount)))) then
|
||||
sendMsg(address, PROTOCOLE_OK, PROTOCOLE_MAKE_TRANSACTION)
|
||||
else
|
||||
sendMsg(address, PROTOCOLE_ERROR_UNKNOWN, PROTOCOLE_MAKE_TRANSACTION)
|
||||
@@ -265,7 +265,7 @@ local function listener(sig, local_add, remote_add, port, dist, command, arg)
|
||||
log("==> " .. remote_add .. " " .. command .. " " .. arg)
|
||||
arg = serialization.unserialize(arg)
|
||||
-------------------------------------
|
||||
if (command == PROTOCOLE_GET_CREDIT) then
|
||||
if (command == PROTOCOLE_GET_CREDIT) then
|
||||
log(arg.cbData.uuid .. arg.cbData.cbUUID)
|
||||
if (cb.checkCBdata(arg.cbData, getKey(true))) then
|
||||
handlerGetCredit(remote_add, arg.cbData)
|
||||
|
@@ -91,8 +91,11 @@ function crypttool.Proxy.new(filesystemComponent, aesKey)
|
||||
local eFile = self.rawFS.open(path, mode)
|
||||
assert(eFile, "Could not open the encrypted file")
|
||||
local tFile
|
||||
if (mode:match("b")) then tFile = io.open(self.handles[handle].tmpFilePath, "wb")
|
||||
else tFile = io.open(self.handles[handle].tmpFilePath, "w") end
|
||||
if (mode:match("b")) then
|
||||
tFile = io.open(self.handles[handle].tmpFilePath, "wb")
|
||||
else
|
||||
tFile = io.open(self.handles[handle].tmpFilePath, "w")
|
||||
end
|
||||
assert(tFile)
|
||||
local eData = ""
|
||||
repeat
|
||||
@@ -136,7 +139,12 @@ function crypttool.Proxy.new(filesystemComponent, aesKey)
|
||||
self.handles[handle] = nil
|
||||
end
|
||||
|
||||
event.listen("component_removed", function(e, a, t) if (a == self.rawFS.address) then fs.umount(self); return false end end)
|
||||
event.listen("component_removed", function(e, a, t)
|
||||
if (a == self.rawFS.address) then
|
||||
fs.umount(self);
|
||||
return false
|
||||
end
|
||||
end)
|
||||
|
||||
return self
|
||||
end
|
||||
|
@@ -5,33 +5,41 @@ local computer = {}
|
||||
|
||||
---Tries to start the computer. Returns true on success, false otherwise. Note that this will also return false if the computer was already running. If the computer is currently shutting down, this will cause the computer to reboot instead.
|
||||
---@return boolean
|
||||
function computer.start() end
|
||||
function computer.start()
|
||||
end
|
||||
|
||||
---Tries to stop the computer. Returns true on success, false otherwise. Also returns false if the computer is already stopped.
|
||||
---@return boolean
|
||||
function computer.stop() end
|
||||
function computer.stop()
|
||||
end
|
||||
|
||||
---Returns whether the computer is currently running.
|
||||
---@return boolean
|
||||
function computer.isRunning() end
|
||||
function computer.isRunning()
|
||||
end
|
||||
|
||||
---Plays a tone, useful to alert users via audible feedback. Supports frequencies from 20 to 2000Hz, with a duration of up to 5 seconds.
|
||||
---@param frequency number
|
||||
---@param duration number
|
||||
function computer.beep(frequency, duration) end
|
||||
function computer.beep(frequency, duration)
|
||||
end
|
||||
|
||||
---Returns a table of device information. Note that this is architecture-specific and some may not implement it at all.
|
||||
---@return table
|
||||
function computer.getDeviceInfo() end
|
||||
function computer.getDeviceInfo()
|
||||
end
|
||||
|
||||
---Attempts to crash the computer for the specified reason.
|
||||
---@param reason string
|
||||
function computer.crash(reason) end
|
||||
function computer.crash(reason)
|
||||
end
|
||||
|
||||
---Returns the computer's current architecture.
|
||||
---@return string
|
||||
function computer.getArchitecture() end
|
||||
function computer.getArchitecture()
|
||||
end
|
||||
|
||||
---Returns whether or not the computer is, in fact, a robot.
|
||||
---@return boolean
|
||||
function computer.isRobot() end
|
||||
function computer.isRobot()
|
||||
end
|
||||
|
@@ -7,41 +7,49 @@ local data = {}
|
||||
---Computes CRC-32 hash of the data. Result is in binary format.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.crc32(data) end
|
||||
function data.crc32(data)
|
||||
end
|
||||
|
||||
---Applies base64 decoding to the data.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.decode64(data) end
|
||||
function data.decode64(data)
|
||||
end
|
||||
|
||||
---Applies base64 encoding to the data. Result is in binary format.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.encode64(data) end
|
||||
function data.encode64(data)
|
||||
end
|
||||
|
||||
---Computes MD5 hash of the data. Result is in binary format
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.md5(data) end
|
||||
function data.md5(data)
|
||||
end
|
||||
|
||||
---Computes SHA2-256 hash of the data. Result is in binary format.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.sha256(data) end
|
||||
function data.sha256(data)
|
||||
end
|
||||
|
||||
---Applies deflate compression to the data.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.deflate(data) end
|
||||
function data.deflate(data)
|
||||
end
|
||||
|
||||
---Applies inflate decompression to the data.
|
||||
---@param data string
|
||||
---@return string
|
||||
function data.inflate(data) end
|
||||
function data.inflate(data)
|
||||
end
|
||||
|
||||
---The maximum size of data that can be passed to other functions of the card.
|
||||
---@return number
|
||||
function data.getLimit() end
|
||||
function data.getLimit()
|
||||
end
|
||||
|
||||
--endregion
|
||||
|
||||
@@ -52,19 +60,22 @@ function data.getLimit() end
|
||||
---@param key string
|
||||
---@param iv string
|
||||
---@return string
|
||||
function data.encrypt(data, key, iv) end
|
||||
function data.encrypt(data, key, iv)
|
||||
end
|
||||
|
||||
---Reverses AES encryption on the data using the key and the IV.
|
||||
---@param data string
|
||||
---@param key string
|
||||
---@param iv string
|
||||
---@return string
|
||||
function data.decrypt(data, key, iv) end
|
||||
function data.decrypt(data, key, iv)
|
||||
end
|
||||
|
||||
---Generates a random binary string of len length.
|
||||
---@param len number
|
||||
---@return string
|
||||
function data.random(len) end
|
||||
function data.random(len)
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
||||
@@ -75,11 +86,13 @@ local ecKey = {}
|
||||
|
||||
---is the key public
|
||||
---@return boolean
|
||||
function ecKey.isPublic() end
|
||||
function ecKey.isPublic()
|
||||
end
|
||||
|
||||
---serialize the key to save it
|
||||
---@return string
|
||||
function ecKey.serialize() end
|
||||
function ecKey.serialize()
|
||||
end
|
||||
|
||||
---@class EcKeyPublic : EcKey
|
||||
|
||||
@@ -91,7 +104,8 @@ function ecKey.serialize() end
|
||||
---key.serialize():string Keys also contain the function key.isPublic():boolean
|
||||
---@param bitLen? 256 | 384
|
||||
---@return EcKeyPublic publicKey, EcKeyPrivate privateKey
|
||||
function data.generateKeyPair(bitLen) end
|
||||
function data.generateKeyPair(bitLen)
|
||||
end
|
||||
|
||||
---Generates a signiture of data using a private key. If signature is present
|
||||
---verifies the signature using the public key, the previously generated
|
||||
@@ -100,7 +114,8 @@ function data.generateKeyPair(bitLen) end
|
||||
---@param key EcKey
|
||||
---@param sig? string
|
||||
---@return string|boolean
|
||||
function data.ecdsa(data, key, sig) end
|
||||
function data.ecdsa(data, key, sig)
|
||||
end
|
||||
|
||||
--- Generates a Diffie-Hellman shared key using the first user's private key and
|
||||
--- the second user's public key. An example of a basic key relation:
|
||||
@@ -108,12 +123,14 @@ function data.ecdsa(data, key, sig) end
|
||||
---@param privateKey EcKeyPrivate
|
||||
---@param publicKey EcKeyPublic
|
||||
---@return string
|
||||
function data.ecdh(privateKey, publicKey) end
|
||||
function data.ecdh(privateKey, publicKey)
|
||||
end
|
||||
|
||||
---Transforms a key from string to it's arbitrary type.
|
||||
---@param data string
|
||||
---@param type "ec-public" | "ec-private"
|
||||
---@return table
|
||||
function data.deserializeKey(data, type) end
|
||||
function data.deserializeKey(data, type)
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
@@ -6,12 +6,15 @@ local disk_drive = {}
|
||||
---Eject the currently present medium from the drive.
|
||||
---@param velocity? number
|
||||
---@return boolean
|
||||
function disk_drive.eject(velocity) end
|
||||
function disk_drive.eject(velocity)
|
||||
end
|
||||
|
||||
---Check whether some medium is currently in the drive.
|
||||
---@return boolean
|
||||
function disk_drive.isEmpty() end
|
||||
function disk_drive.isEmpty()
|
||||
end
|
||||
|
||||
---Return the internal floppy disk address.
|
||||
---@return string|nil address, string|nil reason
|
||||
function disk_drive.media() end
|
||||
function disk_drive.media()
|
||||
end
|
||||
|
@@ -6,40 +6,49 @@ local drive = {}
|
||||
---Read a single byte at the specified offset.
|
||||
---@param offset number
|
||||
---@return number
|
||||
function drive.readByte(offset) end
|
||||
function drive.readByte(offset)
|
||||
end
|
||||
|
||||
---Write a single byte to the specified offset.
|
||||
---@param offset number
|
||||
---@param value number
|
||||
function drive.writeByte(offset, value) end
|
||||
function drive.writeByte(offset, value)
|
||||
end
|
||||
|
||||
---Returns the size of a single sector on the drive, in bytes.
|
||||
---@return number
|
||||
function drive.getSectorSize() end
|
||||
function drive.getSectorSize()
|
||||
end
|
||||
|
||||
---Get the current label of the drive.
|
||||
---@return string
|
||||
function drive.getLabel() end
|
||||
function drive.getLabel()
|
||||
end
|
||||
|
||||
---Sets the label of the drive. Returns the new value, which may be truncated.
|
||||
---@param value string
|
||||
---@return string
|
||||
function drive.setLabel(value) end
|
||||
function drive.setLabel(value)
|
||||
end
|
||||
|
||||
---Read the current contents of the specified sector.
|
||||
---@param sector number
|
||||
---@return string
|
||||
function drive.readSector(sector) end
|
||||
function drive.readSector(sector)
|
||||
end
|
||||
|
||||
---Write the specified contents to the specified sector.
|
||||
---@param sector number
|
||||
---@param value string
|
||||
function drive.writeSector(sector, value) end
|
||||
function drive.writeSector(sector, value)
|
||||
end
|
||||
|
||||
---Returns the number of platters in the drive.
|
||||
---@return number
|
||||
function drive.getPlatterCount() end
|
||||
function drive.getPlatterCount()
|
||||
end
|
||||
|
||||
---Returns the total capacity of the drive, in bytes.
|
||||
---@return number
|
||||
function drive.getCapacity() end
|
||||
function drive.getCapacity()
|
||||
end
|
||||
|
@@ -5,92 +5,110 @@ local filesytem = {}
|
||||
|
||||
---The currently used capacity of the file system, in bytes.
|
||||
---@return number bytes
|
||||
function filesytem.spaceUsed() end
|
||||
function filesytem.spaceUsed()
|
||||
end
|
||||
|
||||
---Opens a new file descriptor and returns its handle.
|
||||
---@param path string
|
||||
---@param mode? string
|
||||
---@return number hanlde
|
||||
---@nodiscard
|
||||
function filesytem.open(path, mode) end
|
||||
function filesytem.open(path, mode)
|
||||
end
|
||||
|
||||
---Seeks in an open file descriptor with the specified handle. Returns the new pointer position.
|
||||
---@param handle number
|
||||
---@param whence string
|
||||
---@param offset number
|
||||
---@return number
|
||||
function filesytem.seek(handle, whence, offset) end
|
||||
function filesytem.seek(handle, whence, offset)
|
||||
end
|
||||
|
||||
---Creates a directory at the specified absolute path in the file system. Creates parent directories, if necessary.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.makeDirectory(path) end
|
||||
function filesytem.makeDirectory(path)
|
||||
end
|
||||
|
||||
---Returns whether an object exists at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.exists(path) end
|
||||
function filesytem.exists(path)
|
||||
end
|
||||
|
||||
---Returns whether the file system is read-only.
|
||||
---@return boolean
|
||||
function filesytem.isReadOnly() end
|
||||
function filesytem.isReadOnly()
|
||||
end
|
||||
|
||||
---Writes the specified data to an open file descriptor with the specified handle.
|
||||
---@param handle number
|
||||
---@param value string
|
||||
---@return boolean
|
||||
function filesytem.write(handle, value) end
|
||||
function filesytem.write(handle, value)
|
||||
end
|
||||
|
||||
---The overall capacity of the file system, in bytes.
|
||||
---@return number
|
||||
function filesytem.spaceTotal() end
|
||||
function filesytem.spaceTotal()
|
||||
end
|
||||
|
||||
---Returns whether the object at the specified absolute path in the file system is a directory.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.isDirectory(path) end
|
||||
function filesytem.isDirectory(path)
|
||||
end
|
||||
|
||||
---Renames/moves an object from the first specified absolute path in the file system to the second.
|
||||
---@param from string
|
||||
---@param to any
|
||||
---@return boolean
|
||||
function filesytem.rename(from, to) end
|
||||
function filesytem.rename(from, to)
|
||||
end
|
||||
|
||||
---Returns a list of names of objects in the directory at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return table
|
||||
function filesytem.list(path) end
|
||||
function filesytem.list(path)
|
||||
end
|
||||
|
||||
---Returns the (real world) timestamp of when the object at the specified absolute path in the file system was modified.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesytem.lastModified(path) end
|
||||
function filesytem.lastModified(path)
|
||||
end
|
||||
|
||||
---Get the current label of the file system.
|
||||
---@return string
|
||||
function filesytem.getLabel() end
|
||||
function filesytem.getLabel()
|
||||
end
|
||||
|
||||
---Removes the object at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesytem.remove(path) end
|
||||
function filesytem.remove(path)
|
||||
end
|
||||
|
||||
---Closes an open file descriptor with the specified handle.
|
||||
---@param handle number
|
||||
function filesytem.close(handle) end
|
||||
function filesytem.close(handle)
|
||||
end
|
||||
|
||||
---Returns the size of the object at the specified absolute path in the file system.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesytem.size(path) end
|
||||
function filesytem.size(path)
|
||||
end
|
||||
|
||||
---Reads up to the specified amount of data from an open file descriptor with the specified handle. Returns nil when EOF is reached.
|
||||
---@param handle number
|
||||
---@param count number
|
||||
---@return string or nil
|
||||
function filesytem.read(handle, count) end
|
||||
function filesytem.read(handle, count)
|
||||
end
|
||||
|
||||
---Sets the label of the file system. Returns the new value, which may be truncated.
|
||||
---@param value string
|
||||
---@return string
|
||||
function filesytem.setLabel(value) end
|
||||
function filesytem.setLabel(value)
|
||||
end
|
||||
|
@@ -7,86 +7,104 @@ local gpu = {}
|
||||
---@param address string
|
||||
---@param reset? boolean
|
||||
---@return boolean sucess, string|nil reason
|
||||
function gpu.bind(address, reset) end
|
||||
function gpu.bind(address, reset)
|
||||
end
|
||||
|
||||
---Get the address of the screen the GPU is bound to. Since 1.3.2.
|
||||
---@return string address
|
||||
function gpu.getScreen() end
|
||||
function gpu.getScreen()
|
||||
end
|
||||
|
||||
---Gets the current background color. This background color is applied to all “pixels” that get changed by other operations.
|
||||
---Note that the returned number is either an RGB value in hexadecimal format, i.e. 0xRRGGBB, or a palette index. The second returned value indicates which of the two it is (true for palette color, false for RGB value).
|
||||
---@return number color, boolean isPaletteIndex
|
||||
function gpu.getBackground() end
|
||||
function gpu.getBackground()
|
||||
end
|
||||
|
||||
---Sets the background color to apply to “pixels” modified by other operations from now on. The returned value is the old background color, as the actual value it was set to (i.e. not compressed to the color space currently set). The first value is the previous color as an RGB value. If the color was from the palette, the second value will be the index in the palette. Otherwise it will be nil. Note that the color is expected to be specified in hexadecimal RGB format, i.e. 0xRRGGBB. This is to allow uniform color operations regardless of the color depth supported by the screen and GPU.
|
||||
---@param color number
|
||||
---@param isPaletteIndex? boolean
|
||||
---@return number previousColor, number|nil paletIndex
|
||||
function gpu.setBackground(color, isPaletteIndex) end
|
||||
function gpu.setBackground(color, isPaletteIndex)
|
||||
end
|
||||
|
||||
---Like getBackground, but for the foreground color.
|
||||
---@return number color, boolean isPaletteIndex
|
||||
function gpu.getForeground() end
|
||||
function gpu.getForeground()
|
||||
end
|
||||
|
||||
---Like setBackground, but for the foreground color.
|
||||
---@param color number
|
||||
---@param isPaletteIndex? boolean
|
||||
---@return number previousColor, number|nil paletIndex
|
||||
function gpu.setForeground(color, isPaletteIndex) end
|
||||
function gpu.setForeground(color, isPaletteIndex)
|
||||
end
|
||||
|
||||
---Gets the RGB value of the color in the palette at the specified index.
|
||||
---@param index number
|
||||
---@return number color rbg color
|
||||
function gpu.getPaletteColor(index) end
|
||||
function gpu.getPaletteColor(index)
|
||||
end
|
||||
|
||||
---Sets the RGB value of the color in the palette at the specified index.
|
||||
---@param index number
|
||||
---@param value number rbg color
|
||||
---@return number oldPatetteColor rbg color
|
||||
function gpu.setPaletteColor(index, value) end
|
||||
function gpu.setPaletteColor(index, value)
|
||||
end
|
||||
|
||||
---Gets the maximum supported color depth supported by the GPU and the screen it is bound to (minimum of the two).
|
||||
---@return number maxDepth maximum color depth
|
||||
function gpu.maxDepth() end
|
||||
function gpu.maxDepth()
|
||||
end
|
||||
|
||||
---The currently set color depth of the GPU/screen, in bits. Can be 1, 4 or 8.
|
||||
---@return number colorDepth color depth
|
||||
function gpu.getDepth() end
|
||||
function gpu.getDepth()
|
||||
end
|
||||
|
||||
---Sets the color depth to use. Can be up to the maximum supported color depth. If a larger or invalid value is provided it will throw an error. Returns the old depth as one of the strings OneBit, FourBit, or EightBit.
|
||||
---@param bit number
|
||||
function gpu.setDepth(bit) end
|
||||
function gpu.setDepth(bit)
|
||||
end
|
||||
|
||||
---Gets the maximum resolution supported by the GPU and the screen it is bound to (minimum of the two).
|
||||
---@return number x, number y
|
||||
function gpu.maxResolution() end
|
||||
function gpu.maxResolution()
|
||||
end
|
||||
|
||||
---Gets the currently set resolution.
|
||||
---@return number x, number y
|
||||
function gpu.getResolution() end
|
||||
function gpu.getResolution()
|
||||
end
|
||||
|
||||
---Sets the specified resolution. Can be up to the maximum supported resolution. If a larger or invalid resolution is provided it will throw an error. Returns true if the resolution was changed (may return false if an attempt was made to set it to the same value it was set before), false otherwise.
|
||||
---@return number oldX, number oldY
|
||||
function gpu.setResolution(width, height) end
|
||||
function gpu.setResolution(width, height)
|
||||
end
|
||||
|
||||
---Get the current viewport resolution.
|
||||
---@return number x, number y
|
||||
function gpu.getViewport() end
|
||||
function gpu.getViewport()
|
||||
end
|
||||
|
||||
---Set the current viewport resolution. Returns true if it was changed (may return false if an attempt was made to set it to the same value it was set before), false otherwise. This makes it look like screen resolution is lower, but the actual resolution stays the same. Characters outside top-left corner of specified size are just hidden, and are intended for rendering or storing things off-screen and copying them to the visible area when needed. Changing resolution will change viewport to whole screen.
|
||||
---@param width number
|
||||
---@param height number
|
||||
---@return boolean
|
||||
function gpu.setViewport(width, height) end
|
||||
function gpu.setViewport(width, height)
|
||||
end
|
||||
|
||||
---Gets the size in blocks of the screen the graphics card is bound to. For simple screens and robots this will be one by one. Deprecated, use screen.getAspectRatio() instead.
|
||||
---@deprecated
|
||||
---@return number x, number y
|
||||
function gpu.getSize() end
|
||||
function gpu.getSize()
|
||||
end
|
||||
|
||||
---Gets the character currently being displayed at the specified coordinates. The second and third returned values are the fore- and background color, as hexvalues. If the colors are from the palette, the fourth and fifth values specify the palette index of the color, otherwise they are nil.
|
||||
---@return string character, number foreground, number background, number|nil frgPaletIndex, number|nil bgrPaletIndex
|
||||
function gpu.get(x, y) end
|
||||
function gpu.get(x, y)
|
||||
end
|
||||
|
||||
---Writes a string to the screen, starting at the specified coordinates. The string will be copied to the screen's buffer directly, in a single row. This means even if the specified string contains line breaks, these will just be printed as special characters, the string will not be displayed over multiple lines. Returns true if the string was set to the buffer, false otherwise.
|
||||
---The optional fourth argument makes the specified text get printed vertically instead, if true.
|
||||
@@ -94,7 +112,8 @@ function gpu.get(x, y) end
|
||||
---@param y number
|
||||
---@param value string
|
||||
---@param vertical? boolean
|
||||
function gpu.set(x, y, value, vertical) end
|
||||
function gpu.set(x, y, value, vertical)
|
||||
end
|
||||
|
||||
---Copies a portion of the screens buffer to another location. The source rectangle is specified by the x, y, width and height parameters. The target rectangle is defined by x + tx, y + ty, width and height. Returns true on success, false otherwise.
|
||||
---@param x number
|
||||
@@ -104,7 +123,8 @@ function gpu.set(x, y, value, vertical) end
|
||||
---@param tx number
|
||||
---@param ty number
|
||||
---@return boolean
|
||||
function gpu.copy(x, y, width, height, tx, ty) end
|
||||
function gpu.copy(x, y, width, height, tx, ty)
|
||||
end
|
||||
|
||||
---Fills a rectangle in the screen buffer with the specified character. The target rectangle is specified by the x and y coordinates and the rectangle's width and height. The fill character char must be a string of length one, i.e. a single character. Returns true on success, false otherwise.
|
||||
---Note that filling screens with spaces ( ) is usually less expensive, i.e. consumes less energy, because it is considered a “clear” operation (see config).
|
||||
@@ -114,49 +134,59 @@ function gpu.copy(x, y, width, height, tx, ty) end
|
||||
---@param height number
|
||||
---@param char string
|
||||
---@return boolean
|
||||
function gpu.fill(x, y, width, height, char) end
|
||||
function gpu.fill(x, y, width, height, char)
|
||||
end
|
||||
|
||||
--#region video_buffer
|
||||
|
||||
--Returns the index of the currently selected buffer. 0 is reserved for the screen, and may return 0 even when there is no screen
|
||||
---@return number index
|
||||
function gpu.getActiveBuffer() end
|
||||
function gpu.getActiveBuffer()
|
||||
end
|
||||
|
||||
--Sets the active buffer to index. 0 is reserved for the screen and can be set even when there is no screen. Returns nil for an invalid index (0 is valid even with no screen)
|
||||
---@param index number
|
||||
---@return number previousIndex
|
||||
function gpu.setActiveBuffer(index) end
|
||||
function gpu.setActiveBuffer(index)
|
||||
end
|
||||
|
||||
---Returns an array of all current page indexes (0 is not included in this list, that is reserved for the screen).
|
||||
---@return table
|
||||
function gpu.buffers() end
|
||||
function gpu.buffers()
|
||||
end
|
||||
|
||||
---Allocates a new buffer with dimensions width*heigh (gpu max resolution by default). Returns the index of this new buffer or error when there is not enough video memory. A buffer can be allocated even when there is no screen bound to this gpu. Index 0 is always reserved for the screen and thus the lowest possible index of an allocated buffer is always 1.
|
||||
---@param width? number
|
||||
---@param height? number
|
||||
---@return number
|
||||
function gpu.allocateBuffer(width, height) end
|
||||
function gpu.allocateBuffer(width, height)
|
||||
end
|
||||
|
||||
---Removes buffer at index (default: current buffer index). Returns true if the buffer was removed. When you remove the currently selected buffer, the gpu automatically switches back to index 0 (reserved for a screen)
|
||||
---@param index? number
|
||||
---@return boolean
|
||||
function gpu.freeBuffer(index) end
|
||||
function gpu.freeBuffer(index)
|
||||
end
|
||||
|
||||
---Removes all buffers, freeing all video memory. The buffer index is always 0 after this call.
|
||||
function gpu.freeAllBuffers() end
|
||||
function gpu.freeAllBuffers()
|
||||
end
|
||||
|
||||
---Returns the total memory size of the gpu vram. This does not include the screen.
|
||||
---@return number
|
||||
function gpu.totalMemory() end
|
||||
function gpu.totalMemory()
|
||||
end
|
||||
|
||||
---Returns the total free memory not allocated to buffers. This does not include the screen.
|
||||
---@return number
|
||||
function gpu.freeMemory() end
|
||||
function gpu.freeMemory()
|
||||
end
|
||||
|
||||
---Returns the buffer size at index (default: current buffer index). Returns the screen resolution for index 0. Returns nil for invalid indexes
|
||||
---@param index? number
|
||||
---@return number, number
|
||||
function gpu.getBufferSize(index) end
|
||||
function gpu.getBufferSize(index)
|
||||
end
|
||||
|
||||
---Copy a region from buffer to buffer, screen to buffer, or buffer to screen. Defaults:
|
||||
--- - dst = 0, the screen
|
||||
@@ -172,6 +202,7 @@ function gpu.getBufferSize(index) end
|
||||
---@param src? number
|
||||
---@param fromCol? number
|
||||
---@param fromRow? number
|
||||
function gpu.bitblt(dst, col, row, width, height, src, fromCol, fromRow) end
|
||||
function gpu.bitblt(dst, col, row, width, height, src, fromCol, fromRow)
|
||||
end
|
||||
|
||||
---#endregion
|
||||
|
@@ -7,24 +7,28 @@ local internet = {}
|
||||
|
||||
---Returns whether TCP connections can be made (config setting).
|
||||
---@return boolean
|
||||
function internet.isTcpEnabled() end
|
||||
function internet.isTcpEnabled()
|
||||
end
|
||||
|
||||
---Returns whether HTTP requests can be made (config setting).
|
||||
---@return boolean
|
||||
function internet.isHttpEnabled() end
|
||||
function internet.isHttpEnabled()
|
||||
end
|
||||
|
||||
---Opens a new TCP connection. Returns the handle of the connection.
|
||||
---@param address string
|
||||
---@param port? number
|
||||
---@return TcpSocket
|
||||
function internet.connect(address, port) end
|
||||
function internet.connect(address, port)
|
||||
end
|
||||
|
||||
---Sends a new HTTP request. Returns the handle of the connection.
|
||||
---@param url string
|
||||
---@param postData? string
|
||||
---@param headers? table
|
||||
---@return HttpRequest
|
||||
function internet.request(url, postData, headers) end
|
||||
function internet.request(url, postData, headers)
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
||||
@@ -36,23 +40,28 @@ local TcpSocket = {}
|
||||
---Tries to read data from the socket stream. Returns the read byte array.
|
||||
---@param n? number
|
||||
---@return string
|
||||
function TcpSocket.read(n) end
|
||||
function TcpSocket.read(n)
|
||||
end
|
||||
|
||||
---Closes an open socket stream.
|
||||
function TcpSocket.close() end
|
||||
function TcpSocket.close()
|
||||
end
|
||||
|
||||
---Tries to write data to the socket stream. Returns the number of bytes written.
|
||||
---@param data string
|
||||
---@return number
|
||||
function TcpSocket.write(data) end
|
||||
function TcpSocket.write(data)
|
||||
end
|
||||
|
||||
---Ensures a socket is connected. Errors if the connection failed.
|
||||
---@return boolean
|
||||
function TcpSocket.finishConnect() end
|
||||
function TcpSocket.finishConnect()
|
||||
end
|
||||
|
||||
---Returns the id for this socket.
|
||||
---@return string
|
||||
function TcpSocket.id() end
|
||||
function TcpSocket.id()
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
||||
@@ -64,17 +73,21 @@ local HttpRequest = {}
|
||||
---Tries to read data from the response. Returns the read byte array.
|
||||
---@param n? number
|
||||
---@return string
|
||||
function HttpRequest.read(n) end
|
||||
function HttpRequest.read(n)
|
||||
end
|
||||
|
||||
---Get response code, message and headers.
|
||||
---@return number status, string statusName, table headers
|
||||
function HttpRequest.response() end
|
||||
function HttpRequest.response()
|
||||
end
|
||||
|
||||
---Closes an open socket stream.
|
||||
function HttpRequest.close() end
|
||||
function HttpRequest.close()
|
||||
end
|
||||
|
||||
---Ensures a response is available. Errors if the connection failed.
|
||||
---@return boolean
|
||||
function HttpRequest.finishConnect() end
|
||||
function HttpRequest.finishConnect()
|
||||
end
|
||||
|
||||
--#endregion
|
||||
|
@@ -5,35 +5,44 @@
|
||||
local modem = {}
|
||||
|
||||
---@return boolean
|
||||
function modem.isWireless() end
|
||||
function modem.isWireless()
|
||||
end
|
||||
|
||||
---@deprecated
|
||||
---@return number
|
||||
function modem.maxPacketSize() end
|
||||
function modem.maxPacketSize()
|
||||
end
|
||||
|
||||
---@param port number
|
||||
---@return boolean
|
||||
function modem.isOpen(port) end
|
||||
function modem.isOpen(port)
|
||||
end
|
||||
|
||||
---@param port number
|
||||
function modem.open(port) end
|
||||
function modem.open(port)
|
||||
end
|
||||
|
||||
---@param port number?
|
||||
---@return boolean
|
||||
function modem.close(port) end
|
||||
function modem.close(port)
|
||||
end
|
||||
|
||||
---@param address string
|
||||
---@param port number
|
||||
---@varargs ModemSafeType
|
||||
function modem.send(address, port, ...) end
|
||||
function modem.send(address, port, ...)
|
||||
end
|
||||
|
||||
---@param port number
|
||||
---@varargs ModemSafeType
|
||||
function modem.broadcast(port, ...) end
|
||||
function modem.broadcast(port, ...)
|
||||
end
|
||||
|
||||
---@return number
|
||||
function modem.getStrength() end
|
||||
function modem.getStrength()
|
||||
end
|
||||
|
||||
---@param message string
|
||||
---@param fuzzy boolean?
|
||||
function modem.setWakeMessage(message, fuzzy) end
|
||||
function modem.setWakeMessage(message, fuzzy)
|
||||
end
|
||||
|
@@ -9,10 +9,12 @@ local os_cardwriter = {}
|
||||
---@param locked boolean
|
||||
---@param color colors
|
||||
---@return boolean cardWritten
|
||||
function os_cardwriter.write(data, displayName, locked, color) end
|
||||
function os_cardwriter.write(data, displayName, locked, color)
|
||||
end
|
||||
|
||||
---flashes data to an eeprom
|
||||
---@param data string
|
||||
---@param title string
|
||||
---@param writelock boolean
|
||||
function os_cardwriter.flash(data, title, writelock) end
|
||||
function os_cardwriter.flash(data, title, writelock)
|
||||
end
|
||||
|
@@ -5,11 +5,13 @@ local os_magreader = {}
|
||||
|
||||
---Sets the event name returned when you click it with a card, default is magData
|
||||
---@param eventName string
|
||||
function os_magreader.setEventName(eventName) end
|
||||
function os_magreader.setEventName(eventName)
|
||||
end
|
||||
|
||||
---Enables/disables automatic lights on the magreader. If true, it will function as it normally does when clicked with a card. If false, you have to call setLightState to change the lights on the magreader. default is true.
|
||||
---@param enableLights boolean
|
||||
function os_magreader.swipeIndicator(enableLights) end
|
||||
function os_magreader.swipeIndicator(enableLights)
|
||||
end
|
||||
|
||||
---Sets the light state of the magreader. Takes in a number from 0 to 7. default is 0
|
||||
--- - 1 : red
|
||||
@@ -17,4 +19,5 @@ function os_magreader.swipeIndicator(enableLights) end
|
||||
--- - 4 : green
|
||||
---@param lightState number light state as a binary number (1 : red, 3 red + yellow)
|
||||
---@return boolean lightChanged
|
||||
function os_magreader.setLightState(lightState) end
|
||||
function os_magreader.setLightState(lightState)
|
||||
end
|
||||
|
@@ -27,43 +27,54 @@ local stargate = {}
|
||||
---@return stargateState state
|
||||
---@return number engaged
|
||||
---@return stargateDirection direction number of engared chevron
|
||||
function stargate.stargateState() end
|
||||
function stargate.stargateState()
|
||||
end
|
||||
|
||||
---Returns the amount of energy in the gate's internal buffer plus the buffers of any attached Stargate Power Units. This is the energy available for the next dialling operation. If the interface is not connected to a functioning stargate, zero is returned.
|
||||
---@return number su
|
||||
function stargate.energyAvailable() end
|
||||
function stargate.energyAvailable()
|
||||
end
|
||||
|
||||
---Returns the amount of energy that would be needed to connect to the stargate at the given address.
|
||||
---@param address string
|
||||
---@return number su
|
||||
function stargate.energyToDial(address) end
|
||||
function stargate.energyToDial(address)
|
||||
end
|
||||
|
||||
---Returns the address of the attached stargate. If the interface is not connected to a functioning stargate, an empty string is returned.
|
||||
---@return string
|
||||
function stargate.localAddress() end
|
||||
function stargate.localAddress()
|
||||
end
|
||||
|
||||
---Returns the address of the connected stargate. If there is no connection, or the interface is not connected to a functioning stargate, an empty string is returned.
|
||||
---@return string
|
||||
function stargate.remoteAddress() end
|
||||
function stargate.remoteAddress()
|
||||
end
|
||||
|
||||
---Dials the given address.
|
||||
---@param address string
|
||||
function stargate.dial(address) end
|
||||
function stargate.dial(address)
|
||||
end
|
||||
|
||||
---Closes any open connection.
|
||||
function stargate.disconnect() end
|
||||
function stargate.disconnect()
|
||||
end
|
||||
|
||||
---Returns a string indicating the state of the iris: Closed, Opening, Open, Closing. Returns Offline if no iris is fitted or the interface is not connected to a functioning stargate.
|
||||
---@return irisState
|
||||
function stargate.irisState() end
|
||||
function stargate.irisState()
|
||||
end
|
||||
|
||||
---Closes the iris, if fitted.
|
||||
function stargate.closeIris() end
|
||||
function stargate.closeIris()
|
||||
end
|
||||
|
||||
---Opens the iris, if fitted.
|
||||
function stargate.openIris() end
|
||||
function stargate.openIris()
|
||||
end
|
||||
|
||||
---Sends a message through an open connection to any stargate interfaces attached to the destination stargate. Any number of arguments may be passed. The message is delivered to connected computers as an sgMessageReceived event. Has no effect if no stargate connection is open.
|
||||
---@param arg string|number|boolean
|
||||
---@param ... string|number|boolean
|
||||
function stargate.sendMessage(arg, ...) end
|
||||
function stargate.sendMessage(arg, ...)
|
||||
end
|
||||
|
@@ -8,7 +8,8 @@ local transposer = {}
|
||||
---@param sinkSide side
|
||||
---@param count number
|
||||
---@return boolean, number
|
||||
function transposer.transferFluid(sourceSide, sinkSide, count) end
|
||||
function transposer.transferFluid(sourceSide, sinkSide, count)
|
||||
end
|
||||
|
||||
---Store an item stack description in the specified slot of the database with the specified address.
|
||||
---@param side side
|
||||
@@ -16,7 +17,8 @@ function transposer.transferFluid(sourceSide, sinkSide, count) end
|
||||
---@param dbAddress string
|
||||
---@param dbSlot number
|
||||
---@return boolean
|
||||
function transposer.store(side, slot, dbAddress, dbSlot) end
|
||||
function transposer.store(side, slot, dbAddress, dbSlot)
|
||||
end
|
||||
|
||||
---Compare an item in the specified slot in the inventory on the specified side with one in the database with the specified address.
|
||||
---@param side side
|
||||
@@ -25,41 +27,48 @@ function transposer.store(side, slot, dbAddress, dbSlot) end
|
||||
---@param dbSlot number
|
||||
---@param checkNBT? boolean
|
||||
---@return boolean
|
||||
function transposer.compareStackToDatabase(side, slot, dbAddress, dbSlot, checkNBT) end
|
||||
function transposer.compareStackToDatabase(side, slot, dbAddress, dbSlot, checkNBT)
|
||||
end
|
||||
|
||||
---Get number of items in the specified slot of the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@return number
|
||||
function transposer.getSlotStackSize(side, slot) end
|
||||
function transposer.getSlotStackSize(side, slot)
|
||||
end
|
||||
|
||||
---Get the maximum number of items in the specified slot of the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@return number
|
||||
function transposer.getSlotMaxStackSize(side, slot) end
|
||||
function transposer.getSlotMaxStackSize(side, slot)
|
||||
end
|
||||
|
||||
---Get the the name of the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@return string
|
||||
function transposer.getInventoryName(side) end
|
||||
function transposer.getInventoryName(side)
|
||||
end
|
||||
|
||||
---Get the number of slots in the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@return number
|
||||
function transposer.getInventorySize(side) end
|
||||
function transposer.getInventorySize(side)
|
||||
end
|
||||
|
||||
---Get a description of the fluid in the the specified tank on the specified side.
|
||||
---@param side side
|
||||
---@param tank number
|
||||
---@return table
|
||||
function transposer.getFluidInTank(side, tank) end
|
||||
function transposer.getFluidInTank(side, tank)
|
||||
end
|
||||
|
||||
---Get the amount of fluid in the specified tank on the specified side.
|
||||
---@param side side
|
||||
---@param tank number
|
||||
---@return number
|
||||
function transposer.getTankLevel(side, tank) end
|
||||
function transposer.getTankLevel(side, tank)
|
||||
end
|
||||
|
||||
---Transfer some items between two inventories.
|
||||
---@param sourceSide side
|
||||
@@ -68,7 +77,8 @@ function transposer.getTankLevel(side, tank) end
|
||||
---@param sourceSlot? number
|
||||
---@param sinkSlot? number
|
||||
---@return number
|
||||
function transposer.transferItem(sourceSide, sinkSide, count, sourceSlot, sinkSlot) end
|
||||
function transposer.transferItem(sourceSide, sinkSide, count, sourceSlot, sinkSlot)
|
||||
end
|
||||
|
||||
---Get whether the items in the two specified slots of the inventory on the specified side of the device are of the same type.
|
||||
---@param side side
|
||||
@@ -76,31 +86,36 @@ function transposer.transferItem(sourceSide, sinkSide, count, sourceSlot, sinkSl
|
||||
---@param slotB number
|
||||
---@param checkNBT? boolean
|
||||
---@return boolean
|
||||
function transposer.compareStacks(side, slotA, slotB, checkNBT) end
|
||||
function transposer.compareStacks(side, slotA, slotB, checkNBT)
|
||||
end
|
||||
|
||||
---Get whether the items in the two specified slots of the inventory on the specified side of the device are equivalent (have shared OreDictionary IDs).
|
||||
---@param side side
|
||||
---@param slotA number
|
||||
---@param slotB number
|
||||
---@return boolean
|
||||
function transposer.areStacksEquivalent(side, slotA, slotB) end
|
||||
function transposer.areStacksEquivalent(side, slotA, slotB)
|
||||
end
|
||||
|
||||
---Get the number of tanks available on the specified side.
|
||||
---@param side side
|
||||
---@return number
|
||||
function transposer.getTankCount(side) end
|
||||
function transposer.getTankCount(side)
|
||||
end
|
||||
|
||||
---Get a description of the stack in the inventory on the specified side of the device.
|
||||
---@param side side
|
||||
---@param slot number
|
||||
---@return table
|
||||
function transposer.getStackInSlot(side, slot) end
|
||||
function transposer.getStackInSlot(side, slot)
|
||||
end
|
||||
|
||||
---Get the capacity of the specified tank on the specified side.
|
||||
---@param side side
|
||||
---@param tank number
|
||||
---@return number
|
||||
function transposer.getTankCapacity(side, tank) end
|
||||
function transposer.getTankCapacity(side, tank)
|
||||
end
|
||||
|
||||
---Get a description of all stacks in the inventory on the specified side of the device.
|
||||
---The return value is callable. Calling it will return a table describing the stack in the inventory or nothing if the iterator reaches end.
|
||||
@@ -113,4 +128,5 @@ function transposer.getTankCapacity(side, tank) end
|
||||
---reset()
|
||||
---@param side side
|
||||
---@return userdata
|
||||
function transposer.getAllStacks(side) end
|
||||
function transposer.getAllStacks(side)
|
||||
end
|
||||
|
@@ -5,22 +5,27 @@ local tunnel = {}
|
||||
|
||||
---Sends the specified data to the card this one is linked to.
|
||||
---@param ... string|number|boolean data
|
||||
function tunnel.send(...) end
|
||||
function tunnel.send(...)
|
||||
end
|
||||
|
||||
---Gets the maximum packet size (config setting).
|
||||
---@return number
|
||||
function tunnel.maxPacketSize() end
|
||||
function tunnel.maxPacketSize()
|
||||
end
|
||||
|
||||
---Gets the tunnel address of the link card. This is also available in linkChannel using an inventory controller and getting the stack from an inventory slot.
|
||||
---@return string
|
||||
function tunnel.getChannel() end
|
||||
function tunnel.getChannel()
|
||||
end
|
||||
|
||||
---Gets the current wake-up message. When the network card detects the wake message (a string in the first argument of a network packet), on any port and the machine is off, the machine is started. This is the same functionality also provided by robots, cases, servers, drones, and tablets.
|
||||
---@return string
|
||||
function tunnel.getWakeMessage() end
|
||||
function tunnel.getWakeMessage()
|
||||
end
|
||||
|
||||
---Sets the wake-up message to the specified string. The message matching can be fuzzy (default is false). A fuzzy match ignores additional trailing arguments in the network packet.
|
||||
---@param message string
|
||||
---@param fuzzy boolean
|
||||
---@return string
|
||||
function tunnel.setWakeMessage(message, fuzzy) end
|
||||
function tunnel.setWakeMessage(message, fuzzy)
|
||||
end
|
||||
|
@@ -26,14 +26,16 @@ local component = {}
|
||||
---@param address string
|
||||
---@param method string
|
||||
---@return string documentation
|
||||
function component.doc(address, method) end
|
||||
function component.doc(address, method)
|
||||
end
|
||||
|
||||
---Calls the method with the specified name on the component with the specified address, passing the remaining arguments as arguments to that method. Returns the result of the method call, i.e. the values returned by the method. Depending on the called method's implementation this may throw.
|
||||
---@param address string
|
||||
---@param method string
|
||||
---@param ... unknown
|
||||
---@return unknown ...
|
||||
function component.invoke(address, method, ...) end
|
||||
function component.invoke(address, method, ...)
|
||||
end
|
||||
|
||||
---Returns a table with all components currently attached to the computer, with address as a key and component type as a value. It also provides iterator syntax via __call, so you can use it like so: for address, componentType in component.list() do ... end
|
||||
---If filter is set this will only return components that contain the filter string (this is not a pattern/regular expression). For example, component.list("red") will return redstone components.
|
||||
@@ -41,55 +43,65 @@ function component.invoke(address, method, ...) end
|
||||
---@param filter? string
|
||||
---@param exact? boolean
|
||||
---@return function iterator
|
||||
function component.list(filter, exact) end
|
||||
function component.list(filter, exact)
|
||||
end
|
||||
|
||||
---Returns a table with the names of all methods provided by the component with the specified address. The names are the keys in the table, the values indicate whether the method is called directly or not.
|
||||
---@param address string
|
||||
---@return table methodeNames
|
||||
function component.methods(address) end
|
||||
function component.methods(address)
|
||||
end
|
||||
|
||||
---Gets a 'proxy' object for a component that provides all methods the component provides as fields, so they can be called more directly (instead of via invoke). This is what's used to generate 'primaries' of the individual component types, i.e. what you get via component.blah.
|
||||
---For example, you can use it like so: component.proxy(component.list("redstone")()).getInput(sides.north), which gets you a proxy for the first redstone component returned by the component.list iterator, and then calls getInput on it.
|
||||
---Note that proxies will always have at least two fields, type with the component's type name, and address with the component's address.
|
||||
---@param address string
|
||||
---@return Component proxy
|
||||
function component.proxy(address) end
|
||||
function component.proxy(address)
|
||||
end
|
||||
|
||||
---Get the component type of the component with the specified address.
|
||||
---@param address string
|
||||
---@return string type
|
||||
function component.type(address) end
|
||||
function component.type(address)
|
||||
end
|
||||
|
||||
---Return slot number which the component is installed into. Returns -1 if it doesn't otherwise make sense.
|
||||
---@param address string
|
||||
---@return number slotNumber
|
||||
function component.slot(address) end
|
||||
function component.slot(address)
|
||||
end
|
||||
|
||||
---Undocumented
|
||||
---@param address string
|
||||
---@return string
|
||||
function component.fields(address) end
|
||||
function component.fields(address)
|
||||
end
|
||||
|
||||
---Tries to resolve an abbreviated address to a full address. Returns the full address on success, or nil and an error message otherwise. Optionally filters by component type.
|
||||
---@param address string
|
||||
---@param componentType string
|
||||
---@return string|nil address, string|nil reason
|
||||
function component.get(address, componentType) end
|
||||
function component.get(address, componentType)
|
||||
end
|
||||
|
||||
---Checks if there is a primary component of the specified component type.
|
||||
---@param componentType string
|
||||
---@return boolean componentAvailable
|
||||
function component.isAvailable(componentType) end
|
||||
function component.isAvailable(componentType)
|
||||
end
|
||||
|
||||
---Gets the proxy for the primary component of the specified type. Throws an error if there is no primary component of the specified type.
|
||||
---@param componentType string
|
||||
---@return Component proxy
|
||||
function component.getPrimary(componentType) end
|
||||
function component.getPrimary(componentType)
|
||||
end
|
||||
|
||||
---Sets a new primary component for the specified component type. The address may be abbreviated, but must be valid if it is not nil. Triggers the component_unavailable and component_available signals if set to nil or a new value, respectively.
|
||||
---Note that the component API has a metatable that allows the following syntax:
|
||||
---@param componentType string
|
||||
---@param address string
|
||||
function component.setPrimary(componentType, address) end
|
||||
function component.setPrimary(componentType, address)
|
||||
end
|
||||
|
||||
return component
|
||||
|
@@ -5,31 +5,38 @@ local computer = {}
|
||||
|
||||
---The component address of this computer.
|
||||
---@return string
|
||||
function computer.address() end
|
||||
function computer.address()
|
||||
end
|
||||
|
||||
---The component address of the computer's temporary file system (if any), used for mounting it on startup.
|
||||
---@return string
|
||||
function computer.tmpAddress() end
|
||||
function computer.tmpAddress()
|
||||
end
|
||||
|
||||
---The amount of memory currently unused, in bytes. If this gets close to zero your computer will probably soon crash with an out of memory error. Note that for OpenOS, it is highly recommended to at least have 1x tier 1.5 RAM stick or more. The os will boot on a single tier 1 ram stick, but quickly and easily run out of memory.
|
||||
---@return number
|
||||
function computer.freeMemory() end
|
||||
function computer.freeMemory()
|
||||
end
|
||||
|
||||
---The total amount of memory installed in this computer, in bytes.
|
||||
---@return number
|
||||
function computer.totalMemory() end
|
||||
function computer.totalMemory()
|
||||
end
|
||||
|
||||
---The amount of energy currently available in the network the computer is in. For a robot this is the robot's own energy / fuel level.
|
||||
---@return number
|
||||
function computer.energy() end
|
||||
function computer.energy()
|
||||
end
|
||||
|
||||
---The maximum amount of energy that can be stored in the network the computer is in. For a robot this is the size of the robot's internal buffer (what you see in the robot's GUI).
|
||||
---@return number
|
||||
function computer.maxEnergy() end
|
||||
function computer.maxEnergy()
|
||||
end
|
||||
|
||||
---The time in real world seconds this computer has been running, measured based on the world time that passed since it was started - meaning this will not increase while the game is paused, for example.
|
||||
---@return number
|
||||
function computer.uptime() end
|
||||
function computer.uptime()
|
||||
end
|
||||
|
||||
---Shuts down the computer. Optionally reboots the computer, if reboot is true, i.e. shuts down, then starts it again automatically. This function never returns. This example will reboot the computer if it has been running for at least 300 seconds(5 minutes)
|
||||
---```lua
|
||||
@@ -39,58 +46,69 @@ function computer.uptime() end
|
||||
--- end
|
||||
---```
|
||||
---@param reboot? boolean
|
||||
function computer.shutdown(reboot) end
|
||||
function computer.shutdown(reboot)
|
||||
end
|
||||
|
||||
---Get the address of the filesystem component from which to try to boot first. New since OC 1.3.
|
||||
---@return string
|
||||
function computer.getBootAddress() end
|
||||
function computer.getBootAddress()
|
||||
end
|
||||
|
||||
---Set the address of the filesystem component from which to try to boot first. Call with nil / no arguments to clear. New since OC 1.3.
|
||||
---@param address string
|
||||
function computer.setBootAddress(address) end
|
||||
function computer.setBootAddress(address)
|
||||
end
|
||||
|
||||
---Returns the current runlevel the computer is in. Current Runlevels in OpenOS are:
|
||||
---S: Single-User mode, no components or filesystems initialized yet
|
||||
---1: Single-User mode, filesystems and components initialized - OpenOS finished booting
|
||||
---@return string|number
|
||||
function computer.runlevel() end
|
||||
function computer.runlevel()
|
||||
end
|
||||
|
||||
---A list of all users registered on this computer, as a tuple. To iterate the result as a list, use table.pack on it, first. Please see the user rights documentation.
|
||||
---@return string, ...
|
||||
function computer.users() end
|
||||
function computer.users()
|
||||
end
|
||||
|
||||
---Registers a new user with this computer. Returns true if the user was successfully added. Returns nil and an error message otherwise.
|
||||
---The user must be currently in the game. The user will gain full access rights on the computer. In the shell, useradd USER is a command line option to invoke this method.
|
||||
---@param name string
|
||||
---@return boolean or nil, string
|
||||
function computer.addUser(name) end
|
||||
function computer.addUser(name)
|
||||
end
|
||||
|
||||
---Unregisters a user from this computer. Returns true if the user was removed, false if they weren't registered in the first place.
|
||||
---The user will lose all access to this computer. When the last user is removed from the user list, the computer becomes accessible to all players. userdel USER is a command line option to invoke this method.
|
||||
---@param name string
|
||||
---@return boolean
|
||||
function computer.removeUser(name) end
|
||||
function computer.removeUser(name)
|
||||
end
|
||||
|
||||
---Pushes a new signal into the queue. Signals are processed in a FIFO order. The signal has to at least have a name. Arguments to pass along with it are optional. Note that the types supported as signal parameters are limited to the basic types nil, boolean, number, string, and tables. Yes tables are supported (keep reading). Threads and functions are not supported.
|
||||
---Note that only tables of the supported types are supported. That is, tables must compose types supported, such as other strings and numbers, or even sub tables. But not of functions or threads.
|
||||
---@param name string
|
||||
---@param ...? any
|
||||
function computer.pushSignal(name, ...) end
|
||||
function computer.pushSignal(name, ...)
|
||||
end
|
||||
|
||||
---Tries to pull a signal from the queue, waiting up to the specified amount of time before failing and returning nil. If no timeout is specified waits forever.
|
||||
---The first returned result is the signal name, following results correspond to what was pushed in pushSignal, for example. These vary based on the event type. Generally it is more convenient to use event.pull from the event library. The return value is the very same, but the event library provides some more options.
|
||||
---@param timeout? number
|
||||
---@return string signalName, any ...
|
||||
function computer.pullSignal(timeout) end
|
||||
function computer.pullSignal(timeout)
|
||||
end
|
||||
|
||||
---if frequency is a number it value must be between 20 and 2000.
|
||||
---Causes the computer to produce a beep sound at frequency Hz for duration seconds. This method is overloaded taking a single string parameter as a pattern of dots . and dashes - for short and long beeps respectively.
|
||||
---@param frequency? number|string
|
||||
---@param duration? number
|
||||
function computer.beep(frequency, duration) end
|
||||
function computer.beep(frequency, duration)
|
||||
end
|
||||
|
||||
---Returns a table of information about installed devices in the computer.
|
||||
---@return table
|
||||
function computer.getDeviceInfo() end
|
||||
function computer.getDeviceInfo()
|
||||
end
|
||||
|
||||
return computer
|
||||
|
@@ -11,7 +11,8 @@ local event = {}
|
||||
---@param event string
|
||||
---@param callback function
|
||||
---@return number|boolean
|
||||
function event.listen(event, callback) end
|
||||
function event.listen(event, callback)
|
||||
end
|
||||
|
||||
---Unregister a previously registered event listener.
|
||||
---event - name of the signal to unregister.
|
||||
@@ -21,14 +22,16 @@ function event.listen(event, callback) end
|
||||
---@param event string
|
||||
---@param callback function
|
||||
---@return boolean
|
||||
function event.ignore(event, callback) end
|
||||
function event.ignore(event, callback)
|
||||
end
|
||||
|
||||
---Cancels a timer previously created with event.timer.
|
||||
---timerId - a timer ID as returned by event.timer.
|
||||
---Returns: true if the timer was stopped, false if there was no timer with the specified ID.
|
||||
---@param timerId number
|
||||
---@return boolean
|
||||
function event.cancel(timerId) end
|
||||
function event.cancel(timerId)
|
||||
end
|
||||
|
||||
---Starts a new timer that will be called after the time specified in interval.
|
||||
---interval - time in seconds between each invocation of the callback function. Can be a fraction like 0.05.
|
||||
@@ -40,7 +43,8 @@ function event.cancel(timerId) end
|
||||
---@param callback function
|
||||
---@param times? number
|
||||
---@return number
|
||||
function event.timer(interval, callback, times) end
|
||||
function event.timer(interval, callback, times)
|
||||
end
|
||||
|
||||
---Pulls and returns the next available event from the queue, or waits until one becomes available.
|
||||
---timeout - if passed the function will wait for a new event for this many seconds at maximum then returns nil if no event was queued during that time.
|
||||
@@ -55,7 +59,8 @@ function event.timer(interval, callback, times) end
|
||||
---@param ... any
|
||||
---@return string, any ...
|
||||
---@overload fun(name:string,...:any):string, ...:any
|
||||
function event.pull(timeout, name, ...) end
|
||||
function event.pull(timeout, name, ...)
|
||||
end
|
||||
|
||||
---(Since 1.5.9) Pulls and returns the next available event from the queue, or waits until one becomes available but allows filtering by specifying filter function. timeout - if passed the function will wait for a new event for this many seconds at maximum then returns nil if no event was queued during that time.
|
||||
---filter - if passed the function will use it as a filtering function of events. Allows for advanced filtering.
|
||||
@@ -85,21 +90,25 @@ function event.pull(timeout, name, ...) end
|
||||
---@param filter? function
|
||||
---@return string, any ...
|
||||
---@overload fun(filer:function):string,...:any
|
||||
function event.pullFiltered(timeout, filter) end
|
||||
function event.pullFiltered(timeout, filter)
|
||||
end
|
||||
|
||||
---As its arguments pullMultiple accepts multiple event names to be pulled, allowing basic filtering of multiple events at once.
|
||||
---@param ... string
|
||||
---@return any ...
|
||||
function event.pullMultiple(...) end
|
||||
function event.pullMultiple(...)
|
||||
end
|
||||
|
||||
---Global event callback error handler. If an event listener throws an error, we handle it in this function to avoid it bubbling into unrelated code (that only triggered the execution by calling event.pull). Per default, this logs errors into a file on the temporary file system.
|
||||
---You can replace this function with your own if you want to handle event errors in a different way.
|
||||
---@param message any
|
||||
function event.onError(message) end
|
||||
function event.onError(message)
|
||||
end
|
||||
|
||||
---This is only an alias to computer.pushSignal. This does not modify the arguments in any way. It seemed logical to add the alias to the event library because there is also an event.pull for signals.
|
||||
---@param name string
|
||||
---@param ... any
|
||||
function event.push(name, ...) end
|
||||
function event.push(name, ...)
|
||||
end
|
||||
|
||||
return event
|
||||
|
@@ -5,126 +5,149 @@ local filesystem = {}
|
||||
|
||||
---Returns whether autorun is currently enabled. If this is true, newly mounted file systems will be checked for a file named autorun[.lua] in their root directory. If such a file exists, it is executed.
|
||||
---@return boolean
|
||||
function filesystem.isAutorunEnabled() end
|
||||
function filesystem.isAutorunEnabled()
|
||||
end
|
||||
|
||||
---Sets whether autorun files should be ran on startup.
|
||||
---@param value boolean
|
||||
function filesystem.setAutorunEnabled(value) end
|
||||
function filesystem.setAutorunEnabled(value)
|
||||
end
|
||||
|
||||
---Returns the canonical form of the specified path, i.e. a path containing no “indirections” such as . or ... For example, the paths /tmp/../bin/ls.lua and /bin/./ls.lua are equivalent, and their canonical form is /bin/ls.lua.
|
||||
---Note that this function truncates relative paths to their topmost “known” directory. For example, ../bin/ls.lua becomes bin/ls.lua. It stays a relative path, however - mind the lack of a leading slash.
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.canonical(path) end
|
||||
function filesystem.canonical(path)
|
||||
end
|
||||
|
||||
---Returns a table containing one entry for each canonical segment of the given path. Examples:
|
||||
--- - filesystem.segments("foo/bar") → {"foo","bar"}
|
||||
--- - filesystem.segments("foo/bar/../baz") → {"foo","baz"}
|
||||
---@param path string
|
||||
---@return table
|
||||
function filesystem.segments(path) end
|
||||
function filesystem.segments(path)
|
||||
end
|
||||
|
||||
---Concatenates two or more paths. Note that all paths other than the first are treated as relative paths, even if they begin with a slash. The canonical form of the resulting concatenated path is returned, so fs.concat("a", "..") results in an empty string.
|
||||
---@param pathA string
|
||||
---@param pathB string
|
||||
---@param ... string
|
||||
---@return string
|
||||
function filesystem.concat(pathA, pathB, ...) end
|
||||
function filesystem.concat(pathA, pathB, ...)
|
||||
end
|
||||
|
||||
---Returns the path component of a path to a file, i.e. everything before the last slash in the canonical form of the specified path.
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.path(path) end
|
||||
function filesystem.path(path)
|
||||
end
|
||||
|
||||
---Returns the file name component of a path to a file, i.e. everything after the last slash in the canonical form of the specified path.
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.name(path) end
|
||||
function filesystem.name(path)
|
||||
end
|
||||
|
||||
---Mounts a file system at the specified path. The first parameter can be either a file system component's proxy, its address or its label. The second is a path into the global directory tree. Returns true if the file system was successfully mounted, nil and an error message otherwise.
|
||||
---@param fs ComponentFilesystem|string
|
||||
---@param path string
|
||||
---@return string
|
||||
function filesystem.mount(fs, path) end
|
||||
function filesystem.mount(fs, path)
|
||||
end
|
||||
|
||||
---This is similar to component.proxy, except that the specified string may also be a file system component's label. We check for the label first, if no file system has the specified label we fall back to component.proxy. Returns the proxy of the specified file system, or nil and an error message if no file system matching the specified filter was found.
|
||||
---@param filter string
|
||||
---@return table or nil, string
|
||||
function filesystem.proxy(filter) end
|
||||
function filesystem.proxy(filter)
|
||||
end
|
||||
|
||||
---Returns an iterator function over all currently mounted file system component's proxies and the paths at which they are mounted. This means the same proxy may appear multiple times, but with different mount paths.
|
||||
---@return function -> table, string
|
||||
function filesystem.mounts() end
|
||||
function filesystem.mounts()
|
||||
end
|
||||
|
||||
---Unmounts a file system. The parameter can either be a file system component's proxy or (abbreviated) address, in which case all mount points of this file system will be removed, or a path into the global directory structure, in which case the file system mount containing that directory will be unmounted.
|
||||
---@param fsOrPath string|ComponentFilesystem
|
||||
---@return boolean
|
||||
function filesystem.umount(fsOrPath) end
|
||||
function filesystem.umount(fsOrPath)
|
||||
end
|
||||
|
||||
---Checks if the object at the specified path is a symlink, if so returns the path to where it links (as of 1.3.3).
|
||||
---@param path string
|
||||
---@return boolean, string|nil
|
||||
function filesystem.isLink(path) end
|
||||
function filesystem.isLink(path)
|
||||
end
|
||||
|
||||
---Creates a symbolic link to the specified target path at the specified path. This is a 'soft' link, i.e. it the target file does not actually have to exist at the time of creation, and the link will not be deleted if the target file is deleted. Symbolic links do not persist across reboots.
|
||||
---@param target string
|
||||
---@param linkpath string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.link(target, linkpath) end
|
||||
function filesystem.link(target, linkpath)
|
||||
end
|
||||
|
||||
---Gets the file system component's proxy that contains the specified path. Returns the proxy and mount path, or nil and an error message.
|
||||
---@param path string
|
||||
---@return table, string or nil, string
|
||||
function filesystem.get(path) end
|
||||
function filesystem.get(path)
|
||||
end
|
||||
|
||||
---Checks whether a file or folder exist at the specified path.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesystem.exists(path) end
|
||||
function filesystem.exists(path)
|
||||
end
|
||||
|
||||
---Gets the file size of the file at the specified location. Returns 0 if the path points to anything other than a file.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesystem.size(path) end
|
||||
function filesystem.size(path)
|
||||
end
|
||||
|
||||
---Gets whether the path points to a directory. Returns false if not, either because the path points to a file, or file.exists(path) is false.
|
||||
---@param path string
|
||||
---@return boolean
|
||||
function filesystem.isDirectory(path) end
|
||||
function filesystem.isDirectory(path)
|
||||
end
|
||||
|
||||
---Returns the real world unix timestamp of the last time the file at the specified path was modified. For directories this is usually the time of their creation.
|
||||
---@param path string
|
||||
---@return number
|
||||
function filesystem.lastModified(path) end
|
||||
function filesystem.lastModified(path)
|
||||
end
|
||||
|
||||
---Returns an iterator over all elements in the directory at the specified path. Returns nil and an error messages if the path is invalid or some other error occurred.
|
||||
---Note that directories usually are postfixed with a slash, to allow identifying them without an additional call to fs.isDirectory.
|
||||
---@param path string
|
||||
---@return function -> string or nil, string
|
||||
function filesystem.list(path) end
|
||||
function filesystem.list(path)
|
||||
end
|
||||
|
||||
---Creates a new directory at the specified path. Creates any parent directories that do not exist yet, if necessary. Returns true on success, nil and an error message otherwise.
|
||||
---@param path string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.makeDirectory(path) end
|
||||
function filesystem.makeDirectory(path)
|
||||
end
|
||||
|
||||
---Deletes a file or folder. If the path specifies a folder, deletes all files and subdirectories in the folder, recursively. Return true on success, nil and an error message otherwise.
|
||||
---@param path string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.remove(path) end
|
||||
function filesystem.remove(path)
|
||||
end
|
||||
|
||||
---Renames a file or folder. If the paths point to different file system components this will only work for files, because it actually perform a copy operation, followed by a deletion if the copy succeeds.
|
||||
---Returns true on success, nil and an error message otherwise.
|
||||
---@param oldPath string
|
||||
---@param newPath string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.rename(oldPath, newPath) end
|
||||
function filesystem.rename(oldPath, newPath)
|
||||
end
|
||||
|
||||
---Copies a file to the specified location. The target path has to contain the target file name. Does not support folders.
|
||||
---@param fromPath string
|
||||
---@param toPath string
|
||||
---@return boolean|nil, string
|
||||
function filesystem.copy(fromPath, toPath) end
|
||||
function filesystem.copy(fromPath, toPath)
|
||||
end
|
||||
|
||||
---@class FileHandler
|
||||
local file
|
||||
@@ -137,26 +160,31 @@ local file
|
||||
---@param path string
|
||||
---@param mode string
|
||||
---@return FileHandler|nil fileHandler, string|nil reason
|
||||
function filesystem.open(path, mode) end
|
||||
function filesystem.open(path, mode)
|
||||
end
|
||||
|
||||
---Closes the file stream, releasing the handle on the underlying file system.
|
||||
function file:close() end
|
||||
function file:close()
|
||||
end
|
||||
|
||||
---Tries to read the specified number of bytes from the file stream. Returns the read string, which may be shorter than the specified number. Returns nil when the end of the stream was reached. Returns nil and an error message if some error occurred.
|
||||
---@param n number
|
||||
---@return string|nil, string|nil reason
|
||||
function file:read(n) end
|
||||
function file:read(n)
|
||||
end
|
||||
|
||||
---Jumps to the specified position in the file stream, if possible. Only supported by file streams opened in read mode. The first parameter determines the relative location to seek from and can be cur for the current position, set for the beginning of the stream and end for the end of the stream. The second parameter is the offset by which to modify the position. Returns the new position or nil and an error message if some error occurred.
|
||||
---The default value for the second parameter is 0, so f:seek("set") will reset the position to the start of the file, f:seek("cur") will return the current position in the file.
|
||||
---@param whence string
|
||||
---@param offset? number
|
||||
---@return number|nil, string|nil reason
|
||||
function file:seek(whence, offset) end
|
||||
function file:seek(whence, offset)
|
||||
end
|
||||
|
||||
---Writes the specified data to the stream. Returns true on success, nil and an error message otherwise.
|
||||
---@param str any
|
||||
---@return boolean|nil, string|nil reason
|
||||
function file:write(str) end
|
||||
function file:write(str)
|
||||
end
|
||||
|
||||
return filesystem
|
||||
|
@@ -5,7 +5,8 @@ local os = {}
|
||||
|
||||
---Returns an approximation of the amount in seconds of CPU time used by the program.
|
||||
---@return number
|
||||
function os.clock() end
|
||||
function os.clock()
|
||||
end
|
||||
|
||||
---Returns a string or a table containing date and time, formatted according to the given string format.
|
||||
---
|
||||
@@ -21,26 +22,35 @@ function os.clock() end
|
||||
---@param format? string
|
||||
---@param time? string | number
|
||||
---@return string | table
|
||||
function os.date(format, time) end
|
||||
function os.date(format, time)
|
||||
end
|
||||
|
||||
function os.execute() end
|
||||
function os.execute()
|
||||
end
|
||||
|
||||
---@param code? any
|
||||
---@param close? any
|
||||
function os.exit(code, close) end
|
||||
function os.exit(code, close)
|
||||
end
|
||||
|
||||
function os.setenv() end
|
||||
function os.setenv()
|
||||
end
|
||||
|
||||
function os.remove() end
|
||||
function os.remove()
|
||||
end
|
||||
|
||||
function os.rename() end
|
||||
function os.rename()
|
||||
end
|
||||
|
||||
function os.time() end
|
||||
function os.time()
|
||||
end
|
||||
|
||||
function os.tmpname() end
|
||||
function os.tmpname()
|
||||
end
|
||||
|
||||
---Sleep for x seconds
|
||||
---@param time? number
|
||||
function os.sleep(time) end
|
||||
function os.sleep(time)
|
||||
end
|
||||
|
||||
return os
|
||||
|
@@ -17,7 +17,6 @@ local sides = {
|
||||
[4] = "right",
|
||||
[5] = "left",
|
||||
[6] = "unknown",
|
||||
|
||||
bottom = 0,
|
||||
top = 1,
|
||||
back = 2,
|
||||
@@ -25,21 +24,18 @@ local sides = {
|
||||
right = 4,
|
||||
left = 5,
|
||||
unknown = 6,
|
||||
|
||||
down = 0,
|
||||
up = 1,
|
||||
north = 2,
|
||||
south = 3,
|
||||
west = 4,
|
||||
east = 5,
|
||||
|
||||
negy = 0,
|
||||
posy = 1,
|
||||
negz = 2,
|
||||
posz = 3,
|
||||
negx = 4,
|
||||
posx = 5,
|
||||
|
||||
forward = 3
|
||||
}
|
||||
|
||||
|
@@ -67,7 +67,7 @@ local function readPassword()
|
||||
return false
|
||||
end)
|
||||
event_keyboard = event.listen("key_down", function(self, uuid, char, code, player)
|
||||
if (char == 8) then
|
||||
if (char == 8) then
|
||||
password = string.sub(password, 1, -2)
|
||||
garble = string.sub(garble, 1, -2)
|
||||
term.setCursor(cursorPosX, cursorPosY)
|
||||
@@ -166,7 +166,7 @@ end
|
||||
verbose(serialization.serialize(configRaw))
|
||||
local config = serialization.unserialize(configRaw)
|
||||
|
||||
--[[config syntax
|
||||
--[[config syntax
|
||||
{
|
||||
doors"{
|
||||
{name="door1",component="uuid",side=side,default=false,inv=false}
|
||||
@@ -178,7 +178,6 @@ local config = serialization.unserialize(configRaw)
|
||||
}
|
||||
}
|
||||
]]
|
||||
|
||||
-- creating doors
|
||||
local doors = {}
|
||||
if (#config.doors > 0) then
|
||||
@@ -198,8 +197,10 @@ if (ops.config or ops.c) then
|
||||
while try < 3 do
|
||||
io.write("Admin password :")
|
||||
local password = readPassword()
|
||||
if (password == config.adminCode) then break
|
||||
else try = try + 1
|
||||
if (password == config.adminCode) then
|
||||
break
|
||||
else
|
||||
try = try + 1
|
||||
end
|
||||
end
|
||||
if (try >= 3) then
|
||||
@@ -221,7 +222,7 @@ if (ops.config or ops.c) then
|
||||
print("q : Exit")
|
||||
io.write(">")
|
||||
local op = io.read()
|
||||
if (tonumber(op)) then
|
||||
if (tonumber(op)) then
|
||||
op = tonumber(op)
|
||||
if (op >= 1 and op <= #doors) then
|
||||
local door = doors[op]
|
||||
@@ -244,7 +245,7 @@ if (ops.config or ops.c) then
|
||||
print("q : Exit")
|
||||
io.write(">" .. doorID .. ">")
|
||||
local op = io.read()
|
||||
if (op == "r") then
|
||||
if (op == "r") then
|
||||
io.write(">" .. doorID .. ">r>[" .. door:getName() .. "]")
|
||||
local newName = io.read()
|
||||
if (newName ~= "") then
|
||||
@@ -268,9 +269,13 @@ if (ops.config or ops.c) then
|
||||
config.doors[doorID].side = sides[door:getSide()]
|
||||
saveConfig(config)
|
||||
end
|
||||
elseif (op == "t") then door:toggle()
|
||||
elseif (op == "b") then break
|
||||
elseif (op == "q") then run = false break
|
||||
elseif (op == "t") then
|
||||
door:toggle()
|
||||
elseif (op == "b") then
|
||||
break
|
||||
elseif (op == "q") then
|
||||
run = false
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -322,7 +327,7 @@ if (ops.config or ops.c) then
|
||||
print("q : Exit")
|
||||
io.write(">s>")
|
||||
op = io.read()
|
||||
if (op == "p") then
|
||||
if (op == "p") then
|
||||
print("Enter new password")
|
||||
io.write(">s>p>")
|
||||
local p1 = readPassword()
|
||||
@@ -349,8 +354,11 @@ if (ops.config or ops.c) then
|
||||
elseif (tonumber(op) and tonumber(op) > 1 and tonumber(op) <= #config.whitelist) then
|
||||
table.remove(config.whitelist, tonumber(op))
|
||||
saveConfig(config)
|
||||
elseif (op == "b") then break
|
||||
elseif (op == "q") then run = false break
|
||||
elseif (op == "b") then
|
||||
break
|
||||
elseif (op == "q") then
|
||||
run = false
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif (op == "q") then
|
||||
@@ -359,7 +367,6 @@ if (ops.config or ops.c) then
|
||||
end
|
||||
term.clear()
|
||||
else
|
||||
|
||||
local function closeGUI()
|
||||
event.cancel(event_touch)
|
||||
event.cancel(event_term)
|
||||
@@ -374,7 +381,10 @@ else
|
||||
local allowed = false
|
||||
if (#config.whitelist > 0) then
|
||||
for index, item in ipairs(config.whitelist) do
|
||||
if (item == playerName) then allowed = true break end
|
||||
if (item == playerName) then
|
||||
allowed = true
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
allowed = true
|
||||
|
@@ -3,13 +3,13 @@
|
||||
--=====================================
|
||||
|
||||
---@class libcb
|
||||
local cb = {} --table returned by require
|
||||
local data = require("component").data --data component used for cryptocraphic stuf
|
||||
local serialization = require("serialization") --data serialization and unserialization
|
||||
local event = require("event")
|
||||
local proxy = require("component").proxy
|
||||
local computer = require("computer")
|
||||
local lastMagRead = {}
|
||||
local cb = {} --table returned by require
|
||||
local data = require("component").data --data component used for cryptocraphic stuf
|
||||
local serialization = require("serialization") --data serialization and unserialization
|
||||
local event = require("event")
|
||||
local proxy = require("component").proxy
|
||||
local computer = require("computer")
|
||||
local lastMagRead = {}
|
||||
|
||||
---@class cardData
|
||||
---@field uuid string account UUID
|
||||
@@ -51,11 +51,14 @@ end
|
||||
---@return Component|boolean proxy
|
||||
function cb.waitForCB(timeout)
|
||||
local eventDetails = table.pack(event.pullFiltered(timeout, function(a, b, c, d, e, f)
|
||||
if (a == "component_added" and c == "drive") then return true end
|
||||
if (a == "magData") then return true end
|
||||
end))
|
||||
if (eventDetails[1]) then return proxy(eventDetails[2])
|
||||
else return false end
|
||||
if (a == "component_added" and c == "drive") then return true end
|
||||
if (a == "magData") then return true end
|
||||
end))
|
||||
if (eventDetails[1]) then
|
||||
return proxy(eventDetails[2])
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
cb.loadCB = {}
|
||||
@@ -173,7 +176,7 @@ function cb.createNew(uuid, cbUUID, privateKey)
|
||||
local aesIV = data.md5(cbUUID)
|
||||
local newCB = {}
|
||||
newCB.uuid = uuid
|
||||
newCB.sig = data.encode64(data.ecdsa(uuid .. cbUUID, privateKey)--[[@as string]] )
|
||||
newCB.sig = data.encode64(data.ecdsa(uuid .. cbUUID, privateKey) --[[@as string]])
|
||||
---@diagnostic disable-next-line: cast-local-type
|
||||
newCB = data.encode64(data.encrypt(serialization.serialize(newCB), aesKey, aesIV))
|
||||
return newCB, pin
|
||||
@@ -191,7 +194,7 @@ end
|
||||
---@param cbDrive ComponentDrive|ComponentOsCardWriter the floppy's component proxy
|
||||
---@return boolean cardWritten
|
||||
function cb.writeCB(rawCBdata, cbDrive)
|
||||
if (cbDrive.type == "drive") then
|
||||
if (cbDrive.type == "drive") then
|
||||
---@cast cbDrive ComponentDrive
|
||||
local buffer = serialization.serialize(rawCBdata)
|
||||
cbDrive.writeSector(1, buffer)
|
||||
|
@@ -1,25 +1,25 @@
|
||||
local Class = {Object=require("libClass/Object")}
|
||||
local Class = {Object = require("libClass/Object")}
|
||||
|
||||
function Class.newClass(newType,parent)
|
||||
assert(type(newType) == "string","arg #1 must be a string")
|
||||
function Class.newClass(newType, parent)
|
||||
assert(type(newType) == "string", "arg #1 must be a string")
|
||||
parent = parent or Class.Object
|
||||
assert(parent.class or Class.Object.class,"not a compatible class")
|
||||
assert(parent.class or Class.Object.class, "not a compatible class")
|
||||
local newClass = parent:clone()
|
||||
if(parent.constructor) then
|
||||
table.insert(newClass.class.parentConstructor,parent.constructor)
|
||||
if (parent.constructor) then
|
||||
table.insert(newClass.class.parentConstructor, parent.constructor)
|
||||
end
|
||||
newClass.constructor = nil
|
||||
newClass.class.type = newType
|
||||
table.insert(newClass.class.parentsType,parent.class.type)
|
||||
table.insert(newClass.class.parentsType, parent.class.type)
|
||||
return newClass
|
||||
end
|
||||
|
||||
function Class.instanceOf(obj,class)
|
||||
if(obj.class.type == class.class.type) then
|
||||
function Class.instanceOf(obj, class)
|
||||
if (obj.class.type == class.class.type) then
|
||||
return true
|
||||
else
|
||||
for _,val in ipairs(obj.class.parentsType) do
|
||||
if(val == class.class.type) then
|
||||
for _, val in ipairs(obj.class.parentsType) do
|
||||
if (val == class.class.type) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@@ -1,30 +1,30 @@
|
||||
local function deepcopy(orig)
|
||||
local orig_type = type(orig)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
for orig_key, orig_value in next, orig, nil do
|
||||
copy[deepcopy(orig_key)] = deepcopy(orig_value)
|
||||
end
|
||||
setmetatable(copy, deepcopy(getmetatable(orig)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig
|
||||
local orig_type = type(orig)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
for orig_key, orig_value in next, orig, nil do
|
||||
copy[deepcopy(orig_key)] = deepcopy(orig_value)
|
||||
end
|
||||
return copy
|
||||
setmetatable(copy, deepcopy(getmetatable(orig)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig
|
||||
end
|
||||
return copy
|
||||
end
|
||||
|
||||
local function callConstructor(self,...)
|
||||
for _,constructor in ipairs(self.class.parentConstructor) do constructor(self,...) end
|
||||
if(self.constructor) then self:constructor(...) end
|
||||
local function callConstructor(self, ...)
|
||||
for _, constructor in ipairs(self.class.parentConstructor) do constructor(self, ...) end
|
||||
if (self.constructor) then self:constructor(...) end
|
||||
end
|
||||
|
||||
local construcMetaTable = {
|
||||
__call = function(self,...)
|
||||
__call = function(self, ...)
|
||||
local cp = deepcopy(self)
|
||||
local cpMeta = getmetatable(cp)
|
||||
cpMeta.__call = nil
|
||||
setmetatable(cp,cpMeta)
|
||||
callConstructor(cp,...) -- call the constructor
|
||||
setmetatable(cp, cpMeta)
|
||||
callConstructor(cp, ...) -- call the constructor
|
||||
return cp
|
||||
end
|
||||
}
|
||||
@@ -38,6 +38,6 @@ local Object = {
|
||||
},
|
||||
clone = function(self) return deepcopy(self) end
|
||||
}
|
||||
setmetatable(Object.class,{__tostring=function(self)return self.type end})
|
||||
setmetatable(Object,construcMetaTable)
|
||||
setmetatable(Object.class, {__tostring = function(self) return self.type end})
|
||||
setmetatable(Object, construcMetaTable)
|
||||
return Object
|
||||
|
@@ -11,7 +11,7 @@ local ID_COIN_GOLD = "ordinarycoins:coingold"
|
||||
local COIN_PLATINUM = COIN_GOLD * CONVERTION_RATE
|
||||
local ID_COIN_PLATINUM = "ordinarycoins:coinplatinum"
|
||||
|
||||
local coin = {}
|
||||
local coin = {}
|
||||
|
||||
---count the coins
|
||||
---@param side side
|
||||
@@ -124,7 +124,7 @@ function coin.moveCoin(amount, from, to)
|
||||
|
||||
local moved_bronze, moved_silver, moved_gold, moved_platinum = 0, 0, 0, 0
|
||||
while (moved_bronze < need_bronze) do
|
||||
local moved_coin = transposer.transferItem(from, to, need_bronze, coin.findFirstStack(from, ID_COIN_BRONZE)--[[@as number]] )
|
||||
local moved_coin = transposer.transferItem(from, to, need_bronze, coin.findFirstStack(from, ID_COIN_BRONZE) --[[@as number]])
|
||||
if (moved_coin == 0) then
|
||||
break
|
||||
else
|
||||
@@ -132,7 +132,7 @@ function coin.moveCoin(amount, from, to)
|
||||
end
|
||||
end
|
||||
while (moved_silver < need_silver) do
|
||||
local moved_coin = transposer.transferItem(from, to, need_silver, coin.findFirstStack(from, ID_COIN_SILVER)--[[@as number]] )
|
||||
local moved_coin = transposer.transferItem(from, to, need_silver, coin.findFirstStack(from, ID_COIN_SILVER) --[[@as number]])
|
||||
if (moved_coin == 0) then
|
||||
break
|
||||
else
|
||||
@@ -140,7 +140,7 @@ function coin.moveCoin(amount, from, to)
|
||||
end
|
||||
end
|
||||
while (moved_gold < need_gold) do
|
||||
local moved_coin = transposer.transferItem(from, to, need_gold, coin.findFirstStack(from, ID_COIN_GOLD)--[[@as number]] )
|
||||
local moved_coin = transposer.transferItem(from, to, need_gold, coin.findFirstStack(from, ID_COIN_GOLD) --[[@as number]])
|
||||
if (moved_coin == 0) then
|
||||
break
|
||||
else
|
||||
@@ -148,7 +148,7 @@ function coin.moveCoin(amount, from, to)
|
||||
end
|
||||
end
|
||||
while (moved_platinum < need_platinum) do
|
||||
local moved_coin = transposer.transferItem(from, to, need_platinum, coin.findFirstStack(from, ID_COIN_PLATINUM)--[[@as number]] )
|
||||
local moved_coin = transposer.transferItem(from, to, need_platinum, coin.findFirstStack(from, ID_COIN_PLATINUM) --[[@as number]])
|
||||
if (moved_coin == 0) then
|
||||
break
|
||||
else
|
||||
|
@@ -39,7 +39,8 @@ function Keypad.getMaxInputLen(self) return self.private.maxInputLen end
|
||||
|
||||
function Keypad.setMaxInputLen(self, len) self.private.maxInputLen = len or self.private.maxInputLen end
|
||||
|
||||
function Keypad.private.validateCallback(self) end
|
||||
function Keypad.private.validateCallback(self)
|
||||
end
|
||||
|
||||
function Keypad.setValidateCallback(self, fct) if (type(fct) == "function") then self.private.validateCallback = fct end end
|
||||
|
||||
@@ -69,7 +70,7 @@ function Keypad.collide(self, x, y)
|
||||
end
|
||||
|
||||
function Keypad.private.keyboardHandler(self, eventName, keyboardUUID, char, key, playerName)
|
||||
if (48 <= char and char <= 57) then
|
||||
if (48 <= char and char <= 57) then
|
||||
self.private.input = self.private.input .. string.char(char)
|
||||
elseif (char == 8) then
|
||||
self.private.input = self:getInput():sub(1, #self:getInput() - 1)
|
||||
@@ -97,7 +98,7 @@ function Keypad.private.screenHandler(self, eventName, ScreenUUID, x, y, button,
|
||||
y = (y - self:getY() - 1) / 2
|
||||
|
||||
if (x >= 1 and x <= 3 and y >= 1 and y <= 4) then --keys[y][x] might be null if the event is not on a key
|
||||
if (keys[y][x] == 'X') then --if X got pressed
|
||||
if (keys[y][x] == 'X') then --if X got pressed
|
||||
self.private.input = self:getInput():sub(1, #self:getInput() - 1) --remove the last char from the input
|
||||
elseif (keys[y][x] == 'V') then --if V got pressed
|
||||
self.private.validateCallback(self)
|
||||
@@ -123,12 +124,12 @@ function Keypad.private.drawInput(self)
|
||||
gpu.fill(self:getX() + 1, self:getY() + 1, self:getWidth() - 2, 1, " ")
|
||||
|
||||
--fill the text field
|
||||
local displayText = self:getInput():sub(-1 * (self:getWidth() - 2))
|
||||
local displayText = self:getInput():sub( -1 * (self:getWidth() - 2))
|
||||
if (self:isInputHidden()) then
|
||||
displayText = displayText:gsub('.', '*') --replace each char with '*'
|
||||
end
|
||||
if (#self:getInput() > self:getWidth() - 2) then --if the input if longer than the text field
|
||||
displayText = "<" .. displayText:sub(-1 * (self:getWidth() - 3)) --replace the first character of the displayed text with "<" to indicate a trucated string
|
||||
displayText = "<" .. displayText:sub( -1 * (self:getWidth() - 3)) --replace the first character of the displayed text with "<" to indicate a trucated string
|
||||
end
|
||||
|
||||
gpu.set(self:getX() + 1, self:getY() + 1, displayText)
|
||||
|
@@ -110,7 +110,7 @@ local function openPPM(path)
|
||||
if (i % 1000 == 0) then os.sleep() end
|
||||
local rgb = {}
|
||||
local pixel = ""
|
||||
if (img.property.TYPE == "P6") then
|
||||
if (img.property.TYPE == "P6") then
|
||||
rgb.R = file:read(1):byte()
|
||||
rgb.G = file:read(1):byte()
|
||||
rgb.B = file:read(1):byte()
|
||||
@@ -150,7 +150,7 @@ ImageFile.open = function(self, path)
|
||||
if (not (fs.exists(path) and not fs.isDirectory(path))) then
|
||||
error("No file with path : " .. path, 2)
|
||||
end
|
||||
if (path:match("%..+$") == ".pam") then
|
||||
if (path:match("%..+$") == ".pam") then
|
||||
imgTable = openPAM(path)
|
||||
elseif (path:match("%..+$") == ".ppm") then
|
||||
imgTable = openPPM(path)
|
||||
|
@@ -7,7 +7,7 @@ local os = require "os"
|
||||
local Screen = libClass.newClass("Screen")
|
||||
Screen.childs = {}
|
||||
Screen.addChild = function(self, child)
|
||||
if (not child.class) then
|
||||
if (not child.class) then
|
||||
error("arg #2 is not a class", 2)
|
||||
elseif (not libClass.instanceOf(child, Widget) and not libClass.instanceOf(child, Screen)) then
|
||||
error("arg #2 is not a Widget", 2)
|
||||
|
@@ -1,23 +1,23 @@
|
||||
local ImageFile = require("libGUI/ImageFile")
|
||||
local gpu = require("component").gpu
|
||||
local ImageFile = require("libGUI/ImageFile")
|
||||
local gpu = require("component").gpu
|
||||
|
||||
local Image = require("libClass").newClass("Image", require("libGUI/widget/Widget"))
|
||||
local Image = require("libClass").newClass("Image", require("libGUI/widget/Widget"))
|
||||
|
||||
Image.DRAW_METHOD_OLD = false
|
||||
Image.DRAW_METHOD_NEW = true
|
||||
Image.imageData = {}
|
||||
Image.private.drawMethod = Image.DRAW_METHOD_OLD
|
||||
|
||||
Image.constructor = function(self, x, y, img, drawMethod)
|
||||
if (type(img) == "string") then
|
||||
Image.constructor = function(self, x, y, img, drawMethod)
|
||||
if (type(img) == "string") then
|
||||
self.imageData = ImageFile(img)
|
||||
elseif (type("table") and img.class == "ImageFile") then
|
||||
self.imageData = img
|
||||
end
|
||||
if (drawMethod ~= nil) then self:setDrawMethod(drawMethod) end
|
||||
end
|
||||
Image.private.draw = {}
|
||||
Image.private.draw.old = function(self)
|
||||
Image.private.draw = {}
|
||||
Image.private.draw.old = function(self)
|
||||
local background = gpu.getBackground()
|
||||
for deltaX, column in ipairs(self.imageData:getPixel()) do
|
||||
for deltaY, pixel in ipairs(column) do
|
||||
@@ -29,7 +29,7 @@ Image.private.draw.old = function(self)
|
||||
end
|
||||
gpu.setBackground(background)
|
||||
end
|
||||
Image.private.draw.new = function(self)
|
||||
Image.private.draw.new = function(self)
|
||||
local bg, fg = gpu.getBackground(), gpu.getForeground()
|
||||
local pixelFg, pixelBg
|
||||
for x = 1, self.imageData:getWidth() do
|
||||
@@ -53,15 +53,15 @@ Image.private.draw.new = function(self)
|
||||
gpu.setForeground(fg)
|
||||
end
|
||||
|
||||
Image.getWidth = function(self) return self.imageData:getWidth() end
|
||||
Image.getHeight = function(self) if (self:getDrawMethod()) then return math.ceil(self.imageData:getHeight() / 2) else return self.imageData:getHeight() end end
|
||||
Image.getSize = function(self) return self.imageData:getSize() end
|
||||
Image.setWidth = function(self) error("Can change a image size", 2) end
|
||||
Image.setHeight = function(self) error("Can change a image size", 2) end
|
||||
Image.setSize = function(self) error("Can change a image size", 2) end
|
||||
Image.setDrawMethod = function(self, drawMethod) self.private.drawMethod = drawMethod end
|
||||
Image.getDrawMethod = function(self) return self.private.drawMethod end
|
||||
Image.draw = function(self)
|
||||
Image.getWidth = function(self) return self.imageData:getWidth() end
|
||||
Image.getHeight = function(self) if (self:getDrawMethod()) then return math.ceil(self.imageData:getHeight() / 2) else return self.imageData:getHeight() end end
|
||||
Image.getSize = function(self) return self.imageData:getSize() end
|
||||
Image.setWidth = function(self) error("Can change a image size", 2) end
|
||||
Image.setHeight = function(self) error("Can change a image size", 2) end
|
||||
Image.setSize = function(self) error("Can change a image size", 2) end
|
||||
Image.setDrawMethod = function(self, drawMethod) self.private.drawMethod = drawMethod end
|
||||
Image.getDrawMethod = function(self) return self.private.drawMethod end
|
||||
Image.draw = function(self)
|
||||
if (self:getDrawMethod() == Image.DRAW_METHOD_NEW) then
|
||||
self.private.draw.new(self)
|
||||
else
|
||||
|
@@ -32,7 +32,7 @@ function Input.setValue(self, text) self:setText(text) end
|
||||
|
||||
function Input.private.onKeyDown(self, eventName, component, char, key, player)
|
||||
if (not eventName == "key_down") then return end
|
||||
if (char == 8) then --backspace
|
||||
if (char == 8) then --backspace
|
||||
self:setText(string.sub(self:getValue(), 0, -2))
|
||||
elseif (char == 13) then --return
|
||||
event.cancel(self.private.keyDownEvent)
|
||||
|
@@ -6,13 +6,19 @@ Rectangle.private.height = 1
|
||||
Rectangle.private.color = 0
|
||||
Rectangle.setWidth = function(self, width) self.private.width = math.max(width or self:getWidth(), 1) end
|
||||
Rectangle.setHeight = function(self, height) self.private.height = math.max(height or self:getHeight(), 1) end
|
||||
Rectangle.setSize = function(self, width, height) self:setWidth(width) self:setHeight(height) end
|
||||
Rectangle.setSize = function(self, width, height)
|
||||
self:setWidth(width)
|
||||
self:setHeight(height)
|
||||
end
|
||||
Rectangle.setColor = function(self, color) self.private.color = color or self:getColor() end
|
||||
Rectangle.getWidth = function(self) return self.private.width end
|
||||
Rectangle.getHeight = function(self) return self.private.height end
|
||||
Rectangle.getSize = function(self) return self:getWidth(), self:getHeight() end
|
||||
Rectangle.getColor = function(self) return self.private.color end
|
||||
Rectangle.constructor = function(self, x, y, width, height, color) self:setSize(width, height) self:setColor(color) end
|
||||
Rectangle.constructor = function(self, x, y, width, height, color)
|
||||
self:setSize(width, height)
|
||||
self:setColor(color)
|
||||
end
|
||||
Rectangle.collide = function(self, x, y)
|
||||
local wx1, wy1 = self:getPos()
|
||||
local wx2 = self:getX() + self:getWidth() - 1
|
||||
|
@@ -1,4 +1,5 @@
|
||||
local function emptyCallback(self, ...) end
|
||||
local function emptyCallback(self, ...)
|
||||
end
|
||||
|
||||
local Widget = require("libClass").newClass("Widget")
|
||||
Widget.type = "Widget"
|
||||
@@ -7,7 +8,10 @@ Widget.setVisible = function(self, visible) self.private.visible = visible end
|
||||
Widget.isVisible = function(self) return self.private.visible end
|
||||
Widget.enable = function(self, enable) self.private.enabled = enable end
|
||||
Widget.isEnabled = function(self) return self.private.enabled end
|
||||
Widget.setPos = function(self, x, y) self:setX(x) self:setY(y) end
|
||||
Widget.setPos = function(self, x, y)
|
||||
self:setX(x)
|
||||
self:setY(y)
|
||||
end
|
||||
Widget.setX = function(self, x) self.private.x = x or self:getX() end
|
||||
Widget.setY = function(self, y) self.private.y = y or self:getY() end
|
||||
Widget.setCallback = function(self, callback) self.private.callback = callback or emptyCallback end
|
||||
@@ -21,6 +25,9 @@ end
|
||||
Widget.collide = function(self, x, y)
|
||||
return (x == self:getX() and y == self:getY())
|
||||
end
|
||||
Widget.constructor = function(self, x, y) self:setPos(x, y) self.private.id = require("uuid").next() end
|
||||
Widget.constructor = function(self, x, y)
|
||||
self:setPos(x, y)
|
||||
self.private.id = require("uuid").next()
|
||||
end
|
||||
|
||||
return Widget
|
||||
|
@@ -43,7 +43,7 @@ local function do_mount()
|
||||
end
|
||||
end
|
||||
|
||||
if #args == 0 then
|
||||
if #args == 0 then
|
||||
if next(opts) then
|
||||
io.stderr:write("Missing argument\n")
|
||||
usage()
|
||||
|
@@ -12,24 +12,29 @@ local OSILayer = {}
|
||||
---@param from string|number
|
||||
---@param to string|number
|
||||
---@param payload string
|
||||
function OSILayer:payloadHandler(from, to, payload) end
|
||||
function OSILayer:payloadHandler(from, to, payload)
|
||||
end
|
||||
|
||||
---Send the payload
|
||||
---@param to string|number destination.
|
||||
---@param payload Payload
|
||||
---@overload fun(payload)
|
||||
function OSILayer:send(to, payload) end
|
||||
function OSILayer:send(to, payload)
|
||||
end
|
||||
|
||||
---Register higher level OSI layer
|
||||
---@param OSILayer any
|
||||
function OSILayer:setLayer(OSILayer) end
|
||||
function OSILayer:setLayer(OSILayer)
|
||||
end
|
||||
|
||||
---Return the maximum payload size
|
||||
---@return number
|
||||
function OSILayer:getMTU() end
|
||||
function OSILayer:getMTU()
|
||||
end
|
||||
|
||||
---@return string|number
|
||||
function OSILayer:getAddr() end
|
||||
function OSILayer:getAddr()
|
||||
end
|
||||
|
||||
--=============================================================================
|
||||
|
||||
@@ -47,9 +52,11 @@ local Payload = {}
|
||||
|
||||
---Prepare the payload for the next layer
|
||||
---@return any ...
|
||||
function Payload:pack() end
|
||||
function Payload:pack()
|
||||
end
|
||||
|
||||
---Get a payload object from the argument
|
||||
---@param ... any
|
||||
---@return Payload
|
||||
function Payload.unpack(...) end
|
||||
function Payload.unpack(...)
|
||||
end
|
||||
|
@@ -141,7 +141,7 @@ function ifconfig.loadInterfaces(file)
|
||||
local opt, arg = line:match("^%s+(%w+)%s+([%d%.]+/%d+)$") --get the option name and argument
|
||||
if (VALID_PARAM[iType] ~= nil) then --known iType
|
||||
if (VALID_PARAM[iType][iMode] ~= nil) then --known iMode
|
||||
readInterfaces[iName] = readInterfaces[iName] or { iName = iName, iType = iType, iMode = iMode }
|
||||
readInterfaces[iName] = readInterfaces[iName] or {iName = iName, iType = iType, iMode = iMode}
|
||||
if (VALID_PARAM[iType][iMode][opt] == true) then
|
||||
flog("\tFound option %q with argument %q", 1, opt, arg)
|
||||
readInterfaces[iName][opt] = arg
|
||||
@@ -226,7 +226,7 @@ function ifconfig.ifup(iName)
|
||||
network.interfaces[iName].udp = layers.udp.UDPLayer(network.interfaces[iName].ip)
|
||||
--router
|
||||
if (interface.gateway) then
|
||||
network.router:addRoute({ network = 0, mask = 0, gateway = layers.ipv4.address.fromString(interface.gateway), metric = tonumber(interface.metric) or 100 })
|
||||
network.router:addRoute({network = 0, mask = 0, gateway = layers.ipv4.address.fromString(interface.gateway), metric = tonumber(interface.metric) or 100})
|
||||
end
|
||||
|
||||
return true
|
||||
|
@@ -69,7 +69,7 @@ setmetatable(ARPFrame, {
|
||||
_tpa = tpa,
|
||||
}
|
||||
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
|
||||
return o
|
||||
end
|
||||
@@ -183,7 +183,7 @@ setmetatable(ARPLayer, {
|
||||
local o = {
|
||||
_layer = osiLayer
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
osiLayer:setLayer(o)
|
||||
return o
|
||||
end
|
||||
@@ -299,7 +299,7 @@ function arp.list(htype, ptype)
|
||||
local l = {}
|
||||
if (arp.internal.cache[ptype]) then
|
||||
for k, v in pairs(arp.internal.cache[ptype]) do
|
||||
table.insert(l, { k, v[htype] })
|
||||
table.insert(l, {k, v[htype]})
|
||||
end
|
||||
end
|
||||
return l
|
||||
|
@@ -64,7 +64,7 @@ setmetatable(EthernetFrame, {
|
||||
_etype = etype,
|
||||
_payload = payload,
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
return o
|
||||
end,
|
||||
})
|
||||
@@ -170,7 +170,7 @@ setmetatable(EthernetInterface, {
|
||||
|
||||
o._modem.open(o._port)
|
||||
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
|
||||
o._listener = event.listen("modem_message", function(...) o:modemMessageHandler(...) end)
|
||||
|
||||
|
@@ -1,8 +1,9 @@
|
||||
local ipv4 = require("layers.ipv4")
|
||||
local event = require("event")
|
||||
local ipv4 = require("layers.ipv4")
|
||||
local event = require("event")
|
||||
local network = require("network")
|
||||
--=============================================================================
|
||||
|
||||
|
||||
---@class icmplib
|
||||
local icmp = {}
|
||||
---@enum icmpType
|
||||
@@ -110,7 +111,7 @@ setmetatable(ICMPPacket, {
|
||||
_param = param or 0,
|
||||
_payload = payload or ""
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
return o
|
||||
end
|
||||
})
|
||||
@@ -191,7 +192,7 @@ setmetatable(ICMPLayer, {
|
||||
local o = {
|
||||
_layer = layer
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
layer:setLayer(o)
|
||||
return o
|
||||
end,
|
||||
|
@@ -1,9 +1,9 @@
|
||||
---@class layersLib
|
||||
local layers = {}
|
||||
layers.ipv4 = require("layers.ipv4")
|
||||
layers.arp = require("layers.arp")
|
||||
local layers = {}
|
||||
layers.ipv4 = require("layers.ipv4")
|
||||
layers.arp = require("layers.arp")
|
||||
layers.ethernet = require("layers.ethernet")
|
||||
layers.icmp = require("layers.icmp")
|
||||
layers.udp = require("layers.udp")
|
||||
layers.icmp = require("layers.icmp")
|
||||
layers.udp = require("layers.udp")
|
||||
|
||||
return layers
|
||||
|
@@ -1,6 +1,7 @@
|
||||
local bit32 = require("bit32")
|
||||
local arp = require("layers.arp")
|
||||
local ethernet = require("layers.ethernet")
|
||||
local bit32 = require("bit32")
|
||||
local arp = require("layers.arp")
|
||||
local ethernet = require("layers.ethernet")
|
||||
|
||||
|
||||
---@class ipv4lib
|
||||
local ipv4lib = {}
|
||||
@@ -68,7 +69,7 @@ setmetatable(IPv4Packet, {
|
||||
_payload = ""
|
||||
}
|
||||
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
---@cast o IPv4Packet
|
||||
o:setSrc(src)
|
||||
o:setDst(dst)
|
||||
@@ -339,7 +340,7 @@ setmetatable(IPv4Layer, {
|
||||
_arp = nil,
|
||||
_router = router,
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
o:setAddr(addr)
|
||||
o:setMask(mask)
|
||||
dataLayer:setLayer(o)
|
||||
@@ -348,7 +349,7 @@ setmetatable(IPv4Layer, {
|
||||
arp.setLocalAddress(arp.HARDWARE_TYPE.ETHERNET, arp.PROTOCOLE_TYPE.IPv4, dataLayer:getAddr(), o:getAddr())
|
||||
--route
|
||||
o._router:setLayer(o)
|
||||
o._router:addRoute({ network = bit32.band(o:getAddr(), o:getMask()), mask = o:getMask(), gateway = o:getAddr(), metric = 0 })
|
||||
o._router:addRoute({network = bit32.band(o:getAddr(), o:getMask()), mask = o:getMask(), gateway = o:getAddr(), metric = 0})
|
||||
return o
|
||||
end,
|
||||
})
|
||||
|
@@ -1,4 +1,3 @@
|
||||
local buffer = require("buffer")
|
||||
local IPv4Packet = require("layers.ipv4").IPv4Packet
|
||||
|
||||
---@class udpLib
|
||||
@@ -31,7 +30,7 @@ setmetatable(UDPPacket, {
|
||||
_dstPort = 0,
|
||||
_payload = ""
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
|
||||
o:setDstPort(dstPort)
|
||||
o:setSrcPort(srcPort)
|
||||
@@ -111,7 +110,7 @@ setmetatable(UDPSocket, {
|
||||
_buffer = {},
|
||||
_layer = layer
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
return o
|
||||
end
|
||||
})
|
||||
@@ -198,7 +197,7 @@ setmetatable(UDPLayer, {
|
||||
_sockets = {},
|
||||
_layer = layer
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
layer:setLayer(o) --tell the IPv4Layer that we exists
|
||||
return o
|
||||
end
|
||||
|
@@ -22,7 +22,7 @@ networklib.router = routing.IPv4Router()
|
||||
---@
|
||||
function networklib.getInterface(filter)
|
||||
checkArg(1, filter, "string", "nil")
|
||||
if (filter) then return { networklib.interfaces.ethernet[component.get(filter, "modem")] or nil } end
|
||||
if (filter) then return {networklib.interfaces.ethernet[component.get(filter, "modem")] or nil} end
|
||||
return networklib.interfaces
|
||||
end
|
||||
|
||||
|
@@ -27,7 +27,7 @@ setmetatable(IPv4Router, {
|
||||
_routes = {},
|
||||
_layers = {}
|
||||
}
|
||||
setmetatable(o, { __index = self })
|
||||
setmetatable(o, {__index = self})
|
||||
return o
|
||||
end
|
||||
})
|
||||
|
@@ -17,7 +17,7 @@ local function normalisePath(path)
|
||||
local pt = {}
|
||||
for seg in path:gmatch("[^/]+") do
|
||||
seg = seg:gsub("?master", "master"):gsub(":master", "master")
|
||||
pt[#pt+1] = seg
|
||||
pt[#pt + 1] = seg
|
||||
end
|
||||
local pre = ""
|
||||
if path:sub(1, 1) == "/" then
|
||||
@@ -57,7 +57,7 @@ local function parseFolders(pack, repo, info)
|
||||
repeat
|
||||
os.sleep(0)
|
||||
local s, c, reason = pcall(result.finishConnect)
|
||||
if (not s) then
|
||||
if (not s) then
|
||||
error(c, 2)
|
||||
elseif (c == nil) then
|
||||
error(reason, 2)
|
||||
@@ -68,7 +68,7 @@ local function parseFolders(pack, repo, info)
|
||||
-- read the response
|
||||
repeat
|
||||
local data, reason = result.read()
|
||||
if not data then
|
||||
if not data then
|
||||
result.close()
|
||||
if reason then
|
||||
error(reason, 2)
|
||||
@@ -122,7 +122,7 @@ local function parseFolders(pack, repo, info)
|
||||
if not files then return nil end
|
||||
local tFiles = {}
|
||||
for _, v in pairs(files) do
|
||||
if v["type"] == "file" then
|
||||
if v["type"] == "file" then
|
||||
local newPath = v["download_url"]:gsub("https?://raw.githubusercontent.com/" .. nonSpecial(repo) .. "(.+)$", "%1"):gsub("/*$", ""):gsub("^/*", "")
|
||||
tFiles[newPath] = relPath
|
||||
elseif v["type"] == "dir" then
|
||||
@@ -214,7 +214,7 @@ for k, v in pairs(programs) do
|
||||
assert(v, "v should not be nil")
|
||||
if v.files then
|
||||
for l, m in pairs(v.files) do
|
||||
dlfiles[#dlfiles+1] = l
|
||||
dlfiles[#dlfiles + 1] = l
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -41,7 +41,7 @@ end
|
||||
|
||||
local pkgmap = {} -- alphabetically sorted list of package names
|
||||
for k, v in pairs(packages) do
|
||||
pkgmap[#pkgmap+1] = k
|
||||
pkgmap[#pkgmap + 1] = k
|
||||
end
|
||||
table.sort(pkgmap)
|
||||
|
||||
@@ -103,7 +103,7 @@ local function drawmenu() -- draw the menu display - nothing but text and VT100
|
||||
print(install.label .. " installer")
|
||||
workingSpace = workingSpace - 1
|
||||
end
|
||||
if selected > start + workingSpace - 3 then
|
||||
if selected > start + workingSpace - 3 then
|
||||
start = math.min(start + 3, #pkgmap - workingSpace)
|
||||
elseif selected < start + 3 then
|
||||
start = math.max(start - 3, 1)
|
||||
@@ -132,13 +132,14 @@ Key codes:
|
||||
105 23 i
|
||||
113 16 q
|
||||
121 21 y
|
||||
]] --
|
||||
]]
|
||||
--
|
||||
|
||||
local run, install = true, true
|
||||
while run do -- menu loop
|
||||
drawmenu()
|
||||
local _, _, ch, co = event.pull("key_down")
|
||||
if ch == 13 and co == 28 then
|
||||
if ch == 13 and co == 28 then
|
||||
run = false
|
||||
elseif ch == 113 and co == 16 then
|
||||
run = false
|
||||
@@ -205,7 +206,7 @@ local function install(pkg, where) -- installs a package, pkg, to where
|
||||
for l, m in pairs(packages[pkg].files) do
|
||||
local lseg = fs.segments(l)
|
||||
local op = ""
|
||||
if (l:sub(1, 1) == ":") then
|
||||
if (l:sub(1, 1) == ":") then
|
||||
l = l:sub(2)
|
||||
op = "-r "
|
||||
m = m .. "/"
|
||||
@@ -238,7 +239,7 @@ local function install(pkg, where) -- installs a package, pkg, to where
|
||||
end
|
||||
if packages[pkg].postinstall then
|
||||
for k, v in pairs(packages[pkg].postinstall) do
|
||||
postinstall[#postinstall+1] = v
|
||||
postinstall[#postinstall + 1] = v
|
||||
end
|
||||
end
|
||||
else
|
||||
|
@@ -1,28 +1,28 @@
|
||||
local stargate = require("component").stargate
|
||||
local gpu = require("component").gpu
|
||||
local io = require "io"
|
||||
local event = require "event"
|
||||
local os = require "os"
|
||||
local filesystem = require "filesystem"
|
||||
local serialization = require("serialization")
|
||||
local gui = require "libGUI"
|
||||
local stargate = require("component").stargate
|
||||
local gpu = require("component").gpu
|
||||
local io = require "io"
|
||||
local event = require "event"
|
||||
local os = require "os"
|
||||
local filesystem = require "filesystem"
|
||||
local serialization = require("serialization")
|
||||
local gui = require "libGUI"
|
||||
|
||||
--CONST
|
||||
local CONFIG_PATH = "/etc/stargate/"
|
||||
local WHITELIST_FILE = CONFIG_PATH .. "whitelist.csv"
|
||||
local BLACKLIST_FILE = CONFIG_PATH .. "blacklist.csv"
|
||||
local CONFIG_FILE = CONFIG_PATH .. "stargate.cfg"
|
||||
local GATE_LIST = CONFIG_PATH .. "gates.csv"
|
||||
local IMG_ROOT = "/usr/share/stargate/"
|
||||
local IRIS_STATE = {IMG_ROOT .. "iris1.pam", IMG_ROOT .. "iris2.pam", IMG_ROOT .. "iris3.pam"}
|
||||
local GATE_STATE = {[0] = IMG_ROOT .. "sg00.pam", IMG_ROOT .. "sg01.pam", IMG_ROOT .. "sg02.pam", IMG_ROOT .. "sg03.pam", IMG_ROOT .. "sg04.pam", IMG_ROOT .. "sg05.pam", IMG_ROOT .. "sg06.pam", IMG_ROOT .. "sg07.pam", IMG_ROOT .. "sg08.pam", IMG_ROOT .. "sg09.pam", IMG_ROOT .. "sg10.pam"}
|
||||
local VORTEX = IMG_ROOT .. "vortex.pam"
|
||||
local CONFIG_PATH = "/etc/stargate/"
|
||||
local WHITELIST_FILE = CONFIG_PATH .. "whitelist.csv"
|
||||
local BLACKLIST_FILE = CONFIG_PATH .. "blacklist.csv"
|
||||
local CONFIG_FILE = CONFIG_PATH .. "stargate.cfg"
|
||||
local GATE_LIST = CONFIG_PATH .. "gates.csv"
|
||||
local IMG_ROOT = "/usr/share/stargate/"
|
||||
local IRIS_STATE = {IMG_ROOT .. "iris1.pam", IMG_ROOT .. "iris2.pam", IMG_ROOT .. "iris3.pam"}
|
||||
local GATE_STATE = {[0] = IMG_ROOT .. "sg00.pam", IMG_ROOT .. "sg01.pam", IMG_ROOT .. "sg02.pam", IMG_ROOT .. "sg03.pam", IMG_ROOT .. "sg04.pam", IMG_ROOT .. "sg05.pam", IMG_ROOT .. "sg06.pam", IMG_ROOT .. "sg07.pam", IMG_ROOT .. "sg08.pam", IMG_ROOT .. "sg09.pam", IMG_ROOT .. "sg10.pam"}
|
||||
local VORTEX = IMG_ROOT .. "vortex.pam"
|
||||
|
||||
--gidget position
|
||||
local GATE_IMG_X, GATE_IMG_Y = 48, -1
|
||||
local LIST_TEXT_X, LIST_TEXT_Y = 2, 3 - 1
|
||||
local DIALLER_X, DIALLER_Y = GATE_IMG_X + 6, GATE_IMG_Y + 23
|
||||
local PASSWORD_X, PASSWORD_Y = GATE_IMG_X + 1, DIALLER_Y + 1
|
||||
local GATE_IMG_X, GATE_IMG_Y = 48, -1
|
||||
local LIST_TEXT_X, LIST_TEXT_Y = 2, 3 - 1
|
||||
local DIALLER_X, DIALLER_Y = GATE_IMG_X + 6, GATE_IMG_Y + 23
|
||||
local PASSWORD_X, PASSWORD_Y = GATE_IMG_X + 1, DIALLER_Y + 1
|
||||
|
||||
--colors
|
||||
local THEME = {BACKGROUNDS = {}, FOREGROUNDS = {}}
|
||||
@@ -78,36 +78,36 @@ local sgMessageRecivedEvent = nil
|
||||
local interruptedEvent = nil
|
||||
|
||||
--global vars
|
||||
local oldResX, oldResY = gpu.getResolution()
|
||||
local run = true
|
||||
local config = nil
|
||||
local gates = {}
|
||||
local waitingForConfirmation = false
|
||||
local irisManual = true
|
||||
local dialDirection = ""
|
||||
local dialDim = false
|
||||
local instantDialed = true
|
||||
local outgoingBlacklist = false
|
||||
local outgoingAuth = false
|
||||
local receivedPassword = false
|
||||
local incomingBlacklist = false
|
||||
local remoteIris = "Offline"
|
||||
local oldResX, oldResY = gpu.getResolution()
|
||||
local run = true
|
||||
local config = nil
|
||||
local gates = {}
|
||||
local waitingForConfirmation = false
|
||||
local irisManual = true
|
||||
local dialDirection = ""
|
||||
local dialDim = false
|
||||
local instantDialed = true
|
||||
local outgoingBlacklist = false
|
||||
local outgoingAuth = false
|
||||
local receivedPassword = false
|
||||
local incomingBlacklist = false
|
||||
local remoteIris = "Offline"
|
||||
|
||||
--global widgets
|
||||
local mainScreen = nil
|
||||
local textRemoteAddr = nil
|
||||
local configScreen = nil
|
||||
local root = nil
|
||||
local buttonIris = nil
|
||||
local vortexLayer = nil
|
||||
local gateLayer = nil
|
||||
local irisLayer = nil
|
||||
local gatesListTexts = {}
|
||||
local nameInput = nil
|
||||
local buttonWhitelist = nil
|
||||
local buttonBlacklist = nil
|
||||
local inputAddr = nil
|
||||
local passwordField = nil
|
||||
local mainScreen = nil
|
||||
local textRemoteAddr = nil
|
||||
local configScreen = nil
|
||||
local root = nil
|
||||
local buttonIris = nil
|
||||
local vortexLayer = nil
|
||||
local gateLayer = nil
|
||||
local irisLayer = nil
|
||||
local gatesListTexts = {}
|
||||
local nameInput = nil
|
||||
local buttonWhitelist = nil
|
||||
local buttonBlacklist = nil
|
||||
local inputAddr = nil
|
||||
local passwordField = nil
|
||||
|
||||
local function closeApp(...)
|
||||
if (touchEvent) then event.cancel(touchEvent) end
|
||||
@@ -118,7 +118,10 @@ local function closeApp(...)
|
||||
if (sgChevronEngadedEvent) then event.cancel(sgChevronEngadedEvent) end
|
||||
if (sgMessageRecivedEvent) then event.cancel(sgMessageRecivedEvent) end
|
||||
if (interruptedEvent) then event.cancel(interruptedEvent) end
|
||||
if (stargate) then stargate.disconnect(); stargate.closeIris() end
|
||||
if (stargate) then
|
||||
stargate.disconnect();
|
||||
stargate.closeIris()
|
||||
end
|
||||
run = false
|
||||
gpu.setResolution(oldResX, oldResY)
|
||||
require("term").clear()
|
||||
@@ -169,11 +172,14 @@ local function setIrisButton()
|
||||
local irisState = stargate.irisState()
|
||||
buttonIris:enable(irisState == remoteIris or remoteIris == "Offline")
|
||||
if (not remoteIris == "Offline") then
|
||||
if (irisState == "Open" and remoteIris == "Opening") then irisState = remoteIris
|
||||
elseif (irisState == "Closed" and remoteIris == "Closing") then irisState = remoteIris end
|
||||
if (irisState == "Open" and remoteIris == "Opening") then
|
||||
irisState = remoteIris
|
||||
elseif (irisState == "Closed" and remoteIris == "Closing") then
|
||||
irisState = remoteIris
|
||||
end
|
||||
end
|
||||
buttonIris:setText(irisState)
|
||||
if (not irisManual) then
|
||||
if (not irisManual) then
|
||||
buttonIris:setBackground(THEME.BACKGROUNDS.IRIS_BUTTON.AUTO)
|
||||
if (not (irisState == "Open" or irisState == "Opening") and outgoingBlacklist and not outgoingAuth) then
|
||||
buttonIris:setText("BLACKLIST")
|
||||
@@ -190,8 +196,11 @@ local function toogleFromList(list, addr)
|
||||
--add the addr in the list if it is not already in it, else remove it
|
||||
--used for the blacklist and whitelist
|
||||
local inList, i = isGateInList(list, addr)
|
||||
if (inList) then table.remove(list, i)
|
||||
else table.insert(list, addr) end
|
||||
if (inList) then
|
||||
table.remove(list, i)
|
||||
else
|
||||
table.insert(list, addr)
|
||||
end
|
||||
end
|
||||
|
||||
local function saveGatesAdd()
|
||||
@@ -387,8 +396,11 @@ local function onStargateStateChange(eventName, componentAddress, toState, fromS
|
||||
if (instantDialed) then
|
||||
--if the gate was "instant dialled" no sgChevronEngadedEvent where recived
|
||||
--in this case, we need to set the chevron img here
|
||||
if (dialDim) then gateLayer.imageData = gui.Image(GATE_STATE[10])
|
||||
else gateLayer.imageData = gui.Image(GATE_STATE[7]) end
|
||||
if (dialDim) then
|
||||
gateLayer.imageData = gui.Image(GATE_STATE[10])
|
||||
else
|
||||
gateLayer.imageData = gui.Image(GATE_STATE[7])
|
||||
end
|
||||
end
|
||||
end
|
||||
if (toState == "Connected") then
|
||||
@@ -463,8 +475,8 @@ local function onDialIn(eventName, componentAddress, remoteGateAddress)
|
||||
textRemoteAddr:setForeground(THEME.FOREGROUNDS.REMOTE_ADRESSE.DIALLLING)
|
||||
incomingBlacklist = (
|
||||
(config.useBlacklist and isGateInList(config.blacklist, stargate.remoteAddress()))
|
||||
or
|
||||
(config.useWhitelist and not isGateInList(config.whitelist, stargate.remoteAddress()))
|
||||
or
|
||||
(config.useWhitelist and not isGateInList(config.whitelist, stargate.remoteAddress()))
|
||||
)
|
||||
if (incomingBlacklist) then
|
||||
textRemoteAddr:setForeground(THEME.FOREGROUNDS.REMOTE_ADRESSE.BLACLISTED)
|
||||
@@ -523,7 +535,7 @@ local function onMessageReceived(eventName, componentAddress, ...)
|
||||
setIrisButton()
|
||||
end
|
||||
end
|
||||
if (arg[1] == "openIris") then
|
||||
if (arg[1] == "openIris") then
|
||||
if (not irisManual and receivedPassword) then
|
||||
--if iris is in automatic mod and the password is correct (defaut to true when not blacklisted)
|
||||
stargate.openIris()
|
||||
@@ -537,7 +549,7 @@ local function onMessageReceived(eventName, componentAddress, ...)
|
||||
stargate.sendMessage("irisState", stargate.irisState())
|
||||
elseif (arg[1] == "irisState") then
|
||||
remoteIris = arg[2]
|
||||
if (arg[2] == "Closing" or arg[2] == "Closed") then
|
||||
if (arg[2] == "Closing" or arg[2] == "Closed") then
|
||||
stargate.closeIris()
|
||||
if (outgoingBlacklist and not outgoingAuth) then irisManual = false end
|
||||
elseif (not irisManual and receivedPassword or dialDirection == "O") then
|
||||
@@ -658,9 +670,11 @@ buttonIris = gui.widget.Text(14, 25, 12, 1, THEME.FOREGROUNDS.IRIS_BUTTON.CLOSED
|
||||
setIrisButton()
|
||||
buttonIris:setCallback(function(...)
|
||||
irisManual = true
|
||||
if (stargate.irisState() == "Open" or stargate.irisState() == "Opening") then
|
||||
if (stargate.irisState() == "Open" or stargate.irisState() == "Opening") then
|
||||
stargate.closeIris()
|
||||
elseif (not outgoingBlacklist or outgoingAuth) then stargate.openIris() end
|
||||
elseif (not outgoingBlacklist or outgoingAuth) then
|
||||
stargate.openIris()
|
||||
end
|
||||
end)
|
||||
mainScreen:addChild(buttonIris)
|
||||
--config
|
||||
@@ -672,7 +686,7 @@ buttonConfig:setCallback(function(...)
|
||||
configScreen:setVisible(true)
|
||||
--wait a little so no event get processed in the config screen
|
||||
event.timer(
|
||||
0.1,
|
||||
0.1,
|
||||
function(...)
|
||||
configScreen:enable(true)
|
||||
end
|
||||
@@ -726,55 +740,85 @@ mainScreen:addChild(gateLayer)
|
||||
buttonWhitelist = gui.widget.Text(2, 2, 18, 1, THEME.FOREGROUNDS.CONFIG_TOGGLE.ON, "Whitelist")
|
||||
buttonWhitelist:setCallback(function(widget, ...)
|
||||
config.useWhitelist = not config.useWhitelist
|
||||
if (config.useWhitelist) then widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.useWhitelist) then
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
buttonBlacklist:enable(not config.useWhitelist)
|
||||
end)
|
||||
if (config.useWhitelist) then buttonWhitelist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else buttonWhitelist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.useWhitelist) then
|
||||
buttonWhitelist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
buttonWhitelist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
buttonWhitelist:enable(not config.useBlacklist)
|
||||
configScreen:addChild(buttonWhitelist)
|
||||
--Blacklist
|
||||
buttonBlacklist = gui.widget.Text(2, 4, 18, 1, THEME.FOREGROUNDS.CONFIG_TOGGLE.ON, "Blacklist")
|
||||
buttonBlacklist:setCallback(function(widget, ...)
|
||||
config.useBlacklist = not config.useBlacklist
|
||||
if (config.useBlacklist) then widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.useBlacklist) then
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
buttonWhitelist:enable(not config.useBlacklist)
|
||||
end)
|
||||
if (config.useBlacklist) then buttonBlacklist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else buttonBlacklist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.useBlacklist) then
|
||||
buttonBlacklist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
buttonBlacklist:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
buttonBlacklist:enable(not config.useWhitelist)
|
||||
configScreen:addChild(buttonBlacklist)
|
||||
--blacklist drop
|
||||
local buttonDropBlacklistConnexion = gui.widget.Text(2, 6, 18, 1, THEME.FOREGROUNDS.CONFIG_TOGGLE.ON, "Drop if blacklist")
|
||||
buttonDropBlacklistConnexion:setCallback(function(widget, ...)
|
||||
config.dropBlacklistedConnexions = not config.dropBlacklistedConnexions
|
||||
if (config.dropBlacklistedConnexions) then widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.dropBlacklistedConnexions) then
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
end)
|
||||
if (config.dropBlacklistedConnexions) then buttonDropBlacklistConnexion:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else buttonDropBlacklistConnexion:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.dropBlacklistedConnexions) then
|
||||
buttonDropBlacklistConnexion:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
buttonDropBlacklistConnexion:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
configScreen:addChild(buttonDropBlacklistConnexion)
|
||||
--autoLearn
|
||||
local buttonLearnNewGates = gui.widget.Text(2, 8, 18, 1, THEME.FOREGROUNDS.CONFIG_TOGGLE.ON, "Learn new gates")
|
||||
buttonLearnNewGates:setCallback(function(widget, ...)
|
||||
config.saveNewGate = not config.saveNewGate
|
||||
if (config.saveNewGate) then widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.saveNewGate) then
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
end)
|
||||
if (config.saveNewGate) then buttonLearnNewGates:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else buttonLearnNewGates:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.saveNewGate) then
|
||||
buttonLearnNewGates:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
buttonLearnNewGates:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
configScreen:addChild(buttonLearnNewGates)
|
||||
--savePassword
|
||||
local buttonSavePassword = gui.widget.Text(2, 10, 18, 1, THEME.FOREGROUNDS.CONFIG_TOGGLE.ON, "Save password")
|
||||
buttonSavePassword:setCallback(function(widget, ...)
|
||||
config.savePassword = not config.savePassword
|
||||
if (config.savePassword) then widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.savePassword) then
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
widget:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
end)
|
||||
if (config.savePassword) then buttonSavePassword:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else buttonSavePassword:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF) end
|
||||
if (config.savePassword) then
|
||||
buttonSavePassword:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.ON)
|
||||
else
|
||||
buttonSavePassword:setBackground(THEME.BACKGROUNDS.CONFIG_TOGGLE.OFF)
|
||||
end
|
||||
configScreen:addChild(buttonSavePassword)
|
||||
--password
|
||||
local passwordLabel = gui.widget.Text(2, 12, 15, 1, THEME.FOREGROUNDS.C_TEXT, "Iris password :")
|
||||
@@ -810,8 +854,11 @@ configScreen:addChild(buttonCancel)
|
||||
--Init screen
|
||||
gpu.setResolution(80, 25)
|
||||
--disconnect the gate as a safety
|
||||
if (stargate.stargateState() ~= "Idle") then stargate.disconnect()
|
||||
else stargate.openIris() end
|
||||
if (stargate.stargateState() ~= "Idle") then
|
||||
stargate.disconnect()
|
||||
else
|
||||
stargate.openIris()
|
||||
end
|
||||
--main loop
|
||||
while (run) do
|
||||
root:draw()
|
||||
|
@@ -17,22 +17,22 @@ local libCB = {} --imported later if required by config
|
||||
assert(transposer, "No transposer found")
|
||||
|
||||
--constants
|
||||
local CONFIG_PATH = "/etc/vending/"
|
||||
local CONFIG_FILE = CONFIG_PATH .. "config.cfg"
|
||||
local CONFIG_PATH = "/etc/vending/"
|
||||
local CONFIG_FILE = CONFIG_PATH .. "config.cfg"
|
||||
local PRODUCT_LIST_FILE = CONFIG_PATH .. "products.csv"
|
||||
local OUT_PATH = "/var/vending/"
|
||||
local SALE_STATS = OUT_PATH .. "sales.csv"
|
||||
local OUT_PATH = "/var/vending/"
|
||||
local SALE_STATS = OUT_PATH .. "sales.csv"
|
||||
|
||||
local COLUMN_SOLD_ITEM = 1
|
||||
local COLUMN_SOLD_QTE = 2
|
||||
local COLUMN_COST_ITEM = 3
|
||||
local COLUMN_COST_QTE = 4
|
||||
local COLUMN_COST_COIN = 5
|
||||
local COLUMN_SOLD_ITEM = 1
|
||||
local COLUMN_SOLD_QTE = 2
|
||||
local COLUMN_COST_ITEM = 3
|
||||
local COLUMN_COST_QTE = 4
|
||||
local COLUMN_COST_COIN = 5
|
||||
|
||||
--global vars
|
||||
local config = {}
|
||||
local products = {}
|
||||
local availableProduct = {}
|
||||
local config = {}
|
||||
local products = {}
|
||||
local availableProduct = {}
|
||||
|
||||
--functions definition
|
||||
local function parseCSVLine(line, sep)
|
||||
@@ -108,7 +108,10 @@ local function payInCoin(amount)
|
||||
repeat
|
||||
io.write("PIN :")
|
||||
local pin = term.read(nil, false, nil, "*")
|
||||
if (not pin) then print(""); return false end
|
||||
if (not pin) then
|
||||
print("");
|
||||
return false
|
||||
end
|
||||
pin = pin:gsub("\n", "") --remove newline cause by term.read
|
||||
cb = libCB.getCB(encryptedCardData, pin)
|
||||
try = try + 1
|
||||
@@ -118,14 +121,14 @@ local function payInCoin(amount)
|
||||
paid = res == 0
|
||||
if (not paid) then
|
||||
print(({
|
||||
[1] = "NO ACCOUNT",
|
||||
[2] = "ERROR ACCOUNT",
|
||||
[3] = "ERROR CB",
|
||||
[4] = "ERROR AMOUNT",
|
||||
[5] = "ERROR_RECEIVING_ACCOUNT",
|
||||
[-1] = "TIMEOUT",
|
||||
[-2] = "WRONG MESSAGE"
|
||||
})[res])
|
||||
[1] = "NO ACCOUNT",
|
||||
[2] = "ERROR ACCOUNT",
|
||||
[3] = "ERROR CB",
|
||||
[4] = "ERROR AMOUNT",
|
||||
[5] = "ERROR_RECEIVING_ACCOUNT",
|
||||
[ -1] = "TIMEOUT",
|
||||
[ -2] = "WRONG MESSAGE"
|
||||
})[res])
|
||||
end
|
||||
else
|
||||
print("NO CB")
|
||||
@@ -156,7 +159,7 @@ local function getFreeSpace(side, item)
|
||||
local freeSpace = 0
|
||||
if (item and item.maxSize) then stackSize = item.maxSize end
|
||||
for chestItem in transposer.getAllStacks(side) do
|
||||
if (not chestItem.name) then
|
||||
if (not chestItem.name) then
|
||||
emptyStack = emptyStack + 1
|
||||
elseif (item and itemEquals(chestItem, item)) then
|
||||
stackSize = chestItem.maxSize
|
||||
@@ -290,7 +293,8 @@ if (not filesystem.isDirectory(OUT_PATH)) then
|
||||
end
|
||||
|
||||
local run = true
|
||||
local event_interrupted = event.listen("interrupted", function() end)
|
||||
local event_interrupted = event.listen("interrupted", function()
|
||||
end)
|
||||
|
||||
--main
|
||||
while (run) do
|
||||
@@ -321,7 +325,9 @@ while (run) do
|
||||
print("Press any key")
|
||||
local _, _, _, _, player = event.pull(10, "key_down")
|
||||
if (player and player == config.adminPlayer) then auth = true end
|
||||
else auth = true end
|
||||
else
|
||||
auth = true
|
||||
end
|
||||
while (auth) do
|
||||
--print the interface
|
||||
term.clear()
|
||||
@@ -340,7 +346,7 @@ while (run) do
|
||||
--read user input
|
||||
io.write("[1-7] >")
|
||||
op = io.read("l")
|
||||
if (op == config.exitString) then --exit
|
||||
if (op == config.exitString) then --exit
|
||||
run = false
|
||||
auth = false
|
||||
elseif (op == nil) then
|
||||
@@ -349,7 +355,7 @@ while (run) do
|
||||
op = tonumber(op)
|
||||
|
||||
--switch
|
||||
if (op == 1) then --Payment settings
|
||||
if (op == 1) then --Payment settings
|
||||
local subMenu = true
|
||||
repeat
|
||||
--interface
|
||||
@@ -367,7 +373,7 @@ while (run) do
|
||||
op = tonumber(op)
|
||||
|
||||
--switch
|
||||
if (op == 1) then --toggle acceptCoin
|
||||
if (op == 1) then --toggle acceptCoin
|
||||
config.acceptCoin = not config.acceptCoin
|
||||
reloadLibs()
|
||||
saveConfig()
|
||||
@@ -386,7 +392,10 @@ while (run) do
|
||||
repeat --ask for pin (3 erros max)
|
||||
io.write("PIN :")
|
||||
local pin = term.read(nil, false, nil, "*")
|
||||
if (not pin) then print(""); return false end
|
||||
if (not pin) then
|
||||
print("");
|
||||
return false
|
||||
end
|
||||
pin = pin:gsub("\n", "") --remove newline cause by term.read
|
||||
cb = libCB.getCB(encryptedCardData, pin)
|
||||
try = try + 1
|
||||
@@ -405,14 +414,18 @@ while (run) do
|
||||
config.cbTimeout = op
|
||||
saveConfig()
|
||||
end
|
||||
elseif (op == 5) then subMenu = false end --exit the submenu
|
||||
elseif (op == 5) then
|
||||
subMenu = false
|
||||
end --exit the submenu
|
||||
until (not subMenu)
|
||||
elseif (op == 2) then --Back chest unloading
|
||||
print("Unloading")
|
||||
while (transposer.transferItem(config.chestBack, config.chestFront) ~= 0) do end
|
||||
while (transposer.transferItem(config.chestBack, config.chestFront) ~= 0) do
|
||||
end
|
||||
elseif (op == 3) then --Back chest loading
|
||||
print("Loading")
|
||||
while (transposer.transferItem(config.chestFront, config.chestBack) ~= 0) do end
|
||||
while (transposer.transferItem(config.chestFront, config.chestBack) ~= 0) do
|
||||
end
|
||||
elseif (config.acceptCoin and op == 4) then --Unload coins
|
||||
libCoin.moveCoin(libCoin.getValue(libCoin.getCoin(config.chestBack)), config.chestBack, config.chestFront)
|
||||
elseif (config.acceptCoin and op == 5) then --Load coins
|
||||
|
Reference in New Issue
Block a user