Advertisement
BlueMond

MCRegisterServer

Sep 5th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.24 KB | None | 0 0
  1. local version = "1.15"  --change this to allow for an update (3 chars only)
  2. local filename = "MCAuth"  --change this to the name of the file holding this program
  3. local paste = "nGjQhbbZ"  --change this to the pastebin entry code
  4.  
  5. local function update()
  6.         local url = "http://pastebin.com/raw/"..paste
  7.         local temp = http.get(url)
  8.         local ver = string.sub(temp.readLine(), 18, 21)
  9.        
  10.         if ver ~= version then
  11.                 fs.delete(filename)
  12.                 shell.run("pastebin get "..paste.." "..filename)
  13.                 shell.run(filename)
  14.                 return true
  15.         end
  16.        
  17.         return false
  18.        
  19. end
  20.  
  21. --start
  22. if update() then
  23.     error()
  24. end
  25. shell.run("clear")
  26.  
  27. local function insSend()
  28.    
  29. end
  30.  
  31. local function split(str, pat)
  32.    local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  33.    local fpat = "(.-)" .. pat
  34.    local last_end = 1
  35.    local s, e, cap = str:find(fpat, 1)
  36.    while s do
  37.       if s ~= 1 or cap ~= "" then
  38.      table.insert(t,cap)
  39.       end
  40.       last_end = e+1
  41.       s, e, cap = str:find(fpat, last_end)
  42.    end
  43.    if last_end <= #str then
  44.       cap = str:sub(last_end)
  45.       table.insert(t, cap)
  46.    end
  47.    return t
  48. end
  49.  
  50. rednet.open("top")
  51.  
  52. --check for directory
  53. if not fs.exists("USERS") then
  54.     fs.makeDir("USERS")
  55. end
  56.  
  57. --host protocol for id
  58. rednet.host("MCAuth","AuthenticationServer")
  59.  
  60. while true do
  61.     local event, p1, p2, p3 = os.pullEvent()
  62.    
  63.     if event == "rednet_message" and type(p2) == "string" then
  64.         local id = p1
  65.         local msgData = split(p2, ":")
  66.        
  67.         --cut out if not right length
  68.         if msgData[4] ~= nil or msgData[5] == nil then
  69.             if msgData[1] == "$REGISTER$" then
  70.                 --debug
  71.                 print(textutils.serialize(msgData))
  72.                
  73.                 if not fs.exists("USERS/"..msgData[2]) then
  74.                     local file = fs.open("USERS/"..msgData[2], "w")
  75.                    
  76.                     --password
  77.                     file.writeLine(msgData[3])
  78.                     --age
  79.                     file.writeLine(msgData[4])
  80.                     file.close()
  81.                    
  82.                     rednet.send(id, "$REGISTER$:COMPLETE")
  83.                    
  84.                 else
  85.                     rednet.send(id, "$REGISTER$:EXISTS")
  86.                    
  87.                 end
  88.                
  89.             else
  90.                 rednet.send(id, "$REGISTER$:ERROR") --make enums for message codes?
  91.                
  92.             end
  93.        
  94.         else
  95.             rednet.send(id, "$REGISTER$:LENGTH")
  96.            
  97.         end
  98.        
  99.     end
  100.    
  101. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement