fix: packet coding

This commit is contained in:
cha0s 2020-06-29 06:04:31 -05:00
parent d27d382add
commit ee3996048f
6 changed files with 11 additions and 11 deletions

View File

@ -28,7 +28,7 @@ export default class EntityListUpdateEntityPacket extends Packet {
const unpacked = super.unpack(packet);
const {data} = unpacked;
for (let i = 0; i < data.length; i++) {
data[i].packets = BundlePacket.unpack(data[i].packets);
data[i].packets = BundlePacket.unpack(data[i].packets).data;
}
return unpacked;
}

View File

@ -34,7 +34,7 @@ export default class EntityUpdateTraitPacket extends SynchronizedUpdatePacket {
for (let i = 0; i < data.traits.length; i++) {
const {default: Trait} = fromId(data.traits[i].type);
data.traits[i].type = Trait.type();
data.traits[i].packets = BundlePacket.unpack(data.traits[i].packets);
data.traits[i].packets = BundlePacket.unpack(data.traits[i].packets).data;
}
return unpacked;
}

View File

@ -64,9 +64,10 @@ export default class BundlePacket extends Packet {
const {default: Packet} = fromId(packetId);
// Unpack and instantiate the packet.
const unpacked = Packet.unpack(packedPacket);
packets.push(new Packet(unpacked));
packets.push(new Packet(unpacked.data));
}
return packets;
unpacked.data = packets;
return unpacked;
}
}

View File

@ -1,4 +1,5 @@
import schemapack from 'schemapack';
import {BINARY_EVENT} from './socket.io-parser';
export class Packet {
@ -22,9 +23,9 @@ export class Packet {
static pack(packet) {
return this.builder.encode({
id: packet.id,
nsp: packet.nsp,
type: packet.type,
id: packet.id || 0,
nsp: packet.nsp || '/',
type: packet.type || BINARY_EVENT,
_id: packet.data[0],
data: packet.data[1],
});

View File

@ -28,9 +28,7 @@ export default class LayersUpdateLayerPacket extends Packet {
const unpacked = super.unpack(packet);
const {data} = unpacked;
for (let i = 0; i < data.length; i++) {
data[i].layerPackets = BundlePacket.unpack(
data[i].layerPackets
);
data[i].layerPackets = BundlePacket.unpack(data[i].layerPackets).data;
}
return unpacked;
}

View File

@ -20,7 +20,7 @@ export default class RoomUpdateLayersPacket extends SynchronizedUpdatePacket {
static unpack(packet) {
const unpacked = super.unpack(packet);
const {data} = unpacked;
data.layersPackets = BundlePacket.unpack(data.layersPackets);
data.layersPackets = BundlePacket.unpack(data.layersPackets).data;
return unpacked;
}