Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is only a non-tested version, so easy-to-fix bugs may occurs
- dataPlugin = {}
- dataMenu = {}
- functionR = {}
- function createConfig()
- if fs.exists("/serverFolder/server.config") then
- return "nothing"
- else
- print("Thanks you for download this rednet protocol :)")
- os.sleep(2)
- term.clear()
- term.setCursorPos(1, 1)
- write("Enter the side of your modem :")
- local modemSide = io.read()
- local idServ = os.computerID()
- term.clear()
- term.setCursorPos(1, 1)
- print("You have finished the configuration of your program")
- local conf = io.open("/serverFolder/server.config", "w")
- local data = {side = modemSide, id = idServ}
- local dataS = textutils.serialize(data)
- local writeIsFail = conf:write(dataS)
- conf:close()
- print("Config succesfully written")
- sleep(2)
- end
- end
- local function loadPlugin(plugin)
- pluginF = fs.open("/serverFolder/Plugins/"..plugin, "r")
- pluginData = pluginF.readLine()
- pluginData = textutils.unserialize(pluginData)
- pluginF.close()
- pluginNameSize = #pluginData[1]
- pluginDataL = {pluginData[1], pluginData[2], pluginNameSize}
- return pluginDataL
- end
- function loadConfig()
- term.clear()
- term.setCursorPos(1, 1)
- if fs.exists("/serverFolder/Plugins") then
- loadPlugin("coreplugin")
- local pluginList = fs.list("/serverFolder/Plugins")
- local sizeList = #pluginList
- for x=1, sizeList do
- local dataPlug = loadPlugin(pluginList[x])
- table.insert(dataPlugin, dataPlug[1])
- table.insert(dataPlugin, dataPlug[2])
- table.insert(dataPlugin, dataPlug[3])
- end
- else
- print("File not found : plug-ins folder")
- end
- if fs.exists("/serverFolder/server.config") then
- local conf = fs.open("/serverFolder/server.config", "r")
- local dataS = conf.readAll()
- conf.close()
- local data = textutils.unserialize(dataS)
- local side = data.side
- local id = data.id
- rednet.open(side)
- return id
- else
- print("Cannot find the config file, please restart this program")
- os.sleep(3)
- return
- end
- end
- local function drawMenu(list)
- local sizeList = #list
- local x = 2
- local y = 4
- for count=3, #list, 3 do
- local a = x+list[count]+1
- gui.drawButton(x, y, a, y+2, list[count-2])
- if x+list[count] >= 49 then
- y=y+5
- x=2
- else
- x=x+list[count]
- end
- dataMenu.insert(x)
- dataMenu.insert(y)
- dataMenu.insert(a)
- end
- end
- local function menuSel()
- local sizeTMenu = #dataMenu
- local counterTime = 1
- for counter=1, sizeTMenu, 3 do
- wait..counterTime = function()
- gui.buttonWaitClick(dataMenu[counter], dataMenu[counter+1], dataMenu[counter+2], dataMenu[counter+1]+2 )
- end
- counterTime = counterTime+1
- end
- if counterTime == 1 then
- wait1
- return 1
- elseif counterTime == 2 then
- input = parallel.waitForAny(wait1, wait2)
- return input
- elseif counterTime == 3 then
- input = parallel.waitForAny(wait1, wait2, wait3)
- return input
- elseif counterTime == 4 then
- input = parallel.waitForAny(wait1, wait2, wait3, wait4)
- return input
- end
- end
- local function runSelPlugin(input)
- if input == 1 then
- shell.run("/serverFolder/Plugins/coreplugin")
- elseif input == 2 then
- local plugSel = dataMenu[4]
- shell.run("/serverFolder/Plugins/"..plugSel)
- elseif input == 3 then
- local plugSel = dataMenu[7]
- shell.run("/serverFolder/Plugins/"..plugSel)
- elseif input == 4 then
- local plugSel = dataMenu[10]
- shell.run("/serverFolder/Plugins/"..plugSel)
- end
- end
- shell.run("clear")
- createConfig()
- id = tonumber(loadConfig())
- drawMenu(dataPlugin)
- runSelPlugin(menuSel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement