@hytopia.com/server-protocol 1.0.19 → 1.0.21
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 +1 -0
- package/packets/PacketDefinitions.ts +3 -4
- package/packets/outbound/World.ts +11 -0
- package/schemas/World.ts +18 -0
package/package.json
CHANGED
package/packets/PacketCore.ts
CHANGED
|
@@ -24,13 +24,12 @@ export function isValidPacket(packet: unknown): packet is AnyPacket {
|
|
|
24
24
|
if (
|
|
25
25
|
typeof packet !== 'object' ||
|
|
26
26
|
packet === null ||
|
|
27
|
-
|
|
28
|
-
packet[1] === undefined
|
|
29
|
-
typeof packet[0] !== 'number'
|
|
27
|
+
typeof packet[0] !== 'number' || packet[0] < 0 ||
|
|
28
|
+
packet[1] === undefined
|
|
30
29
|
) {
|
|
31
30
|
return false;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
const packetDef = registeredPackets.get(packet[0]);
|
|
35
34
|
return !!packetDef && packetDef.validate(packet[1]);
|
|
36
|
-
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
|
+
import type { IPacket } from '../PacketCore';
|
|
3
|
+
import { worldSchema } from '../../schemas/World';
|
|
4
|
+
import type { WorldSchema } from '../../schemas/World';
|
|
5
|
+
|
|
6
|
+
export type WorldPacket = IPacket<typeof PacketId.WORLD, WorldSchema>;
|
|
7
|
+
|
|
8
|
+
export const worldPacketDefinition = definePacket(
|
|
9
|
+
PacketId.WORLD,
|
|
10
|
+
worldSchema,
|
|
11
|
+
);
|
package/schemas/World.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { JSONSchemaType } from 'ajv';
|
|
2
|
+
|
|
3
|
+
export type WorldSchema = {
|
|
4
|
+
i: number; // id
|
|
5
|
+
f?: boolean; // focused
|
|
6
|
+
n?: string; // name
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const worldSchema: JSONSchemaType<WorldSchema> = {
|
|
10
|
+
type: 'object',
|
|
11
|
+
properties: {
|
|
12
|
+
i: { type: 'number' },
|
|
13
|
+
f: { type: 'boolean', nullable: true },
|
|
14
|
+
n: { type: 'string', nullable: true }
|
|
15
|
+
},
|
|
16
|
+
required: [ 'i' ],
|
|
17
|
+
additionalProperties: false,
|
|
18
|
+
}
|