Advertisement
cyber_Ahn

Command Computer Server

Jan 8th, 2016
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.90 KB | None | 0 0
  1. --config--
  2. local channel = 43
  3. modem = peripheral.wrap("back")
  4.  
  5. --vars--
  6. local power = true
  7.  
  8. -- func split--
  9. function split(pString,pPattern)
  10. local Table = {}
  11. local fpat = "(.-)"..pPattern
  12. local last_end = 1
  13. local s,e,cap = pString:find(fpat,1)
  14. while s do
  15. if s ~= 1 or cap ~= "" then
  16. table.insert(Table,cap)
  17. end
  18. last_end = e+1
  19. s,e,cap = pString:find(fpat,last_end)
  20. end
  21. if last_end <= #pString then
  22. cap = pString:sub(last_end)
  23. table.insert(Table,cap)
  24. end
  25. return Table
  26. end
  27.  
  28. --func decode--
  29. function decode(msg)
  30. if msg == "rain" then
  31. commands.toggledownfall()
  32. elseif msg == "sunrise" then
  33. commands.time("set", 0)
  34. elseif msg == "midday" then
  35. commands.time("set", 5000)
  36. elseif msg == "sunset" then
  37. commands.time("set", 12000)
  38. elseif msg == "midnight" then
  39. commands.time("set", 13000)
  40. elseif msg == "zero_hour" then
  41. commands.time("set", 18000)
  42. elseif msg == "world_survival" then
  43. commands.defaultgamemode(0)
  44. elseif msg == "world_creative" then
  45. commands.defaultgamemode(1)
  46. elseif msg == "shutdown" then
  47. shell.run("shutdown")
  48. elseif msg == "weather_rain" then
  49. commands.weather("rain")
  50. elseif msg == "weather_clear" then
  51. commands.weather("clear")
  52. elseif msg == "weather_thunder" then
  53. commands.weather("thunder")
  54. else
  55. data = split(msg,"#")
  56. if data[1] == "gamemode" then
  57. commands.gamemode(data[2],data[3])
  58. end
  59. if data[1] == "xp" then
  60. commands.xp(data[2],data[3])
  61. end
  62. if data[1] == "setblock" then
  63. print("set Block:"..data[5])
  64. commands.setblock(data[2],data[3],data[4],data[5])
  65. end
  66. if data[1] == "give" then
  67. commands.give(data[2],data[3],data[4])
  68. end
  69. --....---
  70. end
  71. end
  72.  
  73. --program--
  74. print("start command Server");
  75. print("start modem on channel "..channel)
  76. modem.open(channel)
  77. print("command Server started")
  78.  
  79. --open pull event--
  80. while power == true do
  81. event, modemside, sendchan, replaychan, message, dist = os.pullEvent("modem_message")
  82. print(message)
  83. decode(message)
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement