Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Other Authors
- -- https://sites.google.com/site/kleebcominecraft/kleebco---computer-craft----lets-play
- -- http://pastebin.com/s5aXm3Gs
- local serverAdminPassword = ""
- local Doors = {}
- local Passwords = {}
- local IsValid = 0
- local function count() -- counts the amount of users in the 'Users' table and returns them
- local count = 0
- for _ in pairs(Doors) do count = count + 1 end
- return count
- end
- local function ServiceMenu() -- rednet state / server state
- while true do
- local mon = peripheral.wrap("back")
- mon.restoreTo = term.current()
- term.redirect(mon)
- DrawMenu()
- print ("idling...")
- rednet.open("right")
- id, message = rednet.receive()
- IsValid = AuthDoor(id, message)
- if IsValid == -1 then
- rednet.send(id, "InValid")
- print ("Invalid Request From ID:"..id)
- elseif IsValid == 1 then
- rednet.send(id, "Valid")
- print ("Serviced Valid request from ID:"..id)
- end
- if message == "OPEN" then
- term.redirect(mon.restoreTo)
- SetupDoors()
- break
- end
- end
- end
- local function clear() -- clears the screen
- term.clear()
- term.setCursorPos (1,1)
- end
- function AuthDoor(id, password)
- for i=0, count() do
- if Passwords[i] == password then
- return 1
- else
- return -1
- end
- end
- end
- function SetupDoors() --
- while true do
- clear()
- print ("wanna setup a new door?")
- print ("Warning! once you move on the server goes into")
- print ("rednet mopde, it will not be able to iterface with you")
- print ("to open up this menu again send a 'OPEN' command to this")
- print ("ID:", os.getComputerID())
- print ("type Y/N , or type DELETE to enter delete mode")
- write ("here: ")
- input = read()
- if input == "Y" then
- clear()
- print (" this Computer's id: ", os.getComputerID())
- print (" Input the id of the door")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- print (" Input the password of the door")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- term.setCursorPos(5,4)
- local NewDoorID = read()
- term.setCursorPos(5,4)
- print ("ID Set")
- term.setCursorPos(5,8)
- local NewDoorPassword = read()
- term.setCursorPos(5,8)
- print ("Password set for door with ID: "..NewDoorID)
- print ("creating new door hold on ...")
- sleep(3)
- if AddDoor(NewDoorID, NewDoorPassword) == true then
- print ("SUCCESS New Door Created!")
- sleep(1)
- else
- print ("Door already exists!")
- sleep(1)
- end
- elseif input == "DELETE" then
- DeleteMenu()
- break
- elseif input == "N" then
- ServiceMenu()
- break
- end
- end
- end
- local function SetupID() -- sets up the Server labvel and Admin password **THIS IS THE STARTUP FUNCTION**
- clear()
- print (" this Computer's id: ", os.getComputerID())
- print (" Set this Computer's label:")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- print (" SET *ADMIN PASSWORD* ")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- term.setCursorPos(5,4)
- local IgnLabel = read()
- if IgnLabel == "no" then
- term.setCursorPos(5,4)
- print ("no label set !")
- term.setCursorPos(5,8)
- else
- os.setComputerLabel(IgnLabel)
- term.setCursorPos(5,4)
- print ("Label successful")
- term.setCursorPos(5,8)
- end
- serverAdminPassword = read()
- term.setCursorPos(5,8)
- print ("Admin password set!")
- sleep(1)
- clear()
- print ("Setting up Door Menu!")
- SetupDoors()
- end
- function AddDoor(doorID, password)
- if DoorExists(Doorid) == true then
- return false
- else
- table.insert(Doors, doorID)
- table.insert(Passwords, password)
- print ("Door"..doorID.."created")
- sleep(3)
- return true
- end
- end
- function DoorExists(DoorID)
- for i = 0, count() do
- if doorID == Doors[i] then
- return true
- end
- if i == count then
- return false
- end
- end
- end
- function DeleteDoor(Door)
- if DoorExists(Door) == true then
- for i = 0, count() do
- if Door == Doors[i] then
- table.remove(Doors, i)
- table.remove(Passwords, i)
- print ("Door"..Door.."deleted")
- sleep(1)
- end
- return true
- end
- elseif DoorExists(Door) == false then
- print("Door does not exist!")
- return false
- end
- end
- function DrawMenu() -- Creates a makeshift menu whenever called
- print (" +--------------------------+ ")
- print (" | WELCOME TO THE SERVER | ")
- print (" +--------------------------+ ")
- print (" this Computer's id: ", os.getComputerID())
- print (" +--------------------------+ ")
- print (" | THE SERVER IS AUTOMATIC | ")
- print (" | *MESSAGES DISPLAYING* | ")
- print (" +--------------------------+ ")
- end
- function DeleteMenu()
- while true do
- clear()
- print ("THIS IS THE DELETE MENU")
- print ("to go back input 'N' instead of id")
- print (" Input the id of the door")
- print (" +--------------------------+ ")
- print (" | ")
- print (" +--------------------------+ ")
- term.setCursorPos(5,5)
- input = read()
- if input == "N" then
- SetupDoors()
- break
- else
- if DeleteDoor(input) == true then
- print ("deleted Door with ID:"..input)
- sleep(2)
- else
- print ("Unable to delete given door:"..input)
- sleep(2)
- end
- end
- end
- end
- SetupID()
Advertisement
Add Comment
Please, Sign In to add comment