Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x, y = term.getSize()
- local buttons = {}
- local log = {}
- local Users = {}
- serverID = nil
- serverName = nil
- serverPass = nil
- page = 1
- if not fs.exists("db") then -- Checks for db
- downloadDB = http.get("http://pastebin.com/raw.php?i=SfXFSh0a")
- downloadDBView = downloadDB.readAll()
- downloadDB.close()
- writeDB = fs.open("db", "w")
- writeDB.write(downloadDBView)
- writeDB.close()
- os.loadAPI("db")
- elseif fs.exists("db") then
- os.loadAPI("db")
- end
- -- Drawing functions
- function centered(str, height)
- term.setCursorPos(x / 2 - #str / 2, height)
- term.write(str)
- end
- function indented(str, indent, height)
- term.setCursorPos(indent, height)
- term.write(str)
- end
- function left(str, height)
- term.setCursorPos(1, height)
- term.write(str)
- end
- function right(str, height)
- term.setCursorPos(x - #str, height)
- term.write(str)
- end
- function clearLine(colour, height)
- term.setCursorPos(1, height)
- term.setBackgroundColour(colours[colour])
- term.clearLine()
- end
- function drawBorder(xMin, yMin, xMax, yMax, colour)
- paintutils.drawBox(xMin, yMin, xMax, yMax, colours[colour])
- end
- function drawBox(xMin, yMin, xMax, yMax, colour)
- paintutils.drawFilledBox(xMin, yMin, xMax, yMax, colours[colour])
- end
- -- Button API
- function enableButton(buttonName)
- for k,v in pairs(buttons) do
- if v["buttonName"] == buttonName then
- buttons[k]["Enabled"] = true
- return true
- end
- end
- return false
- end
- function disableButton(buttonName)
- for k,v in pairs(buttons) do
- if v["buttonName"] == buttonName then
- buttons[k]["Enabled"] = false
- return true
- end
- end
- return false
- end
- function buttonNameToNumber(buttonName)
- for k,v in pairs(buttons) do
- if v["buttonName"] == buttonName then
- return k
- end
- end
- return false
- end
- function checkButtonClick()
- while true do
- event, button, xPos, yPos = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- for k,v in pairs(buttons) do
- if xPos >= v["xPosStart"] and xPos <= v["xPosStop"] and yPos >= v["yPos"] and yPos <= v["yPos"]+2 and v["Enabled"] == true then
- if v["Function"] then
- if v["Function"] == "connect" and page == 1 then
- if type(tonumber(serverID)) == "number" then
- if db.getConnection(tonumber(serverID), serverName, serverPass) == "Connection" then
- term.setBackgroundColour(colours.cyan)
- term.setTextColour(colours.green)
- centered("Login successful. Redirecting..",6)
- sleep(1.5)
- page = 2
- pageLayout()
- elseif db.getConnection(tonumber(serverID), serverName, serverPass) == "Wrong_Details" then
- term.setBackgroundColour(colours.cyan)
- term.setTextColour(colours.red)
- centered("Wrong Username/Password!",6)
- sleep(2)
- page = 1
- main()
- elseif db.getConnection(tonumber(serverID), serverName, serverPass) == "No_Connection" then
- term.setBackgroundColour(colours.cyan)
- term.setTextColour(colours.red)
- centered("No connection!",6)
- sleep(2)
- page = 1
- main()
- end
- else
- term.setBackgroundColour(colours.cyan)
- term.setTextColour(colours.red)
- centered("Not a correct server ID!",6)
- sleep(2)
- page = 1
- main()
- end
- elseif v["Function"] == "addUser" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- indented("Username: ", 7, 7)
- indented("Password: ", 7, 9)
- term.setCursorPos(17, 7)
- username = read()
- term.setCursorPos(17, 9)
- password = read("*")
- if db.addUser(tonumber(serverID), serverName, serverPass, username, password) == true then
- term.setTextColour(colours.green)
- centered("Success.", 10)
- sleep(2)
- pageLayout()
- elseif db.addUser(tonumber(serverID), serverName, serverPass, username, password) == false then
- term.setTextColour(colours.red)
- centered("Failed.", 10)
- sleep(2)
- pageLayout()
- end
- elseif v["Function"] == "editValue" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- indented("Username: ", 7, 7)
- indented("Value: ", 7, 9)
- indented("New Value: ", 7, 11)
- term.setCursorPos(17, 7)
- username = read()
- term.setCursorPos(14, 9)
- value = read()
- term.setCursorPos(18, 11)
- nValue = read()
- if db.editValue(tonumber(serverID), serverName, serverPass, username, value, nValue) == true then
- term.setTextColour(colours.green)
- centered("Success.", 10)
- sleep(2)
- pageLayout()
- elseif db.editValue(tonumber(serverID), serverName, serverPass, username, value, nValue) == false then
- term.setTextColour(colours.red)
- centered("Failed.", 10)
- sleep(2)
- pageLayout()
- end
- elseif v["Function"] == "addValue" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- indented("Username: ", 7, 7)
- indented("Value: ", 7, 9)
- indented("New Value: ", 7, 11)
- term.setCursorPos(17, 7)
- username = read()
- term.setCursorPos(14, 9)
- value = read()
- term.setCursorPos(18, 11)
- nValue = read()
- if db.addValue(tonumber(serverID), serverName, serverPass, username, value, nValue) == true then
- term.setTextColour(colours.green)
- centered("Success.", 10)
- sleep(2)
- pageLayout()
- elseif db.addValue(tonumber(serverID), serverName, serverPass, username, value, nValue) == false then
- term.setTextColour(colours.red)
- centered("Failed.", 10)
- sleep(2)
- pageLayout()
- end
- elseif v["Function"] == "editUser" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- indented("Username: ", 7, 7)
- indented("Password: ", 7, 9)
- term.setCursorPos(17, 7)
- username = read()
- term.setCursorPos(17, 9)
- password = read("*")
- if db.editUser(tonumber(serverID), serverName, serverPass, username, password) == true then
- term.setTextColour(colours.green)
- centered("Success.", 10)
- sleep(2)
- pageLayout()
- elseif db.editUser(tonumber(serverID), serverName, serverPass, username, password) == false then
- term.setTextColour(colours.red)
- centered("Failed.", 10)
- sleep(2)
- pageLayout()
- end
- elseif v["Function"] == "stopServer" and page == 2 then
- if db.stopServer(tonumber(serverID), serverName, serverPass) == true then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- term.setTextColour(colours.green)
- centered("Success.", 10)
- disableButton("stopServer")
- sleep(2)
- term.setTextColour(colours.red)
- centered("Server closed. Aborting.", 10)
- sleep(2)
- page = 1
- begin()
- end
- elseif v["Function"] == "getValue" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- indented("Username: ", 7, 7)
- indented("Value: ", 7, 9)
- term.setCursorPos(17, 7)
- username = read()
- term.setCursorPos(14, 9)
- value = read()
- if db.getValue(tonumber(serverID), serverName, serverPass, username, value) == "No_Value" then
- centered("User has no value.", 10)
- sleep(2)
- pageLayout()
- else
- centered("Value: "..db.getValue(tonumber(serverID), serverPass, serverPass, username, value), 10)
- sleep(2)
- pageLayout()
- end
- elseif v["Function"] == "pingServer" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- if db.getConnection(tonumber(serverID), serverName, serverPass) == "Connection" then
- term.setTextColour(colours.green)
- centered("Success", 10)
- sleep(2)
- pageLayout()
- elseif db.getConnection(tonumber(serverID), serverName, serverPass) == "No_Connection" then
- term.setTextColour(colours.red)
- centered("Failed.", 10)
- centered("Server closed. Aborting.", 11)
- sleep(2)
- page = 1
- begin()
- end
- elseif v["Function"] == "leave" and page == 2 then
- serverID = nil
- serverName = nil
- serverPass = nil
- page = 1
- begin()
- elseif v["Function"] == "removeUser" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- indented("Username: ", 7, 7)
- username = read()
- if db.removeUser(tonumber(serverID), serverName, serverPass, username) == true then
- term.setTextColour(colours.green)
- centered("Success.", 10)
- sleep(2)
- pageLayout()
- elseif db.removeUser(tonumber(serverID), serverName, serverPass, username) == false then
- term.setTextColour(colours.red)
- centered("Failed.", 10)
- sleep(2)
- pageLayout()
- end
- elseif v["Function"] == "checkUser" and page == 2 then
- drawBorder(5, 5, x - 5, y - 5, "blue")
- drawBox(6, 6, x - 6, y - 6, "lightBlue")
- indented("Username: ", 7, 7)
- indented("Password: ", 7, 9)
- term.setCursorPos(17, 7)
- username = read()
- term.setCursorPos(17, 9)
- password = read("*")
- if db.checkUser(tonumber(serverID), serverName, serverPass, username, password) == true then
- term.setTextColour(colours.green)
- centered("Success.", 10)
- sleep(2)
- pageLayout()
- elseif db.checkUser(tonumber(serverID), serverName, serverPass, username, password) == false then
- term.setTextColour(colours.red)
- centered("Failed.", 10)
- sleep(2)
- pageLayout()
- end
- elseif v["Function"] == "log" and page == 2 then
- term.setBackgroundColour(colours.black)
- term.clear()
- term.setTextColour(colours.white)
- Log = db.getAllLogs(tonumber(serverID), serverName, serverPass)
- local yPos = 1
- term.setCursorPos(1, yPos)
- for k, v in pairs(Log) do
- if v[2] == "Info" then
- term.setTextColour(colours.blue)
- term.write("[ "..v[2].." ] ")
- term.setTextColour(colours.lightGrey)
- term.write(v[1])
- yPos = yPos + 1
- term.setCursorPos(1, yPos)
- elseif v[2] == "Success" then
- term.setTextColour(colours.green)
- term.write("[ "..v[2].. " ] ")
- term.setTextColour(colours.lightGrey)
- term.write(v[1])
- yPos = yPos + 1
- term.setCursorPos(1, yPos)
- elseif v[2] == "Warning" or v[2] == "Error" or v[2] == "Alert" then
- term.setTextColour(colours.red)
- term.write("[ "..v[2].." ] ")
- term.setTextColour(colours.lightGrey)
- term.write(v[1])
- yPos = yPos + 1
- term.setCursorPos(1, yPos)
- end
- end
- event, key = os.pullEvent("key")
- pageLayout()
- elseif v["Function"] == "listUsers" and page == 2 then
- term.setBackgroundColour(colours.black)
- term.clear()
- term.setTextColour(colours.white)
- Users = db.getAllUsers(tonumber(serverID), serverName, serverPass)
- term.setCursorPos(1, 1)
- for k, v in pairs(Users) do
- print(v["name"])
- end
- event, key = os.pullEvent("key")
- pageLayout()
- end
- end
- end
- end
- end
- end
- end
- function removeButton(buttonName)
- table.remove(buttons, buttonNameToNumber(buttonName))
- end
- function drawButton(xPos,yPos,bgColor,txtColor,length,txt,buttonName,functionName)
- term.setBackgroundColour(colours[bgColor])
- term.setTextColour(colours[txtColor])
- local X = xPos + math.floor((length/2)-(string.len(txt)/2))
- if not buttonName then
- buttonName = "Test"..tostring(#buttons+1)
- end
- for i = yPos,yPos+2 do
- if i ~= yPos+1 then
- term.setCursorPos(xPos,i)
- term.write(string.rep(" ", length))
- else
- term.setCursorPos(xPos,i)
- term.write(string.rep(" ", length))
- term.setCursorPos(X,i)
- buttons[#buttons+1] = {["Function"] = functionName, ["buttonName"] = buttonName, ["xPosStart"] = xPos, ["xPosStop"] = xPos+length-1, ["yPos"] = yPos, ["Enabled"] = true}
- term.write(txt)
- end
- end
- end
- -- Main Code
- function printHeader(page)
- if page == 1 then
- clearLine("blue", 1)
- clearLine("blue", 2)
- clearLine("blue", 3)
- term.setTextColour(colours.lightBlue)
- indented("EpiClient", 3, 2)
- elseif page == 2 then
- clearLine("blue", 1)
- clearLine("blue", 2)
- clearLine("blue", 3)
- term.setTextColour(colours.lightBlue)
- indented("EpiClient", 3, 2)
- amount = db.amountUsers(tonumber(serverID), serverName, serverPass)
- amount = tonumber(amount)
- term.setBackgroundColour(colours.blue)
- if amount == 1 then
- term.setCursorPos(45, 2)
- write(amount.." User")
- elseif amount ~= 1 then
- term.setCursorPos(44, 2)
- write(amount.." Users")
- end
- end
- end
- function pageLayout()
- if page == 1 then
- term.setBackgroundColour(colours.cyan)
- term.clear()
- printHeader(1)
- elseif page == 2 then
- term.setBackgroundColour(colours.cyan)
- term.clear()
- printHeader(2)
- drawButton(3, 6, "blue", "lightBlue", 10, "Add User", "addUser", "addUser")
- drawButton(14, 6, "blue", "lightBlue", 12, "Edit Value", "editValue", "editValue")
- drawButton(27, 6, "blue", "lightBlue", 11, "Add Value", "addValue", "addValue")
- drawButton(39, 6, "blue", "lightBlue", 11, "Edit User", "editUser", "editUser")
- drawButton(3, 10, "blue", "lightBlue", 13, "Stop Server", "stopServer", "stopServer")
- drawButton(17, 10, "blue", "lightBlue", 11, "Get Value", "getValue", "getValue")
- drawButton(29, 10, "blue", "lightBlue", 13, "Ping Server", "pingServer", "pingServer")
- drawButton(43, 10, "blue", "lightBlue", 7, "Leave", "leave", "leave")
- drawButton(3, 14, "blue", "lightBlue", 7, "Users", "listUsers", "listUsers")
- drawButton(11, 14, "blue", "lightBlue", 10, "View Log", "log", "log")
- drawButton(22, 14, "blue", "lightBlue", 13, "Remove User", "removeUser", "removeUser")
- drawButton(36, 14, "blue", "lightBlue", 14, "Check a User", "checkUser", "checkUser")
- term.setBackgroundColour(colours.cyan)
- term.setTextColour(colours.blue)
- indented("This client was made by smigger22 and the data-", 3, 17)
- centered("base was designed by jasperdekiller.", 18)
- checkButtonClick()
- end
- end
- function main()
- pageLayout()
- term.setBackgroundColour(colours.cyan)
- indented("ID: ", 7, 7)
- indented("Username: ", 7, 9)
- indented("Password: ", 7, 11)
- term.setCursorPos(11, 7)
- serverID = read()
- term.setCursorPos(17, 9)
- serverName = read()
- term.setCursorPos(17, 11)
- serverPass = read("*")
- drawButton(16, 14, "blue", "lightBlue", 17, "Connect", "connect", "connect")
- end
- function begin()
- parallel.waitForAll(main, checkButtonClick)
- end
- rednet.open("top")
- begin()
Advertisement
Add Comment
Please, Sign In to add comment