Advertisement
RiseAboveHate

DNS Beta System (ComputerCraft API)

Dec 13th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. -- DNS - Domain Name Server | Programmed by Yosi Yuval.
  2. -- This Is a test program! (-:
  3. --
  4. --
  5. -- |---------------------------------|
  6. -- | 33333333    33     3  333333333 |
  7. -- | 3       3   3 3    3  3         |
  8. -- | 3        3  3  3   3  3         |        
  9. -- | 3        3  3   3  3  333333333 |
  10. -- | 3       3   3    3 3          3 |
  11. -- | 33333333    3     33  333333333 |
  12. -- |---------------------------------|
  13.  
  14. local fFile = ""
  15. local fFileData = ""
  16.  
  17. local statelist = {
  18.   ["top"] = rs.getInput("top"),
  19.   ["front"] = rs.getInput("front"),
  20.   ["left"] = rs.getInput("left"),
  21.   ["right"] = rs.getInput("right"),
  22.   ["back"] = rs.getInput("back"),
  23.   ["bottom"] = rs.getInput("bottom"),
  24. }
  25.  
  26. local domain_wrong_symbols = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "!", "@", "#", "$", "*", "(", ")", "-", "=", "/", "?", ".", "|", "", ":", ";", "~", "`", "<", ">", "{", "}", "[", "]"}
  27.  
  28. local domain_extensions = {".com", ".co.il", ".org", ".cc", ".il"}
  29.  
  30. function HostServer(domain, host_name)
  31.     if domain == nil or host_name == nil then print("missing parameters") end
  32.     for v,side in pairs(statelist) do rednet.open("back") end
  33.     rednet.host("80", domain)
  34.     os.setComputerLabel(host_name.." | "..domain)
  35.     print("Server Name: "..host_name.." | Domain: "..domain.." |")
  36. end
  37.  
  38. function isServerExist(domain)
  39.     local ServerHost = rednet.lookup("80", domain)
  40.     if ServerHost then return true
  41.     else return false end
  42. end
  43.  
  44. function connectToServer(domain)
  45.     local ServerHost = rednet.lookup("80", domain)
  46.     return ServerHost
  47. end
  48.  
  49. function getDomainServerID(domain)
  50.     return rednet.lookup("80", domain)
  51. end
  52.  
  53. function sendFileFromServer(pid, domain, file_to_send)
  54.     local fileToSend = fs.open(file_to_send, "r")
  55.     --fFileData = fileToGet.readAll()
  56.     FData = fileToSend.readAll()
  57.     fileToSend.close()
  58.     rednet.send(pid, sfileData)
  59. end
  60.  
  61. function getFileFromServer(domain, file_to_get)
  62.     sendFileFromServer(os.getComputerID(), getDomainServerID(domain), file_to_get)
  63.     local id, msg, dis = rednet.receive()
  64.     if id == getDomainServerID(domain) then
  65.         local fileData = msg
  66.         local fileToGet = fs.open(file_to_get, "w")
  67.             fileToGet.writr(fileData)
  68.         fileToGet.close()  
  69.     end
  70. end
  71.  
  72. function sendFilesListFromServer(pid)
  73.     local fList = fs.list("")
  74.     rednet.send(pid, fList)
  75. end
  76.  
  77. function getFilesListFromServer(domain_pc)
  78.     local id, msg, dis = rednet.receive()
  79.     if id == getDomainServerID(domain) then
  80.         print("File List from Domain"..d.."("..getDomainServerID(d)..")\n"..msg)
  81.     end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement