Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This program uses the String Metatable hack for transfering files without modems.
- --[[
- THIS PROGRAM HAS BEEN PATCHED AS OF CC 1.7. Sorry.
- You will only be able to use this program on servers that have enabled it manually...but good luck on that!
- --]]
- local tArg = {...}
- function showControls()
- print("*msend send [filename] <target id>")
- print("*msend receive <filter id>")
- print("*msend about")
- print("*msend update")
- print("[neccessary] <optional>")
- end
- function showAbout()
- print(" mSend was programmed by LDDestroier.")
- print(" mSend is a utility to send and receive individual files from machine to machine across infinite distance and across different multiplayer worlds. It does this by setting a string metatable to the contents of a file, along with some metadata to make sure that the intended recipiant gets the file, then converts it back to a file.")
- os.pullEvent("key")
- print(" mSend can send files to anyone listening and send files to individual computer IDs. mSend can also receive files from anyone, or only receive files from a certain ID.")
- print(" Beware, that not inputting an ID argument will allow anyone to send you a file, or anyone to take your file. For private functions, it is reccommended that you input ID arguments.")
- print(" If there is an update, it is reccommended that you update. LDDestroier put a lot of hard work so that you could easily update it using a simple argument. New updates bring new features, usually.")
- print(" mSend may not work in ComputerCraft 1.7 and later. Sorry.")
- end
- local function makeFile(getFile, name)
- local file = fs.open(name, "w")
- file.write( fileContents )
- file.close()
- end
- local function updateProgram(directory)
- local updateFile = http.get("http://pastebin.com/raw.php?i=ZaenH6wc")
- if fs.exists("/msendupdate") then
- fs.delete("/msendupdate")
- end
- local file = fs.open("/msendupdate", "w")
- local update = updateFile:readAll()
- file.write(update)
- file.close()
- shell.run("msendupdate " .. directory)
- print("done.")
- fs.delete("/msendupdate")
- return true
- end
- local function receive(id, timeout)
- if id == -1 then
- print("Receiving file...ID is " .. os.getComputerID())
- else
- print("Receiving file from " .. id .. "...ID is " .. os.getComputerID())
- end
- while true do
- if id == -1 then
- if getmetatable("").targetFileID == -1 or getmetatable("").targetFileID == os.getComputerID() then
- receiveFile()
- return true
- end
- else
- if getmetatable("").senderFileID == tonumber(id) then
- if getmetatable("").targetFileID == -1 or getmetatable("").targetFileID == os.getComputerID() then
- receiveFile()
- return true
- end
- end
- end
- sleep(0.04)
- end
- end
- function local receiveFile()
- localID = getmetatable("").targetFileID
- fileName = getmetatable("").fileName
- fileContents = getmetatable("").fileContents
- senderFileID = getmetatable("").senderFileID
- if fs.exists(shell.dir() .. fileName) then
- if fileName == "msend" then
- print("'" .. fileName .. "' would overwrite msend! Canceled.")
- return false
- else
- print("'" .. fileName .. "' already exists. Overwrite? (y/n)")
- while true do
- local event, key = os.pullEvent("char")
- if key == "n" then
- print("Cancelled.")
- return false
- end
- if key == "y" then
- fs.delete(fs.combine(shell.dir(), fileName))
- makeFile(fileContents, fileName)
- print(fileName .. " overwritten from " .. senderFileID .. ".")
- return true
- end
- end
- end
- else
- makeFile(fileContents, fileName)
- print(fileName .. " received from " .. senderFileID .. ".")
- end
- end
- local function send(name, id)
- if fs.exists(name) == true then
- local file = fs.open(name, "r")
- getmetatable("").targetFileID = tonumber(id)
- getmetatable("").senderFileID = os.getComputerID()
- getmetatable("").fileContents = file.readAll()
- getmetatable("").fileName = name
- sleep(0.05)
- getmetatable("").targetFileID = nil
- getmetatable("").senderFileID = nil
- getmetatable("").fileContents = nil
- getmetatable("").fileName = nil
- getmetatable("").isServing = false
- return true
- else
- error(name .. ": file does not exist")
- end
- end
- if tArg[ 1 ] == nil then
- showControls()
- return false
- else
- if tArg[ 1 ] == "about" then
- showAbout()
- return false
- else
- if tArg[ 1 ] == "update" then
- updateProgram(shell.dir())
- return true
- else
- if tArg[ 1 ] == "send" then
- if tArg[ 3 ] == nil then
- send(tArg[ 2 ], -1)
- else
- if tonumber(tArg[ 3 ]) < 0 then
- send(tArg[ 2 ], -1)
- else
- send(tArg[ 2 ], tArg[ 3 ])
- end
- end
- else
- if tArg[ 1 ] == "receive" then
- if tArg[ 2 ] == nil then
- receive(-1)
- else
- if tonumber(tArg[ 2 ]) >= 0 then
- receive(tArg[ 2 ])
- end
- end
- else
- if tArg[ 2 ] == nil then
- send(tArg[ 1 ], -1)
- else
- if tonumber(tArg[ 2 ]) < 0 then
- send(tArg[ 1 ], -1)
- else
- send(tArg[ 1 ], tArg[ 2 ])
- end
- end
- end
- return false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement