Advertisement
Guest User

v2

a guest
Feb 27th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.67 KB | None | 0 0
  1. os.loadAPI("sha256.lua")
  2. local chatBox = peripheral.find("chat_box")
  3. local name = "\167l\1672KristList"
  4. local prefixColor = "\1670"
  5. local lines = {}
  6.  
  7. local function countLines()
  8.     local file = fs.open("posts","r")
  9.    
  10.     if file then
  11.         lines = {}
  12.         local line = file.readLine()
  13.        
  14.         while line do
  15.             table.insert(lines,line)
  16.             line = file.readLine()
  17.         end
  18.         file.close()
  19.     end
  20. end
  21.  
  22. while true do
  23.  local event, user, command, args = os.pullEvent("command")
  24.     if command == "kristlist" then
  25.         countLines()
  26.        
  27.         if args[1] == "post" then
  28.             table.remove(args,1)
  29.             local message = table.concat(args, " ")
  30.             local file = fs.open("posts","a")
  31.             file.writeLine(user..": "..message)
  32.             file.close()
  33.  
  34.         elseif args[1] == "read" then
  35.              
  36.             if args[2] == nil then
  37.                 chatBox.tell(user,"\167rInsufficient arguments, \1674\\kristlist help <command> \167r for more information on how to use kristlist",name,prefixColor)
  38.                
  39.             elseif tonumber(args[2]) > 0 and tonumber(args[2]) <= #lines then
  40.                 local file = fs.open("posts","r")
  41.                
  42.                 for i = 1, args[2] do
  43.                     chatBox.tell(user,"\167r"..file.readLine(),name,prefixColor)
  44.                 end
  45.             end
  46.  
  47.         elseif args[1] == "register" then
  48.    
  49.             if args[2] == nil then
  50.                 chatBox.tell(user,"\167Please provide a password to register. NOTE: Your passwords are not stored in plaintext.",name,prefixColor)
  51.             else
  52.                 local file = fs.open("users","a")
  53.                 local input = tostring(args[2])
  54.                 local hashedPassword = sha256.hash(input)
  55.                 local salt = math.random(1,1000)
  56.                 local password = hashedPassword..salt
  57.                 local newUser =file.writeLine(user.." : "..password)
  58.                 file.close()
  59.             end
  60.  
  61.        
  62.         elseif args[1] == "help" then
  63.            
  64.             if args[2] == nil then
  65.                 chatBox.tell(user,"167rThe following arguments are accepted: \1674\kstlist post, \kstlist read",name,prefixColor)
  66.             end
  67.        
  68.         elseif args[1] == nil then
  69.             chatBox.tell(user,"\167rInsufficient arguments, \1674\\kristlist help <command> \167r for more information on how to use kristlist",name,prefixColor)        
  70.         else
  71.             chatBox.tell(user,"\167rInvalid argument, \1674\\kristlist help <command> \167r for more information on how to use kristlist",name,prefixColor)
  72.         end    
  73.     end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement