local tArgs = {...} termX, termY = term.getSize() Peripheral = { GetPeripheral = function(_type) for i, p in ipairs(Peripheral.GetPeripherals()) do if p.Type == _type then return p end end end, Call = function(type, ...) local tArgs = {...} local p = GetPeripheral(type) peripheral.call(p.Side, unpack(tArgs)) end, GetPeripherals = function(filterType) local peripherals = {} for i, side in ipairs(peripheral.getNames()) do local name = peripheral.getType(side):gsub("^%l", string.upper) local code = string.upper(side:sub(1,1)) if side:find('_') then code = side:sub(side:find('_')+1) end local dupe = false for i, v in ipairs(peripherals) do if v[1] == name .. ' ' .. code then dupe = true end end if not dupe then local _type = peripheral.getType(side) local isWireless = false if _type == 'modem' then if not pcall(function()isWireless = peripheral.call(sSide, 'isWireless') end) then isWireless = true end if isWireless then _type = 'wireless_modem' name = 'W '..name end end if not filterType or _type == filterType then table.insert(peripherals, {Name = name:sub(1,8) .. ' '..code, Fullname = name .. ' ('..Capitalise(side)..')', Side = side, Type = _type, Wireless = isWireless}) end end end return peripherals end, GetPeripheral = function(_type) for i, p in ipairs(Peripheral.GetPeripherals()) do if p.Type == _type then return p end end end, PresentNamed = function(name) return peripheral.isPresent(name) end, CallType = function(type, ...) local tArgs = {...} local p = Peripheral.GetPeripheral(type) return peripheral.call(p.Side, unpack(tArgs)) end, CallNamed = function(name, ...) local tArgs = {...} return peripheral.call(name, unpack(tArgs)) end } Capitalise = function(str) return str:sub(1, 1):upper() .. str:sub(2, -1) end -- Modem Functions Called For Info On Modems, Or To Change Modem Status modem = { channels = { discover = 6019, fileSend = 6021, reply = 6023, }, isOpen = function(channel) --Returns if the channel is open or not Peripheral.CallType('wireless_modem', 'isOpen', channel) end, Open = function(channel) --Open a channel if not already open if not modem.isOpen(channel) then Peripheral.CallType('wireless_modem', 'open', channel) end end, Close = function(channel) --Close channel specified Peripheral.CallType('wireless_modem', 'close', channel) end, CloseAll = function() --Close all channels Peripheral.CallType('wireless_modem', 'closeAll') end, Transmit = function(channel, replyChannel, message) --Transmit a message over the modem... The message is serialized first so it can hold data.... Use FormatMessage() Peripheral.CallType('wireless_modem', 'transmit', channel, replyChannel, textutils.serialize(message)) end, isPresent = function() if Peripheral.GetPeripheral('wireless_modem') == nil then return false else return true end end, SendMessage = function(channel, message, reply, messageID, destinationID) reply = reply or modem.channels.reply modem.Open(channel) modem.Open(reply) local _message = modem.FormatMessage(message, messageID, destinationID) modem.Transmit(channel, reply, _message) return _message end, FormatMessage = function(message, messageID, destinationID) return { content = textutils.serialize(message), senderID = os.getComputerID(), senderName = os.getComputerLabel(), channel = channel, replyChannel = reply } end, Initialise = function() if modem.isPresent() then for i, c in pairs(modem.channels) do modem.Open(c) LogFile.i(c.." Open", runningProgram) end end end, checkMessage = function(event, side, channel, reply, _message, distance) message = textutils.unserialize(_message) LogFile.i('message received: '..textutils.serialize(message), runningProgram) if channel == modem.channels.discover then if PCwaiting then if message == "discoverClients" then local message = {} message["idno"] = os.getComputerID() message["name"] = os.getComputerLabel() LogFile.i('Sending Message: '..tostring(message), runningProgram) rmessage = textutils.serialize(message) LogFile.i('Compiled Message: '..tostring(rmessage), runningProgram) modem.Transmit(modem.channels.reply, modem.channels.discover, message) return end end elseif channel == modem.channels.fileSend then if PCwaiting then if message['content'] == "downloadConfirm" and tonumber(message['dest']) == os.getComputerID() then tableClear() drawTitle() printer.centered('Transfer Request', 6) term.setTextColor(colors.gray) printer.centered('Computer '..message['name']..' ('..message['idno']..')', 8) printer.centered('Wants to send you a file ('..message['fileName']..')', 9) printer.centered('Do you accept or deny the request?', 11) deny = btnInit("Deny", nil, nil, 2, 18, 1, colors.blue, colors.black, 1, function() local senderID = message['idno'] local message = {} message['content'] = "DENY" message['idno'] = os.getComputerID() message['name'] = os.getComputerLabel() message['dest'] = senderID modem.Transmit(modem.channels.fileSend, modem.channels.reply, message) mainMenu() end, false) accept = btnInit("Accept", nil, nil, termX-4-#"Accept", 18, 1, colors.blue, colors.black, 1, function() senderID = message['idno'] local message = {} message['content'] = "ACCEPT" message['idno'] = os.getComputerID() message['name'] = os.getComputerLabel() message['dest'] = senderID modem.Transmit(modem.channels.fileSend, modem.channels.reply, message) tableClear() drawTitle() printer.centered('Waiting For Download', 6) term.setTextColor(colors.gray) printer.centered('You have accepted the download', 10) printer.centered('we are just waiting for the sender', 11) printer.centered('to transfer the file', 12) while true do local e, p1, p2, p3, p4, p5 = os.pullEvent() if e == "mouse_click" then doClick(e, p1, p2, p3) elseif e == "modem_message" then message = textutils.unserialize(p4) if message['proto'] == "fileTransfer" then if tonumber(message['dest']) == os.getComputerID() then message['fileName'] = fileConflict(message['fileName']) tableClear() drawTitle() printer.centered('Downloading File', 10) local text = stripText(message['fileName']) printer.centered(text, 11) printer.centered("", 12) sleep(0.6) local f = fs.open(message['fileName'], 'w') f.write(message['content']) f.close() drawTitle() printer.centered('Download Complete', 6) local _message = {} _message['dest'] = senderID _message['idno'] = os.getComputerID() _message['name'] = os.getComputerLabel() or 'CCDrop Client' _message['content'] = 'downloadComplete' modem.Transmit(modem.channels.fileSend, modem.channels.reply, _message) term.setTextColor(colors.gray) printer.centered('File has been saved to; ', 8) printer.centered(message['fileName'], 9) term.setTextColor(colors.black) printer.centered('Click anywhere to continue', 19) os.pullEvent('mouse_click') mainMenu() end elseif message['proto'] == 'dirTransfer' and message['dest'] == os.getComputerID() then drawTitle() tableClear() printer.centered('Downloading Directories', 6) term.setTextColor(colors.gray) printer.centered('The file being sent is a folder containing multiple', 8) printer.centered('files, we are downloading them now', 9) while true do local e, p1, p2, p3, p4, p5 = os.pullEvent() if e == 'mouse_click' then doClick(e, p1, p2, p3) elseif e == "modem_message" then p4 = textutils.unserialize(p4) if tonumber(p4['dest']) == os.getComputerID() then if p4['proto'] == 'dirTransfer' or p4['proto'] == 'dirTransferFinal' then drawTitle() p4['fileName'] = fileConflict(p4['fileName']) drawTitle() printer.centered('Downloading', 10) local text = stripText(p4['fileName']) printer.centered(p4['fileName'], 11) local h = fs.open(p4['fileName'], 'w') h.write(p4['content']) h.close() local _message = {} _message['dest'] = p4['idno'] _message['content'] = 'downloadComplete' modem.Transmit(modem.channels.fileSend, modem.channels.reply, _message) if p4['proto'] == 'dirTransferFinal' then drawTitle() printer.centered('Download Complete', 6) local _message = {} _message['dest'] = senderID _message['idno'] = os.getComputerID() _message['name'] = os.getComputerLabel() or 'CCDrop Client' _message['content'] = 'downloadComplete' modem.Transmit(modem.channels.fileSend, modem.channels.reply, _message) term.setTextColor(colors.gray) printer.centered('The download is finished!', 8) printer.centered('Click anywhere to continue', 19) os.pullEvent('mouse_click') mainMenu() end else error'Incorrect protocol' end else error('Incorrect ID: '..os.getComputerID()..":<>:"..p4['dest']..":EntireMessage:"..textutils.serialize(p4)) end end end end end end end, false) elseif message['content'] == 'downloadExpired' and message['dest'] == os.getComputerID() then tableClear() drawTitle() printer.centered('Download Revoked', 6) printer.centered('Click anywhere to return', 19) term.setTextColor(colors.gray) printer.centered('The sender revoked the download', 10) os.pullEvent('mouse_click') mainMenu() end elseif PCsending then if message['content'] == 'ACCEPT' and message['dest'] == os.getComputerID() then os.queueEvent('accept') elseif message['content'] == 'DENY' and message['dest'] == os.getComputerID() then os.queueEvent('deny') elseif message['content'] == "downloadComplete" and message['dest'] == os.getComputerID() then drawTitle() tableClear() printer.centered('Transfer Complete', 6) term.setTextColor(colors.gray) printer.centered('Client '..message['idno']..' has completed the download', 8) term.setTextColor(colors.black) printer.centered('Click anywhere to continue', 19) os.pullEvent('mouse_click') mainMenu() end end end end, } function stripText(text) if #text > 20 then local s1 = string.sub(text, 1, 10) local s2 = string.sub(text, -10) LogFile.i('Stripping text: '..text.."::Part One: "..s1.."Part Two: "..s2, runningProgram) local text = (s1.."..."..s2) return text end return text end local blackList = { "\\" } function fileConflict(file) LogFile.i('Checking File conflict: '..file, runningProgram) tableClear() if fs.exists(file) then LogFile.i('CONFLICT: '..file, runningProgram) drawTitle() printer.centered('File Conflict', 6) printer.centered(file, 19) term.setTextColor(colors.gray) printer.centered('A file already exists with the same name', 8) printer.centered('as the file you are trying to download', 9) printer.centered('Do you want to overwrite the file or save', 11) printer.centered('elsewhere', 12) saveelse = btnInit("Save Elsewhere", nil, nil, termX-4-#"Save Elsewhere", 18, 1, colors.blue, colors.black, 1, function() os.queueEvent('saveelse') end, false) overwrite = btnInit("Overwrite", nil, nil, saveelse.x-4-#"Overwrite", 18, 1, colors.blue, colors.black, 1, function() os.queueEvent('overwrite') end, false) while true do local e, p1, p2, p3, p4, p5 = os.pullEvent() if e == "mouse_click" then doClick(e, p1, p2, p3) elseif e == "overwrite" then fs.delete(file) return file elseif e == "saveelse" then drawTitle() tableClear() printer.centered('Rename File', 6) term.setTextColor(colors.gray) printer.centered('Enter the new path for the download', 8) local text = "New Path: " term.setCursorPos(termX/2-#text, 12) write(text) local input = uInput.restrictedKeyRead(termX*10, nil, elements, blackList) if input ~= "" then return input end end end end return file end local required = { 'LogFile', 'element', 'printer', 'titleBar', 'uInput' } Events = {} elements = {} computers = {} function downloadFile(getUrl, toPath) for i = 1, 3 do local response = http.get(getUrl) if response then data = response.readAll() if fs.exists(toPath) then fs.delete(toPath) end if toPath then if fs.exists(toPath) then fs.delete(toPath) end local file = fs.open(toPath, "w") file.write(data) file.close() print(getUrl) print(toPath) sleep(0) return true else return false end else return false end end return false end if not fs.exists('api') then fs.makeDir('api') end if not fs.exists('systemFiles') then fs.makeDir('systemFiles') end for i, v in pairs(required) do print(v) if not fs.exists('/api/'..v) then if not downloadFile("https://raw.githubusercontent.com/hbomb79/securitySystemPro/master/api/"..v, "/api/"..v) then error('Failed to download: '..v) end end if not os.loadAPI('/api/'..v) then error('Failed to load API: '..v) end end LogFile.Initialise() function btnInit(btnText, btnWidth, btnHeight, btnX, btnY, btnTC, btnBG, oTC, oBG, onClick, toggle, secBG, secTC, secText, parent) --Function to create button local btn = element.create(btnText, btnWidth, btnHeight, btnX, btnY, btnTC, btnBG, oTC, oBG, onClick, toggle, secBG, secTC, secText, parent) --Calls API to generate button table.insert(elements, btn) --Inserts into table so it can be scanned later element.opacity(btn, true) --Sets visibility to true return btn end function doClick(event, btn, x, y) functionToRun = element.tryClick(elements, x, y) if functionToRun then --Check click location functionToRun() end end function eventRegister(event, functionToRun) LogFile.i('Registered Event: '..event, runningProgram) if not Events[event] then Events[event] = {} end table.insert(Events[event], functionToRun) end function eventLoop() while true do local event, arg1, arg2, arg3, arg4, arg5, arg6 = os.pullEventRaw() if Events[event] then for i, e in ipairs(Events[event]) do e(event, arg1, arg2, arg3, arg4, arg5, arg6) end end end end function drawTitle() titleBar.draw('CCDrop', 'Wireless Transfer', colors.white, 1, colors.blue, colors.white, colors.black) end displayButtons = {} function tableClear(optional) term.setCursorBlink(false) if optional then tablesToRemove = {displayButtons, elements, computers} else tablesToRemove = {displayButtons, elements} end for i, v in ipairs (tablesToRemove) do local k = next(v) while k do v[k] = nil k = next(v) end end end local blackList = { "\\" } function pingDiscover() pcMsg = {} timeout = os.startTimer(3) while true do local e, p1, p2, p3, p4, p5 = os.pullEvent() if e == "modem_message" then timeout = os.startTimer(1) table.insert(pcMsg, p4) elseif e == "timer" then if p1 == timeout then addComputers() break end end end end function addComputers() tableClear(true) for i, v in ipairs(pcMsg) do _message = textutils.unserialize(v) local DUPE = false for _, pc in ipairs(computers) do if tonumber(_message['idno']) == pc then DUPE = true end end if not DUPE then table.insert(computers, _message) LogFile.i("Inserted "..tostring(_message['idno']).." Into Table", runningProgram) if _message['name'] then LogFile.i(_message['name'], runningProgram) end end end end function listClients() term.setCursorBlink(false) tableClear() drawTitle() printer.centered("Please Wait While We Search For Clients", 6) term.setTextColor(colors.gray) printer.centered("Run this program on other computers and", 8) printer.centered("They will appear here", 9) modem.Transmit(modem.channels.discover, modem.channels.reply, "discoverClients") pingDiscover() if #computers < 1 then tableClear() drawTitle() printer.centered("We Couldn't Find Any Clients", 6) term.setTextColor(colors.gray) printer.centered("In order to find some you must have", 8) printer.centered("other computers running this program in", 9) printer.centered("WAIT mode", 10) term.setTextColor(colors.black) printer.centered("Click Anywhere To Return", 19) os.pullEvent('mouse_click') return 'NOCLIENTS' else tableClear() drawTitle() printer.centered('Clients Found: '..#computers, 6) printer.centered('Please wait while we render the menu', 8) local function clientList() local title = "Choose the device to send your file to" local tArgs = computers local pages = {[1]={}} for i = 1, #tArgs, 1 do if #pages[ #pages ] == 6 then pages[ #pages + 1 ] = {} end pages[ #pages ][ #pages[#pages] + 1 ] = tArgs[ i ] end local maxx, maxy = term.getSize() local page = 1 local selected = 1 local function render() local tbl = pages[ page ] tableClear() drawTitle() printer.centered(title, 4) local xValue = 2 local Count = 1 local yValue = 8 LogFile.i("Length Of PreRender: "..tostring(#tbl), runningProgram) if pages[page-1] then prevBtn = btnInit("Previous Page", nil, nil, 2, 18, 1, colors.cyan, colors.black, 1, function() os.queueEvent("PreviousPage") end, false, nil, nil, nil, nil) end if pages[page+1] then nxtBtn = btnInit("Next Page", nil, nil, termX - 2 - #"Next Page", 18, 1, colors.cyan, colors.black, 1, function() os.queueEvent("NextPage") end, false, nil, nil, nil, nil) end backBtn = btnInit("Return", nil, nil, termX/2-#"Return"/2, 18, 1, colors.red, colors.black, 1, function() os.queueEvent("back") end, false, nil, nil, nil, nil) LogFile.i(tostring(textutils.serialize(tbl)), runningProgram) LogFile.i(tostring(textutils.serialize(computers)), runningProgram) for i = 1, #tbl do local lastName = tbl[i]['name'] or "CCDrop Client" LogFile.i("Iteration "..i.." Name: "..tostring(lastName).." ID: "..tostring(tbl[i]['idno']), runningProgram) if Count == 1 then x = 2 y = 8 elseif Count == 2 then y = 8 x = termX-6-#lastName-#tostring(tbl[i]['idno']) elseif Count == 3 then y = 11 x = 2 elseif Count == 4 then y = 11 x = termX-6-#lastName-#tostring(tbl[i]['idno']) elseif Count == 5 then y = 14 x = 2 elseif Count == 6 then y = 14 x = termX-6-#lastName-#tostring(tbl[i]['idno']) Count = 1 end displayButtons[tbl[i]] = btnInit(tostring(lastName)..' ('..tostring(tbl[i]['idno'])..')', nil, nil, x, y, 1, colors.blue, colors.black, 1, function() clientToSend = tbl[i]['idno'] os.queueEvent('Done') end, false, nil, nil, nil, nil) Count = Count + 1 end if pages[ page - 1 ] then element.opacity(prevBtn, true) end if pages[ page + 1 ] then element.opacity(nxtBtn, true) end term.setTextColor(colors.gray) local str = "(" .. page .. "/" .. #pages .. ")" printer.centered( str , 19) term.setTextColor(colors.black) end while true do render() local event, param1, p2, p3 = os.pullEvent() if event == "mouse_click" then doClick(event, param1, p2, p3) elseif event == "PreviousPage" then if pages[page-1] then printer.centered("Loading, Please Wait...", 4) sleep(0) page = page -1 element.opacity(prevBtn, false) element.opacity(nxtBtn, false) tableClear() drawTitle() else prevBtn.visible = false LogFile.w("Previous Button Fired When On First Page!", runningProgram) end elseif event == "NextPage" then if pages[page+1] then printer.centered("Loading, Please Wait...", 4) sleep(0.2) page = page + 1 element.opacity(prevBtn, false) element.opacity(nxtBtn, false) tableClear() drawTitle() else nxtBtn.visible = false LogFile.w("Next Button Fired When On Last Page!", runningProgram) end elseif event == "Done" then return clientToSend elseif event == "back" then tableClear() drawTitle() mainMenu() end end end client = clientList() return client end end function directoryFound(dir, protocol) if protocol == false then term.setTextColor(colors.black) printer.centered('Found directory!', 6) term.setTextColor(colors.gray) printer.centered("We found this directory", 8) printer.centered(stripText(dir), 9) printer.centered('Do you want to transmit files in here too?', 11) back = btnInit("Yes", nil, nil, termX-2-#"Yes", 18, 1, colors.green, colors.black, 1, function() os.queueEvent('yes') end, false) back = btnInit("Nope", nil, nil, 2, 18, 1, colors.red, colors.black, 1, function() os.queueEvent('no') end, false) while true do local e, p1, p2, p3 = os.pullEvent() if e == 'mouse_click' then doClick(e, p1, p2, p3) elseif e == 'yes' then return true elseif e == 'no' then return false end end else return true end end function transferDir(mainDir, clientToSend, transferAll) local dirs, fileToSend = {}, {} local tablesToRemove = {fileToSend, dirs} for i, v in ipairs (tablesToRemove) do local k = next(v) while k do v[k] = nil k = next(v) end end tableClear() drawTitle() printer.centered('Searching '..mainDir, 6) term.setTextColor(colors.gray) printer.centered('We are searching the main directory', 8) printer.centered('for files and folders to send', 9) for i, v in ipairs(fs.list(mainDir)) do sleep() v = mainDir..'/'..v LogFile.i('List File: '..v, runningProgram) if fs.isDir(v) then if directoryFound(v, transferAll) then table.insert(dirs, v) LogFile.i('Added directory: '..v, runningProgram) end else LogFile.i('Adding file: '..v, runningProgram) table.insert(fileToSend, v) end end LogFile.i('Secondary Check', runningProgram) for i, v in ipairs(dirs) do for _, k in ipairs(fs.list(v)) do sleep() k = v..'/'..k LogFile.i('Scanning File: '..k, runningProgram) if fs.isDir(k) and directoryFound(k, transferAll) then LogFile.i('DIRECTORY Found: '..k, runningProgram) table.insert(dirs, k) else LogFile.i('File Found: '..k, runningProgram) table.insert(fileToSend, k) end end end LogFile.i('File Found: '..textutils.serialize(fileToSend)..' Dirs: '..textutils.serialize(dirs), runningProgram) if #fileToSend < 1 and #dirs < 1 then tableClear() drawTitle() printer.centered('Nothing To Send', 6) printer.centered('Click Anywhere To Return', 19) term.setTextColor(colors.gray) printer.centered('We cannot find any files or folders', 8) printer.centered('inside of '..mainDir, 9) else tableClear() drawTitle() local messageProbe = {} messageProbe['idno'] = os.getComputerID() messageProbe['dest'] = clientToSend messageProbe['proto'] = 'dirTransfer' modem.Transmit(modem.channels.fileSend, modem.channels.reply, messageProbe) printer.centered('Transfering Files', 6) term.setTextColor(colors.gray) printer.centered('Any files in directories you requested', 6) printer.centered('to be sent will be transfered as well', 7) for i, v in ipairs(fileToSend) do term.setTextColor(colors.black) printer.centered('Sending '..stripText(v), 10) printer.centered('', 11) term.setTextColor(colors.gray) local message = {} message['dest'] = clientToSend message['idno'] = os.getComputerID() message['name'] = os.getComputerLabel() if i < #fileToSend then message['proto'] = 'dirTransfer' elseif i == #fileToSend then LogFile.i('Last Message', runningProgram) message['proto'] = 'dirTransferFinal' end message['fileName'] = v local f = fs.open(message['fileName'], 'r') message['content'] = f.readAll() f.close() modem.Transmit(modem.channels.fileSend, modem.channels.reply, message) LogFile.i('Sent File: '..textutils.serialize(message), runningProgram) while true do printer.centered('Waiting For Client', 11) LogFile.i('Awaiting Client Confirmation', runningProgram) local e, p1, p2, p3, p4, p5 = os.pullEvent() if e == 'modem_message' then p4 = textutils.unserialize(p4) if p4['dest'] == os.getComputerID() and p4['content'] == 'downloadComplete' then LogFile.i('Client Confirmed', runningProgram) break end end end if i == #fileToSend then drawTitle() printer.centered('Download Finished!', 6) printer.centered('Click Anywhere To Continue', 19) term.setTextColor(colors.gray) printer.centered('The client has downloaded all the files', 8) printer.centered('you sent', 9) os.pullEvent('mouse_click') end end mainMenu() end end function transferFile(file, clientToSend) tableClear() drawTitle() printer.centered('Starting Download', 6) term.setTextColor(colors.gray) printer.centered('The client accepted your download request', 8) printer.centered('please wait while transfer your file', 9) term.setTextColor(colors.black) printer.centered('Gathering Information', 6) local message = {} message['dest'] = clientToSend message['idno'] = os.getComputerID() message['name'] = os.getComputerLabel() or "CCDrop Client" message['proto'] = 'fileTransfer' message['fileName'] = file printer.centered('Extracting File', 6) if not fs.exists(file) then error'File no longer exists!' end local f = fs.open(file, 'r') local fileToSend = f.readAll() f.close() message['content'] = fileToSend printer.centered('Transfering...', 6) modem.Transmit(modem.channels.fileSend, modem.channels.reply, message) end function sendFile(args) while true do if not args then tableClear() drawTitle() submit = btnInit("Choose Cient", nil, nil, termX/2-#"Choose Client"/2, 18, 1, colors.blue, colors.black, 1, function() os.queueEvent("submit_Result") end, false) back = btnInit("Back", nil, nil, 2, 18, 1, colors.red, colors.black, 1, function() os.queueEvent('submit_Result') mainMenu() end, false) printer.centered("File Send", 6) term.setTextColor(colors.gray) printer.centered("To send a file or directory, enter its path", 8) printer.centered("and click \"Choose Client\" to continue", 9) printer.centered("NOTE: You can use backward dirs (..)", 19) local text = "File Path: " term.setCursorPos(termX/2-#text, 11) write(text) input = uInput.restrictedEventRead(termX*10, nil, elements, blackList) else input = tostring(args) end if input ~= "" then fileToSend = input if fs.isDir(input) then drawTitle() tableClear() printer.centered('Transfer Directory', 6) term.setTextColor(colors.gray) printer.centered('The path you entered is a directory', 8) printer.centered('If you continue then we will send the contents', 9) printer.centered('If you did this on accident then click back', 10) goBtn = btnInit("Go Ahead!", nil, nil, termX-2-#"Go Ahead!", 18, 1, colors.blue, colors.black, 1,function() os.queueEvent('continue') end, false) backBtn = btnInit("No Thanks", nil, nil, goBtn.x-4-#"No Thanks", 18, 1, colors.blue, colors.black, 1, function() os.queueEvent('back') end, false) while true do local e, p1, p2, p3 = os.pullEvent() LogFile.i(e, runningProgram) if e == "mouse_click" then doClick(e, p1, p2, p3) elseif e == 'back' then tableClear() drawTitle() mainMenu() elseif e == 'continue' then break end end end if fs.exists(input) then clientToSend = listClients() if clientToSend == "NOCLIENTS" then break end local message = {} message['dest'] = clientToSend message['idno'] = os.getComputerID() message['name'] = os.getComputerLabel() or "CCDrop Client" message['fileName'] = fileToSend or "ERROR, DONT DOWNLOAD" message['content'] = "downloadConfirm" PCsending = true modem.Transmit(modem.channels.fileSend, modem.channels.reply, message) tableClear() drawTitle() printer.centered('Waiting For Consent', 6) term.setTextColor(colors.gray) printer.centered("Client "..tostring(clientToSend).." needs to accept your request", 8) printer.centered("When the client accepts, the download will begin", 10) back = btnInit("Cancel", nil, nil, termX/2-#"Cancel"/2, 18, 1, colors.red, colors.black, 1, function() os.queueEvent('cancel') end, false) while true do local e, p1, p2, p3, p4, p5 = os.pullEvent() if e == "accept" then --Transfer file. if fs.isDir(input) then drawTitle() tableClear() printer.centered('More Directories', 6) term.setTextColor(colors.gray) printer.centered('When we check this directory we may find', 8) printer.centered('more directories, If you like you can tell us now', 9) printer.centered('to send any and all directories we find inside of', 10) printer.centered(input, 11) goBtn = btnInit("Transfer All", nil, nil, termX-2-#"Transfer All", 18, 1, colors.blue, colors.black, 1,function() os.queueEvent('all') end, false) backBtn = btnInit("Let Me Choose", nil, nil, goBtn.x-4-#"Let Me Choose", 18, 1, colors.blue, colors.black, 1, function() os.queueEvent('pick') end, false) while true do local e, p1, p2, p3 = os.pullEvent() LogFile.i(e, runningProgram) if e == "mouse_click" then doClick(e, p1, p2, p3) elseif e == 'pick' then transferDir(input, clientToSend, false) elseif e == 'all' then transferDir(input, clientToSend, true) end end else transferFile(input, clientToSend) end elseif e == "deny" then tableClear() drawTitle() printer.centered("Download Denied", 6) term.setTextColor(colors.gray) printer.centered("The client denied your download request", 10) printer.centered("Click Anywhere To Continue", 19) os.pullEvent('mouse_click') drawTitle() tableClear() mainMenu() elseif e == "cancel" then local message = {} message['dest'] = clientToSend message['idno'] = os.getComputerID() message['name'] = os.getComputerLabel() or "CCDrop Client" message['content'] = "downloadExpired" modem.Transmit(modem.channels.fileSend, modem.channels.reply, message) tableClear() drawTitle() mainMenu() elseif e == "mouse_click" then doClick(e, p1, p2, p3) elseif e == "modem_message" then modem.checkMessage(e, p1, p2, p3, p4, p5) end end else printer.centered("File Doesn't Exist!", 19) sleep(0.5) if args then mainMenu() end end else printer.centered("You Must Enter A File Path", 19) sleep(0.5) end end mainMenu() end function mainMenu() PCwaiting = false PCsending = false tableClear() drawTitle() printer.centered("Welcome To CCDrop", 6) term.setTextColor(colors.gray) printer.centered("This program allows you to easily transfer", 10) printer.centered("files from PC to PC", 11) printer.centered("If you wish to transfer then click send", 13) printer.centered("otherwise click wait if you are expecting a file", 14) sendBtn = btnInit("Send", nil, nil, termX-2-#"Send", 18, 1, colors.blue, colors.black, 1, sendFile, false) waitBtn = btnInit("Wait", nil, nil, sendBtn.x-4-#"Wait", 18, 1, colors.blue, colors.black, 1, waitFile, false) exitBtn = btnInit("Exit", nil, nil, 2, 18, 1, colors.red, colors.black, 1, function() term.setBackgroundColor(colors.black) term.setTextColor(1) term.clear() term.setCursorPos(1, 1) shell.run("shell") end) if waitON then waitON = false waitFile() end eventLoop() end function waitFile() tableClear() drawTitle() back = btnInit("Back", nil, nil, 2, 18, 1, colors.red, colors.black, 1, function() mainMenu() end, false) printer.centered("Waiting For File...", 6) term.setTextColor(colors.gray) printer.centered("To send a file simply select the send option", 8) printer.centered("on the computer that has the file you want to send", 9) printer.centered("When we receive the file well let you know", 11) PCwaiting = true end function Initialise() printer.centered("Please Wait...", 6) printer.centered("Registering Events", 6) eventRegister("terminate", function() error'You Have Terminated This Program' end) eventRegister("mouse_click", doClick) eventRegister("modem_message", modem.checkMessage) drawTitle() while not modem.isPresent() do printer.centered("Please attach a wireless modem to continue", 6) printer.centered("This program uses rednet to transfer files", 8) printer.centered("between computers", 9) os.pullEvent() end modem.Initialise() --Shell args if #tArgs == 1 then if fs.exists(tArgs[1]) then sendFile(tArgs[1]) elseif tArgs[1] == "-w" then waitON = true else printer.centered("Shell Arg Error", 6) printer.centered("Click Anywhere To Continue", 19) printer.centered(tArgs[1].." Doesn't Exist", 11) term.setTextColor(colors.gray) printer.centered("The file you are trying to send", 8) printer.centered("via the shell doesn't exist", 9) os.pullEvent('mouse_click') mainMenu() end elseif #tArgs > 1 then printer.centered("Program Arguments Detected", 6) printer.centered('Click Anywhere To Continue', 19) printer.centered(shell.getRunningProgram().." ", 11) printer.centered(shell.getRunningProgram().." -w (To Wait For Files)", 13) term.setTextColor(colors.gray) printer.centered("This program accepts only one shell arg.", 8) printer.centered("Use the following syntax;", 9) printer.centered("Or", 12) os.pullEvent('mouse_click') end mainMenu() end if pocket then error'This program doesnt support pocket computers yet, sorry' elseif not term.isColor() then error'The device must be advanced to use this program' else Initialise() end error'Apologies, The program has left the loop, Please report this with steps to reproduce'