Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw -- eliminates ability to kill program with keybind
- serverID = 0 -- computer id of server unit that holds employee data (practically the same thing as an ip in computercraft)
- insuranceserverID = 1 -- computer id of insurance server to access data from (for this demonstration only one will be used to avoid confusion)
- adminusername = "temp"
- adminpassword = "password"
- local function displayTextLogin()
- print("Enter username: ")
- username = read()
- print("Enter password: ")
- password = read()
- return username, password
- end
- local function displayTextMenu()
- print("Please Choose an Option")
- print("1: Calculate/Display Medical Information")
- print("2: Calculate/Display Retirement Information")
- print("0: Log Out")
- return tonumber(read())
- end
- local function getBalances()
- message = "balances " .. username .. " " .. password -- string request to be processed by server
- rednet.send(serverID, message) -- sends user info to company server to get any medical info
- id, balances = rednet.receive(nil, 3) -- listens if the server found user, if not in 3 seconds will return nil (ie empty variable)
- return balances
- end
- local function getInfo(info)
- message = info .. " " .. username .. " " .. password -- string request to be processed by server
- rednet.send(insuranceserverID, message) -- sends user info to insurance server to get any medical info
- id, info = rednet.receive(nil, 3) -- listens if the server found user, if not in 3 seconds will return nil (ie empty variable)
- return info
- end
- local function authorization()
- while true do
- print("Do you authorize this program to access your insurance information on your behalf? (yes, or no)")
- choice = read()
- if choice == "yes" then
- return true
- end
- if choice ~= "no" then
- return false
- end
- print("incorrect input, try again (its case sensitive)")
- end
- end
- function checkCredentials(username, password)
- message = "search " .. username .. " " .. password -- string request to be processed by server
- rednet.send(serverID, message) -- sends user info to company server to get any medical info
- id, value = rednet.receive(nil, 3) -- listens if the server found user, if not in 3 seconds will return nil (ie empty variable)
- os.sleep(1)
- return value
- end
- function medimath(balance, insurance)
- crazycoolmaththings = balance * insurance --temp code as all of this is made up for demonstation purposes
- return crazycoolmaththings
- end
- function retiremath(balance, insurance)
- crazycoolmaththings = balance * insurance --temp code as all of this is made up for demonstation purposes
- return crazycoolmaththings
- end
- function twoInputStrip(str)
- first, second = str:match("(%S+)%s+(%S+)")
- return first, second
- end
- while true do
- username, password = displayTextLogin()
- if username == adminusername and password == adminpassword then
- return 1 -- breaks out of loop if admin login is detected to edit this script
- end
- confirm = checkCredentials(username, password)
- if confirm ~= nil then
- if authorization() then
- while true do
- choice = displayTextMenu()
- --unfortunately switch statements are not in lua to use :(
- if choice == 0 then
- break
- end
- if choice == 1 then
- info = getInfo("medicalinfo")
- if info == nil then
- print("error getting insurance info")
- break
- end
- balances = getBalances()
- if balances == nil then
- print("error getting balance info")
- break
- end
- balance1 = twoInputStrip(balances) --assuming that both retirement and medical balances are returned separated by a space
- finaltotal = medimath(balance1, info)
- print("Medical balance = " .. balance1)
- print("Medical Insurance Info = " .. info)
- print("Final Calculated Total " .. finaltotal)
- print("Press enter to return to menu")
- read()
- end
- if choice == 2 then
- info = getInfo("retirementinfo")
- if info == nil then
- print("error getting insurance info")
- break
- end
- balances = getBalances()
- if balances == nil then
- print("error getting balance info")
- break
- end
- balance1, balance2 = twoInputStrip(balances) --assuming that both retirement and medical balances are returned separated by a space
- finaltotal = retiremath(balance2, insurance)
- print("Retirement balance = " .. balance2)
- print("Retirement Insurance Info = " .. info)
- print("Final Calculated Total " .. finaltotal)
- print("Press enter to return to menu")
- read()
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement