Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Originally by team-econ
- os.loadAPI("APIs/config")
- local function startScreen()
- redraw()
- end
- local function newmenu(tList,x,y,height)
- local function maxlen(t)
- local len=0
- for i=1,#t do
- local curlen=string.len(type(t[i])=='table' and t[i][1] or t[i])
- if curlen>len then len=curlen end
- end
- return len
- end
- local max=maxlen(tList)
- x=x or 1
- y=y or 1
- y=y-1
- height=height or #tList
- height=height+1
- local selected=1
- local scrolled=0
- local function render()
- for num,item in ipairs(tList) do
- if num>scrolled and num<scrolled+height then
- term.setCursorPos(x,y+num-scrolled)
- local current=(type(item)=='table' and item[1] or item)
- write((num==selected and '[' or ' ')..current..(num==selected and ']' or ' ')..(max-#current>0 and string.rep(' ',max-#current) or ''))
- end
- end
- end
- while true do
- render()
- local evts={os.pullEvent('key')}
- if evts[1]=="key" and evts[2]==200 and selected>1 then
- if selected-1<=scrolled then scrolled=scrolled-1 end
- selected=selected-1
- elseif evts[1]=="key" and evts[2]==208 and selected<#tList then
- selected=selected+1
- if selected>=height+scrolled then scrolled=scrolled+1 end
- elseif evts[1]=="key" and evts[2]==28 or evts[2]==156 then
- return (type(tList[selected])=='table' and tList[selected][2](tList[selected][1]) or tList[selected])
- end
- end
- end
- local function limitRead(limX, rChar)
- term.setCursorBlink(true)
- local origX, origY = term.getCursorPos()
- local returnString = ""
- while true do
- local xPos, yPos = term.getCursorPos()
- local event, p1, p2 = os.pullEvent()
- if event == "char" then
- returnString = returnString..p1
- if not rChar then
- if not limX then
- write(p1)
- else
- if string.len(returnString) >= limX then
- term.setCursorPos(origX, origY)
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- elseif string.len(returnString) < limX then
- write(p1)
- end
- end
- else
- if not limX then
- write(rChar)
- else
- if string.len(returnString) >= limX then
- term.setCursorPos(origX, origY)
- write(string.rep(rChar, limX))
- elseif string.len(returnString) < limX then
- write(rChar)
- end
- end
- end
- elseif event == "key" and p1 == 14 then --backspace
- returnString = string.sub(returnString, 1, (string.len(returnString))-1)
- term.setCursorPos(xPos-1,yPos)
- write(" ")
- term.setCursorPos(origX, origY)
- if string.len(returnString) >= limX then
- if not rChar then
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- else
- write(string.rep(rChar,limX))
- end
- else
- if not rChar then
- write(returnString)
- else
- write(string.rep(rChar, string.len(returnString)))
- end
- end
- elseif event == "key" and p1 == 28 then --enter
- break
- end
- end
- term.setCursorBlink(false)
- return returnString
- end
- local function clearscreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- clearscreen()
- local function accCreate(auserid,adpass,aign)
- rednet.send(dbpc,"acccreate"..auserid..aign)
- local bsenderId, bmessage, bdistance = rednet.receive()
- if bsenderId ~= dbpc or bmessage == "existingid" then
- cardreader.setInsertCardLight(false)
- redraw()
- print("OMG! We'd never thought you'd see this error!")
- print("You've got a 504 error!")
- sleep(0.5)
- print()
- term.setTextColour(colours.red)
- print("*Please contact the owner of this shop and provide them with the error number")
- print()
- sleep(2)
- print("*As a temporary solution, get another blank mag-stripe card and register again")
- term.setTextColour(colours.yellow)
- print("You will receive compensation")
- term.setTextColour(colours.white)
- print()
- print("Press E to continue")
- while true do
- local ev,charpress = os.pullEvent("char")
- if charpress == "e" then
- break
- end
- end
- print()
- write("Rebooting")
- for i=1,3 do
- sleep(0.5)
- write(". ")
- end
- sleep(0.8)
- os.reboot()
- elseif bsenderId == dbpc and bmessage == "freeid" then
- rednet.send(dbpc,adpass)
- while true do
- local csenderId1, cmessage1, cdistance1 = rednet.receive()
- if csenderId1 == dbpc and cmessage1 == "success" then
- return true
- end
- end
- end
- end
- local function pingdb()
- rednet.send(dbpc,"ping")
- while true do
- os.startTimer(3)
- local ev,aId,aMsg,aDist = os.pullEvent()
- if ev == "timer" then
- return false
- elseif ev == "rednet_message" then
- if aId == dbpc then
- if aMsg == "pongdb" then
- return true
- end
- end
- end
- end
- end
- local function loadConfig()
- if fs.exists("config") then
- config.load(nil,"config")
- if config.readVal("DatabaseID") == nil then
- print("Account Registry")
- print()
- write("Please set the Database PC ID: ")
- local dbpcs = read()
- config.writeVal("DatabaseID",dbpcs)
- config.save()
- clearscreen()
- print("Account Registry")
- print()
- print("Database PC ID set to "..dbpcs)
- print("You can change the settings in the config file")
- print("Rebooting...")
- sleep(3)
- os.reboot()
- else
- dbpc = tonumber(config.readVal("DatabaseID"))
- end
- else
- config.load(nil,"config")
- print("Account Registry")
- print()
- write("Please set the Database PC ID: ")
- local dbpcs = read()
- config.writeVal("DatabaseID",dbpcs)
- config.save()
- clearscreen()
- print("Account Registry")
- print()
- print("Database PC ID set to "..dbpcs)
- print("You can change the settings in the config file")
- print("Rebooting...")
- sleep(3)
- os.reboot()
- end
- end
- loadConfig()
- local function getModemSide()
- for n,sSidem in pairs(rs.getSides()) do
- if peripheral.getType(sSidem) == "modem" then
- sidem = sSidem
- break
- end
- end
- if sidem ~= nil then
- return sidem
- else
- print("Please attach a modem!")
- sleep(2)
- os.shutdown()
- end
- end
- local function getReaderSide()
- for n,sSider in pairs(rs.getSides()) do
- if peripheral.getType(sSider) == "mag card reader" then
- sider = sSider
- break
- end
- end
- if sider ~= nil then
- return sider
- else
- print("Please attach a mag card reader!")
- sleep(2)
- os.shutdown()
- end
- end
- local function redraw()
- clearscreen()
- print("Account Registry")
- print()
- end
- local modemSide = getModemSide()
- rednet.open(modemSide)
- if pingdb() == false then
- clearscreen()
- print("Database down... please check back later!")
- while true do
- sleep(5)
- if pingdb() == true then
- break
- end
- end
- end
- local function getStuff()
- redraw()
- modemSide = getModemSide()
- readerSide = getReaderSide()
- end
- local function createAccount()
- if peripheral.isPresent(readerSide) == true and peripheral.getType(readerSide) == "mag card reader" then
- cardreader = peripheral.wrap(readerSide)
- redraw()
- print("You must have a blank mag-stripe card!")
- write("IGN: ")
- ign = limitRead(16)
- print()
- write("Desired password (max 16 char.): ")
- print()
- dpass = limitRead(16,"*")
- print()
- print( "*Try restarting (CTRL+R) if it takes too long to register" )
- print()
- print( "*If the problem persists, please contact your local tech support (gknova61)" )
- while true do
- math.randomseed( os.clock()*os.time()+os.computerID() )
- local rand = tostring( math.random(1001,9999) )
- math.randomseed( os.clock()*os.time()+os.computerID()+math.random(0,1000) )
- local rand2 = tostring( math.random(1001,9999) )
- local userid = rand..rand2
- while true do
- redraw()
- print("Account registered!")
- print("Your unique account ID is "..userid)
- print("Press F2 to take a screenshot of it")
- print("Please keep it in a safe place")
- print()
- print("Please swipe a blank mag-stripe card twice")
- cardreader.setInsertCardLight(true)
- while true do
- local ev, data = os.pullEvent("mag_swipe")
- if data == "" then
- cardreader.beginWrite(userid,ign.."\'s card")
- while true do
- local ev, arg1, arg2, arg3 = os.pullEvent()
- if ev == "mag_write_done" then
- redraw()
- print("Card successfully registered!")
- cardreader.setInsertCardLight(false)
- if accCreate(userid,dpass,ign) == true then
- print("Sent")
- end
- print("Restarting...")
- sleep(2)
- os.reboot()
- end
- end
- else
- print("Please swipe an empty card!")
- end
- end
- end
- end
- else
- print("Registry set up incorrectly.")
- sleep(2)
- os.shutdown()
- end
- end
- local function modAccount()
- while true do
- redraw()
- local fMenu=newmenu({"Change Password", "Change Name"},2,({term.getSize()})[2]-16)
- end
- end
- while true do
- redraw()
- local fMenu=newmenu({"Create An Account", "Modify an existing account"},2,({term.getSize()})[2]-16)
- if fMenu == "Create An Account" then
- getStuff()
- createAccount()
- elseif fMenu == "Modify an existing account" then
- getStuff()
- modAccount()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement