Advertisement
NuAoA

ServerRules2.0

Mar 1st, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. local p = peripheral.wrap("top")
  2. local mon = peripheral.wrap("front")
  3. os.loadAPI("Draw")
  4.  
  5. function getHTTP()
  6. return http.get("https://raw.github.com/AlienMC/AlienMC-FTBSubreddit-Public-Server/master/Server%20Rules.md")
  7. end
  8.  
  9. function deepcopy(orig)
  10. local orig_type = type(orig)
  11. local copy
  12. if orig_type == 'table' then
  13. copy = {}
  14. for orig_key, orig_value in next, orig, nil do
  15. copy[deepcopy(orig_key)] = deepcopy(orig_value)
  16. end
  17. setmetatable(copy, deepcopy(getmetatable(orig)))
  18. else -- number, string, boolean, etc
  19. copy = orig
  20. end
  21. return copy
  22. end
  23.  
  24. function getAndParseRules()
  25. local xmax,ymax = mon.getSize()
  26. local rules = getHTTP()
  27. local tt = {}
  28. local line = ""
  29. while line ~= nil do
  30. line = rules.readLine()
  31. if line ~= nil then
  32. line = string.gsub(line,"<b>","&"..Draw.getHexOf(colors.red))
  33. line = string.gsub(line,"</b>"," &"..Draw.getHexOf(colors.lime))
  34. line = string.gsub(line,"<li>","")
  35. line = string.gsub(line,"<%S+>","")
  36. line = string.gsub(line,"<a %S+>","")
  37. line = string.match(line,"%s+(.+)")
  38. if #line > xmax then
  39. local str = ""
  40. for word in string.gsub(line,"%S+") do
  41. if string.len(str.." "..word) < xmax then
  42. str = str.." "..word
  43. else
  44. table.insert(str)
  45. str = " "..word
  46. end
  47. end
  48. end
  49. table.insert(tt,line)
  50. end
  51. end
  52. return deepcopy(tt)
  53. end
  54.  
  55. function looking()
  56. mon.setTextScale(2)
  57. local xmax,ymax = mon.getSize()
  58. local tc = Draw.emptyScreen(mon,xmax,ymax)
  59. Draw.tc(tc,1,1,colors.black,xmax,ymax)
  60. Draw.draw(mon,tc,1,1,colors.black,tt2)
  61. end
  62.  
  63. local tt2 = getAndParseRules()
  64. while true do
  65. looking()
  66. sleep(15)
  67. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement