Advertisement
craftyoyo

craftnanny

Oct 16th, 2015
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. -----------------PASTEBINs--------------------------
  4. installer = "Q8ah3K9S"
  5.  
  6. player_module = "rWp0GXDW"
  7. redstone_module = "KkCYWkSU"
  8. fluid_module = "x7K3zUAC"
  9. energy_module = "RxLuZWHp"
  10.  
  11. hash_api = "FLQ68J88"
  12. startup = "KnmEN37h"
  13. ---------------------------------------------
  14. term.clear()
  15. local token = ''
  16. local module_name = ''
  17. local username = ''
  18. local type = ''
  19. local updating = false
  20.  
  21. function draw_text_term(x, y, text, text_color, bg_color)
  22.   term.setTextColor(text_color)
  23.   term.setBackgroundColor(bg_color)
  24.   term.setCursorPos(x,y)
  25.   write(text)
  26. end
  27.  
  28. function draw_line_term(x, y, length, color)
  29.     term.setBackgroundColor(color)
  30.     term.setCursorPos(x,y)
  31.     term.write(string.rep(" ", length))
  32. end
  33.  
  34. function bars()
  35.     draw_line_term(1, 1, 51, colors.lime)
  36.     draw_line_term(1, 19, 51, colors.lime)
  37.     draw_text_term(12, 1, 'CraftNanny Module Installer', colors.gray, colors.lime)
  38.     draw_text_term(17, 19, 'craftnanny.org', colors.gray, colors.lime)
  39. end
  40.  
  41. -- saves current token variable to local text file
  42. function save_config()
  43.   sw = fs.open("config.txt", "w")  
  44.     sw.writeLine(token)
  45.     sw.writeLine(module_name)
  46.     sw.writeLine(username)
  47.     sw.writeLine(type)
  48.   sw.close()
  49. end
  50.  
  51. function load_config()
  52.   sr = fs.open("config.txt", "r")
  53.     token = sr.readLine()
  54.     module_name = sr.readLine()
  55.     username = sr.readLine()
  56.     type = sr.readLine()
  57.   sr.close()
  58. end
  59.  
  60. function launch_module()
  61.   shell.run("CN_module")
  62. end
  63.  
  64. function install_module()
  65.     if type == '1' then
  66.         pastebin = player_module
  67.     else if type == '2' then
  68.         pastebin = energy_module
  69.     else if type == '3' then
  70.         pastebin = fluid_module
  71.     else if type == '4' then
  72.         pastebin = redstone_module
  73.     end
  74.     end
  75.     end
  76.     end
  77.    
  78.     term.clear()
  79.     bars()
  80.     draw_text_term(1, 3, 'successfully logged in', colors.lime, colors.black)
  81.     sleep(0.5)
  82.     draw_text_term(1, 4, 'installing...', colors.white, colors.black)
  83.     sleep(0.5)
  84.    
  85.     draw_text_term(1, 5, 'removing old versions', colors.white, colors.black)
  86.     if fs.exists("CN_module") then
  87.       fs.delete("CN_module")
  88.     end
  89.     sleep(0.5)
  90.    
  91.     draw_text_term(1, 6, 'fetch from pastebin', colors.white, colors.black)
  92.     term.setCursorPos(1,7)
  93.     term.setTextColor(colors.white)
  94.   shell.run("pastebin get "..pastebin.." CN_module")
  95.   sleep(0.5)
  96.  
  97.   draw_text_term(1, 9, 'create startup file', colors.white, colors.black)
  98.     term.setCursorPos(1,10)
  99.     term.setTextColor(colors.white)
  100.   if fs.exists("startup") then
  101.     fs.delete("startup")
  102.   end
  103.   shell.run("pastebin get "..startup.." startup")
  104.   sleep(1)
  105.  
  106.   draw_text_term(1, 13, 'Setup Complete', colors.lime, colors.black)
  107.  
  108.   draw_text_term(1, 14, 'press enter to continue', colors.lightGray, colors.black)
  109.  
  110.   if updating then
  111.  
  112.   else
  113.     input = read()
  114.   end
  115.  
  116.   launch_module()
  117. end
  118.  
  119. function hash(password)
  120.     shell.run("pastebin get "..hash_api.." sha1_api")
  121.     os.loadAPI('sha1_api')
  122.     response = http.post(
  123.                 "http://craftnanny.org/code/salt.php",
  124.                 "user="..user)
  125.     salt = response.readAll()
  126.     hash = sha1_api.sha1(salt..password)
  127.     return hash
  128. end
  129.  
  130. function login()
  131.     term.clear()
  132.     bars()
  133.     draw_text_term(1, 3, 'Register module to your CraftNanny account.', colors.lime, colors.black)
  134.     draw_text_term(1, 4, 'Create an account at www.craftnanny.org', colors.lightGray, colors.black)
  135.    
  136.     draw_text_term(1, 6, 'Username: ', colors.lime, colors.black)
  137.     term.setTextColor(colors.white)
  138.     user = read()
  139.     draw_text_term(1, 7, 'Password: ', colors.lime, colors.black)
  140.     term.setTextColor(colors.white)
  141.     pass = read("*")
  142.    
  143.     password = hash(pass)
  144.    
  145.     response = http.post(
  146.                 "http://craftnanny.org/code/signin.php",
  147.                 "user="..user.."&pass="..password.."&id="..os.getComputerID().."&name="..module_name.."&module_type="..type)
  148.     token = response.readAll()
  149.  
  150.     if token == 'error' then
  151.         draw_text_term(1, 8, 'login failed', colors.red, colors.black)
  152.         sleep(2)
  153.         login()
  154.     else
  155.         username = user
  156.         save_config()
  157.         install_module()
  158.     end
  159. end
  160.  
  161. function name()
  162.     term.clear()
  163.     bars()
  164.    
  165.     draw_text_term(1, 3, 'Give this module a unique name:', colors.lime, colors.black)
  166.     term.setCursorPos(2,4)
  167.     term.setTextColor(colors.white)
  168.     module_name = read()
  169.     os.setComputerLabel(string.gsub(module_name, "%s+", ""))
  170.     login()
  171. end
  172.  
  173. function player_tracker()
  174.    
  175.     -- code to check that openperipheral sensor is present. give relavent error
  176.    
  177.     type = '1'
  178.     name()
  179. end
  180.  
  181. function choose_module(input)
  182.     if input == '1' then
  183.         player_tracker()
  184.     elseif input == '2' then
  185.         type = '2'
  186.         name()
  187.     elseif input == '3' then
  188.         type = '3'
  189.         name()
  190.     elseif input == '4' then
  191.         type = '4'
  192.         name()
  193.     elseif input == '5' then
  194.    
  195.     end
  196.    
  197. end
  198.  
  199. function install_select()
  200.     term.clear()
  201.     bars()
  202.     draw_text_term(15, 3, 'Welcome to CraftNanny!', colors.lime, colors.black)
  203.     draw_text_term(1, 5, 'What module would you like to install?', colors.white, colors.black)
  204.    
  205.     draw_text_term(2, 7, '1. Player Tracking', colors.white, colors.black)
  206.     draw_text_term(2, 8, '2. Energy Monitor', colors.white, colors.black)
  207.     draw_text_term(2, 9, '3. Fluid Monitor', colors.white, colors.black)
  208.     draw_text_term(2, 10, '4. Redstone Controls', colors.white, colors.black)
  209.     draw_text_term(2, 11, '5. Rednet Controls', colors.white, colors.black)
  210.     draw_text_term(1, 13, 'Enter number:', colors.white, colors.black)
  211.     term.setCursorPos(1,14)
  212.     term.setTextColor(colors.white)
  213.     input = read()
  214.    
  215.     choose_module(input)
  216. end
  217.  
  218. function start()
  219.   term.clear()
  220.   if fs.exists("config.txt") then
  221.     load_config()
  222.     updating = true
  223.     install_module()
  224.   else
  225.     install_select()
  226.   end
  227. end
  228.  
  229. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement