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

How to send program over rednet wireless

Started by Trackspeeder, 23 June 2014 - 08:43 PM
Trackspeeder #1
Posted 23 June 2014 - 10:43 PM
I am wanting to create a CC minigame that is like the game WatchDogs. I want to have a program that the player can use to send a fake CC virus program to another computer in the game through wireless rednet.

Does anyone know how to do this, if so please post the code?


Please remember this is not a malicious code or will not be used by one.
It is for the minigame. The code you post must be able to send a program that is on a pocket computer to a nother computer through rednet in any way. ALSO PLEASE EXPLAIN IN STEPS MABY HOW IT WORKS AND HOW TO SET IT UP!

THANK YOU! :)/>
Lyqyd #2
Posted 23 June 2014 - 10:56 PM
Moved to Ask a Pro.
AssossaGPB #3
Posted 23 June 2014 - 11:23 PM
This is rather simple to perform. I am not going to post the code because you learn more if you write it yourself. There are many ways to send programs over rednet, but the two simplest are:
1. Sending each line of the program as a separate rednet message
2. Formatting the whole program into one long string and sending that

Number 1 is rather simple and doesn't need much explaining, but I do recommend making a special rednet message (say "Stop") to indicate the end of sending the program, then just have the other side write each message to a file till it reaches "Stop"

Number 2 is a little more advanced. First you need to think of a separating character (or string), this can be |,~,/n,etc. The way I would encode the file is putting each line into a table and having the separating character/string as the every other table entry. Then just do table.concat(yourTable) to get the final string. For the receiving side, you would want to loop through the string and every time it hits that character/string it writes that text to a file.

That is the basic concepts, if you need more help or clarification just ask!
Lyqyd #4
Posted 23 June 2014 - 11:31 PM
Or you could just send the table of lines over, or a multiline string, which you got close to saying, but didn't quite make the connection. File transfer of plain text is pretty easy.
AssossaGPB #5
Posted 23 June 2014 - 11:42 PM
Oh, I did not realize you can send a multiline string over rednet, that's very useful! I assume you use /n to create a multiline string?
Lyqyd #6
Posted 24 June 2014 - 12:57 AM
Well, \n is the actual character. You can just read the whole file into one string and send that though, no roundabout string creation necessary.
guesswhat123212 #7
Posted 24 June 2014 - 02:43 AM
you can also use fileData = fs.readAll() which will save it all to that var then send the var, still some other things you might want to do but that should help you to find the rest. however please note the other computer will need to be listening for this and know how to fs.write() it as well
Umbre0n #8
Posted 24 June 2014 - 05:23 PM
You can use parts of my program if you want!
http://www.computercraft.info/forums2/index.php?/topic/19342-file-transfer-in-computercraft/
Good luck for you game!
Trackspeeder #9
Posted 24 June 2014 - 07:10 PM
This is rather simple to perform. I am not going to post the code because you learn more if you write it yourself. There are many ways to send programs over rednet, but the two simplest are:
1. Sending each line of the program as a separate rednet message
2. Formatting the whole program into one long string and sending that

Number 1 is rather simple and doesn't need much explaining, but I do recommend making a special rednet message (say "Stop") to indicate the end of sending the program, then just have the other side write each message to a file till it reaches "Stop"

Number 2 is a little more advanced. First you need to think of a separating character (or string), this can be |,~,/n,etc. The way I would encode the file is putting each line into a table and having the separating character/string as the every other table entry. Then just do table.concat(yourTable) to get the final string. For the receiving side, you would want to loop through the string and every time it hits that character/string it writes that text to a file.

That is the basic concepts, if you need more help or clarification just ask!

Does the computer receiving need to be listening? If so is there a way so the computer is forever listening?
Bomb Bloke #10
Posted 25 June 2014 - 03:20 AM
Yes, like a real computer, nothing is done without instruction. All transmissions are effectively ignored unless you specifically rig the receiver to do something with them.

For eg:

rednet.open("side")

while true do
	local senderID, message = rednet.receive()
	
	print(message)
end
0099 #11
Posted 27 June 2014 - 10:31 PM
To avoid these text-formatting problems, you can compile a program at sender side (just write "function f() –[[your code]] end"), then use string.dump() to retrieve LuaVM code and send it over rednet. Then, all you have to do is load it with loadstring() and run it.
AssossaGPB #12
Posted 01 July 2014 - 01:21 AM
To avoid these text-formatting problems, you can compile a program at sender side (just write "function f() –[[your code]] end"), then use string.dump() to retrieve LuaVM code and send it over rednet. Then, all you have to do is load it with loadstring() and run it.
Wow, I never thought of doing it that way. Pretty clever!