Redxone

[CC - Logsys] - Client

May 17th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.60 KB | None | 0 0
  1. if(not fs.exists("sha256"))then
  2.     print("sha256 is required to run this program.")
  3.     print("download? [Y][N]")
  4.     local _, key = os.pullEvent("key")
  5.     if(key == keys.y)then
  6.         --]] Attempt to download SHA256...
  7.         if(http.checkURL("http://pastebin.com/raw/gsFrNjbt") and http)then
  8.             local file = http.get("http://pastebin.com/raw/gsFrNjbt")
  9.             local contents = file.readAll()
  10.             file.close()
  11.             local file = fs.open("sha256","w")
  12.             file.write(contents)
  13.             file.close()
  14.             print("Sha256 downloaded successfully!")
  15.             print("You may have to edit sha256 and remove the 'local' from the function sha256()")
  16.             os.loadAPI("sha256")
  17.         else
  18.             error("Failed to retrieve sha256 (Invaild URL) or HTTP not enabled. ")
  19.         end
  20.     else
  21.         error("Program needs sha256 to run. ")
  22.     end
  23. else
  24.     os.loadAPI("sha256")
  25. end
  26.  
  27. function getModemSide()
  28.     local listOfSides = rs.getSides()
  29.    
  30.     for i = 1, #listOfSides do
  31.         if(peripheral.isPresent(listOfSides[i]) and peripheral.getType(listOfSides[i]) == "modem")then
  32.             return listOfSides[i]
  33.         end
  34.     end
  35.  
  36.     error("No modem found, please attach a modem. ")
  37. end
  38.  
  39. function hash(txt)
  40.     return sha256.sha256(txt)
  41. end
  42.  
  43. local function sendLoginRequest(serverprotocol,request,username,password)
  44.     local hashcol = sha256.sha256(serverprotocol)
  45.     rednet.broadcast("nil",hashcol)
  46.     local serverid, mes, _ = rednet.receive(hashcol,2)
  47.     if(mes == nil)then
  48.         return "no-connection"
  49.     end
  50.     if(mes:sub(1,8) == "[LOGSYS]")then
  51.         rednet.send(serverid,request,hashcol)
  52.         rednet.send(serverid,{username,sha256.sha256(password)},hashcol)
  53.         local _, mes, _ = rednet.receive(hashcol,2)
  54.         if(mes=="")then print("WARNING: server might have crashed!") end
  55.         return mes
  56.     end
  57. end
  58.  
  59.  
  60. function checkLogin(serverprotocol,username,password)
  61.     return sendLoginRequest(serverprotocol,"checkLogin",username,password)
  62. end
  63.  
  64. function deleteLogin(serverprotocol,username,password)
  65.     return sendLoginRequest(serverprotocol,"deleteLogin",username,password)
  66. end
  67.  
  68. function createLogin(serverprotocol,username,password)
  69.     return sendLoginRequest(serverprotocol,"createLogin",username,password)
  70. end
  71.  
  72. function customRequest(serverprotocol,crequest,datatable)
  73.     local hashcol = sha256.sha256(serverprotocol)
  74.     rednet.broadcast("nil",hashcol)
  75.     local serverid, mes, _ = rednet.receive(hashcol,2)
  76.     if(mes == nil)then
  77.         print("No connection to server!")
  78.         return false
  79.     end
  80.     if(mes:sub(1,8) == "[LOGSYS]")then
  81.         rednet.send(serverid,crequest,hashcol)
  82.         rednet.send(serverid,datatable,hashcol)
  83.         local _, mes, _ = rednet.receive(hashcol,2)
  84.         if(mes=="")then print("WARNING: server might have crashed!") end
  85.         return mes
  86.     end
  87. end
Add Comment
Please, Sign In to add comment