Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. --[[||
  2. Wow's users API
  3. This API need:
  4. -Modem
  5. -StringUtilsAPI
  6. ||]]
  7.  
  8. --[[
  9. Error codes:
  10. 0x0: no error
  11. 0x1: nil arg
  12. 0x2: not connected
  13. 0x3: Rednet not opened
  14. 0x4:
  15. 0x5: unknown function
  16. ]]
  17. if not os.loadAPI("StringUtils") then print("Need StringUtils") return end
  18. local channel = 644
  19. local modem = peripheral.find("modem")
  20.  
  21. local function checkopened()
  22. if not modem.isOpen(channel) then modem.open(channel) end
  23. return true
  24. end
  25.  
  26. local function addCheck(sTable, Username, token)
  27. local cryptoken = StringUtils.encrypt("true", token)
  28. sTable["tokenUsername"] = Username
  29. sTable["tokenCheck"] = cryptoken
  30. return sTable
  31. end
  32.  
  33. local function send(sTable, token, Username)
  34. checkopened()
  35. if sTable == nil then return 0x1 end
  36. local sTable = addCheck(sTable, token, Username)
  37. modem.transmit(channel, channel, sTable)
  38. local x = true
  39. while x do
  40. local event, side, sChan, rChan, msg, distance = os.pullEvent("modem_message")
  41. if sChan == channel then
  42. x = false
  43. return msg
  44. end
  45. end
  46. end
  47.  
  48.  
  49. function createUser(username, password, biolock, al, uName, uToken)
  50. if username == nil or password == nil or biolock == nil or type(al) ~= "number" or type(uName) ~= "string" or type(uToken) ~= "string" then
  51. return 0x1
  52. else
  53. local TEMP_TABLE = {type = "database", todo = "createUser", Username = username, Password = password, Biolock = biolock, accesslevel = al}
  54. local lol = textutils.serialise(TEMP_TABLE)
  55. return send(TEMP_TABLE, uName, uToken)
  56. end
  57. end
  58.  
  59. function resetDB(uName, uToken)
  60. if type(uName) ~= "string" or type(uToken) ~= "string" then return 0x1 end
  61. local TEMP_TABLE = {type = "database", todo = "reset"}
  62. return send(TEMP_TABLE, uName,uToken)
  63. end
  64.  
  65. function getInfo(who, uName, uToken)
  66. if type(who) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then
  67. return 0x1
  68. else
  69. local TEMP_TABLE = {type = "database", todo = "Userinfo", Username = who}
  70. return send(TEMP_TABLE, uName, uToken)
  71. end
  72. end
  73.  
  74. function updateInfo(whatupdate, new, who, uName, uToken)
  75. if type(whatupdate) ~= "string" or type(new) ~= "string" or type(who) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then return 0x5 end
  76. local TEMP_TABLE = {type = "database", todo = "update", toupdate = whatupdate, newupdate = new, who = who}
  77. return send(TEMP_TABLE, uName, uToken)
  78. end
  79.  
  80. function findBiolock(bioID, uName, uToken)
  81. if type(bioID) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then return 0x1 end
  82. local TEMP_TABLE = {type = "database", todo = "findBL", toFind = bioID}
  83. return send(TEMP_TABLE, uName, uToken)
  84. end
  85.  
  86. function newToken(user, pass)
  87. if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
  88. local rMath = tostring(math.random(1,0xBEEF))
  89. local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
  90. local TEMP_TABLE = {type = "token", todo = "createToken", math = rMath, Username = user, enc = encPass}
  91. return send(TEMP_TABLE)
  92. end
  93.  
  94. function getToken(user, pass)
  95. if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
  96. local rMath = tostring(math.random(1,0xBEEF))
  97. local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
  98. local TEMP_TABLE = {type = "token", todo = "getToken", math = rMath, Username = user, enc = encPass}
  99. return send(TEMP_TABLE)
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement