Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 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, token, Username)
  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.  
  58. function resetDB(uName, uToken)
  59. if type(uName) ~= "string" or type(uToken) ~= "string" then return 0x1 end
  60. local TEMP_TABLE = {type = "database", todo = "reset"}
  61. return send(TEMP_TABLE, uName,uToken)
  62. end
  63.  
  64. function getInfo(who, uName, uToken)
  65. if type(who) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then
  66. return 0x1
  67. else
  68. local TEMP_TABLE = {type = "database", todo = "Userinfo", Username = who}
  69. return send(TEMP_TABLE, uName, uToken)
  70. end
  71. end
  72.  
  73. function updateInfo(whatupdate, new, who, uName, uToken)
  74. if type(whatupdate) ~= "string" or type(new) ~= "string" or type(who) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then return 0x5 end
  75. local TEMP_TABLE = {type = "database", todo = "update", toupdate = whatupdate, newupdate = new, who = who}
  76. return send(TEMP_TABLE, uName, uToken)
  77. end
  78.  
  79. function newToken(user, pass)
  80. if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
  81. local rMath = tostring(math.random(1,0xBEEF))
  82. local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
  83. local TEMP_TABLE = {type = "token", todo = "createToken", math = rMath, Username = user, enc = encPass}
  84. return send(TEMP_TABLE)
  85. end
  86.  
  87. function getToken(user, pass)
  88. if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
  89. local rMath = tostring(math.random(1,0xBEEF))
  90. local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
  91. local TEMP_TABLE = {type = "token", todo = "getToken", math = rMath, Username = user, enc = encPass}
  92. return send(TEMP_TABLE)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement