Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ntc = {
- _baseURL = "http://imgood.zapto.org/ntc/",
- _escape = function(s)
- return tostring(s):gsub("[&=%?%%]", function(c) return "%"..string.byte(c) end)
- end,
- _parseArgs = function(args)
- local s = ''
- for i,v in pairs(args) do
- s = s .. "&" .. ntc._escape(i) .. "=" .. ntc._escape(v)
- end
- return "?"..s:sub(2)
- end,
- _decodeJSON = function(str)
- s = str:gsub("[%[%]:]", {['[']='{', [']']='}', [':']='='}):gsub('"([^"]+)"%s?=', '["%1"]=')--:gsub('([%d]+)%s?=', '[%1]=')
- local func, e = _G[ntc.isCraftOS and "loadstring" or "load"]( "return "..s )
- if not func then
- return false, "Error decoding"
- else
- return func()
- end
- end
- }
- if os.version and os.version():find("^CraftOS") then
- ntc.isCraftOS = true
- ntc._getRaw = function(page, args)
- local url = ntc._baseURL .. page .. ntc._parseArgs(args)
- local data = http.get(url).readAll();
- local status, response = data:match("([01])%s(.+)")
- if status and response then
- return status=="1", response
- else
- return false, "Invalid Response"
- end
- end
- else
- ntc.isCraftOS = false
- ntc._getRaw = function(page, args)
- local url = ntc._baseURL .. page .. ntc._parseArgs(args)
- local data = ""
- for s in http.request(url) do data = data .. s end
- local status, response = data:match("([01])%s(.+)")
- if status and response then
- return status=="1", response
- else
- return false, "Invalid Response"
- end
- end
- end
- ntc.login = function(username, password)
- ntc._username = username
- ntc._password = password
- end
- ntc.register = function(username, password)
- local ok, resp = ntc._getRaw("register.py", {username=username, password=password})
- if ok then
- ntc._username = username
- ntc._password = password
- end
- return ok, resp
- end
- ntc.transfer = function(to, amount)
- return ntc._getRaw("transfer.py", {from=ntc._username, to=to, password=ntc._password, amount=amount})
- end
- ntc.balance = function()
- local ok, resp = ntc._getRaw("balance.py", {username=ntc._username, password=ntc._password})
- if ok then return tonumber(resp) else return false, resp end
- end
- ntc.getlog = function()
- local ok, resp = ntc._getRaw("getlog.py", {username=ntc._username, password=ntc._password})
- if ok then return ntc._decodeJSON(resp) else return false, resp end
- end
- ntc.genkey = function(amount)
- local ok, resp = ntc._getRaw("genkey.py", {username=ntc._username, password=ntc._password, amount=amount})
- if ok then return resp else return false, resp end
- end
- ntc.redeemkey = function(key)
- return ntc._getRaw("redeemkey.py", {username=ntc._username, password=ntc._password, key=key})
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement