Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Hideously Smashed Together by Compilr, a Hideous Smash-Stuff-Togetherer, (c) 2014 oeed --
- -- This file REALLLLLLLY isn't suitable to be used for anything other than being executed --
- -- To extract all the files, run: "<filename> --extract" in the Shell --
- local files = {
- r = "os.reboot()",
- startup = "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()\
- \
- local communicate = Communicate:Initialise(program)\
- \
- local info = {\
- Name = 'A Server',\
- Actions = {\
- {\
- Name = '',\
- MessageType = '',\
- Function = function(message)\
- end\
- },\
- {\
- Name = 'Reboot System',\
- MessageType = 'reboot',\
- Function = function(message)\
- os.reboot()\
- end\
- }\
- }\
- }\
- \
- communicate:RegisterMessageType('discover', function(message)\
- if message.content == 'Ping!' then\
- local _info = {}\
- _info.Name = info.Name\
- _info.Actions = {}\
- for i, v in ipairs(info.Actions) do\
- table.insert(_info.Actions, {Name = v.Name, MessageType = v.MessageType})\
- end\
- return _info\
- end\
- end)\
- \
- for i, v in ipairs(info.Actions) do\
- communicate:RegisterMessageType(v.MessageType, v.Function)\
- end\
- \
- communicate:RegisterMessageType('ping', function(message)\
- if message.content == 'Ping!' then\
- return 'Pong!'\
- end\
- end)\
- \
- program:Run(function()\
- end)",
- Views = {
- [ "main.view" ] = "{\
- Children = {}\
- -- BackgroundColour = 'white',\
- -- Children = {\
- -- {\
- -- Y = 3,\
- -- Width = \"100%\",\
- -- Align = \"Center\",\
- -- TextColour = 'blue',\
- -- Type = 'Label',\
- -- }\
- -- }\
- }",
- },
- APIs = {
- [ "Communicate.lua" ] = "\
- Channel = 42000\
- Callbacks = {}\
- CallbackTimeouts = {}\
- MessageTimeout = 0.5\
- MessageTypeHandlers = {}\
- \
- local getNames = peripheral.getNames or function()\
- local tResults = {}\
- for n,sSide in ipairs( rs.getSides() ) do\
- if peripheral.isPresent( sSide ) then\
- table.insert( tResults, sSide )\
- local isWireless = false\
- if pcall(function()isWireless = peripheral.call(sSide, 'isWireless') end) then\
- isWireless = true\
- end \
- if peripheral.getType( sSide ) == \"modem\" and not isWireless then\
- local tRemote = peripheral.call( sSide, \"getNamesRemote\" )\
- for n,sName in ipairs( tRemote ) do\
- table.insert( tResults, sName )\
- end\
- end\
- end\
- end\
- return tResults\
- end\
- \
- GetModems = function(self, callback)\
- local ok = false\
- for i, name in ipairs(getNames()) do\
- ok = true\
- if callback and peripheral.getType( name ) == \"modem\" then\
- local p = peripheral.wrap(name)\
- callback(p, name)\
- end\
- end\
- return ok\
- end\
- \
- Initialise = function(self, bedrock)\
- local new = {}\
- setmetatable(new, {__index = self})\
- new.Bedrock = bedrock\
- new.Bedrock:RegisterEvent('modem_message', function(_, event, name, channel, replyChannel, message, distance)\
- new:OnMessage(event, name, channel, replyChannel, message, distance)\
- end)\
- if new:GetModems(function(modem, name)\
- modem.open(new.Channel)\
- end)\
- then\
- return new\
- end\
- return false\
- end\
- \
- RegisterMessageType = function(self, msgType, callback)\
- self.MessageTypeHandlers[msgType] = callback\
- end\
- \
- OnMessage = function(self, event, name, channel, replyChannel, message, distance)\
- if channel == self.Channel and type(message) == 'table' and message.msgType and message.thread and message.id ~= os.getComputerID() then\
- if self.Callbacks[message.thread] then\
- local response, callback = self.Callbacks[message.thread](message.content, message, distance)\
- if response ~= nil then\
- self:Reply(response, message, callback)\
- end\
- elseif self.MessageTypeHandlers[message.msgType] then\
- local response = self.MessageTypeHandlers[message.msgType](message, message.msgType, message.content, distance)\
- if response ~= nil then\
- self:Reply(response, message)\
- end\
- else\
- end\
- return true\
- else\
- return false\
- end\
- end\
- \
- Reply = function(self, content, message, callback)\
- self:SendMessage(message.msgType, content, callback, message.thread)\
- end\
- \
- SendMessage = function(self, msgType, content, callback, thread, multiple)\
- thread = thread or tostring(math.random())\
- if self:GetModems(function(modem, name)\
- modem.transmit(self.Channel, self.Channel, {msgType = msgType, content = content, thread = thread, id = os.getComputerID()})\
- end)\
- then\
- if callback then\
- self.Callbacks[thread] = function(...)\
- if not multiple then\
- self.Callbacks[thread] = nil\
- self.CallbackTimeouts[thread] = nil\
- end\
- return callback(...), callback\
- end\
- \
- self.CallbackTimeouts[thread] = self.Bedrock:StartTimer(function(_, timer)\
- if timer == self.CallbackTimeouts[thread] then\
- callback(false)\
- end\
- end, self.MessageTimeout)\
- end\
- return true\
- end\
- return false\
- end",
- },
- }
- local function run(tArgs)
- local fnFile, err = loadstring(files['startup'], 'startup')
- if err then
- error(err)
- end
- local function split(str, pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- local function resolveTreeForPath(path, single)
- local _files = files
- local parts = split(path, '/')
- if parts then
- for i, v in ipairs(parts) do
- if #v > 0 then
- if _files[v] then
- _files = _files[v]
- else
- _files = nil
- break
- end
- end
- end
- elseif #path > 0 and path ~= '/' then
- _files = _files[path]
- end
- if not single or type(_files) == 'string' then
- return _files
- end
- end
- local oldFs = fs
- local env
- env = {
- fs = {
- list = function(path)
- local list = {}
- if fs.exists(path) then
- list = fs.list(path)
- end
- for k, v in pairs(resolveTreeForPath(path)) do
- if not fs.exists(path .. '/' ..k) then
- table.insert(list, k)
- end
- end
- return list
- end,
- exists = function(path)
- if fs.exists(path) then
- return true
- elseif resolveTreeForPath(path) then
- return true
- else
- return false
- end
- end,
- isDir = function(path)
- if fs.isDir(path) then
- return true
- else
- local tree = resolveTreeForPath(path)
- if tree and type(tree) == 'table' then
- return true
- else
- return false
- end
- end
- end,
- isReadOnly = function(path)
- if not fs.isReadOnly(path) then
- return false
- else
- return true
- end
- end,
- getName = fs.getName,
- getSize = fs.getSize,
- getFreespace = fs.getFreespace,
- makeDir = fs.makeDir,
- move = fs.move,
- copy = fs.copy,
- delete = fs.delete,
- combine = fs.combine,
- open = function(path, mode)
- if fs.exists(path) then
- return fs.open(path, mode)
- elseif type(resolveTreeForPath(path)) == 'string' then
- local handle = {close = function()end}
- if mode == 'r' then
- local content = resolveTreeForPath(path)
- handle.readAll = function()
- return content
- end
- local line = 1
- local lines = split(content, '\n')
- handle.readLine = function()
- if line > #lines then
- return nil
- else
- return lines[line]
- end
- line = line + 1
- end
- return handle
- else
- error('Cannot write to read-only file (compilr archived).')
- end
- else
- return fs.open(path, mode)
- end
- end
- },
- io = {
- input = io.input,
- output = io.output,
- type = io.type,
- close = io.close,
- write = io.write,
- flush = io.flush,
- lines = io.lines,
- read = io.read,
- open = function(path, mode)
- if fs.exists(path) then
- return io.open(path, mode)
- elseif type(resolveTreeForPath(path)) == 'string' then
- local content = resolveTreeForPath(path)
- local f = fs.open(path, 'w')
- f.write(content)
- f.close()
- if mode == 'r' then
- return io.open(path, mode)
- else
- error('Cannot write to read-only file (compilr archived).')
- end
- else
- return io.open(path, mode)
- end
- end
- },
- loadfile = function( _sFile )
- local file = env.fs.open( _sFile, "r" )
- if file then
- local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
- file.close()
- return func, err
- end
- return nil, "File not found: ".._sFile
- end,
- dofile = function( _sFile )
- local fnFile, e = env.loadfile( _sFile )
- if fnFile then
- setfenv( fnFile, getfenv(2) )
- return fnFile()
- else
- error( e, 2 )
- end
- end
- }
- setmetatable( env, { __index = _G } )
- local tAPIsLoading = {}
- env.os.loadAPI = function( _sPath )
- local sName = fs.getName( _sPath )
- if tAPIsLoading[sName] == true then
- printError( "API "..sName.." is already being loaded" )
- return false
- end
- tAPIsLoading[sName] = true
- local tEnv = {}
- setmetatable( tEnv, { __index = env } )
- local fnAPI, err = env.loadfile( _sPath )
- if fnAPI then
- setfenv( fnAPI, tEnv )
- fnAPI()
- else
- printError( err )
- tAPIsLoading[sName] = nil
- return false
- end
- local tAPI = {}
- for k,v in pairs( tEnv ) do
- tAPI[k] = v
- end
- env[sName] = tAPI
- tAPIsLoading[sName] = nil
- return true
- end
- env.shell = shell
- setfenv( fnFile, env )
- fnFile(unpack(tArgs))
- end
- local function extract()
- local function node(path, tree)
- if type(tree) == 'table' then
- fs.makeDir(path)
- for k, v in pairs(tree) do
- node(path .. '/' .. k, v)
- end
- else
- local f = fs.open(path, 'w')
- if f then
- f.write(tree)
- f.close()
- end
- end
- end
- node('', files)
- end
- local tArgs = {...}
- if #tArgs == 1 and tArgs[1] == '--extract' then
- extract()
- else
- run(tArgs)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement