· 4 years ago · Jul 31, 2021, 01:42 AM
1--Title: Dark Client
2Version = 4.26
3--Author: Darkrising (minecraft name djhannz)
4--Platform: ComputerCraft Lua Virtual Machine
5term.clear()
6term.setCursorPos(1,1)
7AutoUpdate = true
8x,y = term.getSize()
9oldEvent = os.pullEvent
10os.pullEvent = os.pullEventRaw
11if fs.exists("dark") == false then -- load darkAPI
12 print("Missing DarkAPI")
13 sleep(2)
14 print("Attempting to download...")
15 status, getGit = pcall(http.get,"https://raw.github.com/darkrising/darkprograms/darkprograms/api/dark.lua")
16 if not status then
17 print("\nFailed to get Dark API")
18 print("Error: ".. getGit)
19 return exit
20 end
21 getGit = getGit.readAll()
22 file = fs.open("dark", "w")
23 file.write(getGit)
24 file.close()
25end
26if not dark then
27 os.loadAPI("dark")
28end
29function rednetSendE(ID, Message)
30 if not config.enCode then
31 Message = dark.repCrypt(Message, 1)
32 else
33 Message = dark.repCrypt(Message, config.enCode)
34 end
35 rednet.send(ID, Message)
36end
37function rednetReceiveE(TimeA)
38 local Se,Me,Di = rednet.receive(TimeA)
39 if Me then
40 if not config.enCode then
41 Me = dark.repdeCrypt(Me, 1)
42 else
43 Me = dark.repdeCrypt(Me, config.enCode)
44 end
45 return Se,Me,Di
46 end
47end
48function header(text, lText, rText)
49 dark.printL("-", 1, nil, "gray", "gray")
50 dark.printA("|", x, 2, nil, "gray", "gray")
51 dark.printA("|", 1, 2, nil, "gray", "gray")
52 dark.printC(string.rep(" ", x), 2, nil, "white", "gray")
53 if lText then dark.printA(lText, 1, 2, nil, "white", "blue") end
54 if rText then dark.printA(rText, x - #rText, 2, nil, "white", "blue") end
55 dark.printC(text, 2, nil, "white", "gray")
56 dark.printL("-", 3, 5, "gray", "gray")
57end
58function footer()
59 dark.printL("-", y, nil, "gray", "gray")
60 dark.printA("Veritas Systems", x-14, y, nil, "white", "gray")
61end
62function keycard_mainProgram()
63 while true do
64 event, eventinfo, extrainfo = os.pullEventRaw("disk")
65 if event == "disk" then
66 com2 = {}
67 com2.computerid = os.getComputerID()
68 com2.area = tonumber(config.securityLevel)
69
70 if disk.hasData(eventinfo) == true then
71 com2.diskQuery = disk.getID(eventinfo)
72 SendString = textutils.serialize(com2)
73 rednetSendE(config.serverID, SendString)
74
75 S, M = rednetReceiveE(2)
76
77 if M == "#granted" then
78 disk.eject(eventinfo)
79 rs.setOutput(config.doorside, true)
80 sleep(config.pulseTime)
81 rs.setOutput(config.doorside, false)
82 end
83 disk.eject(eventinfo)
84 else
85 disk.eject(eventinfo)
86 end
87 end
88 end
89end
90function userandpassword_mainProgram()
91 while true do
92 com = {}
93 com.computerid = os.getComputerID()
94 com.area = tonumber(config.securityLevel)
95
96 term.clear() term.setCursorPos(1,1)
97 footer()
98 header(config.tLabel)
99 print("") print("")
100
101 write("> Username: ")
102 status, User = pcall(read)
103 com.userQuery = string.lower(User)
104
105 write("> Password: ")
106 status, password = pcall(read, "*")
107 com.passQuery = password
108
109 SendString = textutils.serialize(com)
110
111 if ((User ~= nil) and (password ~= nil)) then
112 rednetSendE(config.serverID, SendString)
113 ID, MES = rednetReceiveE(2)
114 if MES == nil then
115 print("\nWrong or no response from server.")
116 sleep(2)
117 else
118 if MES == "#granted" then
119 dark.printC("Correct", 5, 5)
120 rs.setOutput(config.doorside, true)
121 sleep(config.pulseTime)
122 rs.setOutput(config.doorside, false)
123 end
124 end
125 end
126 end
127end
128
129S = dark.findPeripheral("modem")
130if S == false then
131 print("Please attach Modem")
132 return exit
133else
134 rednet.open(S)
135end
136function stealthUpdate()
137 if AutoUpdate == true then
138 if ((dark.gitUpdate("client", shell.getRunningProgram(), Version) == true) or (dark.gitUpdate("dark", "dark", dark.DARKversion) == true)) then
139 os.reboot()
140 end
141 end
142end
143if fs.exists(".DarkC_conf") == false then
144 config = {}
145 SideList = rs.getSides()
146
147 term.clear()
148 term.setCursorPos(1,1)
149 header("Dark Client Setup")
150
151 print("Computer's id is ".. os.getComputerID())
152 while true do
153 write("\nPlease type the server's computer id: ")
154 config.serverID = tonumber(io.read())
155 print("\nPinging server...")
156 sleep(1)
157 com = {}
158 com.ping = true
159 rednetSendE(config.serverID, textutils.serialize(com))
160 s,m,d = rednetReceiveE(2)
161 if m and m == "#pong" then
162 print("Server responded, test complete.")
163 break
164 else
165 print("\nNo response, this could be down to a number of things...")
166 print("\nTry again?")
167 write("y / n: ")
168 ans = read()
169 end
170 if ans == "n" then
171 break
172 end
173 end
174
175 repeat
176 write("\nTerminal Security Level: ")
177 config.securityLevel = io.read()
178 until tonumber(config.securityLevel)
179 config.securityLevel = tonumber(config.securityLevel)
180
181 repeat
182 write("\nRedstone output side: ")
183 doorside = io.read()
184 until dark.db.search(doorside, SideList) > 0
185 config.doorside = doorside
186
187 write("\nRedstone pulse time (in seconds): ")
188 pulseTime = tonumber(io.read())
189 config.pulseTime = pulseTime
190
191 write("\nTerminal label: ")
192 config.tLabel = io.read()
193
194 print("\nWhat type of terminal is this?")
195 print("options: 'keycard', 'password' or 'both'")
196 repeat
197 write(": ")
198 tType = read()
199 until ((tType == "keycard") or (tType == "password") or (tType == "both"))
200 config.tType = tType
201
202 print("\nShall I try and add myself automatically to the server?")
203 print("options: y / n")
204 repeat
205 write(": ")
206 encKey = read()
207 until (encKey == "y") or (encKey == "n")
208 if encKey == "n" then
209 repeat
210 write("Encryption key: ")
211 encKey = read()
212 until tonumber(encKey)
213 else
214 while true do
215 print("\nWe will now try and add this client to the server using an admin account.")
216 print("Please type your server Admin username and password.")
217 com = {}
218 write("\nUsername: ")
219 com.userQuery = read()
220 write("Password: ")
221 com.passQuery = read("*")
222 com.area = tonumber(config.securityLevel)
223 com.computerid = os.getComputerID()
224 com.super = true
225 com.addMe = true
226 message = textutils.serialize(com)
227 rednetSendE(config.serverID, message)
228 s,m,d = rednetReceiveE(2)
229 if s then
230 print("Success!")
231 config.enCode = tonumber(m)
232 break
233 else
234 print("Failed, Press enter to try again.")
235 read()
236 end
237 end
238 end
239
240 dark.db.save(".DarkC_conf", config)
241
242 print("\nsetup complete!")
243 sleep(1.5)
244end
245
246config = dark.db.load(".DarkC_conf")
247
248if config.tType == "keycard" then
249 parallel.waitForAll(keycard_mainProgram, stealthUpdate)
250elseif config.tType == "password" then
251 parallel.waitForAll(userandpassword_mainProgram, stealthUpdate)
252elseif config.tType == "both" then
253 parallel.waitForAll(userandpassword_mainProgram, keycard_mainProgram, stealthUpdate)
254end
255os.pullEvent = oldEvent