Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("text.lua")
- exitcode = 0
- rednet.open("back")
- phoneServerID = 21
- serverID = 3
- passwordfile = "adminsuccess.txt"
- userFile = "usersuccess.txt"
- local function download(url, fileName)
- if http then
- local response = http.get(url)
- if response then
- local file = fs.open(fileName, "w")
- file.write(response.readAll())
- file.close()
- print("Downloaded " .. fileName)
- else
- print("Failed to download " .. url)
- end
- else
- print("HTTP not enabled")
- end
- os.sleep(3)
- end
- function getExitCode()
- return exitcode
- end
- function twoInputStrip(str)
- first, second = str:match("(%S+)%s+(%S+)")
- return first, second
- end
- function readAdminPassword()
- local file = fs.open(passwordfile, "r")
- if file then
- line = file.readLine()
- file.close()
- return line
- end
- end
- function readUserLogin()
- local file = fs.open(userFile, "r")
- if file then
- line = file.readLine()
- line2 = file.readLine()
- file:close() -- Close the file
- return line, line2
- end
- end
- function login(dusername, dpassword)
- while true do
- -- Display login screen
- print("Login Screen")
- print("Enter username:")
- local username = read()
- print("Enter password:")
- local password = read("*")
- if username == "admin" and password == readAdminPassword() then
- print("ADMIN")
- os.sleep(1)
- exitcode = 1
- os.exit(1)
- end
- -- If login is successful, unlock the screen
- if username == dusername and password == dpassword then
- print("Login successful")
- os.sleep(3)
- term.clear()
- term.setCursorPos(1, 1)
- return true
- elseif dusername == nil or dpassword == nil then
- print("User Login Corrupted")
- print("Please See a Celtico Representative")
- os.sleep(3)
- return false
- else
- print("Login failed")
- os.sleep(3)
- term.clear()
- term.setCursorPos(1, 1)
- end
- end
- end
- local function displayMenu(dusername)
- print("Welcome " .. dusername .. "!")
- print("1. Text Messages")
- print("2. Transfer Funds")
- print("3. Buy Request")
- print("4. Services")
- print("0. Exit")
- end
- local function displayServiceMenu(dusername)
- print("Welcome " .. dusername .. "!")
- print("1. Games")
- print("2. Turtle Services")
- print("0. Exit")
- end
- local function displayGameMenu(dusername)
- print("Welcome " .. dusername .. "!")
- print("1. Flappy Bird")
- print("0. Exit")
- print("\nWarning: Some Games may Require a Manual Shut Off to Exit!\n")
- end
- local function userChoice(dusername)
- io.write("Enter your choice: ")
- return tonumber(io.read())
- end
- local function sendServer(message)
- rednet.send(serverID, message)
- id, message = rednet.receive(nil, 3)
- if id == serverID then
- return message
- else
- return "error"
- end
- end
- local function transferFunds(dusername, dpassword)
- balance = sendServer("search " .. dusername .. " " .. dpassword)
- if balance == nil then
- print("Error: Server Offline")
- os.sleep(2)
- elseif balance == "false" then
- print("Error: Phone Login not in Server Database")
- os.sleep(2)
- elseif balance == "error" then
- print("Error: Server Interference")
- os.sleep(2)
- else
- print("Your Balance: " .. balance)
- print("Enter the Recipients Username: ")
- recipient = io.read()
- print("Enter the Amount to Transfer: ")
- amount = io.read()
- success = sendServer("transfer " .. dusername .. " " .. dpassword .. " " .. amount .. " " .. recipient)
- if success == nil then
- print("Error: Server Offline")
- os.sleep(2)
- elseif success == "false" then
- print("Error: Recipient not in Server Database or Impossible Amount")
- os.sleep(5)
- elseif success == "error" then
- print("Error: Server Interference")
- os.sleep(2)
- else
- print("Success!")
- os.sleep(2)
- end
- end
- end
- function buyAccept()
- id, message = rednet.receive(nil, 30)
- print(message)
- if id == nil then
- print("Could Not Find Cashier Terminal")
- os.sleep(3)
- return
- end
- rednet.send(id, "ping")
- if message ~= nil then
- command, cost = twoInputStrip(message)
- if command == "buyrequest" then
- print("Buy Request of " .. cost .. " Received")
- print("Press 1 to Confirm Payment")
- confirmation = read()
- if tonumber(confirmation) == 1 then
- rednet.send(serverID, "buy " .. dusername .. " " .. dpassword .. " " .. cost)
- newid, success = rednet.receive(nil, 3)
- if success ~= nil then
- print("Payment Success!")
- os.sleep(3)
- else
- print("Payment Error")
- os.sleep(3)
- end
- else
- print("Payment Cancelled")
- os.sleep(3)
- rednet.send(id, "cancel")
- end
- else
- print("Buy Request Intercepted, Please Retry")
- os.sleep(3)
- end
- else
- print("No Buy Request Found Exiting to Menu")
- os.sleep(3)
- end
- end
- function main()
- while true do
- dusername, dpassword = readUserLogin()
- if login(dusername, dpassword) then
- while true do
- displayMenu(dusername)
- choice = userChoice(dusername)
- if choice == 1 then
- term.clear()
- term.setCursorPos(1, 1)
- text.text(dusername, phoneServerID)
- term.clear()
- term.setCursorPos(1, 1)
- elseif choice == 2 then
- term.clear()
- term.setCursorPos(1, 1)
- transferFunds(dusername, dpassword)
- term.clear()
- term.setCursorPos(1, 1)
- elseif choice == 3 then
- buyAccept()
- term.clear()
- term.setCursorPos(1, 1)
- elseif choice == 4 then
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- displayServiceMenu(dusername)
- schoice = userChoice(dusername)
- if schoice == 1 then
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- displayGameMenu(dusername)
- gchoice = userChoice(dusername)
- if gchoice == 1 then
- download("https://github.com/bartek18887/ComputerCraft-FlappyBird/raw/main/main.lua", "flappybird.lua")
- os.loadAPI("flappybird.lua")
- elseif gchoice == 0 then
- break
- end
- end
- elseif schoice == 2 then
- print("\nTurtle Services Not Available in Early Access")
- print("(ie I am not paid enough to have it done yet)\n")
- print("type anything to return to the menu")
- read()
- break
- elseif schoice == 0 then
- break
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- elseif choice == 0 then
- term.clear()
- term.setCursorPos(1, 1)
- break
- else
- print("Incorrect Input")
- os.sleep(1)
- term.clear()
- term.setCursorPos(1, 1)
- end
- end
- end
- end
- end
- --os.pullEvent = os.pullEventRaw
- pcall(main)
- --os.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement