Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Password Server for Minecraft 1.5 with Computercraft installed.
- This script is written by Albrat
- Version 2
- Credits to www.coronlabs.com for help in string splitting function by Rob Miracle
- This program is intended to use rednet and several computers to create a working door system
- that locks and will not allow access untill the correct pass code is given.
- This password server will also function as a client login system.
- The program uses Usernames and Passwords over rednet login to a server.
- (This script keeps a log of all login names, But not the passwords.)
- the log is handy to see who tried to log in / who has used the door.
- If you use this program with my client program I suggest that you not type the comments
- if you use the pastebin.get command, save this as server01 and create a startup file with
- the next line of code in it... and have a monitor above the server comp.
- shell.run("monitor top server01")
- --]]
- -- local variable
- local servver = "2.0.1"
- local cmpid = os.getComputerID()
- local debug = false -- This is the debug value Default is 0 so no messages are outputted on the server.
- local Log = 1 -- Log (capital L) is a varible.
- local log = { "" } -- log (small case) is a table.
- local message = ""
- local pas = ""
- local firstCycle = true
- local validSender = false
- local moSide = "top" -- change to the side of the computer your modem is on
- local valid = false
- local oldpull=os.pullEvent -- we always backup the os.pullEvent
- if not debug then os.pullEvent=os.pullEventRaw end -- if in debug mode do not lockout CTRL + T
- -- Note : Users and Passwords are not account names for minecraft they are what you make them.
- users = { [1]= { "user", "pass1" }; [2] = { "guest", "pass2" }; [3] = { "admin", "23super" }; } --no gaps in name / pass. access with users[x][y]
- -- fx . users[1][2] would give "pass1" , users[1][1] would give "user"...
- senders = { 11, 2, 3, 12, 10, 32, 1 } -- computer ID's of the computers you want to accept requests from
- local adminid = 12 -- this is the id of the only computer that can release the servers anti CTRL + T lockout.
- -- you can get computer ID's by going to the computer, type lua [enter], type os.getComputerID() [enter]
- -- That will output the ID of the computer.
- -- I suggest that you write the little bit of code I use though, always use it so I never confuse them.
- -- local cmpid = os.getComputerID()
- -- print(cmpid)
- -- *************************
- -- ** Functions listing **
- -- *************************
- -- Our string handling Function
- function string:split( inSplitPattern, outResults ) -- not completely efficient but returns exactly what I want.
- if not outResults then
- outResults = { }
- end
- local theStart = 1
- local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- while theSplitStart do
- table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
- theStart = theSplitEnd + 1
- theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
- end
- table.insert( outResults, string.sub( self, theStart ) )
- return outResults
- end
- -- Boot up Function
- function bootUp()
- rednet.open(moSide)
- end
- -- Clear the Terminal Function
- function server()
- term.clear()
- term.setCursorPos(1,1)
- print("This is PassServ V "..servver)
- print("Please find a computer and login there.")
- print("Computer ID : ".. cmpid)
- end
- -- *********************
- -- ** Program Start **
- -- *********************
- server() -- Setup screen output
- -- os.pullEvent = os.pullEventRaw
- while true do -- loop infinite
- validSender = false
- if firstCycle then
- bootUp()
- firstCycle = false
- end
- senderId, mess, distance = rednet.receive()
- ---[[
- -- Commentable section of code To turn off and on the logging feature.
- -- To turn on this section of code add a - to the first two - in this -- [[ section.
- -- Note : this section of code is just to output the login list.
- if mess == "log " then -- remember we added a space as the seperator...
- for i=1, #log do -- If a computer asks for the log output the login names to screen.
- print(log[i])
- end
- sleep(10) -- show for 10 seconds (yes the server is out of touch while showing this)
- server() -- reset server screen (this is why I made it a function)
- end
- --]]
- ---[[ splitting Algorythm
- -- I should make this a function as it is used like a function.
- tablemes = string.split(mess, " ")
- message = tablemes[1] -- This is the string splitter and its processing.
- pas = tablemes[2]
- --]]
- ---[[ Logging algorythm
- log[Log] = message
- Log = Log + 1
- --]]
- ---[[ Debugging Code
- -- We want to debug the code and check that all messages are correctly decoded.
- -- I wrote this section for debugging my origional code and checking what messages i got
- -- I never removed the debugging code as it helps you to understand how I know it works.
- if debug then
- print(mess)
- print("output 1 : ", message)
- print("Output 2 : ", pas)
- print(senderId)
- for i=1, #log do
- print(log[i])
- end
- end
- --]]
- for i,v in ipairs(senders) do
- if v == senderId then
- validSender = true -- Are we a valid sender ID ? listed in the local variable section
- break
- end
- local validuser = false -- Reset out user to false.
- end
- if validSender then -- if we are a valid sender then check the passwords !!
- for i = 1, #users do
- if message == users[i][1] then -- If the message matches a user password set our response to true
- validuser = true
- passval = i
- break
- end
- end
- if passval ~= nil then
- if validuser and users[passval][2] == pas then
- valid = true
- else
- valid = false
- end
- end
- if valid then -- if we are valid respond the pass
- rednet.send(senderId, "valid", true)
- else
- rednet.send(senderId, "Not Valid", true) -- otherwise respond Not Valid
- end
- end
- if message == "admin" and valid == true and senderId == adminid then os.pullEvent = oldpull print(".")end
- -- if we have the admin name, pass and the right computer then we can disable the stop on the server.
- -- do not tell anyone that we did it though... our admin will know (".")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement