SHARE
TWEET

Untitled

a guest Oct 4th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[||
  2.   Wow's database 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: Bad ID
  15.   0x5: unknown function
  16. ]]
  17. os.loadAPI("StringUtils")
  18. local id = 78
  19. local channel = 644
  20. local modem = peripheral.find("modem")
  21.  
  22. local function checkopened()
  23.     if not modem.isOpen(channel) then modem.open(channel) end
  24.     return true
  25. end
  26.  
  27.  
  28. local function send(sTable)
  29.   checkopened()
  30.   if sTable == nil then return 0x1 end
  31.   modem.send(id, sTable)
  32.   local x = true
  33.   while x do
  34.     local side, sChan, rChan, msg, distance = os.pullEvent("modem_message")
  35.     if sChan == channel then
  36.         x = false
  37.         return msg
  38.     end
  39.   end
  40. end
  41.  
  42. function database(action, arg1, arg2, arg3, arg4, arg5)
  43.   if action == "createUser" then
  44.     if arg1 == nil or arg2 == nil or arg3 == nil or arg4 == nil or type(arg4) ~= "number" or type(arg1) ~= "string" or type(arg2) ~= "string" or type(arg3) ~= "string" then
  45.       return 0x1
  46.     else
  47.       local TEMP_TABLE = {type = "database", todo = action, Username = arg1, Password = arg2, Biolock = arg3, accesslevel = arg4}
  48.       local lol = textutils.serialise(TEMP_TABLE)
  49.       return(send(TEMP_TABLE))
  50.     end
  51.   elseif action == "resetDB" then
  52.     local TEMP_TABLE = {type = "database", todo = "reset"}
  53.     return(send(TEMP_TABLE))
  54.   elseif action == "getinfo" then
  55.     if type(arg1) ~= "string" then
  56.       return 0x1
  57.     else
  58.       local TEMP_TABLE = {type = "database", todo = "Userinfo", Username = arg1}
  59.       return(send(TEMP_TABLE))
  60.     end
  61.   else
  62.     return 0x5
  63.   end
  64. end
  65.  
  66. function newToken(user, pass)
  67.   if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
  68.   local rMath = tostring(math.random(1,0xBEEF))
  69.   local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
  70.   local TEMP_TABLE = {type = "token", todo = "createToken", math = rMath, Username = user, enc = encPass}
  71.   return send(TEMP_TABLE)
  72. end
  73.  
  74. function getToken(user, pass)
  75.   if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
  76.   local rMath = tostring(math.random(1,0xBEEF))
  77.   local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
  78.   local TEMP_TABLE = {type = "token", todo = "getToken", math = rMath, Username = user, enc = encPass}
  79.   return send(TEMP_TABLE)
  80. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top