This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
whatsfast's profile picture

Running a program sent from another computer?

Started by whatsfast, 26 November 2012 - 03:44 AM
whatsfast #1
Posted 26 November 2012 - 04:44 AM
How would I do it that I receive a file from a main computer through rednet and then run it on my computer. How would I do that? I want do it as a safety precaution on my server. If there's another better way then tell me that too. Thanks!
bjornir90 #2
Posted 26 November 2012 - 05:02 AM
Look at the program I made it's buggy but the main thing is here.
It's on line 112 here :
http://pastebin.com/bEBmy1Zt
Zudo #3
Posted 26 November 2012 - 05:02 AM
Do you mean send the PROGRAM through rednet or run a local program on a rednet signal?
Zudo #4
Posted 26 November 2012 - 05:03 AM
To send a signal to run a local program do:

id, message, dist = rednet.receive()
shell.run(message)
whatsfast #5
Posted 26 November 2012 - 05:17 AM
How would you send a program through rednet is my question.
whatsfast #6
Posted 26 November 2012 - 09:57 AM
Above
bjornir90 #7
Posted 26 November 2012 - 10:05 AM
I already show you, the sample is after the (if msgType == "f" then), somewhere after the line 120.

Look at the program I made it's buggy but the main thing is here.
It's on line 112 here :
http://pastebin.com/bEBmy1Zt
whatsfast #8
Posted 26 November 2012 - 10:16 AM
So when I do loadString(msg1) () it should load my string and start it or should I add like a shell.run() and a bunch of stuff?

line 124 btw
whatsfast #9
Posted 26 November 2012 - 11:49 AM
I tried but it doesn't work. Can anyone else help me? It says im trying to call nil.

Code:
loadstring(message) ()
Lyqyd #10
Posted 26 November 2012 - 12:22 PM
First chunk is the sender, second chunk is the receiver:


local filePath = "fileName"
local fileHandle = io.open(filePath, "r")
if fileHandle then
    rednet.send(1, "file:"..filePath..";"..fileHandle:read("*a"))
    fileHandle:close()
end

id, message = rednet.receive()
local fileHandle = io.open(string.match(message, "file:(.-);"), "w")
if fileHandle then
    fileHandle:write(string.match(message, ";(.*)")
    fileHandle:close()
end
whatsfast #11
Posted 26 November 2012 - 12:55 PM
Im trying to make it so that the program is being accessed from another computer not through a file. What you just did here will help me in the future for when I make a email system so it won't go to waste. But still my question isn't answered. How would I make it so that a string with the program is sent to another computer "the client" and then run on that one without any saving on the client side and they can't see anything. I want this because I have a server and I cant have people accessing my files and getting into my system. I got everything. The only problem I have is making a string run like a program and the code note being accessible. for that program.
Lyqyd #12
Posted 26 November 2012 - 01:08 PM
You're not going to actually be able to prevent them from getting a hold of the code if you're transmitting them to it in any way, but you can try this. Again, first is the sender, second is the receiver:


local filePath = "fileName"
local fileHandle = io.open(filePath, "r")
if fileHandle then
    rednet.send(1, fileHandle:read("*a"))
    fileHandle:close()
end

id, message = rednet.receive()
loadstring(message)()
whatsfast #13
Posted 26 November 2012 - 01:33 PM
Where it asks for file path if it the computer folder or is the hard drive path. Or is it something completely different?
Lyqyd #14
Posted 26 November 2012 - 01:40 PM
The first line there? Set that to wherever the file you want the client to be sent to run is located. If it's not stored as a file, you just send the string that the code is in:


rednet.send(1, codeStringVariableHere)
whatsfast #15
Posted 26 November 2012 - 01:45 PM
That brings me back to my first problem. Whenever I send the code. It goes through all fine until the line loadstring(message) ()
It give me the error client:15: attempted to call nil. This is whenever I try to send a string.
whatsfast #16
Posted 26 November 2012 - 02:09 PM
Can anyone help?
Lyqyd #17
Posted 26 November 2012 - 02:17 PM
Is the string you're sending it a legitimate piece of code? If it can't load the string, it won't work. You could also try loadstring("function() "..message.." end")().
ChunLing #18
Posted 26 November 2012 - 02:19 PM
I like to use a simple function to do loadstring calls because they are a hassle otherwise.
local function ldstrng(luacd)
local tmpfnc,rslt = loadstring(luacd)
    if tmpfnc then _,rslt = pcall(tmpfnc) end
return rslt end
whatsfast #19
Posted 26 November 2012 - 02:29 PM
Ok I did that and no errors but the program isnt starting.

<p> </p>
<div>local function ldstrng(message)</div>
<div> local tmpfnc,rslt = loadstring(message)</div>
<div> if tmpfnc then _,rslt = pcall(message) end</div>
<div>  return rslt end</div>
ChunLing #20
Posted 26 November 2012 - 02:44 PM
Use "print(ldstrng(message))" and you should get a display of exactly why the program doesn't run.
whatsfast #21
Posted 26 November 2012 - 03:02 PM
It turns out when I do print(message) it says nil. The client is ok because the ID goes through fine. Heres the server code for sending:
SpoilerRemoved. SORRY. Don't want leeches
whatsfast #22
Posted 26 November 2012 - 05:10 PM
Can anyone help or is this a unfixable problem?
Lyqyd #23
Posted 26 November 2012 - 05:13 PM
No, you still have the same problem I told you about several posts ago. You have to declare your variables before you use them. How the hell is it supposed to know what the value of loginclient is before you've told it what the value is? Of course it sends nil.
whatsfast #24
Posted 27 November 2012 - 10:03 AM
No, you still have the same problem I told you about several posts ago. You have to declare your variables before you use them. How the hell is it supposed to know what the value of loginclient is before you've told it what the value is? Of course it sends nil.
Wow. I can't believe I didn't notice that! Thank you so much. And I apologize for being so stupid. The biggest error can come from the smallest mistakes. So far it works.