mirror of
https://github.com/zenith391/OCEmu.git
synced 2025-09-30 08:35:26 -04:00
allow nils in modem message
This commit is contained in:
parent
cc4b06af67
commit
71e5adabd0
@ -10,12 +10,13 @@ local function cerror(...)
|
|||||||
|
|
||||||
local sep = ''
|
local sep = ''
|
||||||
|
|
||||||
for _,arg in ipairs(args) do
|
for _,arg in pairs(args) do
|
||||||
local p;
|
local p;
|
||||||
if (type(arg) == "userdata") then p = "userdata"
|
if (type(arg) == "userdata") then p = "userdata"
|
||||||
|
elseif (type(arg) == "string") then p = arg
|
||||||
else p = ser.serialize(arg) end
|
else p = ser.serialize(arg) end
|
||||||
io.stderr:write(p .. sep)
|
io.stderr:write(sep .. tostring(_) .. '=' .. p)
|
||||||
sep = '\t'
|
sep = ','
|
||||||
end
|
end
|
||||||
|
|
||||||
io.stderr:write('\n')
|
io.stderr:write('\n')
|
||||||
@ -55,6 +56,7 @@ function modem_host.createPacketArray(packetType, address, port, ...)
|
|||||||
0, -- distance
|
0, -- distance
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
|
|
||||||
cerror("resultant packed", packed)
|
cerror("resultant packed", packed)
|
||||||
return packed
|
return packed
|
||||||
end
|
end
|
||||||
@ -71,8 +73,11 @@ function modem_host.packetArrayToPacket(packed)
|
|||||||
packet.distance = packed[5]
|
packet.distance = packed[5]
|
||||||
packet.payload = {}
|
packet.payload = {}
|
||||||
|
|
||||||
for i=6,#packed do
|
-- all other keys will be index values but may skip some (nils)
|
||||||
table.insert(packet.payload, packed[i])
|
for k,v in pairs(packed) do
|
||||||
|
if k > 5 then
|
||||||
|
packet.payload[k-5] = v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return packet
|
return packet
|
||||||
@ -86,15 +91,22 @@ function modem_host.packetArrayToDatagram(packed)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function modem_host.packetToPacketArray(packet)
|
function modem_host.packetToPacketArray(packet)
|
||||||
return
|
local packed =
|
||||||
{
|
{
|
||||||
packet.type,
|
packet.type,
|
||||||
packet.target,
|
packet.target,
|
||||||
packet.source,
|
packet.source,
|
||||||
packet.port,
|
packet.port,
|
||||||
packet.distance,
|
packet.distance,
|
||||||
table.unpack(packet.payload or {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if packet.payload then
|
||||||
|
for i,v in pairs(packet.payload) do
|
||||||
|
packed[i+5] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return packed
|
||||||
end
|
end
|
||||||
|
|
||||||
function modem_host.datagramToPacketArray(datagram)
|
function modem_host.datagramToPacketArray(datagram)
|
||||||
@ -248,17 +260,17 @@ function modem_host.recvPendingMessages()
|
|||||||
local connectionResponse
|
local connectionResponse
|
||||||
local accepted = false
|
local accepted = false
|
||||||
if handshake.type ~= "handshake" then
|
if handshake.type ~= "handshake" then
|
||||||
connectionResponse = modem_host.createPacketArray("handshake", modem_host.id, -1,
|
connectionResponse = modem_host.createPacketArray("handshake", 0, -1,
|
||||||
false, "unsupported message type");
|
false, "unsupported message type");
|
||||||
elseif modem_host.validTarget(handshake.source) then -- repeated client
|
elseif modem_host.validTarget(handshake.source) then -- repeated client
|
||||||
connectionResponse = modem_host.createPacketArray("handshake", modem_host.id, -1,
|
connectionResponse = modem_host.createPacketArray("handshake", 0, -1,
|
||||||
false, "computer address conflict detected, ignoring connection");
|
false, "computer address conflict detected, ignoring connection");
|
||||||
else
|
else
|
||||||
client:settimeout(0, 't')
|
client:settimeout(0, 't')
|
||||||
modem_host.clients[handshake.source] = client
|
modem_host.clients[handshake.source] = client
|
||||||
accepted = true
|
accepted = true
|
||||||
|
|
||||||
connectionResponse = modem_host.createPacketArray("handshake", modem_host.id, -1, true);
|
connectionResponse = modem_host.createPacketArray("handshake", 0, -1, true);
|
||||||
end
|
end
|
||||||
|
|
||||||
modem_host.sendPacketArray(client, connectionResponse)
|
modem_host.sendPacketArray(client, connectionResponse)
|
||||||
@ -505,6 +517,11 @@ local function logAll(t, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
logAll(obj)
|
logAll(obj)
|
||||||
logAll(modem_host, "processPendingMessages", "recvPendingMessages")
|
logAll(modem_host,
|
||||||
|
"processPendingMessages",
|
||||||
|
"recvPendingMessages",
|
||||||
|
"readDatagram",
|
||||||
|
"readPacket",
|
||||||
|
"readPacketArray")
|
||||||
|
|
||||||
return obj,cec,doc
|
return obj,cec,doc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user