MarcosKoco

TRC_Server

Jun 5th, 2021 (edited)
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.22 KB | None | 0 0
  1. -- Turtle Remote Controle Server
  2.  
  3. -- Minecraft 1.16.5
  4. -- Forge 36.1.66
  5. -- Mod: cc-tweaked-1.16.4-1.96.0.jar
  6.  
  7. local Version = "1.0.5"
  8.  
  9. local System = os -- Used for System things like os.time() to System.time()
  10. local Screen = term -- Used for Screen thing on the turtle or computer like term.clear() to Screen.clear()
  11. local Per = peripheral -- Used shortcut for peripheral
  12. local Text = textutils -- Used shortcut for textilils
  13. local Pack = Text.serialize -- Makes a new command for packing ( shortcut used from local Text)
  14. local UnPack = Text.unserialize -- Makes a new command for unpacking ( shortcut used from local Text)
  15.  
  16. local Monitor = {}
  17.  
  18. Monitor[0] = Screen -- sets Monitor[0] to term
  19.  
  20. local file = fs.exists("/API/Logo.lua")
  21.  
  22. if not(file) then
  23.  
  24.     shell.run("pastebin get s3aBGUVr /API/Logo.lua")
  25.    
  26.     Monitor[0].clear()
  27.     Monitor[0].setCursorPos(1,1)
  28.    
  29. end
  30.  
  31. System.loadAPI("/API/Logo.lua")
  32.  
  33. local w, h = Monitor[0].getSize()
  34.  
  35. Monitor[0].clear()
  36.  
  37. Logo.drawLogo(Monitor[0], "Head", math.floor(w/2)-6, math.floor(h/2)-4)
  38.  
  39. Monitor[0].setCursorPos(1, (h-1))
  40. Monitor[0].clearLine()
  41. Monitor[0].setBackgroundColor(colors.white)
  42. Monitor[0].setTextColor(colors.black)
  43. Monitor[0].setCursorPos(math.floor((w - string.len("Looking for file...")) /2), (h-1))
  44.  
  45. print("Looking for files...")
  46.  
  47. local file0 = fs.exists("/API/Functions.lua")
  48. local file1 = fs.exists("/API/Button.lua")
  49. local file2 = fs.exists("/API/MonButton.lua")
  50.  
  51. Monitor[0].setBackgroundColor(colors.black)
  52. Monitor[0].setTextColor(colors.white)
  53.  
  54. sleep(1)
  55.  
  56. if not(file0) then
  57.    
  58.     Monitor[0].setCursorPos(1, (h-1))
  59.     Monitor[0].clearLine()
  60.     Monitor[0].setBackgroundColor(colors.white)
  61.     Monitor[0].setTextColor(colors.black)
  62.     Monitor[0].setCursorPos(math.floor((w - string.len("Downloading Function file...")) /2), (h-1))
  63.  
  64.     print("Downloading Function file...")
  65.    
  66.     shell.run("pastebin get sujHjqXC /API/Functions.lua")
  67.    
  68.     Monitor[0].setBackgroundColor(colors.black)
  69.     Monitor[0].setTextColor(colors.white)
  70.    
  71.     sleep(1)
  72.    
  73. end
  74.  
  75. if not(file1) then
  76.    
  77.     Monitor[0].setCursorPos(1, (h-1))
  78.     Monitor[0].clearLine()
  79.     Monitor[0].setBackgroundColor(colors.white)
  80.     Monitor[0].setTextColor(colors.black)
  81.     Monitor[0].setCursorPos(math.floor((w - string.len("Downloading Button file...")) /2), (h-1))
  82.  
  83.     print("Downloading Button file...")
  84.    
  85.     shell.run("pastebin get mKpxpWmZ /API/Button.lua")
  86.    
  87.     Monitor[0].setBackgroundColor(colors.black)
  88.     Monitor[0].setTextColor(colors.white)
  89.    
  90.     sleep(1)
  91.    
  92. end
  93.  
  94. if not(file2) then
  95.    
  96.     Monitor[0].setCursorPos(1, (h-1))
  97.     Monitor[0].clearLine()
  98.     Monitor[0].setBackgroundColor(colors.white)
  99.     Monitor[0].setTextColor(colors.black)
  100.     Monitor[0].setCursorPos(math.floor((w - string.len("Downloading Monitor Button file...")) /2), (h-1))
  101.  
  102.     print("Downloading Monitor Button file...")
  103.    
  104.     shell.run("pastebin get mKpxpWmZ /API/MonButton.lua")
  105.    
  106.     Monitor[0].setBackgroundColor(colors.black)
  107.     Monitor[0].setTextColor(colors.white)
  108.    
  109.     sleep(1)
  110.    
  111. end
  112.  
  113. Monitor[0].clear()
  114.  
  115. Logo.drawLogo(Monitor[0], "Head", math.floor(w/2)-6, math.floor(h/2)-4)
  116.  
  117. Monitor[0].setCursorPos(1, (h-1))
  118. Monitor[0].clearLine()
  119. Monitor[0].setBackgroundColor(colors.white)
  120. Monitor[0].setTextColor(colors.black)
  121. Monitor[0].setCursorPos(math.floor((w - string.len("Installing files...")) /2), (h-1))
  122.  
  123. print("Installing files...")
  124.  
  125. System.loadAPI("/API/Functions.lua")
  126. System.loadAPI("/API/Button.lua")
  127. System.loadAPI("/API/MonButton.lua")
  128.  
  129. Button.setMonitor(false)
  130.  
  131. Functions.SetColors(Monitor[0], colors.black, colors.white)
  132.  
  133. sleep(1)
  134.  
  135. Monitor[0].setCursorPos(1, (h-1))
  136. Monitor[0].clearLine()
  137.  
  138. local Disk = Functions.FindDisk()
  139.  
  140. sleep(1)
  141.  
  142. if Disk then
  143.    
  144.     Monitor[0].setCursorPos(1, (h-1))
  145.     Monitor[0].clearLine()
  146.     Functions.SetColors(Monitor[0], colors.white, colors.black)
  147.     Monitor[0].setCursorPos(math.floor((w - string.len("Installing Disk...")) /2), (h-1))
  148.    
  149.     print("Installing Disk...")
  150.    
  151.     Disk = Per.wrap(Disk)
  152.    
  153.     Functions.SetColors(Monitor[0], colors.black, colors.white)
  154.    
  155.     sleep(1)
  156.    
  157. end
  158.  
  159. Monitor[0].setCursorPos(1, (h-1))
  160. Monitor[0].clearLine()
  161.  
  162. local Modem = Functions.FindModem()
  163.  
  164. sleep(1)
  165.  
  166. if Modem then
  167.    
  168.     Monitor[0].setCursorPos(1, (h-1))
  169.     Monitor[0].clearLine()
  170.     Functions.SetColors(Monitor[0], colors.white, colors.black)
  171.     Monitor[0].setCursorPos(math.floor((w - string.len("Installing Modem...")) /2), (h-1))
  172.    
  173.     print("Installing Modem...")
  174.    
  175.     Modem = Per.wrap(Modem)
  176.    
  177.     Modem.Send = Modem.transmit
  178.     Modem.closeAll()
  179.    
  180.     Functions.SetColors(Monitor[0], colors.black, colors.white)
  181.    
  182.     sleep(1)
  183.    
  184. end
  185.  
  186. Monitor[0].setCursorPos(1, (h-1))
  187. Monitor[0].clearLine()
  188.  
  189. local WModem = Functions.FindWirelessModem()
  190.  
  191. sleep(1)
  192.  
  193. if WModem then
  194.    
  195.     Monitor[0].setCursorPos(1, (h-1))
  196.     Monitor[0].clearLine()
  197.     Functions.SetColors(Monitor[0], colors.white, colors.black)
  198.     Monitor[0].setCursorPos(math.floor((w - string.len("Installing Wireless Modem...")) /2), (h-1))
  199.  
  200.     print("Installing Wireless Modem...")
  201.    
  202.     WModem = Per.wrap(WModem)
  203.    
  204.     WModem.Send = WModem.transmit
  205.     WModem.closeAll()
  206.    
  207.     Functions.SetColors(Monitor[0], colors.black, colors.white)
  208.    
  209.     sleep(1)
  210.    
  211. end
  212.  
  213. Monitor[0].setCursorPos(1, (h-1))
  214. Monitor[0].clearLine()
  215.  
  216. Monitor[1] = Functions.FindMonitor()
  217.  
  218. sleep(1)
  219.  
  220. if Monitor[1] then
  221.    
  222.     Monitor[0].setCursorPos(1, (h-1))
  223.     Monitor[0].clearLine()
  224.     Functions.SetColors(Monitor[0], colors.white, colors.black)
  225.     Monitor[0].setCursorPos(math.floor((w - string.len("Installing Monitor...")) /2), (h-1))
  226.  
  227.     print("Installing Monitor...")
  228.    
  229.     Monitor[1] = Per.wrap(Monitor[1])
  230.    
  231.     MonButton.setMonitor(true)
  232.    
  233.     Functions.SetColors(Monitor[0], colors.black, colors.white)
  234.    
  235.     local mw, mh = Monitor[1].getSize()
  236.    
  237.     Logo.drawLogo(Monitor[1], "Head", math.floor(mw/2)-6, math.floor(mh/2)-3)
  238.    
  239.     sleep(1)
  240.    
  241. end
  242.  
  243. Monitor[0].setCursorPos(1, (h-1))
  244. Monitor[0].clearLine()
  245.  
  246. local Printer = Functions.FindPrinter()
  247.  
  248. sleep(1)
  249.  
  250. if Printer then
  251.    
  252.     Monitor[0].setCursorPos(1, (h-1))
  253.     Monitor[0].clearLine()
  254.     Functions.SetColors(Monitor[0], colors.white, colors.black)
  255.     Monitor[0].setCursorPos(math.floor((w - string.len("Installing Printer...")) /2), (h-1))
  256.  
  257.     print("Installing Printer...")
  258.    
  259.     Printer = Per.wrap(Printer)
  260.    
  261.     Functions.SetColors(Monitor[0], colors.black, colors.white)
  262.    
  263.     sleep(1)
  264.    
  265. end
  266.  
  267. Monitor[0].setCursorPos(1, (h-1))
  268. Monitor[0].clearLine()
  269.  
  270. local Speaker = Functions.FindSpeaker()
  271.  
  272. sleep(1)
  273.  
  274. if Speaker then
  275.    
  276.     Monitor[0].setCursorPos(1, (h-1))
  277.     Monitor[0].clearLine()
  278.     Functions.SetColors(Monitor[0], colors.white, colors.black)
  279.     Monitor[0].setCursorPos(math.floor((w - string.len("Installing Speaker...")) /2), (h-1))
  280.  
  281.     print("Installing Speaker...")
  282.    
  283.     Speaker = Per.wrap(Speaker)
  284.    
  285.     Functions.SetColors(Monitor[0], colors.black, colors.white)
  286.    
  287.     sleep(1)
  288.    
  289. end
  290.  
  291. Monitor[0].setCursorPos(1, (h-1))
  292. Monitor[0].clearLine()
  293.  
  294.  
  295. Monitor[0].setCursorPos(1, (h-1))
  296. Monitor[0].clearLine()
  297. Functions.SetColors(Monitor[0], colors.white, colors.black)
  298. Monitor[0].setCursorPos(math.floor((w - string.len("Done")) /2), (h-1))
  299.  
  300. print("Done")
  301.  
  302. Functions.SetColors(Monitor[0], colors.black, colors.white)
  303.  
  304. sleep(1)
  305.  
  306. local Server = {System = {ServerName = "Server 01",
  307.                             Status = true,
  308.                             Modem = {ServerID = 0,
  309.                                     HeadServerID = 0,
  310.                                     foundWireless = false,
  311.                                     },
  312.                             First = true,
  313.                             NetherServer = false,
  314.                             NetherServerState = false,
  315.                             Farms = {Normale = {Overworld = {},
  316.                                                 Nether = {},
  317.                                                 },
  318.                                     TreeFarm = {},
  319.                                     },
  320.                            
  321.                             },
  322.                 }
  323.  
  324. local Turtles = {}
  325. local NetherTurtles = {}
  326.  
  327. local BlackListedDigging = {}
  328. local OreLib = {}
  329.  
  330.  
  331. local Temp = {}
  332.  
  333. local Color = { Green = colors.green,
  334.                 Red = colors.red,
  335.                 Black = colors.black,
  336.                 White = colors.white,
  337.                 Orange = colors.orange,
  338.                 Magenta = colors.magenta,
  339.                 LightBlue = colors.lightBlue,
  340.                 Yellow = colors.yellow,
  341.                 Lime = colors.lime,
  342.                 Pink = colors.pink,
  343.                 Gray = colors.gray,
  344.                 LightGray = colors.lightGray,
  345.                 Cyan = colors.cyan,
  346.                 Purple = colors.purple,
  347.                 Blue = colors.blue,
  348.                 Brown = colors.brown,
  349.                 }
  350.  
  351.  
  352. function Load()
  353.    
  354.     if not(Monitor[1]) then
  355.        
  356.         print("No Monitor Found !")
  357.         error()
  358.        
  359.     end
  360.    
  361.     if not(Printer) then
  362.        
  363.         print("No Printer Found !")
  364.         error()
  365.        
  366.     end
  367.    
  368.     if not(WModem) then
  369.        
  370.         print("No WirelessModem Found !")
  371.         error()
  372.        
  373.     end
  374.    
  375. end
  376.  
  377. function LoadOreLib()
  378.    
  379.     local File = fs.exists("/OS/.Data/.OreLib.txt")
  380.    
  381.     while not(File) do
  382.        
  383.         shell.run("pastebin get f8Pw0Ya2 /OS/.Data/.OreLib.txt")
  384.         File = fs.exists("/OS/.Data/.OreLib.txt")
  385.        
  386.     end
  387.    
  388.     OreLib = Functions.LoadFile("/OS/.Data/.OreLib.txt")
  389.    
  390. end
  391.  
  392. function SaveOreLib(SaveData)
  393.    
  394.     local Map = fs.exists("/OS/.Data")
  395.    
  396.     if not(Map) then
  397.        
  398.         fs.makeDir("/OS/.Data")
  399.        
  400.     end
  401.    
  402.     Functions.SaveFile("/OS/.Data/.OreLib.txt", "w", SaveData)
  403.    
  404. end
  405.  
  406. function LoadBlackListedDigging()
  407.    
  408.     local File = fs.exists("/OS/.Data/.BlackListedDigging.txt")
  409.    
  410.     while not(File) do
  411.        
  412.         shell.run("pastebin get TYtxwFZp /OS/.Data/.BlackListedDigging.txt")
  413.         File = fs.exists("/OS/.Data/.BlackListedDigging.txt")
  414.        
  415.     end
  416.    
  417.     BlackListedDigging = Functions.LoadFile("/OS/.Data/.BlackListedDigging.txt")
  418.    
  419. end
  420.  
  421. function SaveBlackListedDigging(SaveData)
  422.    
  423.     local Map = fs.exists("/OS/.Data")
  424.    
  425.     if not(Map) then
  426.        
  427.         fs.makeDir("/OS/.Data")
  428.        
  429.     end
  430.    
  431.     Functions.SaveFile("/OS/.Data/.BlackListedDigging.txt", "w", SaveData)
  432.    
  433. end
  434.  
  435. function SaveLand(SaveData)
  436.    
  437.     print("Saving Land")
  438.    
  439.     local Map = fs.exists("/OS/.Data/.Lands")
  440.    
  441.     if not(Map) then
  442.        
  443.         fs.makeDir("/OS/.Data/.Lands")
  444.        
  445.     end
  446.    
  447.     if SaveData.What == "Normale" then
  448.        
  449.         local T = Server.System.Farms.Normale.Overworld
  450.         local F = #T + 1
  451.         table.insert(Server.System.Farms.Normale.Overworld, F, SaveData)
  452.         Functions.SaveFile("/OS/.Data/.Lands/."..F..".frm", "w", SaveData)
  453.         Functions.SaveFile("/OS/.Data/.Lands/.Count.cou", "w", F)
  454.        
  455.     elseif SaveData.What == "Nether" then
  456.        
  457.         local T = Server.System.Farms.Normale.Nether
  458.         local N = #T + 1
  459.         table.insert(Server.System.Farms.Normale.Nether, N, SaveData)
  460.         Functions.SaveFile("/OS/.Data/.Lands/.N"..N..".frm", "w", SaveData)
  461.         Functions.SaveFile("/OS/.Data/.Lands/.NCount.cou", "w", N)
  462.        
  463.     end
  464.    
  465. end
  466.  
  467. function LoadLand()
  468.    
  469.     print("Loading Land")
  470.    
  471.     local Max = 0
  472.     local NMax = 0
  473.    
  474.     Server.System.Farms.Normale.Overworld = {}
  475.     Server.System.Farms.Normale.Nether = {}
  476.    
  477.     local Map = fs.exists("/OS/.Data/.Lands")
  478.    
  479.     if not(Map) then
  480.        
  481.         fs.makeDir("/OS/.Data/.Lands")
  482.        
  483.     end
  484.    
  485.     local File1 = fs.exists("/OS/.Data/.Lands/.Count.cou")
  486.     local File2 = fs.exists("/OS/.Data/.Lands/.NCount.cou")
  487.    
  488.     if File1 then
  489.        
  490.         Max = Functions.LoadFile("/OS/.Data/.Lands/.Count.cou")
  491.        
  492.     end
  493.    
  494.     if File2 then
  495.        
  496.         NMax = Functions.LoadFile("/OS/.Data/.Lands/.NCount.cou")
  497.        
  498.     end
  499.    
  500.     if Max ~= 0 then
  501.        
  502.         for i = 1, Max do
  503.            
  504.             local Data = Functions.LoadFile("/OS/.Data/.Lands/."..i..".frm")
  505.            
  506.             table.insert(Server.System.Farms.Normale.Overworld, i, Data)
  507.            
  508.         end
  509.        
  510.     end
  511.    
  512.     if NMax ~= 0 then
  513.        
  514.         for i = 1, NMax do
  515.            
  516.             local Data = Functions.LoadFile("/OS/.Data/.Lands/.N"..i..".frm")
  517.            
  518.             table.insert(Server.System.Farms.Normale.Nether, i, Data)
  519.            
  520.         end
  521.        
  522.     end
  523.    
  524. end
  525.  
  526.  
  527. function SaveTreeFarm()
  528.    
  529.     print("Saving Tree Farm")
  530.    
  531.     local Map = fs.exists("/OS/.Data/.TreeFarm")
  532.    
  533.     if not(Map) then
  534.        
  535.         fs.makeDir("/OS/.Data/.TreeFarm")
  536.        
  537.     end
  538.    
  539.     Functions.SaveFile("/OS/.Data/.TreeFarm/.TreeFarm.cor", "w", Server.System.Farms.TreeFarm)
  540.    
  541. end
  542.  
  543. function LoadTreeFarm()
  544.    
  545.     print("Loading Tree Farm")
  546.    
  547.     local Map = fs.exists("/OS/.Data/.TreeFarm")
  548.    
  549.     if not(Map) then
  550.        
  551.         fs.makeDir("/OS/.Data/.TreeFarm")
  552.        
  553.     end
  554.    
  555.     local File1 = fs.exists("/OS/.Data/.TreeFarm/.TreeFarm.cor")
  556.    
  557.     if File1 then
  558.        
  559.         Server.System.Farms.TreeFarm = Functions.LoadFile("/OS/.Data/.TreeFarm/.TreeFarm.cor")
  560.        
  561.     end
  562.    
  563. end
  564.  
  565.  
  566. function Asking()
  567.    
  568.     Screen.clear()
  569.     Screen.setCursorPos(1, 1)
  570.     print("Welcome :-D")
  571.     print(" ")
  572.     write("Server name: ")
  573.     Server.System.ServerName = read()
  574.     write("ServerId: ")
  575.     Server.System.Modem.ServerID = tonumber(read())
  576.    
  577.     write("NetherServer Y/N: ")
  578.    
  579.     local Event, Key, IsHeld = System.pullEvent("key")
  580.    
  581.     if Key == keys.y then
  582.        
  583.         Server.System.NetherServer = true
  584.        
  585.     else
  586.        
  587.         Server.System.NetherServer = false
  588.        
  589.     end
  590.    
  591.     print(" ")
  592.    
  593.     if Server.System.NetherServer == true then
  594.        
  595.         write("HeadServer ID: ")
  596.         Server.System.Modem.HeadServerID = tonumber(read())
  597.        
  598.     end
  599.    
  600.    
  601.    
  602. end
  603.  
  604. function LoadSettings()
  605.    
  606.     print("Loading Settings")
  607.    
  608.     local File = fs.exists("/OS/.Data/.Settings.set")
  609.     local Data
  610.    
  611.     if File then
  612.        
  613.         Data = Functions.LoadFile("/OS/.Data/.Settings.set")
  614.        
  615.         Server.System.First = Data.First
  616.         Server.System.Modem.HeadServerID = Data.HeadServer
  617.         Server.System.Modem.ServerID = Data.ServerId
  618.         Server.System.NetherServer = Data.NetherServer
  619.         Server.System.ServerName = Data.ComputerName
  620.        
  621.     else
  622.        
  623.         if Server.System.First == true then
  624.            
  625.             Asking()
  626.            
  627.             Server.System.First = false
  628.            
  629.         end
  630.        
  631.         SaveSettings()
  632.        
  633.     end
  634.    
  635. end
  636.  
  637. function SaveSettings()
  638.    
  639.     print("Saving Settings")
  640.    
  641.     local Data = {First = Server.System.First, ComputerName = Server.System.ServerName, HeadServer = Server.System.Modem.HeadServerID, ServerId = Server.System.Modem.ServerID, NetherServer = Server.System.NetherServer}
  642.    
  643.     local Map = fs.exists("/OS/.Data")
  644.    
  645.     if not(Map) then
  646.        
  647.         fs.makeDir("/OS/.Data")
  648.        
  649.     end
  650.    
  651.     Functions.SaveFile("/OS/.Data/.Settings.set", "w", Data)
  652.    
  653. end
  654.  
  655. function Startup()
  656.    
  657.     CheckVersion()
  658.    
  659.     System.setComputerLabel(Server.System.ServerName)
  660.    
  661.     LoadSettings()
  662.    
  663.     Load()
  664.    
  665.     LoadBlackListedDigging()
  666.     LoadLand()
  667.     LoadTreeFarm()
  668.    
  669.     WModem.closeAll() -- Closes all channels
  670.     WModem.open(Server.System.Modem.ServerID) -- Opens the givin id channel from local ServerID
  671.    
  672.     Monitor[1].clear()
  673.    
  674.     if Server.System.NetherServer then
  675.        
  676.         sleep(2)
  677.        
  678.         local Data = {What = "Command", Command = "/N3TH3RCH3CK1N/"}
  679.        
  680.         WModem.Send(Server.System.Modem.HeadServerID, Sever.System.Modem.ServerID, Pack(Data))
  681.        
  682.     end
  683.    
  684. end
  685.  
  686. function CheckVersion()
  687.    
  688.     local NewServerVersion
  689.    
  690.     Temp.OldVersion = {}
  691.     Temp.OldVersion.A = tonumber(string.sub (Version, 1, 1))
  692.     Temp.OldVersion.B = tonumber(string.sub (Version, 3, 3))
  693.     Temp.OldVersion.C = tonumber(string.sub (Version, 5, 5))
  694.    
  695.     file = fs.exists("/OS/.Version.txt")
  696.    
  697.     if file then
  698.        
  699.         Functions.DelFile("/OS/.Version.txt")
  700.         shell.run("pastebin get TesjGu7s /OS/.Version.txt")
  701.        
  702.         NewServerVersion = Functions.LoadFile("/OS/.Version.txt")
  703.        
  704.         Temp.NewVersion = {}
  705.         Temp.NewVersion.A = tonumber(string.sub(NewServerVersion, 1, 1))
  706.         Temp.NewVersion.B = tonumber(string.sub(NewServerVersion, 3, 3))
  707.         Temp.NewVersion.C = tonumber(string.sub(NewServerVersion, 5, 5))
  708.        
  709.         if Temp.NewVersion.A == nil or Temp.NewVersion.B == nil or Temp.NewVersion.C == nil or Temp.NewVersion.A > Temp.OldVersion.A or Temp.NewVersion.B > Temp.OldVersion.B or Temp.NewVersion.C > Temp.OldVersion.C then
  710.            
  711.             file = fs.exists("/OS/.Menu.lua")
  712.            
  713.             if file then
  714.                
  715.                 Functions.DelFile("/OS/.Menu.lua")
  716.                
  717.             end
  718.            
  719.             shell.run("pastebin get 2w6RkVHv /OS/.Menu.lua")
  720.            
  721.             Monitor[0].clear()
  722.             Text = "Rebooting..."
  723.             Monitor[0].setCursorPos((w - string.len(Text)) /2, (h/2) + 1)
  724.             Monitor[0].write(Text)
  725.             sleep(3)
  726.            
  727.             System.reboot()
  728.            
  729.         end
  730.        
  731.     else
  732.        
  733.         shell.run("pastebin get TesjGu7s /OS/.Version.txt")
  734.        
  735.         NewServerVersion = Functions.LoadFile("/OS/.Version.txt")
  736.        
  737.         Temp.NewVersion = {}
  738.         Temp.NewVersion.A = tonumber(string.sub(NewServerVersion, 1, 1))
  739.         Temp.NewVersion.B = tonumber(string.sub(NewServerVersion, 3, 3))
  740.         Temp.NewVersion.C = tonumber(string.sub(NewServerVersion, 5, 5))
  741.        
  742.         if Temp.NewVersion.A == nil or Temp.NewVersion.B == nil or Temp.NewVersion.C == nil or Temp.NewVersion.A > Temp.OldVersion.A or Temp.NewVersion.B > Temp.OldVersion.B or Temp.NewVersion.C > Temp.OldVersion.C then
  743.            
  744.             file = fs.exists("/OS/.Menu.lua")
  745.            
  746.             if file then
  747.                
  748.                 Functions.DelFile("/OS/.Menu.lua")
  749.                
  750.             end
  751.            
  752.             shell.run("pastebin get 2w6RkVHv /OS/.Menu.lua")
  753.            
  754.             Monitor[0].clear()
  755.             Text = "Rebooting..."
  756.             Monitor[0].setCursorPos((w - string.len(Text)) /2, (h/2) + 1)
  757.             Monitor[0].write(Text)
  758.             sleep(3)
  759.            
  760.             System.reboot()
  761.            
  762.         end
  763.        
  764.     end
  765.    
  766. end
  767.  
  768. Monitor[0].clear()
  769. Monitor[0].setCursorPos(1, 1)
  770.  
  771. Startup()
  772.  
  773. Monitor[1].setTextScale(1)
  774.  
  775. local mw, mh = Monitor[1].getSize()
  776.  
  777. local NameLen = 8
  778.  
  779. local nHeadOption = 1
  780. local MaxHeadOptions = 3
  781.  
  782. function drawScreen()
  783.    
  784.     Monitor[0].clear()
  785.    
  786.     Logo.drawLogo(Monitor[0], "Sub", 1, 1)
  787.    
  788.     Functions.SetTitle(Monitor[0], Server.System.ServerName)
  789.    
  790.     Functions.printCentered(Monitor[0], math.floor(h/2) -3, Functions.PadString(" Head Menu",NameLen+8))
  791.    
  792.     if nHeadOption == 1 then
  793.        
  794.         Functions.SetColors(Monitor[0], Color.White, Color.Black)
  795.        
  796.     else
  797.        
  798.         Functions.SetColors(Monitor[0], Color.Black, Color.White)
  799.        
  800.     end
  801.    
  802.     Functions.printCenteredNC(Monitor[0], math.floor(h/2) -1, Functions.PadString(" Nothing",NameLen+8))
  803.    
  804.     if nHeadOption == 2 then
  805.        
  806.         Functions.SetColors(Monitor[0], Color.White, Color.Black)
  807.        
  808.     else
  809.        
  810.         Functions.SetColors(Monitor[0], Color.Black, Color.White)
  811.        
  812.     end
  813.    
  814.     Functions.printCenteredNC(Monitor[0], math.floor(h/2) +0, Functions.PadString(" Reset",NameLen+8))
  815.    
  816.     if nHeadOption == 3 then
  817.        
  818.         Functions.SetColors(Monitor[0], Color.White, Color.Black)
  819.        
  820.     else
  821.        
  822.         Functions.SetColors(Monitor[0], Color.Black, Color.White)
  823.        
  824.     end
  825.    
  826.     Functions.printCenteredNC(Monitor[0], math.floor(h/2) +1, Functions.PadString(" Uninstall",NameLen+8))
  827.    
  828.     Functions.SetColors(Monitor[0], Color.White, Color.Black)
  829.    
  830.     Monitor[0].setCursorPos(1, h)
  831.     Monitor[0].write("Press 'Q' to quit.")
  832.    
  833.     Functions.SetColors(Monitor[0], Color.Black, Color.White)
  834.    
  835. end
  836.  
  837. function drawMonitor()
  838.    
  839.     Functions.SetColors(Monitor[1], Color.Black, Color.White)
  840.    
  841.     Monitor[1].clear()
  842.    
  843.     Functions.SetTitle(Monitor[1], Server.System.ServerName)
  844.     Functions.printCentered(Monitor[1], 2, "")
  845.     Functions.printCentered(Monitor[1], 3, Functions.PadString("Name:", NameLen+8)..Functions.PadString("ID:", NameLen)..Functions.PadString("Free:", NameLen)..Functions.PadString("Cor:", NameLen+5)..Functions.PadString("Fuel:", NameLen)..Functions.PadString("ToGo:", NameLen)..Functions.PadString("doing:", NameLen+5))
  846.     Functions.printCentered(Monitor[1], 4, "")
  847.    
  848.     local A = 5
  849.    
  850.     for i = 1, #Turtles do
  851.        
  852.         if Turtles[i].LTG == nil then
  853.            
  854.             Turtles[i].LTG = 0
  855.            
  856.         end
  857.        
  858.         if Turtles[i].Status then
  859.            
  860.             Functions.SetColors(Monitor[1], Color.Black, Color.Lime)
  861.            
  862.         else
  863.            
  864.             Functions.SetColors(Monitor[1], Color.Black, Color.Red)
  865.            
  866.         end
  867.        
  868.         Functions.printCentered(Monitor[1], A, Functions.PadString(tostring(Turtles[i].Name), NameLen+8)..Functions.PadString(tostring(Turtles[i].Id), NameLen)..Functions.PadString(tostring(Turtles[i].Status), NameLen)..Functions.PadString(tostring(Turtles[i].Cor.X.." "..Turtles[i].Cor.Y.." "..Turtles[i].Cor.Z), NameLen+5)..Functions.PadString(tostring(Turtles[i].FuelLevel), NameLen)..Functions.PadString(tostring(Turtles[i].LTG), NameLen)..Functions.PadString(tostring(Turtles[i].Doing), NameLen+5))
  869.        
  870.         A = A + 1
  871.        
  872.         Functions.SetColors(Monitor[1], Color.Black, Color.White)
  873.        
  874.     end
  875.    
  876.     if Server.System.NetherServerState then
  877.        
  878.         A = A + 1
  879.        
  880.         Functions.printCentered(Monitor[1], A, "Nether")
  881.        
  882.         A = A + 2
  883.        
  884.         for i = 1, #NetherTurtles do
  885.            
  886.             if NetherTurtles[i].LTG == nil then
  887.                
  888.                 NetherTurtles[i].LTG = 0
  889.                
  890.             end
  891.            
  892.             if NetherTurtles[i].Status then
  893.                
  894.                 Functions.SetColors(Monitor[1], Color.Black, Color.Lime)
  895.                
  896.             else
  897.                
  898.                 Functions.SetColors(Monitor[1], Color.Black, Color.Red)
  899.                
  900.             end
  901.            
  902.             Functions.printCentered(Monitor[1], A, Functions.PadString(tostring(NetherTurtles[i].Name), NameLen+8)..Functions.PadString(tostring(NetherTurtles[i].Id), NameLen)..Functions.PadString(tostring(NetherTurtles[i].Status), NameLen)..Functions.PadString(tostring(NetherTurtles[i].Cor.X.." "..NetherTurtles[i].Cor.Y.." "..NetherTurtles[i].Cor.Z), NameLen+5)..Functions.PadString(tostring(NetherTurtles[i].FuelLevel), NameLen)..Functions.PadString(tostring(NetherTurtles[i].LTG), NameLen)..Functions.PadString(tostring(NetherTurtles[i].Doing), NameLen+5))
  903.            
  904.             A = A + 1
  905.            
  906.             Functions.SetColors(Monitor[1], Color.Black, Color.White)
  907.            
  908.         end
  909.        
  910.     end
  911.    
  912.     if Server.System.NetherServer then
  913.        
  914.         local Data = {What = "Command", Command = "/N3TH3RUPD4T3/", Data = Turtles}
  915.        
  916.         WModem.Send(Server.System.HeadServerID, Server.System.ServerID, Pack(Data))
  917.        
  918.     end
  919.    
  920. end
  921.  
  922. while Server.System.Status do
  923.    
  924.     drawScreen()
  925.     drawMonitor()
  926.    
  927.     local Event, p1, p2, p3, p4, p5 = System.pullEvent()
  928.    
  929.     if Event == "modem_message" then
  930.        
  931.         local Data = UnPack(p4)
  932.        
  933.         if Data.What == "Command" then
  934.            
  935.             if Data.Command == "/CH3CK1N/" then
  936.                
  937.                 local Deta = {Name = Data.Dita.Name, Id = p3, Status = false, Cor = Data.Dita.Cor, FuelLevel = Data.Dita.FuelLevel, Doing = Data.Dita.Doing, GroupState = Data.Dita.GroupState, Compare = Data.Dita.Compare, Detect = Data.Dita.Detect, Inspect = Data.Dita.Inspect}
  938.                
  939.                 if Turtles[1] == nil then
  940.                    
  941.                     table.insert (Turtles, Deta)
  942.                    
  943.                 else
  944.                    
  945.                     local Already = false
  946.                    
  947.                     for i = 1, #Turtles do
  948.                        
  949.                         if Turtles[i].Id == p3 then
  950.                            
  951.                             Already = true
  952.                            
  953.                         end
  954.                        
  955.                     end
  956.                    
  957.                     if Already == false then
  958.                        
  959.                         local Bigger = false
  960.                        
  961.                         for i = 1, #Turtles do
  962.                            
  963.                             if Turtles[i].Id > p3 then
  964.                                
  965.                                 table.insert (Turtles, i, Deta)
  966.                                 Bigger = true
  967.                                 break
  968.                                
  969.                             end
  970.                            
  971.                         end
  972.                        
  973.                         if Bigger == false then
  974.                            
  975.                             table.insert (Turtles, Deta)
  976.                            
  977.                         end
  978.                        
  979.                     end
  980.                    
  981.                 end
  982.                
  983.             elseif Data.Command == "/N3TH3RCH3CK1N/" then
  984.                
  985.                 Server.System.NetherServerState = true
  986.                
  987.             elseif Data.Command == "/N3TH3RCH3CK0UT/" then
  988.                
  989.                 NetherTurtles = {}
  990.                 Server.System.NetherServerState = false
  991.                
  992.             elseif Data.Command == "/CH3CK0UT/" then
  993.                
  994.                 for i = 1, #Turtles do
  995.                    
  996.                     if Turtles[i].Id == p3 then
  997.                        
  998.                         table.remove (Turtles, i)
  999.                         break
  1000.                        
  1001.                     end
  1002.                    
  1003.                 end
  1004.                
  1005.             elseif Data.Command == "/W0RK1NG/" then
  1006.                
  1007.                 for i = 1, #Turtles do
  1008.                    
  1009.                     if Turtles[i].Id == p3 then
  1010.                        
  1011.                         Turtles[i].Status = false
  1012.                        
  1013.                     end
  1014.                    
  1015.                 end
  1016.                
  1017.             elseif Data.Command == "/FR33/" then
  1018.                
  1019.                 for i = 1, #Turtles do
  1020.                    
  1021.                     if Turtles[i].Id == p3 then
  1022.                        
  1023.                         Turtles[i].Status = true
  1024.                        
  1025.                     end
  1026.                    
  1027.                 end
  1028.                
  1029.             elseif Data.Command == "/CH3CK/" then
  1030.                
  1031.                 WModem.Send(p3, Server.System.Modem.ServerID, Pack(Turtles))
  1032.                
  1033.             elseif Data.Command == "/UPD4T3/" then
  1034.  
  1035.                 local Have = false
  1036.                
  1037.                 if Turtles[1] ~= nil then
  1038.                    
  1039.                     for i = 1, #Turtles do
  1040.                        
  1041.                         if Turtles[i].Id == p3 then
  1042.                            
  1043.                             Turtles[i].Name = Data.Data.Name
  1044.                             Turtles[i].Cor = Data.Data.Cor
  1045.                             Turtles[i].FuelLevel = Data.Data.FuelLevel
  1046.                             Turtles[i].LTG = Data.Data.LTG
  1047.                             Turtles[i].Doing = Data.Data.Doing
  1048.                             Turtles[i].GroupState = Data.Data.GroupState
  1049.                             Turtles[i].Inspect = Data.Data.Inspect
  1050.                             Turtles[i].Compare = Data.Data.Compare
  1051.                             Turtles[i].Detect = Data.Data.Detect
  1052.                             Turtles[i].SlotSelected = Data.Data.SlotSelected
  1053.                             Turtles[i].Slot = Data.Data.Slot
  1054.                             Have = true
  1055.                             break
  1056.                            
  1057.                         end
  1058.                        
  1059.                     end
  1060.                    
  1061.                 end
  1062.                
  1063.                 if not(Have) then
  1064.                    
  1065.                     local Bigger = false
  1066.                    
  1067.                     if Turtles[2] ~= nil then
  1068.                        
  1069.                         for i = 1, #Turtles do
  1070.                            
  1071.                             if Turtles[i].Id > p3 then
  1072.                                
  1073.                                 table.insert (Turtles, i, Data.Data)
  1074.                                 Turtles[i].Id = p3
  1075.                                 Turtles[i].Status = false
  1076.                                 Bigger = true
  1077.                                 break
  1078.                                
  1079.                             end
  1080.                            
  1081.                         end
  1082.                        
  1083.                     end
  1084.                    
  1085.                     if Bigger == false then
  1086.                        
  1087.                         table.insert (Turtles, Data.Data)
  1088.                        
  1089.                         Turtles[#Turtles].Status = false
  1090.                         Turtles[#Turtles].Id = p3
  1091.                        
  1092.                     end
  1093.                    
  1094.                 end
  1095.                
  1096.             elseif Data.Command == "/N3TH3RUPD4T3/" then
  1097.                
  1098.                 if Server.System.NetherServerState == false then
  1099.                    
  1100.                     Server.System.NetherServerState = true
  1101.                    
  1102.                 end
  1103.                
  1104.                 NetherTurtles = Data.Data
  1105.                
  1106.             elseif DataCommand == "/PR1NTL0GST4RT/" then
  1107.                
  1108.                 local NewPageStarted = Printer.newPage()
  1109.                
  1110.                 local i = 1
  1111.                
  1112.                 while not(NewPageStarted) do
  1113.                    
  1114.                     Monitor[0].clear()
  1115.                     Monitor[0].setCursorPos(1, 1)
  1116.                     print("Put Paper and/or Dye in the Printer!!")
  1117.                     read()
  1118.                     NewPageStarted = Printer.newPage()
  1119.                    
  1120.                 end
  1121.                
  1122.                 Printer.setPageTitle("Log's "..tostring(i))
  1123.                
  1124.                 i = i + 1
  1125.                
  1126.                 local l1n3s = 1
  1127.                
  1128.                 local X, Y = Printer.getPageSize()
  1129.                
  1130.                 WModem.Send(p3, Server.System.Modem.ServerID, "R34DY")
  1131.                
  1132.                 local Event, Part1, Id, RId, Message = System.pullEvent("modem_message")
  1133.                
  1134.                 while Message do
  1135.                    
  1136.                     if Message ~= "/D0N3/" then
  1137.                        
  1138.                         Printer.setCursorPos(1, l1n3s)
  1139.                        
  1140.                         Printer.write(Message)
  1141.                    
  1142.                         l1n3s = l1n3s + 1
  1143.                        
  1144.                         if l1n3s > Y then
  1145.                            
  1146.                             EndPage = Printer.endPage()
  1147.                            
  1148.                             while not(EndPage) do
  1149.                                
  1150.                                 EndPage = Printer.endPage()
  1151.                                
  1152.                             end
  1153.                            
  1154.                             if EndPage then
  1155.                                
  1156.                                 NewPageStarted = Printer.newPage()
  1157.                                
  1158.                                 while not(NewPageStarted) do
  1159.                                    
  1160.                                     Monitor[0].clear()
  1161.                                     Monitor[0].setCursorPos(1, 1)
  1162.                                     print("Put Paper and/or Dye in the Printer!!")
  1163.                                     read()
  1164.                                     NewPageStarted = Printer.newPage()
  1165.                                    
  1166.                                 end
  1167.                                
  1168.                                 Printer.setPageTitle("Log's "..tostring(i))
  1169.                                
  1170.                                 i = i + 1
  1171.                                
  1172.                                 l1n3s = 1
  1173.                                
  1174.                             end
  1175.                            
  1176.                         end
  1177.                        
  1178.                         WModem.Send(p3, Server.System.Modem.ServerID, "R34DY")
  1179.                        
  1180.                         Event, Part1, Id, RId, Message = System.pullEvent("modem_message")
  1181.                        
  1182.                     elseif Message == "/D0N3/" then
  1183.                        
  1184.                         EndPage = Printer.endPage()
  1185.                        
  1186.                         while not(EndPage) do
  1187.                            
  1188.                             EndPage = Printer.endPage()
  1189.                            
  1190.                         end
  1191.                        
  1192.                         break
  1193.                        
  1194.                     end
  1195.                    
  1196.                 end
  1197.                
  1198.             elseif Data.Command == "/LoadBlackListedDigging/" then
  1199.                
  1200.                 LoadBlackListedDigging()
  1201.                
  1202.                 WModem.Send(p3, Server.System.Modem.ServerID, Pack(BlackListedDigging))
  1203.                
  1204.             elseif Data.Command == "/SaveBlackListedDigging/" then
  1205.                
  1206.                 SaveBlackListedDigging(Data.Data)
  1207.                 LoadBlackListedDigging()
  1208.                
  1209.             elseif Data.Command == "/LoadOreLib/" then
  1210.                
  1211.                 LoadOreLib()
  1212.                
  1213.                 WModem.Send(p3, Server.System.Modem.ServerID, Pack(OreLib))
  1214.                
  1215.             elseif Data.Command == "/SaveOreLib/" then
  1216.                
  1217.                 SaveOreLib(Data.Data)
  1218.                 LoadOreLib()
  1219.                
  1220.             elseif Data.Command == "/L04DL4ND/" then
  1221.                
  1222.                 LoadLand()
  1223.                
  1224.                 WModem.Send(p3, Server.System.Modem.ServerID, Pack(Server.System.Farms.Normale.Overworld))
  1225.                
  1226.                 WModem.Send(p3, Server.System.Modem.ServerID, Pack(Server.System.Farms.Normale.Nether))
  1227.                
  1228.             elseif Data.Command == "/S4V3L4ND/" then
  1229.                
  1230.                 SaveLand(Data.Data)
  1231.                 LoadLand()
  1232.                
  1233.             elseif Data.Command == "/L04DTR33F4RM/" then
  1234.                
  1235.                 LoadTreeFarm()
  1236.                
  1237.                 WModem.Send(p3, Server.System.Modem.ServerID, Pack(Server.System.Farms.TreeFarm))
  1238.                
  1239.             elseif Data.Command == "/S4V3TR33F4RM/" then
  1240.                
  1241.                 Server.System.Farms.TreeFarm = Data.Data
  1242.                 SaveTreeFarm()
  1243.                
  1244.             end
  1245.            
  1246.         end
  1247.        
  1248.     elseif Event == "key" then
  1249.        
  1250.         if p1 == keys.up or p1 == keys.numPad8 then
  1251.            
  1252.             if nHeadOption > 1 then
  1253.                
  1254.                 nHeadOption = nHeadOption - 1
  1255.                
  1256.             end
  1257.            
  1258.         elseif p1 == keys.down or p1 == keys.numPad2 then
  1259.            
  1260.             if nHeadOption < MaxHeadOptions then
  1261.                
  1262.                 nHeadOption = nHeadOption + 1
  1263.                
  1264.             end
  1265.            
  1266.         elseif p1 == keys.enter or p1 == keys.numPadEnter then
  1267.            
  1268.             if nHeadOption == 1 then
  1269.                
  1270.                
  1271.                
  1272.             elseif nHeadOption == 2 then
  1273.                
  1274.                 Monitor[0].clear()
  1275.                 Functions.printCentered(math.floor(h/2), "Reset Server? ... Y/N")
  1276.                
  1277.                 local Event, p1, p2, p3 = System.pullEvent("key")
  1278.                
  1279.                 if p1 == keys.y then
  1280.                    
  1281.                     local file = fs.exists("/OS/.Data/.Settings.set")
  1282.                    
  1283.                     if file then
  1284.                        
  1285.                         fs.delete("/OS/.Data/.Settings.set")
  1286.                         System.reboot()
  1287.                        
  1288.                     end
  1289.                    
  1290.                 end
  1291.                
  1292.             elseif nHeadOption == 3 then
  1293.                
  1294.                 Monitor[0].clear()
  1295.                 Functions.printCentered(math.floor(h/2), "Run Uninstaller? ... Y/N")
  1296.                
  1297.                 local Event, p1, p2, p3 = System.pullEvent("key")
  1298.                
  1299.                 if p1 == keys.y then
  1300.                    
  1301.                     shell.run("/OS/Unintall.lua")
  1302.                    
  1303.                 end
  1304.                
  1305.             end
  1306.            
  1307.         elseif p1 == keys.q then
  1308.            
  1309.             SaveSettings()
  1310.            
  1311.             Monitor[1].clear()
  1312.            
  1313.             if NetherServer then
  1314.                
  1315.                 WModem.Send(HeadServer, ServerId, "/N3TH3RCH3CK0UT/")
  1316.                
  1317.             end
  1318.            
  1319.             System.shutdown()
  1320.            
  1321.         elseif p1 == keys.slash then
  1322.            
  1323.             SaveSettings()
  1324.            
  1325.             Monitor[1].clear()
  1326.            
  1327.             if NetherServer then
  1328.                
  1329.                 WModem.Send(HeadServer, ServerId, "/N3TH3RCH3CK0UT/")
  1330.                
  1331.             end
  1332.            
  1333.             Server.System.Status = false
  1334.            
  1335.         end
  1336.        
  1337.     end
  1338.    
  1339. end
  1340.  
  1341. Monitor[0].clear()
  1342. Monitor[0].setCursorPos(1, 1)
  1343. print("Type 'Back' to go back to the menu.")
Add Comment
Please, Sign In to add comment