Make rednet.run a little more strict
Also add a test for rednet message sending. Hopefully gives some of the modem and networking code a little bit of coverage (which is clearly the same as being right :p).
This commit is contained in:
parent
924b8ef30f
commit
b31e66686d
|
@ -351,12 +351,12 @@ function run()
|
||||||
-- Got a modem message, process it and add it to the rednet event queue
|
-- Got a modem message, process it and add it to the rednet event queue
|
||||||
local sModem, nChannel, nReplyChannel, tMessage = p1, p2, p3, p4
|
local sModem, nChannel, nReplyChannel, tMessage = p1, p2, p3, p4
|
||||||
if isOpen(sModem) and (nChannel == os.getComputerID() or nChannel == CHANNEL_BROADCAST) then
|
if isOpen(sModem) and (nChannel == os.getComputerID() or nChannel == CHANNEL_BROADCAST) then
|
||||||
if type(tMessage) == "table" and tMessage.nMessageID then
|
if type(tMessage) == "table" and type(tMessage.nMessageID) == "number"
|
||||||
if not tReceivedMessages[tMessage.nMessageID] then
|
and tMessage.nMessageID == tMessage.nMessageID and not tReceivedMessages[tMessage.nMessageID]
|
||||||
tReceivedMessages[tMessage.nMessageID] = true
|
then
|
||||||
tReceivedMessageTimeouts[os.startTimer(30)] = tMessage.nMessageID
|
tReceivedMessages[tMessage.nMessageID] = true
|
||||||
os.queueEvent("rednet_message", nReplyChannel, tMessage.message, tMessage.sProtocol)
|
tReceivedMessageTimeouts[os.startTimer(30)] = tMessage.nMessageID
|
||||||
end
|
os.queueEvent("rednet_message", nReplyChannel, tMessage.message, tMessage.sProtocol)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package dan200.computercraft.ingame
|
||||||
|
|
||||||
|
import dan200.computercraft.ingame.api.GameTest
|
||||||
|
import dan200.computercraft.ingame.api.TestContext
|
||||||
|
import dan200.computercraft.ingame.api.checkComputerOk
|
||||||
|
|
||||||
|
class CraftOsTest {
|
||||||
|
/**
|
||||||
|
* Sends a rednet message to another a computer and back again.
|
||||||
|
*/
|
||||||
|
@GameTest
|
||||||
|
suspend fun `Sends basic rednet messages`(context: TestContext) = context.checkComputerOk(13)
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
-- TurtleTest.`Use compostors`
|
||||||
|
|
||||||
test.eq(true, turtle.dropDown(), "Drop items into compostor")
|
test.eq(true, turtle.dropDown(), "Drop items into compostor")
|
||||||
|
|
||||||
test.ok()
|
test.ok()
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
-- TurtleTest.`Cleaned with cauldrons`
|
||||||
|
|
||||||
local old_details = turtle.getItemDetail(1, true)
|
local old_details = turtle.getItemDetail(1, true)
|
||||||
|
|
||||||
test.assert(turtle.place(), "Dyed turtle")
|
test.assert(turtle.place(), "Dyed turtle")
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
-- CraftOsTest.`Sends basic rednet messages`
|
||||||
|
|
||||||
|
rednet.open("top")
|
||||||
|
|
||||||
|
rednet.send(14, "Test msg")
|
||||||
|
|
||||||
|
local id, msg
|
||||||
|
repeat
|
||||||
|
id, msg = rednet.receive()
|
||||||
|
print(id, msg)
|
||||||
|
until id == 14
|
||||||
|
|
||||||
|
test.eq("Test msg", msg)
|
||||||
|
test.ok()
|
|
@ -0,0 +1,7 @@
|
||||||
|
-- CraftOsTest.`Sends basic rednet messages`
|
||||||
|
|
||||||
|
rednet.open("top")
|
||||||
|
while true do
|
||||||
|
local id, msg, protocol = rednet.receive()
|
||||||
|
rednet.send(id, msg, protocol)
|
||||||
|
end
|
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"computer": 12
|
"computer": 14
|
||||||
}
|
}
|
|
@ -0,0 +1,555 @@
|
||||||
|
{
|
||||||
|
size: [5, 5, 5],
|
||||||
|
entities: [],
|
||||||
|
blocks: [
|
||||||
|
{
|
||||||
|
pos: [0, 0, 0],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 0, 0],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 0, 0],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 0, 0],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 0, 0],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 0, 1],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 0, 1],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 0, 1],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 0, 1],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 0, 1],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 0, 2],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 0, 2],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 0, 2],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 0, 2],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 0, 2],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 0, 3],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 0, 3],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 0, 3],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 0, 3],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 0, 3],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 0, 4],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 0, 4],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 0, 4],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 0, 4],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 0, 4],
|
||||||
|
state: 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nbt: {
|
||||||
|
Label: "Echo",
|
||||||
|
id: "computercraft:computer_advanced",
|
||||||
|
ComputerId: 14,
|
||||||
|
On: 1b
|
||||||
|
},
|
||||||
|
pos: [1, 1, 2],
|
||||||
|
state: 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nbt: {
|
||||||
|
Label: "Main",
|
||||||
|
id: "computercraft:computer_advanced",
|
||||||
|
ComputerId: 13,
|
||||||
|
On: 1b
|
||||||
|
},
|
||||||
|
pos: [3, 1, 2],
|
||||||
|
state: 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nbt: {
|
||||||
|
id: "computercraft:wireless_modem_normal"
|
||||||
|
},
|
||||||
|
pos: [1, 2, 2],
|
||||||
|
state: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nbt: {
|
||||||
|
id: "computercraft:wireless_modem_normal"
|
||||||
|
},
|
||||||
|
pos: [3, 2, 2],
|
||||||
|
state: 3
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 1, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 1, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 1, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 1, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 1, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 2, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 2, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 2, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 2, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 2, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 3, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 3, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 3, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 3, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 3, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 4, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 4, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 4, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 4, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 4, 0],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 1, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 1, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 1, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 1, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 1, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 2, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 2, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 2, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 2, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 2, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 3, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 3, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 3, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 3, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 3, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 4, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 4, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 4, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 4, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 4, 1],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 1, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 1, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 1, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 2, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 2, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 2, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 3, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 3, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 3, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 3, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 3, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 4, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 4, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 4, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 4, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 4, 2],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 1, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 1, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 1, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 1, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 1, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 2, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 2, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 2, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 2, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 2, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 3, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 3, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 3, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 3, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 3, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 4, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 4, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 4, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 4, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 4, 3],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 1, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 1, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 1, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 1, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 1, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 2, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 2, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 2, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 2, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 2, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 3, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 3, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 3, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 3, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 3, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [0, 4, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [1, 4, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [2, 4, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [3, 4, 4],
|
||||||
|
state: 4
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pos: [4, 4, 4],
|
||||||
|
state: 4
|
||||||
|
}
|
||||||
|
],
|
||||||
|
palette: [
|
||||||
|
{
|
||||||
|
Name: "minecraft:polished_andesite"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Properties: {
|
||||||
|
facing: "north",
|
||||||
|
state: "on"
|
||||||
|
},
|
||||||
|
Name: "computercraft:computer_advanced"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Properties: {
|
||||||
|
facing: "north",
|
||||||
|
state: "blinking"
|
||||||
|
},
|
||||||
|
Name: "computercraft:computer_advanced"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Properties: {
|
||||||
|
waterlogged: "false",
|
||||||
|
facing: "down",
|
||||||
|
on: "true"
|
||||||
|
},
|
||||||
|
Name: "computercraft:wireless_modem_normal"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "minecraft:air"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
DataVersion: 2230
|
||||||
|
}
|
Loading…
Reference in New Issue