Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local bedrockPath='/' if OneOS then OneOS.LoadAPI('/System/API/Bedrock.lua', false)elseif fs.exists(bedrockPath..'/Bedrock')then os.loadAPI(bedrockPath..'/Bedrock')else if http then print('Downloading Bedrock...')local h=http.get('http://pastebin.com/raw.php?i=0MgKNqpN')if h then local f=fs.open(bedrockPath..'/Bedrock','w')f.write(h.readAll())f.close()h.close()os.loadAPI(bedrockPath..'/Bedrock')else error('Failed to download Bedrock. Is your internet working?') end else error('This program needs to download Bedrock to work. Please enable HTTP.') end end if Bedrock then Bedrock.BasePath = bedrockPath Bedrock.ProgramPath = shell.getRunningProgram() end
- local program = Bedrock:Initialise()
- --Run the code for when the sevrer starts up
- function Start()
- --Get Conf
- local file = fs.open("data/config","r")
- conf = textutils.unserialize(file.readAll())
- file.close()
- --Use Config
- httpPro = false
- --Setup Running Variable
- running = true
- if conf.templates == "http" then
- httpPro = true
- end
- --Load Server Code
- local s,e = pcall(os.loadAPI, "data/code")
- if not s then --If Code Errored
- print("Failure Loading Server Code.")
- print("Please Debug Your Code.")
- print("----")
- print("Error:")
- print(e)
- error()
- end
- if code.init == nil then
- print("No Init Function Found In Server Code.")
- error()
- end
- if code.packet == nil then
- print("No Packet Function Found In Server Code.")
- error()
- end
- --Wrap Modem
- mod = peripheral.wrap(conf["side"])
- mod.open(100)
- --Initialize Server Code
- code.init()
- end
- --Get Html Page Function
- local function getPage(page)
- if page == nil then
- page = "index"
- end
- local file2 = fs.open("pages/"..page,"r")
- local out = ""
- if file2 == nil then
- out = "404 Page Not Found"
- else
- out = file2.readAll()
- end
- file2.close()
- return out
- end
- --Send Packet Function
- local function send(to,data)
- local pack = {}
- local mod = peripheral.wrap("left")
- pack.to = to
- pack.data = data
- pack.protocol = "returnData"
- pack = textutils.serialize(pack)
- mod.transmit(100,100,pack)
- end
- Start() --Initialize the server
- program:RegisterEvent('modem_message',function(self, event, side, sc, rc, m, d)
- if running then
- if httpPro then
- local pro = ""
- if m.protocol ~= nil then
- pro = m.protocol
- else
- pro = "http"
- end
- if pro == "http" then
- if m.data.page then
- send(m.from,getPage(m.data.page))
- else
- pcall(send,m.from,getPage(m.data))
- end
- end
- end
- code.packet(m)
- end
- end)
- program:Run(function()
- end)
Advertisement
Add Comment
Please, Sign In to add comment