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

Requesting a whitelist list from a other computer using a Wireless Modem.

Started by mattie078, 28 June 2015 - 08:59 AM
mattie078 #1
Posted 28 June 2015 - 10:59 AM
Can someone help me with that ( getting a whitelist list from a other computer using a Wireless Modem.)

I'm doing this at Tekkit Lite, using CCsensors

My code goes as followed


--# Player Detector Front Door Created by Matthijs
--# Change the names to get acces to the whitelist

os.loadAPI("ocs/apis/sensor")
os.pullEvent = os.pullEventRaw
local prox = sensor.wrap("bottom")
local whitelist = {

  ["mattie078"] = true,
  ["stormchaser6"] = true,
  ["ClankS"] = true,
  ["Zeita"] = true,
  ["KingArthur524"] = true,
  ["Pasta_Blizzard"] = true,
  ["Shadow_Demon_666"] = true,
  ["LaFesta1749"] = true,
  ["Orangerageous"] = true,
  ["KaylaXtreme"] = true,
  ["yu1327"] = true,
  ["MsSunshine"] = true,
  ["WhiteDuck"] = true,
  ["Chugslava"] = true,
  ["WhyHiThere"] = true
  
  --# etc
}

while true do
  local targets = prox.getTargets()
  for name, basicDetails in pairs(targets) do
	if basicDetails.Name == "Player" then
	print(name)
	  if whitelist[name] then
	  rs.setOutput("top", true)
	  sleep(2)
	  rs.setOutput("top", false)
	else
	  rs.setOutput("top", false)
	  sleep(0.5)
	  end
	end
  end
end

The thing I want to do;

If I change the whitelist from the main computer, the whitelist on the other computers with the actual Player Detector will change automatically. Is this possible or not?

-Matthijs
Bomb Bloke #2
Posted 28 June 2015 - 11:12 AM
The "simple" method is to divide your script into two functions - one which runs your sensor-checking "while" loop, and another which waits for whitelist updates to arrive via rednet. You can then run these two functions alongside each other using the parallel API.

rednet.open("whateverSide")

local function checkSensor()
	while true do
		local targets = prox.getTargets()
		for name, basicDetails in pairs(targets) do
			if basicDetails.Name == "Player" then
				print(name)
				if whitelist[name] then
					rs.setOutput("top", true)
					sleep(2)
					rs.setOutput("top", false)
				else
					rs.setOutput("top", false)
					sleep(0.5)
				end
			end
		end
		
		sleep(5)  --# Consider what constant sensor checks will do for your server performance, and pick a value.
	end
end

local function checkRednet()
	while true do
		local id, message = rednet.receive()
		
		--# Maybe put some code here to check that the id is correct, and that the message is a table...
		
		whitelist = message
	end
end

parallel.waitForAny(checkSensor, checkRednet)

Note that wireless rednet transmissions can be difficult to secure - an easy method to safeguard things somewhat is to use wired modems instead!