This repository has been archived by the owner on Mar 25, 2019. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
startup.lua
79 lines (68 loc) · 1.94 KB
/
startup.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
os.loadAPI("/lib/strings.lua")
os.loadAPI("/lib/tables.lua")
local modem = false
if fs.exists("/.modem") then
local file = fs.open("/.modem", "r")
modem = file.readLine()
file.close()
if (peripheral.getType(modem) ~= "modem" or not peripheral.call(modem, "isWireless"))
and (peripheral.getType(modem) ~= "peripheralContainer" or not table.contains(peripheral.call(modem, "getContainedPeripherals"), "modem")) then
term.setTextColor(colors.red)
print("[Quacknet] Side set in /.modem does not contain a wireless modem! Removing file...")
os.sleep(2)
fs.delete("/.modem")
modem = false
end
end
if not modem then
for _, side in ipairs(peripheral.getNames()) do
if (peripheral.getType(side) == "peripheralContainer"
and table.contains(peripheral.call(side, "getContainedPeripherals"), "modem"))
or
(peripheral.getType(side) == "modem"
and peripheral.call(side, "isWireless")) then
modem = side
local file = fs.open("/.modem", "w")
file.write(modem)
file.close()
end
end
end
if not modem then
term.setTextColor(colors.red)
print("[Quacknet] No modem detected!")
return
end
local function autorun(directory)
if directory then
directory = "/autorun/" .. directory
else
directory = "/autorun"
end
if fs.exists(directory) and fs.isDir(directory) then
local files = fs.list(directory)
table.sort(files)
for n, file in ipairs(files) do
if file:sub(1, 1) ~= "." and not fs.isDir(directory .. "/" .. file) then
shell.run(directory .. "/" .. file)
end
end
end
end
_G["modemSide"] = modem
autorun("preinit")
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.orange)
print("Loading libquacknet...")
os.loadAPI("/lib/quacknet.lua")
autorun("postinit")
shell.setPath(shell.path() .. ":/programs")
quackkeys.load()
quackdns.load()
quacknet.open(modem)
term.clear()
term.setCursorPos(1, 1)
term.setTextColor(colors.yellow)
print(os.version() .. " with " .. quacknet.version())
autorun()