Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(not fs.exists("sha256"))then
- print("sha256 is required to run this program.")
- print("download? [Y][N]")
- local _, key = os.pullEvent("key")
- if(key == keys.y)then
- --]] Attempt to download SHA256...
- if(http.checkURL("http://pastebin.com/raw/gsFrNjbt") and http)then
- local file = http.get("http://pastebin.com/raw/gsFrNjbt")
- local contents = file.readAll()
- file.close()
- local file = fs.open("sha256","w")
- file.write(contents)
- file.close()
- print("Sha256 downloaded successfully!")
- print("You may have to edit sha256 and remove the 'local' from the function sha256()")
- os.loadAPI("sha256")
- else
- error("Failed to retrieve sha256 (Invaild URL) or HTTP not enabled. ")
- end
- else
- error("Program needs sha256 to run. ")
- end
- else
- os.loadAPI("sha256")
- end
- function getModemSide()
- local listOfSides = rs.getSides()
- for i = 1, #listOfSides do
- if(peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem")then
- return listOfSides[i]
- end
- end
- error("No modem found, please attach a modem. ")
- end
- function hash(txt)
- return sha256.sha256(txt)
- end
- local function sendLoginRequest(serverprotocol,request,username,password)
- local hashcol = sha256.sha256(serverprotocol)
- rednet.broadcast("nil",hashcol)
- local serverid, mes, _ = rednet.receive(hashcol,2)
- if(mes == nil)then
- return "no-connection"
- end
- if(mes:sub(1,8) == "[LOGSYS]")then
- rednet.send(serverid,request,hashcol)
- rednet.send(serverid,{username,sha256.sha256(password)},hashcol)
- local _, mes, _ = rednet.receive(hashcol,2)
- if(mes=="")then print("WARNING: server might have crashed!") end
- return mes
- end
- end
- function checkLogin(serverprotocol,username,password)
- return sendLoginRequest(serverprotocol,"checkLogin",username,password)
- end
- function deleteLogin(serverprotocol,username,password)
- return sendLoginRequest(serverprotocol,"deleteLogin",username,password)
- end
- function createLogin(serverprotocol,username,password)
- return sendLoginRequest(serverprotocol,"createLogin",username,password)
- end
- function customRequest(serverprotocol,crequest,datatable)
- local hashcol = sha256.sha256(serverprotocol)
- rednet.broadcast("nil",hashcol)
- local serverid, mes, _ = rednet.receive(hashcol,2)
- if(mes == nil)then
- print("No connection to server!")
- return false
- end
- if(mes:sub(1,8) == "[LOGSYS]")then
- rednet.send(serverid,crequest,hashcol)
- rednet.send(serverid,datatable,hashcol)
- local _, mes, _ = rednet.receive(hashcol,2)
- if(mes=="")then print("WARNING: server might have crashed!") end
- return mes
- end
- end
Add Comment
Please, Sign In to add comment