Advertisement
albrat

Server - Password

Jun 30th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.40 KB | None | 0 0
  1. --[[    Password Server for Minecraft 1.5 with Computercraft installed.
  2.         This script is written by Albrat  
  3.         Credits to www.coronlabs.com for help in string splitting function by Rob Miracle
  4.        
  5.         This program is intended to use rednet and several computers to create a working door system
  6.         that locks and will not allow access untill the correct pass code is given.
  7.        
  8.         The program uses Usernames and Passwords over rednet login to a server.
  9.        
  10.         (This script keeps a log of all login names, But not the passwords.)  
  11.         the log is handy to see who tried to log in / who has used the door.
  12.        
  13.         If you use this program with my client program I suggest that you not type the comments
  14.         if you use the pastebin.get command, save this as server01 and create a startup file with
  15.         the next line of code in it... and have a monitor above the server comp.
  16.        
  17.         shell.run("monitor top server01")
  18.        
  19. --]]
  20.  
  21.  
  22. -- local variable
  23.  
  24. local cmpid = os.getComputerID()
  25. local debug = false  --  This is the debug value Default is 0 so no messages are outputted on the server.
  26. local Log = 1  -- Log  (capital L) is a varible.
  27. local log = { "" } -- log (small case) is a table.
  28. local message = ""
  29. local pas = ""
  30. local firstCycle = true
  31. local validSender = false
  32. local modemSide = "top" -- change to the side of the computer your modem is on
  33. local valid = false
  34.  
  35. -- Note : Users and Passwords are not account names for minecraft they are what you make them.
  36.  
  37. users = {"user", "guest" } --make sure users and passwords line up , also no gaps in names / pass.
  38. passwords = {"pass1", "pass2" }  -- Passwords have to be whole no gaps , user = pass1 guest = pass2
  39. senders = { 11, 2, 3, 12, 10, 32, 1 } -- computer ID's of the computers you want to accept requests from
  40.  
  41. -- you can get computer ID's by going to the computer, type lua [enter], type os.getComputerID() [enter]
  42. -- That will output the ID of the computer.
  43. -- I suggest that you write the little bit of code I use though, always use it so I never confuse them.
  44.  
  45. -- local cmpid = os.getComputerID()
  46. -- print(cmpid)
  47.  
  48.  
  49. -- *************************
  50. -- **  Functions listing  **
  51. -- *************************
  52.  
  53. -- Our string handling Function
  54.  
  55. function string:split( inSplitPattern, outResults )
  56.  
  57.    if not outResults then
  58.       outResults = { }
  59.    end
  60.    local theStart = 1
  61.    local theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  62.    while theSplitStart do
  63.       table.insert( outResults, string.sub( self, theStart, theSplitStart-1 ) )
  64.       theStart = theSplitEnd + 1
  65.       theSplitStart, theSplitEnd = string.find( self, inSplitPattern, theStart )
  66.    end
  67.    table.insert( outResults, string.sub( self, theStart ) )
  68.    return outResults
  69. end
  70.  
  71. -- Boot up Function
  72. function bootUp()
  73.  rednet.open(modemSide)
  74. end
  75.  
  76. -- Clear the Terminal Function
  77. function server()
  78.  term.clear()
  79.  term.setCursorPos(1,1)
  80.  print("This is a password server. There is no user interaction here.")
  81.  print("Please find a computer and login there.")
  82.  print("Computer ID : ".. cmpid)
  83. end
  84.  
  85. -- *********************
  86. -- **  Program Start  **
  87. -- *********************
  88.  
  89. server()  -- Setup screen output
  90.  -- os.pullEvent = os.pullEventRaw
  91.  
  92.  
  93. while true do   -- loop infinite
  94.  validSender = false
  95.  if firstCycle then
  96.   bootUp()
  97.   firstCycle = false
  98.  end
  99.  senderId, mess, distance = rednet.receive()
  100.  
  101.  ---[[
  102.  -- Commentable section of code To turn off and on the logging feature.
  103.  -- To turn on this section of code add a - to the first two - in this -- [[ section.
  104.  
  105.  -- Note : this section of code is just to output the login list.
  106.  
  107. if mess == "log " then  -- remember we added a space as the seperator...
  108.      for i=1, #log do  -- If a computer asks for the log output the login names to screen.
  109.       print(log[i])
  110.      end
  111.      sleep(10) -- show for 10 seconds (yes the server is out of touch while showing this)
  112.      server() -- reset server screen (this is why I made it a function)
  113. end
  114.  
  115.  --]]
  116.  
  117.  ---[[  splitting Algorythm
  118.  
  119.  -- I should make this a function as it is used like a function.
  120.  
  121.  tablemes = string.split(mess, " ")
  122.  message = tablemes[1]                  --  This is the string splitter and its processing.
  123.  
  124.  pas = tablemes[2]
  125.  
  126. --]]
  127.  
  128. ---[[  Logging algorythm
  129.  log[Log] = message
  130.  Log = Log + 1
  131.  --]]
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  ---[[  Debugging Code
  139.  -- We want to debug the code and check that all messages are correctly decoded.
  140.  -- I wrote this section for debugging my origional code and checking what messages i got
  141.  -- I never removed the debugging code as it helps you to understand how I know it works.
  142.  
  143.  if debug then
  144.  print(mess)
  145.  print("output 1 : ", message)
  146.  print("Output 2 : ", pas)
  147.  print(senderId)
  148.  for i=1, #log do
  149.  print(log[i])
  150.  end
  151.  end
  152.  
  153.  --]]
  154.  
  155.  
  156.  for i,v in ipairs(senders) do
  157.   if v == senderId then
  158.    validSender = true   --  Are we a valid sender ID ? listed in the local variable section
  159.       break
  160.   end
  161.  
  162.  end
  163.  if validSender then  -- if we are a valid sender then check the passwords !!
  164.   for i,v in ipairs(users) do
  165.    if message == v then  -- If the message matches a user password set our response to true
  166.     valid = true  
  167.     password = passwords[i]
  168.     break
  169.    else
  170.     valid = false  -- if no password matches...
  171.    end
  172.   end
  173.   if valid then -- if we are valid respond the pass
  174.    rednet.send(senderId, "valid", true)
  175.   else
  176.    rednet.send(senderId, "Not Valid", true)  -- otherwise respond Not Valid
  177.   end
  178.  end
  179. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement