fix(net): bad channel + change return of sendQuery
This commit is contained in:
parent
5305afe203
commit
4f16cef9f5
11
libs/net.lua
11
libs/net.lua
@ -13,21 +13,20 @@ end
|
|||||||
net.listenQuery = function(hostname, processQueryMessage)
|
net.listenQuery = function(hostname, processQueryMessage)
|
||||||
assertRednetIsOpened()
|
assertRednetIsOpened()
|
||||||
|
|
||||||
rednet.host(QUERY_PROTO, hostname)
|
|
||||||
|
|
||||||
local serverRunning = true
|
local serverRunning = true
|
||||||
|
|
||||||
local function stopServer()
|
local function stopServer()
|
||||||
serverRunning = false
|
serverRunning = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
rednet.host(QUERY_PROTO, hostname)
|
||||||
|
|
||||||
while serverRunning do
|
while serverRunning do
|
||||||
local computerId, message = rednet.receive(QUERY_PROTO)
|
local computerId, message = rednet.receive(QUERY_PROTO)
|
||||||
local responseMessage = processQueryMessage(textutils.unserialize(message), computerId, stopServer)
|
local responseMessage = processQueryMessage(textutils.unserialize(message), computerId, stopServer)
|
||||||
rednet.send(computerId, textutils.serialize(responseMessage), QUERY_RESPONSE_PROTO)
|
rednet.send(computerId, textutils.serialize(responseMessage), QUERY_RESPONSE_PROTO)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- in case we decide to exit the loop in the future
|
|
||||||
rednet.unhost(QUERY_PROTO)
|
rednet.unhost(QUERY_PROTO)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -38,19 +37,19 @@ net.sendQuery = function(hostname, message, timeout)
|
|||||||
local serverId = rednet.lookup(QUERY_PROTO, hostname)
|
local serverId = rednet.lookup(QUERY_PROTO, hostname)
|
||||||
|
|
||||||
if not serverId then
|
if not serverId then
|
||||||
return false, 'hostname lookup error'
|
return nil, 'hostname lookup error'
|
||||||
end
|
end
|
||||||
|
|
||||||
local sendOk = rednet.send(serverId, textutils.serialize(message))
|
local sendOk = rednet.send(serverId, textutils.serialize(message))
|
||||||
|
|
||||||
if not sendOk then
|
if not sendOk then
|
||||||
return false, 'rednet error'
|
return nil, 'rednet error'
|
||||||
end
|
end
|
||||||
|
|
||||||
local responseServerId, responseMessage = rednet.receive(QUERY_RESPONSE_PROTO, timeout)
|
local responseServerId, responseMessage = rednet.receive(QUERY_RESPONSE_PROTO, timeout)
|
||||||
|
|
||||||
if not responseServerId then
|
if not responseServerId then
|
||||||
return false, 'timeout'
|
return nil, 'timeout'
|
||||||
end
|
end
|
||||||
|
|
||||||
return textutils.unserialize(responseMessage)
|
return textutils.unserialize(responseMessage)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user