Streetboy_xD

[Computercraft] File Transfer-Client V.1

Jun 23rd, 2014
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.84 KB | None | 0 0
  1. filedesign = "" -- Write the name of the design program inside the "". / Namen des Design Programmes in die "" schreiben.
  2. id = 2 -- Change this to the Server-ID / Server-ID eintragen.
  3.  
  4.  
  5. dir = "/"
  6. dirText = "X | Downloads"
  7.  
  8. modemside = "back"
  9. color = colors.lightGray
  10. coloritems = colors.white
  11. textcolor = colors.black
  12.  
  13. minnumber = 2
  14. maxnumber = 18
  15. minnum = 2
  16. maxnum = 18
  17. timeout = 0.5
  18. downloadList = {}
  19.  
  20. rednet.open(modemside)
  21.  
  22. fs.makeDir("Downloads")
  23.  
  24. while true do
  25.  
  26. function design()
  27. paint = paintutils.loadImage(filedesign)
  28. paintutils.drawImage(paint,1,1)
  29. end
  30. term.clear()
  31. design()
  32. term.setTextColor(textcolor)
  33. term.setBackgroundColor(color)
  34. term.setCursorPos(9,1)
  35. term.write("| PC |")
  36. term.setCursorPos(36,1)
  37. term.write("| SERVER |")
  38. term.setCursorPos(1,1)
  39. term.write("v^")
  40. term.setCursorPos(29,1)
  41. term.write("v^")
  42. term.setCursorPos(51,19)
  43. term.write("$")
  44. term.setCursorPos(1,19)
  45. term.write(dirText)
  46. term.setBackgroundColor(colors.red)
  47. term.setCursorPos(51,1)
  48. term.write("X")
  49. term.setBackgroundColor(color)
  50. term.setCursorPos(1,1)
  51.  
  52. function scrolldown()
  53.  
  54. minnumber = minnumber + 1
  55. maxnumber = maxnumber + 1
  56.  
  57. end
  58.  
  59. function scrollup()
  60.  
  61. minnumber = minnumber - 1
  62. maxnumber = maxnumber - 1
  63.  
  64. end
  65.  
  66. function scrolldowndownload()
  67.  
  68. minnum = minnum + 1
  69. maxnum = maxnum + 1
  70.  
  71. end
  72.  
  73. function scrollupdownload()
  74.  
  75. minnum = minnum - 1
  76. maxnum = maxnum - 1
  77.  
  78. end
  79.  
  80. function changeDir()
  81.  
  82. if dir == "/" then
  83. dir = "Downloads/"
  84. dirText = "X | Hauptverzeichnis"
  85. else
  86. dir = "/"
  87. dirText = "X | Downloads "
  88. end
  89.  
  90. end
  91.  
  92. function createAuswahlUpload( ypos )
  93.  
  94. if listedPrograms[ypos + minnumber - 2] then
  95. term.setBackgroundColor(color)
  96. term.setCursorPos(15,6)
  97. term.write(" ")
  98. term.setCursorPos(15,7)
  99. term.write(" ")
  100. term.setCursorPos(15,8)
  101. term.write(" ")
  102. term.setCursorPos(15,9)
  103. term.write(" ")
  104. term.setCursorPos(15,10)
  105. term.write(" ")
  106. term.setCursorPos(16,6)
  107. term.write("Name: ")
  108. term.write(listedPrograms[ypos + minnumber - 2])
  109. term.setBackgroundColor(coloritems)
  110. term.setCursorPos(16,7)
  111. term.write(" ")
  112. term.setCursorPos(16,8)
  113. term.write(" Speichern ")
  114. term.setCursorPos(16,9)
  115. term.write(" ")
  116. term.setBackgroundColor(coloritems)
  117.  
  118. event, side, x, y = os.pullEvent("mouse_click")
  119.  
  120. if x >= 16 and x <= 37 and y >= 7 and y <= 9 then
  121.  
  122. program = fs.open(listedPrograms[ypos + minnumber - 2],"r")
  123. programdata = program.readAll()
  124. program.close()
  125. rednet.send(id,"U;"..listedPrograms[ypos + minnumber - 2].."$;"..programdata)
  126. a,b,c = rednet.receive(timeout)
  127. if a == nil then
  128. term.setBackgroundColor(color)
  129. term.setCursorPos(1,19)
  130. term.write("Keine Verbindung zum Server!")
  131. sleep(1)
  132. else
  133. term.setBackgroundColor(color)
  134. term.setCursorPos(1,19)
  135. term.write(b)
  136. sleep(1)
  137. end
  138.  
  139. end
  140. end
  141.  
  142. end
  143.  
  144.  
  145. function createAuswahlDownload( ypos )
  146.  
  147. if downloadList[ypos + minnum - 2] then
  148. term.setBackgroundColor(color)
  149. term.setCursorPos(15,5)
  150. term.write(" ")
  151. term.setCursorPos(15,6)
  152. term.write(" ")
  153. term.setCursorPos(15,7)
  154. term.write(" ")
  155. term.setCursorPos(15,8)
  156. term.write(" ")
  157. term.setCursorPos(15,9)
  158. term.write(" ")
  159. term.setCursorPos(15,10)
  160. term.write(" ")
  161. term.setCursorPos(15,11)
  162. term.write(" ")
  163. term.setCursorPos(16,5)
  164. term.write("Name: ")
  165. term.write(downloadList[ypos + minnum - 2])
  166. term.setBackgroundColor(coloritems)
  167. term.setCursorPos(16,6)
  168. term.write(" ")
  169. term.setCursorPos(16,7)
  170. term.write(" Download ")
  171. term.setCursorPos(16,8)
  172. term.write(" ")
  173. term.setCursorPos(16,9)
  174. term.write(" Delete ")
  175. term.setCursorPos(16,10)
  176. term.write(" ")
  177. term.setBackgroundColor(color)
  178.  
  179. event, side, x, y = os.pullEvent("mouse_click")
  180.  
  181. if x >= 16 and x <= 37 and y == 7 then
  182.  
  183. rednet.send(id,"D;"..downloadList[ypos + minnum - 2])
  184. a, b, c = rednet.receive(timeout)
  185. if a == nil then
  186. term.setBackgroundColor(color)
  187. term.setCursorPos(1,19)
  188. term.write("Keine Verbindung zum Server!")
  189. else
  190. if not fs.exists("Downloads/"..downloadList[ypos + minnum - 2]) then
  191. File = fs.open("Downloads/"..downloadList[ypos + minnum - 2],"w")
  192. File.write(b)
  193. File.close()
  194. term.setCursorPos(1,19)
  195. term.write("Erfolreich heruntergeladen")
  196. sleep(1)
  197. else
  198. term.setCursorPos(1,19)
  199. term.write("Datei existiert bereits!")
  200. sleep(1)
  201. end
  202. end
  203.  
  204. elseif x >= 16 and x <= 37 and y == 9 then
  205.  
  206. rednet.send(id,"B;"..downloadList[ypos + minnum - 2])
  207. a,b,c = rednet.receive(timeout)
  208.  
  209. if a == nil then
  210. term.setBackgroundColor(color)
  211. term.setCursorPos(1,19)
  212. term.write("Keine Verbindung zum Server!")
  213. sleep(1)
  214. else
  215. term.setBackgroundColor(color)
  216. term.setCursorPos(1,19)
  217. term.write(b)
  218. sleep(1)
  219. end
  220.  
  221. end
  222.  
  223. end
  224.  
  225.  
  226. end
  227.  
  228. -- Variablen
  229.  
  230. ItemDownloadVisible = 2
  231. ItemDownloadInvisible = 2
  232. y = 2
  233. visible = 2
  234. invisible = 2
  235. items = ";"
  236. listedPrograms = {}
  237.  
  238. -- Tabellen
  239.  
  240. rednet.send(id,"L;")
  241. a, dL, c = rednet.receive(timeout)
  242. if a == nil then
  243. term.setBackgroundColor(coloritems)
  244. term.setCursorPos(32,2)
  245. term.write("Keine Verbindung")
  246. term.setCursorPos(32,3)
  247. term.write("zum Server!")
  248. else
  249.  
  250. while string.find(dL,";") do
  251.  
  252. findNew = string.find(dL.."",";")
  253. downloadList[ItemDownloadVisible] = string.sub(dL,1,findNew-1)
  254.  
  255. dL = string.sub(dL,string.find(dL.."",";")+1)
  256.  
  257. if ItemDownloadVisible >= minnum and ItemDownloadVisible <= maxnum then
  258. term.setBackgroundColor(coloritems)
  259. term.setCursorPos(32,ItemDownloadInvisible)
  260. term.write(downloadList[ItemDownloadVisible])
  261. ItemDownloadInvisible = ItemDownloadInvisible + 1
  262. end
  263.  
  264. ItemDownloadVisible = ItemDownloadVisible + 1
  265.  
  266. end
  267. end
  268.  
  269. progs = fs.list(dir)
  270.  
  271. for index, sItem in pairs(progs) do
  272. if fs.isDir(sItem)~=true then
  273.  
  274. listedPrograms[visible] = sItem
  275. if visible >= minnumber and visible <= maxnumber then
  276. term.setBackgroundColor(coloritems)
  277. term.setCursorPos(3,invisible)
  278. term.write(listedPrograms[visible])
  279. invisible = invisible + 1
  280. end
  281. visible = visible + 1
  282.  
  283. end
  284.  
  285. end
  286.  
  287. event, side, x, y = os.pullEvent()
  288.  
  289. if event == "mouse_click" then
  290.  
  291. if x > 3 and x < 25 and y > 1 and y < 19 then
  292.  
  293. createAuswahlUpload(y)
  294.  
  295.  
  296. elseif x > 32 and x < 46 and y > 1 and y < 19 then
  297.  
  298. createAuswahlDownload(y)
  299.  
  300. elseif x == 51 and y == 1 then
  301.  
  302. term.setBackgroundColor(colors.black)
  303. term.clear()
  304. term.setCursorPos(1,1)
  305. break
  306.  
  307. elseif x == 51 and y == 19 then
  308.  
  309. shell.run(shell.getRunningProgram())
  310.  
  311. elseif x == 1 and y == 1 and maxnumber < visible-1 and minnumber < visible then
  312.  
  313. scrolldown()
  314.  
  315. elseif x == 2 and y == 1 and maxnumber > 18 and minnumber > 2 then
  316.  
  317. scrollup()
  318.  
  319. elseif x == 29 and y == 1 and maxnum < ItemDownloadVisible-1 and minnum < ItemDownloadVisible then
  320.  
  321. scrolldowndownload()
  322.  
  323. elseif x == 30 and y == 1 and maxnum > 18 and minnum > 2 then
  324.  
  325. scrollupdownload()
  326.  
  327. elseif x == 1 and y == 19 then
  328.  
  329. changeDir()
  330.  
  331. end
  332.  
  333. elseif event == "mouse_scroll" then
  334.  
  335. if side == 1 and maxnumber < visible - 1 and minnumber < visible then
  336.  
  337. scrolldown()
  338. sleep(0.08)
  339.  
  340. elseif side == -1 and maxnumber > 18 and minnumber > 2 then
  341.  
  342. scrollup()
  343. sleep(0.08)
  344.  
  345. elseif side == 1 and maxnum < ItemDownloadVisible-1 and minnum < ItemDownloadVisible then
  346.  
  347. scrolldowndownload()
  348. sleep(0.08)
  349.  
  350. elseif side == -1 and maxnum > 18 and minnum > 2 then
  351.  
  352. scrollupdownload()
  353. sleep(0.08)
  354.  
  355. end
  356.  
  357. end
  358. end
  359.  
  360.  
  361. -- Scripted by Streetboy_xD
  362. -- Please keep this text in the program.
Advertisement
Add Comment
Please, Sign In to add comment