Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --functions
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function Init()
- print("Initializing...")
- --open rednet
- if fs.exists(".rnconfig") == false then
- local file = fs.open(".rnconfig","w")
- file.write("back")
- file.close()
- print(".rnconfig file generated")
- end
- local config = fs.open(".rnconfig","r").readAll()
- rednet.open(tostring(config))
- if rednet.isOpen() == false then
- print("Could Not Open Rednet, Check .rnconfig")
- else
- print("Rednet Opened On Channel "..os.computerID())
- sleep(1)
- end
- --end rn check
- -- user database
- print("Loading Username Database")
- if fs.exists(".users") == false then
- local unames = fs.open(".users","w")
- unames.write('{"admin"}')
- unames.close()
- print("Creating User Database")
- else
- print("User Database Found")
- sleep(1)
- end
- --end user database check
- -- password database check
- print("Loading Password Database")
- if fs.exists(".users") == false then
- local passwds = fs.open(".passwords","w")
- passwds.write('{"admin", "password"}')
- passwds.close()
- print("Creating Password Database")
- else
- sleep(1)
- print("Password Database Found")
- end
- --end password check
- end
- function load(name)
- local f = fs.open(name, "r")
- local data = f.readAll()
- f.close()
- return textutils.unserialise(data)
- end
- function Host()
- while true do
- local client,message,protocol = rednet.receive()
- print(client..": "..message.." : "..protocol)
- local num = tonumber(client)
- local i = tonumber(UID)
- --UID
- if protocol == "UID" then
- UID = message
- print("UID set to :"..message)
- print(client)
- sleep(1)
- rednet.send(num, "confirm")
- end
- --USERNAME
- if protocol == "username" then
- if message == UserData[i] then
- print("Username: "..message)
- rednet.send(num,"confirm")
- else
- print("Username Rejected")
- rednet.send(num, "denied")
- end
- end
- --PASSWORD
- if protocol == "password" then
- if message == PassData[i] then
- print("Password: "..message)
- rednet.send(num, "confirm")
- else
- print("Password Denied")
- rednet.send(num, "denied")
- end
- end
- end
- end
- --Start
- Init()
- print("Init Complete!")
- sleep(1)
- clear()
- UserData = load(".users")
- print("Loaded User Database!")
- sleep(1)
- PassData = load(".passwords")
- print("Loaded Password Database")
- sleep(1)
- clear()
- print("Hosting...")
- local UID = 1
- sleep(1)
- clear()
- Host()
- --test
- --print("Test:")
- --print(UserData[2])
- --print(PassData[2])
- --sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement