Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[||
- Wow's users API
- This API need:
- -Modem
- -StringUtilsAPI
- ||]]
- --[[
- 0 = Nothing
- 1 = nil / bad type
- 2 = unknown user
- 3 = nil token
- 4 = Bad Token
- 5 = Bad Password
- 6 = Bad accesslevel
- 7 = ?
- ]]
- if not fs.exists("/StringUtils") then shell.run("pastebin get ad3aUsVw StringUtils") end
- if not os.loadAPI("StringUtils") then print("Need StringUtils") return end
- 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 addCheck(sTable, Username, token)
- local cryptoken = StringUtils.encrypt("true", token)
- sTable["tokenUsername"] = Username
- sTable["tokenCheck"] = cryptoken
- return sTable
- end
- local function send(sTable, token, Username)
- checkopened()
- if sTable == nil then return 0x1 end
- local sTable = addCheck(sTable, token, Username)
- modem.transmit(channel, channel, sTable)
- local x = true
- while x do
- local event, side, sChan, rChan, msg, distance = os.pullEvent("modem_message")
- if sChan == channel then
- x = false
- return msg
- end
- end
- end
- local pingInfo
- local function timeout()
- sleep(3)
- pingInfo = 1
- return false
- end
- local function localPing()
- checkopened()
- local TEMP_TABLE = {type = "ping"}
- pingInfo = send(TEMP_TABLE)
- return true
- end
- function ping()
- local sTime = os.clock()
- parallel.waitForAny(timeout, localPing)
- local fTime = os.clock() - sTime
- return pingInfo, fTime*1000 --Return the time in ms
- end
- function createUser(username, password, biolock, al, uName, uToken)
- if username == nil or password == nil or biolock == nil or type(al) ~= "number" or type(uName) ~= "string" or type(uToken) ~= "string" then
- return 0x1
- else
- local TEMP_TABLE = {type = "database", todo = "createUser", Username = username, Password = password, Biolock = biolock, accesslevel = al}
- local lol = textutils.serialise(TEMP_TABLE)
- return send(TEMP_TABLE, uName, uToken)
- end
- end
- function resetDB(uName, uToken)
- if type(uName) ~= "string" or type(uToken) ~= "string" then return 0x1 end
- local TEMP_TABLE = {type = "database", todo = "reset"}
- return send(TEMP_TABLE, uName,uToken)
- end
- function getInfo(who, uName, uToken)
- if type(who) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then
- return 0x1
- else
- local TEMP_TABLE = {type = "database", todo = "Userinfo", Username = who}
- return send(TEMP_TABLE, uName, uToken)
- end
- end
- local function updateInfo(whatupdate, new, who, uName, uToken)
- if type(whatupdate) ~= "string" or type(new) ~= "string" or type(who) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then return 0x5 end
- local TEMP_TABLE = {type = "database", todo = "update", toupdate = whatupdate, newupdate = new, who = who}
- return send(TEMP_TABLE, uName, uToken)
- end --Not finished
- function findBiolock(bioID, uName, uToken)
- if type(bioID) ~= "string" or type(uName) ~= "string" or type(uToken) ~= "string" then return 0x1 end
- local TEMP_TABLE = {type = "database", todo = "findBL", toFind = bioID}
- return send(TEMP_TABLE, uName, uToken)
- 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