@hytopia.com/server-protocol 1.4.14 → 1.4.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packets/PacketCore.ts +3 -3
package/package.json
CHANGED
package/packets/PacketCore.ts
CHANGED
|
@@ -86,13 +86,13 @@ export function createPacket<TId extends PacketId, TSchema>(
|
|
|
86
86
|
packetDef: IPacketDefinition<TId, TSchema>,
|
|
87
87
|
data: TSchema,
|
|
88
88
|
worldTick?: WorldTick,
|
|
89
|
-
reusablePacket?:
|
|
89
|
+
reusablePacket?: unknown[],
|
|
90
90
|
): IPacket<TId, TSchema> {
|
|
91
91
|
if (!packetDef.validate(data)) {
|
|
92
92
|
throw new Error(`Invalid payload for packet with id ${packetDef.id}. Error: ${Ajv.instance.errorsText(packetDef.validate.errors)}`);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
const packet
|
|
95
|
+
const packet = reusablePacket ?? [];
|
|
96
96
|
|
|
97
97
|
packet[0] = packetDef.id;
|
|
98
98
|
packet[1] = data;
|
|
@@ -101,7 +101,7 @@ export function createPacket<TId extends PacketId, TSchema>(
|
|
|
101
101
|
packet.push(worldTick);
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
return packet
|
|
104
|
+
return packet as IPacket<TId, TSchema>;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
export function definePacket<TId extends PacketId, TSchema>(
|