Advertisement
Bjornir90

Servertest.lua

Nov 14th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.63 KB | None | 0 0
  1. --This is only a non-tested version, so easy-to-fix bugs may occurs
  2.  dataPlugin = {}
  3.  dataMenu = {}
  4.  functionR = {}
  5.  function createConfig()
  6.  if fs.exists("/serverFolder/server.config") then
  7.   return "nothing"
  8.  else
  9.  print("Thanks you for download this rednet protocol :)")
  10.  os.sleep(2)
  11.  term.clear()
  12.  term.setCursorPos(1, 1)
  13.  write("Enter the side of your modem :")
  14.  local modemSide = io.read()
  15.  local idServ = os.computerID()
  16.  term.clear()
  17.  term.setCursorPos(1, 1)
  18.  print("You have finished the configuration of your program")
  19.  local conf = io.open("/serverFolder/server.config", "w")
  20.  local data = {side = modemSide, id = idServ}
  21.  local dataS = textutils.serialize(data)
  22.  local writeIsFail = conf:write(dataS)
  23.  conf:close()
  24.  print("Config succesfully written")
  25.  sleep(2)
  26. end
  27. end 
  28. local function loadPlugin(plugin)
  29.  pluginF = fs.open("/serverFolder/Plugins/"..plugin, "r")
  30.  pluginData = pluginF.readLine()
  31.  pluginData = textutils.unserialize(pluginData)
  32.  pluginF.close()
  33.  pluginNameSize = #pluginData[1]
  34.  pluginDataL = {pluginData[1], pluginData[2], pluginNameSize}
  35.  return pluginDataL
  36. end 
  37. function loadConfig()
  38.  term.clear()
  39.  term.setCursorPos(1, 1)
  40.  if fs.exists("/serverFolder/Plugins") then
  41.   loadPlugin("coreplugin")
  42.   local pluginList = fs.list("/serverFolder/Plugins")
  43.   local sizeList = #pluginList
  44.   for x=1, sizeList do
  45.    local dataPlug = loadPlugin(pluginList[x])
  46.    table.insert(dataPlugin, dataPlug[1])
  47.    table.insert(dataPlugin, dataPlug[2])
  48.    table.insert(dataPlugin, dataPlug[3])
  49.   end 
  50. else
  51.    print("File not found : plug-ins folder")
  52.  end
  53.  if fs.exists("/serverFolder/server.config") then
  54.   local conf = fs.open("/serverFolder/server.config", "r")
  55.   local dataS = conf.readAll()
  56.   conf.close()
  57.   local data = textutils.unserialize(dataS)
  58.   local side = data.side
  59.   local id = data.id
  60.   rednet.open(side)
  61.   return id
  62.  else
  63.   print("Cannot find the config file, please restart this program")
  64.   os.sleep(3)
  65.   return
  66.  end
  67. end
  68.  local function drawMenu(list)
  69.  local sizeList = #list
  70.  local x = 2
  71.  local y = 4
  72.  for count=3, #list, 3 do
  73.    local a = x+list[count]+1
  74.    gui.drawButton(x, y, a, y+2, list[count-2])
  75.  if x+list[count] >= 49 then
  76.  y=y+5
  77.  x=2 
  78. else
  79.  x=x+list[count]
  80.  end 
  81. dataMenu.insert(x)
  82. dataMenu.insert(y)
  83. dataMenu.insert(a)
  84. end
  85. end 
  86.  
  87. local function menuSel()
  88.  local sizeTMenu = #dataMenu
  89.  local counterTime = 1
  90.  for counter=1, sizeTMenu, 3 do
  91.  wait..counterTime = function()
  92.  gui.buttonWaitClick(dataMenu[counter], dataMenu[counter+1], dataMenu[counter+2], dataMenu[counter+1]+2 )
  93.  end
  94.  counterTime = counterTime+1
  95. end
  96. if counterTime == 1 then
  97. wait1
  98. return 1
  99. elseif counterTime == 2 then
  100. input = parallel.waitForAny(wait1, wait2)
  101. return input
  102. elseif counterTime == 3 then
  103. input = parallel.waitForAny(wait1, wait2, wait3)
  104. return input
  105. elseif counterTime == 4 then
  106. input = parallel.waitForAny(wait1, wait2, wait3, wait4)
  107. return input
  108. end
  109. end
  110.  
  111. local function runSelPlugin(input)
  112.  if input == 1 then
  113.   shell.run("/serverFolder/Plugins/coreplugin")
  114. elseif input == 2 then
  115.  local plugSel = dataMenu[4]
  116.  shell.run("/serverFolder/Plugins/"..plugSel)
  117. elseif input == 3 then
  118.  local plugSel = dataMenu[7]
  119.  shell.run("/serverFolder/Plugins/"..plugSel)
  120. elseif input == 4 then
  121.  local plugSel = dataMenu[10]
  122.  shell.run("/serverFolder/Plugins/"..plugSel)
  123. end
  124. end
  125.  
  126. shell.run("clear")
  127. createConfig()
  128. id = tonumber(loadConfig())
  129. drawMenu(dataPlugin)
  130. runSelPlugin(menuSel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement