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

CC ID

Started by Ninjawolf0007, 08 December 2013 - 08:17 AM
Ninjawolf0007 #1
Posted 08 December 2013 - 09:17 AM
Is there a way to send a false computer ID over Wireless Rednet? I've tried multiple times and I seem unable to figure it out if there is one.

The reason 'm looking at this is because I want to make a computer broadcast at an id of "0" which all computers will receive and prioritize it as the most important message, because priority is based on the id of the sender. Currently I'm just working on the false ID broadcast…

Thank you in advance.
-Ninjawolf0007
Goof #2
Posted 08 December 2013 - 09:20 AM
You just need to overwrite the os.getComputerID() function…

Example:


os.getComputerID = function()
  local falseID = 0 -- the false ID to send
  return falseID
end


You can also return the normal ID by:

local realID = 100
local falseID = 0

os.getComputerID = function()
  return falseID
end

os.resetComputerID = function()
  falseID = realID
end


I hope i could help

:)/>
Edited on 08 December 2013 - 08:22 AM
Ninjawolf0007 #3
Posted 08 December 2013 - 09:25 AM
You just need to overwrite the os.getComputerID() function…

Example:


os.getComputerID = function()
  local falseID = 0 -- the false ID to send
  return falseID
end


You can also return the normal ID by:

local realID = 100
local falseID = 0

os.getComputerID = function()
  return falseID
end

os.resetComputerID = function()
  falseID = realID
end


I hope i could help

:)/>


Thanks you so much… That is a lot easier than what I was doing…. I had ~40 lines of code… I really need to look into my programming skills and lower my ability to over think things. xD

Again. It worked! Thank you so much.
Edited on 08 December 2013 - 08:37 AM
Goof #4
Posted 08 December 2013 - 09:32 AM
Ahem.: You welcome..


But remember:

When you restart the computer ( if this file isnt as startup) then the ID will be reset

So be careful :)/>


Im glad I could help :)/>
TheOddByte #5
Posted 08 December 2013 - 09:43 AM
I would like to add that you can also override the rednet.send function

rednet.send = function(id, fakeID, msg)
     for n,sSide in ipairs( rs.getSides() ) do
        if isOpen( sSide ) then
            peripheral.call( sSide, "transmit", id, fakeID, msg )
            return
        end
    end
    error( "No open sides" )
end
But the code by Mikk809 is easier and shorter.
Ninjawolf0007 #6
Posted 08 December 2013 - 10:18 AM
I would like to add that you can also override the rednet.send function

rednet.send = function(id, fakeID, msg)
	 for n,sSide in ipairs( rs.getSides() ) do
		if isOpen( sSide ) then
			peripheral.call( sSide, "transmit", id, fakeID, msg )
			return
		end
	end
	error( "No open sides" )
end
But the code by Mikk809 is easier and shorter.

Can you explain what "n,sSide in ipairs( rs.getSides() )" the ipairs* part means? Thank you.
Also if I put this in a resource pack under rednet and change the rednet send to this, would that work for a server? can I make it so that every message on a server get's sent to one or two main computers?(Given that they're all in range)
Edited on 08 December 2013 - 09:23 AM
Goof #7
Posted 08 December 2013 - 10:28 AM
I would like to add that you can also override the rednet.send function

rednet.send = function(id, fakeID, msg)
	 for n,sSide in ipairs( rs.getSides() ) do
		if isOpen( sSide ) then
			peripheral.call( sSide, "transmit", id, fakeID, msg )
			return
		end
	end
	error( "No open sides" )
end
But the code by Mikk809 is easier and shorter.

Can you explain what "n,sSide in ipairs( rs.getSides() )" the ipairs* part means? Thank you.
Also if I put this in a resource pack under rednet and change the rednet send to this, would that work for a server? can I make it so that every message on a server get's sent to one or two main computers?(Given that they're all in range)

Hellkid98's function is looping through all sides of the computer, to check if there is a modem on one of the sides.. If so, then it calls the peripheral.call to activate the transmit function with the message and the ID.

But, if you're going to set previous code in a ressource pack, then you're not safe.. then anyone else on the server, can set their "fakeID" to 0 or whatever id you need, and then on that way spam / do something really bad on the main computer..

can I make it so that every message on a server get's sent to one or two main computers?(Given that they're all in range)
errm… Yes that is possible. you "just" need to input two messages to sent ( one for each id of the main computers ) , and then return true / false

example:


mainComputer1 = 0
mainComputer2 = 82
rednet.send = function(id, fakeID, msg)
	 for n,sSide in ipairs( rs.getSides() ) do
		if isOpen( sSide ) then
			peripheral.call( sSide, "transmit", id, fakeID, msg ) -- this is to the id.
			peripheral.call( sSide, "transmit", mainComputer1, fakeID, msg ) -- this is to the mainComputer no. 1.
			peripheral.call( sSide, "transmit", mainComputer2, fakeID, msg ) -- this is to the mainComputer no. 2.
			return
		end
	end
	error( "No open sides" )
end
Edited on 08 December 2013 - 09:32 AM
MKlegoman357 #8
Posted 08 December 2013 - 01:41 PM
You could just use the modem itself:


--// Lets say our modem is on top of the computer
local modem = peripheral.wrap("top")

--// To send messages we use modem.transmit() method
modem.transmit(5, 0, "This is a message.")

--// With that function we send a message to a computer with ID 5 (or a computer which is listening on that channel).
--// We also say that we are computer ID 0 (fake ID)
Edited on 08 December 2013 - 12:41 PM
Ninjawolf0007 #9
Posted 08 December 2013 - 04:58 PM
SpoilerYou could just use the modem itself:


--// Lets say our modem is on top of the computer
local modem = peripheral.wrap("top")

--// To send messages we use modem.transmit() method
modem.transmit(5, 0, "This is a message.")

--// With that function we send a message to a computer with ID 5 (or a computer which is listening on that channel).
--// We also say that we are computer ID 0 (fake ID)

Ok thank you.


Spoiler
I would like to add that you can also override the rednet.send function

rednet.send = function(id, fakeID, msg)
	 for n,sSide in ipairs( rs.getSides() ) do
		if isOpen( sSide ) then
			peripheral.call( sSide, "transmit", id, fakeID, msg )
			return
		end
	end
	error( "No open sides" )
end
But the code by Mikk809 is easier and shorter.

Can you explain what "n,sSide in ipairs( rs.getSides() )" the ipairs* part means? Thank you.
Also if I put this in a resource pack under rednet and change the rednet send to this, would that work for a server? can I make it so that every message on a server get's sent to one or two main computers?(Given that they're all in range)

Hellkid98's function is looping through all sides of the computer, to check if there is a modem on one of the sides.. If so, then it calls the peripheral.call to activate the transmit function with the message and the ID.

But, if you're going to set previous code in a ressource pack, then you're not safe.. then anyone else on the server, can set their "fakeID" to 0 or whatever id you need, and then on that way spam / do something really bad on the main computer..

can I make it so that every message on a server get's sent to one or two main computers?(Given that they're all in range)
errm… Yes that is possible. you "just" need to input two messages to sent ( one for each id of the main computers ) , and then return true / false

example:


mainComputer1 = 0
mainComputer2 = 82
rednet.send = function(id, fakeID, msg)
	 for n,sSide in ipairs( rs.getSides() ) do
		if isOpen( sSide ) then
			peripheral.call( sSide, "transmit", id, fakeID, msg ) -- this is to the id.
			peripheral.call( sSide, "transmit", mainComputer1, fakeID, msg ) -- this is to the mainComputer no. 1.
			peripheral.call( sSide, "transmit", mainComputer2, fakeID, msg ) -- this is to the mainComputer no. 2.
			return
		end
	end
	error( "No open sides" )
end

In the last bit of code, could you give me an example of it with some explanations? Thank you.
Edited on 08 December 2013 - 03:59 PM
Goof #10
Posted 09 December 2013 - 08:19 AM
can I make it so that every message on a server get's sent to one or two main computers?(Given that they're all in range)
errm… Yes that is possible. you "just" need to input two messages to sent ( one for each id of the main computers ) , and then return true / false

example:


mainComputer1 = 0
mainComputer2 = 82
rednet.send = function(id, fakeID, msg)
	 for n,sSide in ipairs( rs.getSides() ) do
		if isOpen( sSide ) then
			peripheral.call( sSide, "transmit", id, fakeID, msg ) -- this is to the id.
			peripheral.call( sSide, "transmit", mainComputer1, fakeID, msg ) -- this is to the mainComputer no. 1.
			peripheral.call( sSide, "transmit", mainComputer2, fakeID, msg ) -- this is to the mainComputer no. 2.
			return
		end
	end
	error( "No open sides" )
end

In the last bit of code, could you give me an example of it with some explanations? Thank you.

errm.. Yeah:


mainComputer1 = 0 -- maincomputer #1 ID
mainComputer2 = 82 -- maincomputer #2 ID
rednet.send = function(id, fakeID, msg) -- Overwrite the rednet.send function
	 for n,sSide in ipairs( rs.getSides() ) do -- checks all sides of the computer.
		if isOpen( sSide ) then -- if a modem exists and is open then
			peripheral.call( sSide, "transmit", id, fakeID, msg ) -- this is to the real id. // Send message to the normal receiver ( not the maincomputers )
			peripheral.call( sSide, "transmit", mainComputer1, fakeID, msg ) -- this is to the mainComputer no. 1. // Send the message to both of the computers
			peripheral.call( sSide, "transmit", mainComputer2, fakeID, msg ) -- this is to the mainComputer no. 2.
			return -- return / exit
		end
	end
	error( "No open sides" ) -- if no modems were found / open
end

I don't know how much more i can explain that code.. Else you might have to ask another :(/>

But I hope thats good and understandable
Edited on 09 December 2013 - 07:19 AM
TheOddByte #11
Posted 09 December 2013 - 11:28 AM
The code that Mikk809h doesn't work since isOpen is a function in rednet and needs to be called by rednet.isOpen( This is mostly my fault since he pretty much copied the code I posted earlier and explained it, In my defence.. I copied it from the rednet api since I was too lazy to write it :P/> ), And it would be easier for you to have the IDs in a table.
And it would be better to have the fakeID as the third argument in the function, Since then it could be like a hidden feature and it wouldn't error if they entered a string as the second argument
in the function.


--# Enter your IDs here
local IDs = {
	0, 82,
}

rednet.send = function(id, msg, fakeID)
	for _, side in ipairs( rs.getSides()) do
		if rednet.isOpen( side) then

			if fakeID ~= nil then
			  --# If the fakeID isn't nil then it sends with the fakeID
				peripheral.call( side, "transmit", id, fakeID, msg)
				for i = 1,#IDs do
					peripheral.call( side, "transmit", IDs[i], fakeID, msg)	  
				end		

			else
			  --# Here it sends with the computer id if the fakeID was nil
				peripheral.call( side, "transmit", id, os.getComputerID(), msg)
				for i = 1,#IDs do
					peripheral.call( side, "transmit", IDs[i], os.getComputerID(), msg)		
				end	
			end
		end
	end
end			
Edited on 09 December 2013 - 10:29 AM