Advertisement
xXm0dzXx

ccTube Servers

Nov 11th, 2012
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. ---ccTube Rednet Servers---
  2. ---------------------------
  3. ------------Team-----------
  4. -- gavsminecraft --
  5. -- lieudusty --
  6. -- xXm0dzXx --
  7. -- --
  8. -- --
  9. ---------------------------
  10. ---------------------------
  11.  
  12. local currentVideos = {}
  13. local currentSavePath = "/currentVidz"
  14.  
  15. local updateTime = 3
  16.  
  17. function loadVideos()
  18. file = fs.open( currentSavePath, "r" )
  19. if file then
  20. currentVideos = textutils.unserialize( file.readAll() )
  21. file.close()
  22. return true
  23. end
  24.  
  25. return false
  26. end
  27.  
  28. function saveVideos()
  29. fs.delete( currentSavePath )
  30. file = fs.open( currentSavePath, "w" )
  31. file.write( textutils.serialize( currentVideos ) )
  32. file.close()
  33.  
  34. return false
  35. end
  36.  
  37. if fs.exists( currentSavePath ) ~= true then
  38. fs.open( currentSavePath, "w" ).close()
  39. end
  40.  
  41. loadVideos()
  42. term.clear()
  43. term.setCursorPos(1,1)
  44. print("Hosting youtube ;D")
  45.  
  46. for i, v in pairs( rs.getSides() ) do
  47. rednet.open( v )
  48. end
  49.  
  50. autoUpdate = os.startTimer( updateTime )
  51. while true do
  52. local event, key, message = os.pullEvent()
  53.  
  54. if event == "rednet_message" then
  55. if message == "request_videos" then
  56. rednet.send( key, textutils.serialize( currentVideos ) )
  57. print( "Video Request Filled :D" )
  58. elseif string.sub(message, 1, #("request_video_")) == "request_video_" then
  59. local videoID = string.sub( message, #("request_video_*"), #message )
  60.  
  61. if currentVideos[ videoID ] then
  62. rednet.send( key, textutils.serialize( currentVideos[ videoID ] ) )
  63. end
  64. end
  65. elseif event == "timer" then
  66. if key == autoUpdate then
  67. saveVideos()
  68. end
  69. end
  70. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement