Advertisement
albrat

CC Pass server V2

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