Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.pullEvent = os.pullEventRaw
- local file = fs.open(".server", "r")
- if file == nil then
- print("No server configured")
- return
- end
- local server = tonumber(file.readLine())
- file.close()
- local sid
- local user = "Guest"
- local modem = peripheral.find("modem")
- local event, side, sChannel, id, data, dist
- local _id = os.getComputerID()
- local admin = false
- local function idRNG()
- modem.close(_id)
- _id = math.random(50000, 55000)
- modem.open(_id)
- end
- local function receive()
- event, side, sChannel, id, data, dist = os.pullEvent("modem_message")
- end
- local function send(to, msg)
- idRNG()
- modem.transmit(to, _id, msg)
- receive()
- end
- local function addmoney(usr, amt)
- send(server,"add")
- send(id,sid..":"..usr..":"..amt)
- end
- local function remusr(usr)
- send(server,"delete")
- send(id,sid..":"..usr)
- end
- local function chmod(usr,bool)
- send(server,"chmod")
- send(id,sid..":"..usr..":"..bool)
- end
- local function PClick()
- local evnt, button, x, y = os.pullEvent("mouse_click")
- local A = x
- local B = y
- local C = button
- return A, B, C
- end
- local function start()
- while true do
- term.setBackgroundColor(8)
- term.setTextColor(16)
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome, " .. user)
- if sid ~= nil then
- term.setCursorPos(3, 4)
- print("[Logout]")
- term.setCursorPos(3, 6)
- print("[Balance]")
- term.setCursorPos(3, 8)
- print("[Transfer]")
- if admin then
- term.setCursorPos(3, 10)
- print("[R/A $]")
- term.setCursorPos(3,12)
- print("[Remove User]")
- term.setCursorPos(3,14)
- print("[Change User Status]")
- x, y, button = PClick()
- if button == 1 and x >= 3 and x <= 9 and y == 10 then
- term.setBackgroundColor(8)
- term.setTextColor(16)
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome, " .. user)
- term.setCursorPos(3, 4)
- write("User: ")
- USR = read()
- term.setCursorPos(3, 5)
- write("Amount: $")
- ammt = read()
- addmoney(USR,ammt)
- elseif button == 1 and x >= 3 and x <= 15 and y == 12 then
- term.setBackgroundColor(8)
- term.setTextColor(16)
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome, " .. user)
- term.setCursorPos(3, 4)
- write("User: ")
- USR = read()
- remusr(USR)
- elseif button == 1 and x >= 3 and x <= 22 and y == 14 then
- term.setBackgroundColor(8)
- term.setTextColor(16)
- term.clear()
- term.setCursorPos(1, 1)
- print("Welcome, " .. user)
- term.setCursorPos(3, 4)
- write("User: ")
- USR = read()
- term.setCursorPos(3, 5)
- write("Admin (true/false): ")
- BOOL = read()
- chmod(USR,BOOL)
- end
- end
- else
- term.setCursorPos(3, 4)
- print("[Login]")
- term.setCursorPos(3, 6)
- print("[Create Account]")
- end
- event, button, x, y = os.pullEvent("mouse_click")
- if x >= 3 and x <= 10 and y == 4 and sid == nil then
- send(server, "login")
- term.clear()
- term.setCursorPos(3, 4)
- write("User: ")
- user = read()
- term.setCursorPos(3, 5)
- write("Pass: ")
- pass = read("*")
- send(id, user .. ":" .. pass)
- if data:find("Login Successful") and data:find(":") then
- if data:find(":", data:find(":") + 1) then
- admin = true
- local c1 = data:find(":")
- local c2 = data:find(":", c1 + 1)
- sid = data:sub(c1 + 1, c2 - 1)
- else
- admin = false
- sid = data:sub(data:find(":") + 1)
- end
- print(data:sub(0, data:find(":") - 1))
- else
- user = "Guest"
- print(data)
- end
- term.setCursorPos(3, 2)
- sleep(1)
- elseif x >= 3 and x <= 10 and y == 4 and sid ~= nil then
- user = "Guest"
- send(server, "logout")
- send(id, sid)
- sid = nil
- print(data)
- sleep(1)
- elseif x >= 3 and x <= 11 and y == 6 and sid ~= nil then
- send(server, "balance")
- send(id, sid)
- term.clear()
- term.setCursorPos(1, 1)
- print("Balance is $" .. data)
- os.pullEvent("mouse_click")
- elseif x >= 3 and x <= 12 and y == 8 and sid ~= nil then
- send(server, "transfer")
- term.clear()
- term.setCursorPos(3, 4)
- write("Amount: $")
- amt = read()
- term.setCursorPos(3, 6)
- write("To User: ")
- user2 = read()
- send(id, sid .. ":" .. user2 .. ":" .. amt)
- term.setCursorPos(3, 2)
- print(data)
- os.pullEvent("mouse_click")
- elseif x >= 3 and x <= 18 and y == 6 and sid == nil then
- term.clear()
- term.setCursorPos(3, 4)
- write("Username: ")
- user = read()
- term.clear()
- term.setCursorPos(3, 4)
- write("Password: ")
- pass = read("*")
- term.clear()
- send(server, "create")
- send(id, user .. ":" .. pass)
- user = "Guest"
- term.setCursorPos(3, 4)
- print(data)
- os.pullEvent("mouse_click")
- end
- end
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement