Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This needs the CCserver base program to work
- --This is only a non-tested version, so easy-to-fix bugs may occurs
- function createConfig()
- if fs.exists("/serverFolder/server.config") then
- return "nothing"
- else
- print("Thanks you for download this rednet protocol")
- os.sleep(2)
- shell.run("clear")
- print("Enter the side of your modem")
- local modemSide = io.read()
- shell.run("clear")
- print("Enter the id of this computer")
- local idServ = io.read()
- shell.run("clear")
- print("You have finished the configuration of your program")
- fs.makeDir("serverFolder")
- fs.makeDir("usermade")
- fs.makeDir("database")
- 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")
- end
- end
- function loadConfig()
- shell.run("clear")
- 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
- function server()
- while exit == 0 do
- msgVerification = 0
- id, msg = rednet.receive()
- if msg == "p" then
- id, msg1 = rednet.receive()
- id, msg2 = rednet.receive()
- shell.run(msg1, msg2)
- elseif msg == "f" then
- id, msgDo = rednet.receive()
- id, msg1 = rednet.receive()
- if msgDo == "e" then
- loadstring(msg1) ()
- elseif msgDo == "s" then
- msgName = rednet.receive()
- newFile = io.open("/usermade/"..msgName, "w")
- newFile:write(msg1)
- newFile:close()
- end
- elseif msg == "exit" then
- shell.run("clear")
- rednet.close("right")
- break
- elseif msg == "database_new" then
- local id, msgDataName = rednet.receive()
- local id, msgData = rednet.receive()
- local data = msgData
- local dataF = fs.open("/database/"..msgDataName, "w")
- dataF.write(data)
- dataF.close()
- elseif msg == "database_append" then
- local id, msgDataName = rednet.receive()
- local id, msgDataAppend = rednet.receive()
- dataF = fs.open("/database/"..msgDataName, "r")
- dataToConc = dataF.readAll()
- dataF.close()
- dataAppend = textutils.unserialize(msgDataAppend)
- dataToConc = textutils.unserialize(dataToConc)
- local sizeTable = #dataAppend
- for x=1, sizeTable do
- table.insert(dataToConc, dataAppend[x])
- end
- dataF = fs.open("/database/"..msgDataName, "w")
- dataToWrite = textutils.serialize(dataToConc)
- dataF.write(dataToWrite)
- dataF.close()
- elseif msg == "database_read" then
- id, msgDataName = rednet.receive()
- dataF = fs.open("/database/"..msgDataName, "r")
- dataToSend = dataF.readAll()
- dataF.close()
- rednet.send(id, dataToSend)
- end
- end
- end
- end
- local msgVerification = 0
- local exit = 0
- term.clear()
- shell.run("id")
- createConfig()
- loadConfig()
- server()
- -- This needs the CCserver base program to work
- --This is only a non-tested version, so easy-to-fix bugs may occurs
- function createConfig()
- if fs.exists("/serverFolder/server.config") then
- return "nothing"
- else
- print("Thanks you for download this rednet protocol")
- os.sleep(2)
- shell.run("clear")
- print("Enter the side of your modem")
- local modemSide = io.read()
- shell.run("clear")
- print("Enter the id of this computer")
- local idServ = io.read()
- shell.run("clear")
- print("You have finished the configuration of your program")
- fs.makeDir("serverFolder")
- fs.makeDir("usermade")
- fs.makeDir("database")
- 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")
- end
- end
- function loadConfig()
- shell.run("clear")
- 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
- function server()
- while exit == 0 do
- msgVerification = 0
- id, msg = rednet.receive()
- if msg == "p" then
- id, msg1 = rednet.receive()
- id, msg2 = rednet.receive()
- shell.run(msg1, msg2)
- elseif msg == "f" then
- id, msgDo = rednet.receive()
- id, msg1 = rednet.receive()
- if msgDo == "e" then
- loadstring(msg1) ()
- elseif msgDo == "s" then
- msgName = rednet.receive()
- newFile = io.open("/usermade/"..msgName, "w")
- newFile:write(msg1)
- newFile:close()
- end
- elseif msg == "exit" then
- shell.run("clear")
- rednet.close("right")
- break
- elseif msg == "database_new" then
- local id, msgDataName = rednet.receive()
- local id, msgData = rednet.receive()
- local data = msgData
- local dataF = fs.open("/database/"..msgDataName, "w")
- dataF.write(data)
- dataF.close()
- elseif msg == "database_append" then
- local id, msgDataName = rednet.receive()
- local id, msgDataAppend = rednet.receive()
- dataF = fs.open("/database/"..msgDataName, "r")
- dataToConc = dataF.readAll()
- dataF.close()
- dataAppend = textutils.unserialize(msgDataAppend)
- dataToConc = textutils.unserialize(dataToConc)
- local sizeTable = #dataAppend
- for x=1, sizeTable do
- table.insert(dataToConc, dataAppend[x])
- end
- dataF = fs.open("/database/"..msgDataName, "w")
- dataToWrite = textutils.serialize(dataToConc)
- dataF.write(dataToWrite)
- dataF.close()
- elseif msg == "database_read" then
- id, msgDataName = rednet.receive()
- dataF = fs.open("/database/"..msgDataName, "r")
- dataToSend = dataF.readAll()
- dataF.close()
- rednet.send(id, dataToSend)
- end
- end
- end
- end
- local msgVerification = 0
- local exit = 0
- term.clear()
- shell.run("id")
- createConfig()
- loadConfig()
- server()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement