You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
962 B
39 lines
962 B
local conf=fs.open('/etc/cnt.conf','r') |
|
local cn_table = {} |
|
line = conf.readLine() |
|
while line ~= nil do |
|
local name=string.sub(line,0,string.find(line, ' ')) |
|
address = tonumber(string.sub(line,string.find(line,' ')+1)) |
|
print(name..address) |
|
cn_table[name]=address |
|
line = conf.readLine() |
|
end |
|
|
|
|
|
print("Waiting for queries...") |
|
while 1 do |
|
local found=0 |
|
local senderId, message, distance = rednet.receive() |
|
query=textutils.unserialize(message) |
|
if query[1] == 'CNT' then |
|
print("Query of "..query[2].." from "..senderId) |
|
for key,value in pairs(cn_table) do |
|
tmp=query[2] |
|
if tonumber(tmp) ~= nil then |
|
if tonumber(value) == tonumber(tmp) then |
|
reply=textutils.serialize({"CNT",key}) |
|
found=1 |
|
end |
|
else |
|
if(string.find(key,tmp,0,true)) then |
|
reply=textutils.serialize({"CNT",value}) |
|
found=1 |
|
end |
|
end |
|
end |
|
if found ~= 1 then |
|
reply=textutils.serialize({"CNT",-1}) |
|
end |
|
rednet.send(senderId,reply) |
|
end |
|
end
|
|
|