Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "1.15" --change this to allow for an update (3 chars only)
- local filename = "MCAuth" --change this to the name of the file holding this program
- local paste = "nGjQhbbZ" --change this to the pastebin entry code
- local function update()
- local url = "http://pastebin.com/raw/"..paste
- local temp = http.get(url)
- local ver = string.sub(temp.readLine(), 18, 21)
- if ver ~= version then
- fs.delete(filename)
- shell.run("pastebin get "..paste.." "..filename)
- shell.run(filename)
- return true
- end
- return false
- end
- --start
- if update() then
- error()
- end
- shell.run("clear")
- local function insSend()
- end
- local function split(str, pat)
- local t = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- rednet.open("top")
- --check for directory
- if not fs.exists("USERS") then
- fs.makeDir("USERS")
- end
- --host protocol for id
- rednet.host("MCAuth","AuthenticationServer")
- while true do
- local event, p1, p2, p3 = os.pullEvent()
- if event == "rednet_message" and type(p2) == "string" then
- local id = p1
- local msgData = split(p2, ":")
- --cut out if not right length
- if msgData[4] ~= nil or msgData[5] == nil then
- if msgData[1] == "$REGISTER$" then
- --debug
- print(textutils.serialize(msgData))
- if not fs.exists("USERS/"..msgData[2]) then
- local file = fs.open("USERS/"..msgData[2], "w")
- --password
- file.writeLine(msgData[3])
- --age
- file.writeLine(msgData[4])
- file.close()
- rednet.send(id, "$REGISTER$:COMPLETE")
- else
- rednet.send(id, "$REGISTER$:EXISTS")
- end
- else
- rednet.send(id, "$REGISTER$:ERROR") --make enums for message codes?
- end
- else
- rednet.send(id, "$REGISTER$:LENGTH")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement