@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hytopia.com/server-protocol",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -30,6 +30,7 @@ export enum PacketId {
30
30
  BLOCK_TYPE = 34,
31
31
  CHUNK = 35,
32
32
  ENTITY = 36,
33
+ WORLD = 37,
33
34
 
34
35
  // Debug Inbound Packet Types: 128 - 191 range
35
36
  // NONE atm, start at 128
@@ -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
- !packet[0] ||
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
+ );
@@ -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
+ }