Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[||
- Wow's database API
- This API need:
- -Modem
- -StringUtilsAPI
- ||]]
- --[[
- Error codes:
- 0x0: no error
- 0x1: nil arg
- 0x2: not connected
- 0x3: Rednet not opened
- 0x4: Bad ID
- 0x5: unknown function
- ]]
- os.loadAPI("StringUtils")
- local id = 78
- local channel = 644
- local modem = peripheral.find("modem")
- local function checkopened()
- if not modem.isOpen(channel) then modem.open(channel) end
- return true
- end
- local function send(sTable)
- checkopened()
- if sTable == nil then return 0x1 end
- modem.send(id, sTable)
- local x = true
- while x do
- local side, sChan, rChan, msg, distance = os.pullEvent("modem_message")
- if sChan == channel then
- x = false
- return msg
- end
- end
- end
- function database(action, arg1, arg2, arg3, arg4, arg5)
- if action == "createUser" then
- 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
- return 0x1
- else
- local TEMP_TABLE = {type = "database", todo = action, Username = arg1, Password = arg2, Biolock = arg3, accesslevel = arg4}
- local lol = textutils.serialise(TEMP_TABLE)
- return(send(TEMP_TABLE))
- end
- elseif action == "resetDB" then
- local TEMP_TABLE = {type = "database", todo = "reset"}
- return(send(TEMP_TABLE))
- elseif action == "getinfo" then
- if type(arg1) ~= "string" then
- return 0x1
- else
- local TEMP_TABLE = {type = "database", todo = "Userinfo", Username = arg1}
- return(send(TEMP_TABLE))
- end
- else
- return 0x5
- end
- end
- function newToken(user, pass)
- if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
- local rMath = tostring(math.random(1,0xBEEF))
- local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
- local TEMP_TABLE = {type = "token", todo = "createToken", math = rMath, Username = user, enc = encPass}
- return send(TEMP_TABLE)
- end
- function getToken(user, pass)
- if type(user) ~= "string" or type(pass) ~= "string" then return 0x1 end
- local rMath = tostring(math.random(1,0xBEEF))
- local encPass = StringUtils.encrypt(tostring(rMath),StringUtils.SHA1(pass))
- local TEMP_TABLE = {type = "token", todo = "getToken", math = rMath, Username = user, enc = encPass}
- return send(TEMP_TABLE)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement