Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear() --Clear any text
- term.setCursorPos(1,1) --Set cursor position to beginning
- write"This is not a user-accessible computer." -- User information
- write"Log in at one of the USER PCs." --User information
- print("")
- local firstCycle = true -- Used to determine whether to run bootUp function. Boolean variable
- local validSender = false --Used to determine whether valid information has been entered. Boolean variable
- local modemSide = "top" --Determines modem side. String variable
- local valid = false --Used to determine whether check is made as to whether to return password or not. Boolean variable
- local DeBug = true -- turns off prints so people cant see passwrds
- users = {{uname = "XenoG", pword = "pl455ey"},
- {uname = "Test", pword = "user"},
- {uname = "Xenogene", pword = "lolgasm"}
- } --Users table. Left is key, right is value. In effect Username-Password (Key-Value)
- senders = {18,20} --Table of all computer ID's that can access server.
- function bootUp() --New function "bootUp()"
- rednet.open(modemSide) --Sends message to rednet to make sure the modem is open
- end --End function
- local function printTEST(...) -- allows you to turn off prints of ueser name set local DeBug = true to local DeBug = false
- if DeBug then
- print(...)
- end
- end
- while true do --Main server loop
- validSender = false --set validSender to false. Needs to be done every loop round
- local user = nil
- local password = nil
- if firstCycle then --If the this is the first cycle then
- bootUp() --Call the bootUp() function
- end --End IF statement
- senderId, message, distance = rednet.receive() --rednet.receive() function call. Loop waits here until a message is received
- for i,v in ipairs(senders) do --For index, value, search in the table senders, then execute next line
- if v == senderId then --If v is equal to a senderId (found in senders table) then
- validSender = true --Set validSender to true
- break --Break the loop
- end --End IF statement
- end --End FOR loop
- if validSender then --If validSender is true, execute next line
- printTEST("MES "..message)
- for k,v in pairs(users) do --For index, value, search in the table users, then execute next line
- printTEST(k..")U "..v.uname.." P "..v.pword)
- if message == v.uname then --If k is equal to message (found in users table) then
- valid = true --Set valid to true
- password = v.pword -- Set password to the value of v
- user = v.uname
- break -- this is needed so valid = false isnt called
- else --Otherwise
- valid = false --Set valid to false
- end --End IF statement
- end --End FOR loop
- if valid then --If valid is true, execute next line
- rednet.send(senderId, password) -- Send the senderID and the password to rednet
- printTEST("Sent "..senderId.." "..password)
- print("User "..user.." Requested Login")
- else --Otherwise
- rednet.send(senderId, "Not Valid") --Send a Not Valid message to rednet
- printTEST("Sent "..senderId.." ".."Not Valid")
- print("Atempted Login Failed")
- end --End IF statement
- end --End IF statement
- end --End WHILE TRUE DO loop
Add Comment
Please, Sign In to add comment