Advertisement
Batword

Untitled

Aug 20th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     --[[ Local Variables ]]--
  2.     -- Root Directories & Extentions --
  3.     local Root = ".Network/"
  4.     local iRoot = ".Network/Info/"
  5.      
  6.     --[[ Functions ]]--
  7.     -- Misc --
  8.     function clear()
  9.             term.clear()
  10.             term.setCursorPos(1,1)
  11.     end
  12.      
  13.     function Reset()
  14.             clear()
  15.      term.setTextColor(colors.red)
  16.             write("E-Mail Network")
  17.      term.setTextColor(colors.yellow)
  18.             printTR("- Installer -")
  19.      term.setTextColor(colors.white)
  20.             printTM("[ Client Edition ]")
  21.             w, h = term.getSize()
  22.             print(string.rep("-", w)) write("\n")
  23.     end
  24.      
  25.     function printTR( text )
  26.             w, h = term.getSize()
  27.             term.setCursorPos(w - #text, 1)
  28.             write(text)
  29.     end
  30.      
  31.     function printTM( text )
  32.             local w, h = term.getSize()
  33.             term.setCursorPos((w - #text) / 2, 1)
  34.             write(text)
  35.     end
  36.      
  37.     function printC( text )
  38.             local x, y = term.getSize()
  39.             term.setCursorPos(( x - string.len(text)) / 2, y / 2)
  40.             write( text )
  41.     end
  42.      
  43.     -- Interface --
  44.     Reset()
  45.     term.setTextColor(colors.yellow)
  46.     print("Setting Up Directories...")
  47.     os.sleep(1)
  48.     fs.makeDir(Root)
  49.     fs.makeDir(iRoot)
  50.     print("Getting Needed Files...")
  51.     Network = --[[ Local Variables ]]--
  52. -- Root Directories & Extentions --
  53. local Root = ".Network/"
  54. local iRoot = ".Network/Info/"
  55.  
  56. -- Misc --
  57. local DoNetwork = false
  58. local DoNewMsg = false
  59. Blacklisted = " key == 14 key == 83 or if key == 144 or if key == 145 or if key == 147 or if key == 181or if key == 13 or if key == 43 or if key == 51 or if key == 52 or if key == 53 or if key == 83 or if key == 144 or if key == 145 or if key == 147 or if key == 181"
  60. if fs.exists(iRoot .. "ServerID.txt") then
  61.         sr = fs.open(iRoot .. "ServerID.txt", "r")
  62.         ServerID = sr.readLine() sr.close()
  63.         Server = tonumber(ServerID)
  64.         IsServer = true
  65. end
  66.  
  67. -- Menu Variables --
  68. UseMainMenu = false
  69. UseLoginMenu = false
  70. UseOptionsMenu = false
  71. UseMessagesMenu = false
  72. if fs.exists(iRoot .. "LoggedIn.txt") then
  73.         LoggedIn = true
  74.         ur = fs.open(iRoot .. "LoggedIn.txt", "r")
  75.         UserLI = ur.readLine()
  76.         ur.close()
  77. else
  78.         LoggedIn = false
  79. end
  80.  
  81. --[[ Functions ]]--
  82. -- Misc --
  83. function clear()
  84.         term.clear()
  85.         term.setCursorPos(1,1)
  86. end
  87.  
  88. function ResetL()
  89.         clear()
  90.         term.setTextColor(colors.red)
  91.         write("E-Mail Network")
  92.         term.setTextColor(colors.white)
  93.         w, h = term.getSize()
  94.         print(string.rep("-", w)) write("\n")
  95. end
  96.  
  97. function Reset()
  98.         clear()
  99.         term.setTextColor(colors.red)
  100.         write("E-Mail Network")
  101.         term.setTextColor(colors.yellow)
  102.         printTR(UserLI)
  103.         term.setTextColor(colors.white)
  104.         w, h = term.getSize()
  105.         print(string.rep("-", w)) write("\n")
  106. end
  107.  
  108. function ResetM( text )
  109.         clear()
  110.         term.setTextColor(colors.red)
  111.         write("E-Mail Network")
  112.         term.setTextColor(colors.yellow)
  113.         printTR(UserLI)
  114.         term.setTextColor(colors.white)
  115.         printTM("[ " .. Msg .. " ]")
  116.         x, y = term.getCursorPos()
  117.         term.setTextColor(colors.orange)
  118.         printBM("  ( Press DEL To Delete | Press BACKSPACE To Exit )  ")
  119.         term.setTextColor(colors.white)
  120.         term.setCursorPos(x, y)
  121.         w, h = term.getSize()
  122.         print(string.rep("-", w)) write("\n")
  123. end
  124.  
  125. function ResetS( text )
  126.         clear()
  127.         term.setTextColor(colors.red)
  128.         write("E-Mail Network")
  129.         term.setTextColor(colors.yellow)
  130.         printTR(UserLI)
  131.         x, y = term.getCursorPos()
  132.         term.setTextColor(colors.orange)
  133.         printBM("( Press DELETE To Cancel )")
  134.         term.setTextColor(colors.white)
  135.         term.setCursorPos(x, y)
  136.         w, h = term.getSize()
  137.         print(string.rep("-", w)) write("\n")
  138. end
  139.  
  140. function printTR( text )
  141.         w, h = term.getSize()
  142.         term.setCursorPos(w - #text, 1)
  143.         write(text)
  144. end
  145.  
  146. function printTM( text )
  147.         local w, h = term.getSize()
  148.         term.setCursorPos((w - #text) / 2, 1)
  149.         write(text)
  150. end
  151.  
  152. function printBM( text )
  153.         local w, h = term.getSize()
  154.         term.setCursorPos((w - #text) / 2, h)
  155.         write(text)
  156. end
  157.  
  158. function printC( text )
  159.         local x, y = term.getSize()
  160.         term.setCursorPos(( x - string.len(text)) / 2, y / 2)
  161.         write( text )
  162. end
  163.  
  164. function Exit()
  165.         clear()
  166.         UseMainMenu = false
  167.         UseLoginMenu = false
  168.         UseMessagesMenu = false
  169.         DoNetwork = false
  170. end
  171.  
  172. -- Menu Function --
  173. function PrintMenu( menu )
  174.         for i = 1, #menu do
  175.                 if i == SelectedItem then
  176.                         if menu[i].MessageName then
  177.                                 term.setTextColor(colors.yellow)
  178.                                 print(menu[i].MessageName)
  179.                                 term.setTextColor(colors.white)
  180.                         elseif menu[i].Option then
  181.                                 if menu[i].Option == "Reload Inbox" then
  182.                                         term.setTextColor(colors.yellow)
  183.                                         print("\n" .. menu[i].Option)
  184.                                         term.setTextColor(colors.white)
  185.                                 else
  186.                                         term.setTextColor(colors.yellow)
  187.                                         print(menu[i].Option)
  188.                                         term.setTextColor(colors.white)
  189.                                 end
  190.                         end
  191.                 else
  192.                         if menu[i].MessageName then
  193.                                 term.setTextColor(colors.gray)
  194.                                 print(menu[i].MessageName)
  195.                                 term.setTextColor(colors.white)
  196.                         elseif menu[i].Option then
  197.                                 if menu[i].Option == "Reload Inbox" then
  198.                                         term.setTextColor(colors.gray)
  199.                                         print("\n" .. menu[i].Option)
  200.                                         term.setTextColor(colors.white)
  201.                                 else
  202.                                         term.setTextColor(colors.gray)
  203.                                         print(menu[i].Option)
  204.                                         term.setTextColor(colors.white)
  205.                                 end
  206.                         end
  207.                 end
  208.         end
  209. end
  210.  
  211. function KeyHandler( key, menu )
  212.         if key == 28 then
  213.                 UseOption(menu)
  214.         elseif key == 200 then
  215.                 if SelectedItem > 1 then
  216.                         SelectedItem = SelectedItem - 1
  217.                 else
  218.                         SelectedItem = #menu
  219.                 end
  220.         elseif key == 208 then
  221.                 if SelectedItem < #menu then
  222.                         SelectedItem = SelectedItem + 1
  223.                 else
  224.                         SelectedItem = 1
  225.                 end
  226.         end
  227. end
  228.  
  229. function UseOption( menu )
  230.         if menu[SelectedItem].MessageName then
  231.                 Msg = menu[SelectedItem].MessageName
  232.                 RUser = Messages[SelectedItem].RUser
  233.                 ResetM(Msg)
  234.                 term.setTextColor(colors.yellow)
  235.                 write("From: ") term.setTextColor(colors.white) write(menu[SelectedItem].Sender) term.setTextColor(colors.yellow) write("\nMessage:") term.setTextColor(colors.white) write("\n\n" .. menu[SelectedItem].Message)
  236.                 repeat
  237.                         event, key = os.pullEvent("key")
  238.                         os.sleep(0.1)
  239.                 until key == 14 or key == 211
  240.                 if key == 211 then
  241.                         rednet.send(Server, "DeleteMessage")
  242.                         os.sleep(0.1)
  243.                         rednet.send(Server, Msg)
  244.                         os.sleep(0.1)
  245.                         rednet.send(Server, RUser)
  246.                         os.sleep(0.1)
  247.                         Inbox()
  248.                 elseif key == 14 then
  249.                         Inbox()
  250.                 end
  251.         elseif menu[SelectedItem].Function then        
  252.                 menu[SelectedItem].Function()
  253.         elseif menu[SelectedItem].Option == "Back" then
  254.                 Back()
  255.         elseif menu[SelectedItem].Option == "Reload Inbox" then
  256.                 Inbox()
  257.         elseif menu[SelectedItem].File then
  258.                 Exit()
  259.                 shell.run(menu[SelectedItem].File)
  260.         else
  261.                 clear()
  262.                 term.setTextColor(colors.red)
  263.                 printC("There Was An Error!")
  264.                 term.setTextColor(colors.white)
  265.                 os.sleep(2)
  266.                 clear()
  267.                 printC("Restarting Computer")
  268.                 os.sleep(2)
  269.                 os.reboot()
  270.         end
  271. end
  272.  
  273. -- Handler Function --
  274. function Back()
  275.         term.setCursorBlink(false)
  276.         os.reboot()
  277. end
  278.  
  279. function FormInbox()
  280.         if Messages then
  281.                 table.remove(Messages)
  282.         end
  283.         Reset()
  284.         print("Loading Inbox...")
  285.         rednet.send(Server, "RetrieveMessage")
  286.         os.sleep(0.1)
  287.         ur = fs.open(iRoot .. "LoggedIn.txt", "r")
  288.         Username = ur.readLine()
  289.         ur.close()
  290.         rednet.send(Server, Username)
  291.         ID, MessageInfo = rednet.receive(5)
  292.         if MessageInfo then
  293.                 Messages = textutils.unserialize(MessageInfo)
  294.         else
  295.                 Reset()
  296.                 term.setTextColor(colors.red)
  297.                 print("Inbox Failed To Load!\nMake Sure That The E-Mail Server Is On!")
  298.                 term.setTextColor(colors.yellow)
  299.                 print("\n(-)Ok")
  300.                 term.setTextColor(colors.white)
  301.                 repeat
  302.                         event, key = os.pullEvent("key")
  303.                         os.sleep(0.1)
  304.                 until key == 28
  305.                 Back()
  306.         end
  307. end
  308.  
  309. function LogIn()
  310.         ResetL()
  311.         if IsServer then
  312.                 print("Log In\n")
  313.                 term.setTextColor(colors.yellow)
  314.                 write("Username: ")
  315.                 x, y = term.getCursorPos()
  316.                 write("\nPassword: ")
  317.                 term.setTextColor(colors.white)
  318.                 x2, y2 = term.getCursorPos()
  319.                 term.setCursorPos(x, y)
  320.                 Username = read()
  321.                 term.setCursorPos(x2, y2)
  322.                 Password = read("*")
  323.                 print("\nVerifying Information...")
  324.                 rednet.send(Server, "VerifyUser")
  325.                 os.sleep(0.1)
  326.                 rednet.send(Server, Username)
  327.                 os.sleep(0.1)
  328.                 rednet.send(Server, Password)
  329.                 ID, Success = rednet.receive(5)
  330.                 if Success then
  331.                         if Success == "true" then
  332.                                 uw = fs.open(iRoot .. "LoggedIn.txt", "w")
  333.                                 uw.writeLine(Username)
  334.                                 uw.close()
  335.                                 term.setTextColor(colors.lime)
  336.                                 print("\nYou Have Been Logged In Successfully!")
  337.                                 term.setTextColor(colors.yellow)
  338.                                 print("\n(-)Ok")
  339.                                 term.setTextColor(colors.white)
  340.                                 repeat
  341.                                         event, key = os.pullEvent("key")
  342.                                         os.sleep(0.1)
  343.                                 until key == 28
  344.                                 LoggedIn = true
  345.                                 UserLI = Username
  346.                                 Back()
  347.                         else
  348.                                 term.setTextColor(colors.red)
  349.                                 print("\nIncorrect Username / Password!")
  350.                                 term.setTextColor(colors.yellow)
  351.                                 print("\n(-)Ok")
  352.                                 repeat
  353.                                         event, key = os.pullEvent("key")
  354.                                         os.sleep(0.1)
  355.                                 until key == 28
  356.                                 Back()
  357.                         end
  358.                 else
  359.                         term.setTextColor(colors.red)
  360.                         print("\nThere Was An Error!\nMake Sure The E-Mail Server Is Turned On!")
  361.                         term.setTextColor(colors.yellow)
  362.                         print("\n(-)Ok")
  363.                         term.setTextColor(colors.white)
  364.                         repeat
  365.                                 event, key = os.pullEvent("key")
  366.                                 os.sleep(0.1)
  367.                         until key == 28
  368.                         Back()
  369.                 end
  370.         else
  371.                 ResetL()
  372.                 print("Log In\n")
  373.                 term.setTextColor(colors.red)
  374.                 print("You Have Not Set Up The Information For Rednet! \nYou Must Set Up The Information In Options Before Logging In!")
  375.                 term.setTextColor(colors.yellow)
  376.                 print("\n(-)Ok")
  377.                 term.setTextColor(colors.white)
  378.                 repeat
  379.                         event, key = os.pullEvent("key")
  380.                         os.sleep(0.1)
  381.                 until key == 28
  382.                 Back()
  383.         end
  384. end
  385.  
  386. function Reboot()
  387.         ResetL()
  388.         textutils.slowPrint("Rebooting Computer...")
  389.         os.sleep(1)
  390.         os.reboot()
  391. end
  392.  
  393. function Shutdown()
  394.         ResetL()
  395.         textutils.slowPrint("Shutting Down Computer...")
  396.         os.sleep(1)
  397.         os.shutdown()
  398. end
  399.  
  400. function SendMessage()
  401.         ResetS()
  402.         print("Compose Message\n")
  403.         term.setTextColor(colors.yellow)
  404.         write("To (Enter Username): ")
  405.         x, y = term.getCursorPos()
  406.         write("\nSubject: ")
  407.         x2, y2 = term.getCursorPos()
  408.         write("\nMessage: ")
  409.         term.setTextColor(colors.white)
  410.         x3, y3 = term.getCursorPos()
  411.         term.setCursorPos(x, y)
  412.         Username = ""
  413.         UsernameLength = 20
  414.         while true do
  415.                 printTM(" [ " .. #Username .. "/" .. UsernameLength .. " ] ")
  416.                 term.setCursorPos(x, y)
  417.                 term.setCursorBlink(true)
  418.                 write(Username)
  419.                
  420.                 local event, key = os.pullEvent()
  421.                 if event == "char" then
  422.                         if key == "," or key == "." or key == "/" or key == "\\" or key == ":" or key == "*" or key == "?" or key == "\"" or key == "<" or key == ">" or key == "|" then
  423.                                 Username = Username .. ""
  424.                         elseif key == " " then
  425.                                 Username = Username .. "_"
  426.                         else
  427.                                 if #Username < UsernameLength then
  428.                                         Username = Username .. key
  429.                                 else
  430.                                         Username = Username .. ""
  431.                                 end
  432.                         end
  433.                 elseif event == "key" then
  434.                         if key == 14 then
  435.                                 Username = Username:sub(1, #Username - 1)
  436.                                 w, h = term.getCursorPos()
  437.                                 term.setCursorPos(w - 1, h)
  438.                                 write(" ")
  439.                                 term.setCursorPos(w, h)
  440.                         elseif key == 211 then
  441.                                 Back()
  442.                         elseif key == 28 then
  443.                                 break
  444.                         end
  445.                 end
  446.         end
  447.         term.setCursorPos(x2, y2)
  448.         MessageName = ""
  449.         MessageNameLength = 14
  450.         while true do
  451.                 printTM(" [ " .. #MessageName .. "/" .. MessageNameLength .. " ] ")
  452.                 term.setCursorPos(x2, y2)
  453.                 term.setCursorBlink(true)
  454.                 write(MessageName)
  455.                
  456.                 local event, key = os.pullEvent()
  457.                 if event == "char" then
  458.                         if key == "," or key == "." or key == "/" or key == "\\" or key == ":" or key == "*" or key == "?" or key == "\"" or key == "<" or key == ">" or key == "|" then
  459.                                 MessageName = MessageName .. ""
  460.                         elseif key == " " then
  461.                                 MessageName = MessageName .. "_"
  462.                         else
  463.                                 if #MessageName < MessageNameLength then
  464.                                         MessageName = MessageName .. key
  465.                                 else
  466.                                         MessageName = MessageName .. ""
  467.                                 end
  468.                         end
  469.                 elseif event == "key" then
  470.                         if key == 14 then
  471.                                 MessageName = MessageName:sub(1, #MessageName - 1)
  472.                                 w, h = term.getCursorPos()
  473.                                 term.setCursorPos(w - 1, h)
  474.                                 write(" ")
  475.                                 term.setCursorPos(w, h)
  476.                         elseif key == 211 then
  477.                                 Back()
  478.                         elseif key == 28 then
  479.                                 break
  480.                         end
  481.                 end
  482.         end
  483.         Message = ""
  484.         MessageLength = 400
  485.         while true do
  486.                 printTM("  [ " .. #Message .. "/" .. MessageLength .. " ]  ")
  487.                 term.setCursorPos(x3, y3)
  488.                 term.setCursorBlink(true)
  489.                 write(Message)
  490.                
  491.                 local event, key = os.pullEvent()
  492.                 if event == "char" then
  493.                         if #Message < MessageLength then
  494.                                         Message = Message .. key
  495.                                 else
  496.                                         Message = Message .. ""
  497.                                 end
  498.                 elseif event == "key" then
  499.                         if key == 14 then
  500.                                 Message = Message:sub(1, #Message - 1)
  501.                                 w, h = term.getCursorPos()
  502.                                 term.setCursorPos(w - 1, h)
  503.                                 write(" ")
  504.                                 term.setCursorPos(w, h)
  505.                         elseif key == 211 then
  506.                                 Back()
  507.                         elseif key == 28 then
  508.                                 break
  509.                         end
  510.                 end
  511.         end
  512.         term.setCursorBlink(false)
  513.         Reset()
  514.         textutils.slowWrite("Sending ") term.setTextColor(colors.yellow) textutils.slowWrite(Username) term.setTextColor(colors.white) textutils.slowWrite("'s Message...")
  515.         cr = fs.open(iRoot .. "LoggedIn.txt", "r")
  516.         Sender = cr.readLine()
  517.         cr.close()
  518.         rednet.send(Server, "SendMessage")
  519.         os.sleep(0.1)
  520.         rednet.send(Server, Username)
  521.         os.sleep(0.1)
  522.         rednet.send(Server, Sender)
  523.         os.sleep(0.1)
  524.         rednet.send(Server, MessageName)
  525.         os.sleep(0.1)
  526.         rednet.send(Server, Message)
  527.         ID, Success = rednet.receive(5)
  528.         if Success then
  529.                 if Success == "true" then
  530.                         Reset()
  531.                         term.setTextColor(colors.lime)
  532.                         print("Message Has Been Sent!")
  533.                         term.setTextColor(colors.yellow)
  534.                         print("\n(-)Ok")
  535.                         term.setTextColor(colors.white)
  536.                         repeat
  537.                                 event, key = os.pullEvent("key")
  538.                                 os.sleep(0.1)
  539.                         until key == 28
  540.                         Back()
  541.                 elseif Success == "false" then
  542.                         Reset()
  543.                         term.setTextColor(colors.red)
  544.                         print("Message Failed To Send!")
  545.                         print("Make Sure The User Exists And That You Typed A Subject And A Message!")
  546.                         term.setTextColor(colors.yellow)
  547.                         print("\n(-)Ok")
  548.                         term.setTextColor(colors.white)
  549.                         repeat
  550.                                 event, key = os.pullEvent("key")
  551.                                 os.sleep(0.1)
  552.                         until key == 28
  553.                         Back()
  554.                 end
  555.         else
  556.                 term.setTextColor(colors.red)
  557.                 print("\nThere Was An Error!\nMake Sure The E-Mail Server Is Turned On!")
  558.                 term.setTextColor(colors.yellow)
  559.                 print("\n(-)Ok")
  560.                 term.setTextColor(colors.white)
  561.                 repeat
  562.                         event, key = os.pullEvent("key")
  563.                         os.sleep(0.1)
  564.                 until key == 28
  565.                 Back()
  566.         end
  567. end
  568.  
  569. function Inbox()
  570.         FormInbox()
  571.         SelectedItem = 1
  572.         UseMessagesMenu = true UseMainMenu = false
  573.         while UseMessagesMenu do
  574.                 Reset()
  575.                 print("Your Inbox\n")
  576.                 PrintMenu(Messages)
  577.                
  578.                 event, key = os.pullEvent("key")
  579.                 KeyHandler(key, Messages)
  580.         end
  581. end
  582.  
  583. function LogOut()
  584.         ResetL()
  585.         textutils.slowPrint("Logging Out...")
  586.         os.sleep(1)
  587.         fs.delete(iRoot .. "LoggedIn.txt")
  588.         os.reboot()
  589. end
  590.  
  591. function SetID()
  592.         ResetL()
  593.         print("Set E-Mail Server's Computer ID\n")
  594.         term.setTextColor(colors.yellow)
  595.         write("Computer ID: ")
  596.         term.setTextColor(colors.white)
  597.         ComputerID = read()
  598.         cw = fs.open(iRoot .. "ServerID.txt", "w")
  599.         cw.write(ComputerID)
  600.         cw.close()
  601.         Server = ComputerID
  602.         term.setTextColor(colors.lime)
  603.         print("\nE-Mail Server ID Has Been Set!")
  604.         term.setTextColor(colors.yellow)
  605.         print("\n(-)Ok")
  606.         term.setTextColor(colors.white)
  607.         repeat
  608.                 event, key = os.pullEvent("key")
  609.                 os.sleep(0.1)
  610.         until key == 28
  611.         os.reboot()
  612. end
  613.  
  614. function NewUser()
  615.         ResetL()
  616.         print("New User Account\n")
  617.         term.setTextColor(colors.yellow)
  618.         write("Enter A Username: ")
  619.         term.setTextColor(colors.white)
  620.         x, y = term.getCursorPos()
  621.         Username = ""
  622.         while true do
  623.                 printTM(" [ " .. #Username .. "/20 ] ")
  624.                 term.setCursorPos(x, y)
  625.                 term.setCursorBlink(true)
  626.                 write(Username)
  627.                
  628.                 local event, key = os.pullEvent()
  629.                 if event == "char" then
  630.                         if key == "," or key == "." or key == "/" or key == "\\" or key == ":" or key == "*" or key == "?" or key == "\"" or key == "<" or key == ">" or key == "|" then
  631.                                 Username = Username .. ""
  632.                         elseif key == " " then
  633.                                 Username = Username .. "_"
  634.                         else
  635.                                 if #Username < 20 then
  636.                                         Username = Username .. key
  637.                                 else
  638.                                         Username = Username .. ""
  639.                                 end
  640.                         end
  641.                 elseif event == "key" then
  642.                         if key == 14 then
  643.                                 Username = Username:sub(1, #Username - 1)
  644.                                 w, h = term.getCursorPos()
  645.                                 term.setCursorPos(w - 1, h)
  646.                                 write(" ")
  647.                                 term.setCursorPos(w, h)
  648.                         elseif key == 211 then
  649.                                 Back()
  650.                         elseif key == 28 then
  651.                                 break
  652.                         end
  653.                 end
  654.         end
  655.         repeat
  656.                 term.setTextColor(colors.yellow)
  657.                 write("\n\nEnter A Password: ")
  658.                 term.setTextColor(colors.white)
  659.                 Password = read("*")
  660.                 term.setTextColor(colors.yellow)
  661.                 write("Confirm Password: ")
  662.                 term.setTextColor(colors.white)
  663.                 ConfirmPassword = read("*")
  664.                 if Password == ConfirmPassword then
  665.                         break
  666.                 else
  667.                         term.setTextColor(colors.red)
  668.                         write("\nPasswords Do Not Match!")
  669.                         term.setTextColor(colors.white)
  670.                 end
  671.         until Password == ConfirmPassword
  672.         rednet.send(Server, "CreateUser")
  673.         os.sleep(0.1)
  674.         rednet.send(Server, Username)
  675.         os.sleep(0.1)
  676.         rednet.send(Server, Password)
  677.         ID, Status = rednet.receive(5)
  678.         if Status then
  679.                 term.setTextColor(colors.lime)
  680.                 print("\nUser Account Created Successfully!")
  681.                 term.setTextColor(colors.yellow)
  682.                 print("\n(-)Ok")
  683.                 term.setTextColor(colors.white)
  684.                 repeat
  685.                         event, key = os.pullEvent("key")
  686.                         os.sleep(0.1)
  687.                 until key == 28
  688.                 Back()
  689.         else
  690.                 term.setTextColor(colors.red)
  691.                 print("\nThere Was An Error!\nThe Username Must Already Exist Or The E-Mail Server Is Not On!")
  692.                 term.setTextColor(colors.yellow)
  693.                 print("\n(-)Ok")
  694.                 term.setTextColor(colors.white)
  695.                 repeat
  696.                         event, key = os.pullEvent("key")
  697.                         os.sleep(0.1)
  698.                 until key == 28
  699.                 Back()
  700.         end
  701. end
  702.  
  703. function DeleteUser()
  704.         ResetL()
  705.         print("Delete A User Account\n")
  706.         term.setTextColor(colors.yellow)
  707.         write("Enter The Username: ")
  708.         term.setTextColor(colors.white)
  709.         Username = read()
  710.         term.setTextColor(colors.yellow)
  711.         write("Enter The Password: ")
  712.         term.setTextColor(colors.white)
  713.         Password = read("*")
  714.         rednet.send(Server, "DeleteUser")
  715.         os.sleep(0.1)
  716.         rednet.send(Server, Username)
  717.         os.sleep(0.1)
  718.         rednet.send(Server, Password)
  719.         ID, Success = rednet.receive(5)
  720.         if Success then
  721.                 if Success == "true" then
  722.                         term.setTextColor(colors.lime)
  723.                         print("\nUser Account Was Remove Successfully!")
  724.                         term.setTextColor(colors.yellow)
  725.                         print("\n(-)Ok")
  726.                         term.setTextColor(colors.white)
  727.                         repeat
  728.                                 event, key = os.pullEvent("key")
  729.                                 os.sleep(0.1)
  730.                         until key == 28
  731.                         Back()
  732.                 elseif Success == "false" then
  733.                         term.setTextColor(colors.red)
  734.                         print("\nUser Account Couldn't Be Deleted!\nMake Sure The Username And Password Are Correct!")
  735.                         term.setTextColor(colors.yellow)
  736.                         print("\n(-)Ok")
  737.                         term.setTextColor(colors.white)
  738.                         repeat
  739.                                 event, key = os.pullEvent("key")
  740.                                 os.sleep(0.1)
  741.                         until key == 28
  742.                         Back()
  743.                 end
  744.         else
  745.                 term.setTextColor(colors.red)
  746.                 print("\nThere Was An Error!\nMake Sure The E-Mail Server Is Turned On!")
  747.                 term.setTextColor(colors.yellow)
  748.                 print("\n(-)Ok")
  749.                 term.setTextColor(colors.white)
  750.                 repeat
  751.                         event, key = os.pullEvent("key")
  752.                         os.sleep(0.1)
  753.                 until key == 28
  754.                 Back()
  755.         end
  756. end
  757.  
  758. function Options()
  759.         SelectedItem = 1
  760.         UseOptionsMenu = true UseMainMenu = false UseLoginMenu = false
  761.         while UseOptionsMenu do
  762.                 ResetL()
  763.                 print("Options\n")
  764.                 PrintMenu(OptionsMenu)
  765.                
  766.                 event, key = os.pullEvent("key")
  767.                 KeyHandler(key, OptionsMenu)
  768.         end
  769. end
  770.  
  771. function Network()
  772.         SelectedItem = 1
  773.         if LoggedIn then
  774.                 UseMainMenu = true UseLoginMenu = false UseMessagesMenu = false UseOptionsMenu = false
  775.                 while UseMainMenu do
  776.                         Reset()
  777.                         print("Main Menu\n")
  778.                         PrintMenu(MainMenu)
  779.                        
  780.                         event, key = os.pullEvent("key")
  781.                         KeyHandler(key, MainMenu)
  782.                 end
  783.         else
  784.                 UseLoginMenu = true UseMainMenu = false
  785.                 while UseLoginMenu do
  786.                         ResetL()
  787.                         print("Welcome!\n")
  788.                         PrintMenu(LoginMenu)
  789.                        
  790.                         event, key = os.pullEvent("key")
  791.                         KeyHandler(key, LoginMenu)
  792.                 end
  793.         end
  794. end
  795.  
  796. --[[ Tables ]]--
  797. -- Menus --
  798. LoginMenu = {
  799.         [1] = { Option = "Log In\n", Function = LogIn },
  800.         [2] = { Option = "Options", Function = Options },
  801.         [3] = { Option = "Reboot", Function = Reboot },
  802.         [4] = { Option = "Shutdown", Function = Shutdown }
  803. }
  804.  
  805. MainMenu = {
  806.         [1] = { Option = "Send A Message", Function = SendMessage },
  807.         [2] = { Option = "Inbox", Function = Inbox },
  808.         [3] = { Option = "Logout", Function = LogOut }
  809. }
  810.  
  811. OptionsMenu = {
  812.         [1] = { Option = "Set E-Mail Server ID", Function = SetID },
  813.         [2] = { Option = "Create New User", Function = NewUser },
  814.         [3] = { Option = "Delete A User\n", Function = DeleteUser },
  815.         [4] = { Option = "Back" }
  816. }
  817.  
  818. --[[ Start The Program ]]--
  819. os.pullEvet = os.pullEventRaw
  820. if peripheral.isPresent("right") and peripheral.getType("right") == "modem" then
  821.         rednet.open("right")
  822.         DoNetwork = true
  823. elseif peripheral.isPresent("left") and peripheral.getType("left") == "modem" then
  824.         rednet.open("left")
  825.         DoNetwork = true
  826. elseif peripheral.isPresent("top") and peripheral.getType("top") == "modem" then
  827.         rednet.open("top")
  828.         DoNetwork = true
  829. elseif peripheral.isPresent("bottom") and peripheral.getType("bottom") == "modem" then
  830.         rednet.open("bottom")
  831.         DoNetwork = true
  832. elseif peripheral.isPresent("front") and peripheral.getType("front") == "modem" then
  833.         rednet.open("front")
  834.         DoNetwork = true
  835. elseif peripheral.isPresent("back") and peripheral.getType("back") == "modem" then
  836.         rednet.open("back")
  837.         DoNetwork = true
  838. else
  839.         ResetL()
  840.         term.setTextColor(colors.red)
  841.         print("You must place a modem on the computer before you can use E-Mail!")
  842.         term.setTextColor(colors.white)
  843. end
  844. while DoNetwork do
  845.         Network()
  846. end
  847.     Startup = -- Local Variables --
  848. Root = ".Network/"
  849.  
  850. -- Interface --
  851. shell.run(Root .. "Network.lua")
  852.  
  853.     f = fs.open("startup", "w")
  854.     f.write(Startup.readAll())
  855.     f.close()
  856.     f = fs.open(Root .. "Network.lua", "w")
  857.     f.write(Network.readAll())
  858.     f.close()
  859.     term.setTextColor(colors.lime)
  860.     print("\nDone!")
  861.     os.sleep(1)
  862.     Reset()
  863.     print("E-Mail Server Downloaded Successfully!\nEdition: Client")
  864.     term.setTextColor(colors.yellow)
  865.     print("\n(-)Ok")
  866.     term.setTextColor(colors.white)
  867.     repeat
  868.             event, key = os.pullEvent("key")
  869.             os.sleep(0.1)
  870.     until key == 28
  871.     os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement