diff --git a/generated/ares_pb.js b/generated/ares_pb.js index 8a88262..a17af65 100644 --- a/generated/ares_pb.js +++ b/generated/ares_pb.js @@ -3,198 +3,189 @@ /* eslint-disable */ // @ts-nocheck -import { proto3 } from '@bufbuild/protobuf' +import { proto3 } from "@bufbuild/protobuf"; /** * @generated from enum ares.EntityType */ -export const EntityType = proto3.makeEnum('ares.EntityType', [ - { no: 0, name: 'MOB' }, - { no: 1, name: 'NPC' }, -]) +export const EntityType = proto3.makeEnum( + "ares.EntityType", + [ + {no: 0, name: "MOB"}, + {no: 1, name: "NPC"}, + ], +); /** * @generated from enum ares.Classe */ -export const Classe = proto3.makeEnum('ares.Classe', [ - { no: 0, name: 'IOP' }, - { no: 1, name: 'SRAM' }, -]) +export const Classe = proto3.makeEnum( + "ares.Classe", + [ + {no: 0, name: "IOP"}, + {no: 1, name: "SRAM"}, + ], +); /** * @generated from enum ares.ErrorCode */ -export const ErrorCode = proto3.makeEnum('ares.ErrorCode', [ - { no: 0, name: 'NO_BETA_ACCESS' }, -]) +export const ErrorCode = proto3.makeEnum( + "ares.ErrorCode", + [ + {no: 0, name: "NO_BETA_ACCESS"}, + ], +); /** * @generated from enum ares.Action */ -export const Action = proto3.makeEnum('ares.Action', [ - { no: 0, name: 'JUMP' }, - { no: 1, name: 'DANCE' }, - { no: 2, name: 'WALK' }, - { no: 3, name: 'RUN' }, - { no: 4, name: 'SIT' }, -]) +export const Action = proto3.makeEnum( + "ares.Action", + [ + {no: 0, name: "JUMP"}, + {no: 1, name: "DANCE"}, + {no: 2, name: "WALK"}, + {no: 3, name: "RUN"}, + {no: 4, name: "SIT"}, + ], +); /** * @generated from message ares.Packet */ -export const Packet = proto3.makeMessageType('ares.Packet', () => [ - { - no: 1, - name: 'signatureRequest', - kind: 'message', - T: SignatureRequest, - oneof: 'type', - }, - { no: 2, name: 'error', kind: 'message', T: Error, oneof: 'type' }, - { - no: 3, - name: 'signatureResponse', - kind: 'message', - T: SignatureResponse, - oneof: 'type', - }, - { - no: 4, - name: 'characterAction', - kind: 'message', - T: CharacterAction, - oneof: 'type', - }, - { - no: 5, - name: 'characterPosition', - kind: 'message', - T: CharacterPosition, - oneof: 'type', - }, - { - no: 6, - name: 'entitySpawn', - kind: 'message', - T: EntitySpawn, - oneof: 'type', - }, - { - no: 7, - name: 'entityDespawn', - kind: 'message', - T: EntityDespawn, - oneof: 'type', - }, -]) +export const Packet = proto3.makeMessageType( + "ares.Packet", + () => [ + { no: 1, name: "signatureRequest", kind: "message", T: SignatureRequest, oneof: "type" }, + { no: 2, name: "error", kind: "message", T: Error, oneof: "type" }, + { no: 3, name: "signatureResponse", kind: "message", T: SignatureResponse, oneof: "type" }, + { no: 4, name: "characterAction", kind: "message", T: CharacterAction, oneof: "type" }, + { no: 5, name: "characterPosition", kind: "message", T: CharacterPosition, oneof: "type" }, + { no: 6, name: "entitySpawn", kind: "message", T: EntitySpawn, oneof: "type" }, + { no: 7, name: "entityDespawn", kind: "message", T: EntityDespawn, oneof: "type" }, + { no: 8, name: "serverInfo", kind: "message", T: ServerInfo, oneof: "type" }, + ], +); /** * @generated from message ares.SignatureRequest */ export const SignatureRequest = proto3.makeMessageType( - 'ares.SignatureRequest', + "ares.SignatureRequest", () => [ - { no: 1, name: 'payload', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, + { no: 1, name: "payload", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ], -) +); /** * @generated from message ares.Error */ -export const Error = proto3.makeMessageType('ares.Error', () => [ - { no: 1, name: 'code', kind: 'enum', T: proto3.getEnumType(ErrorCode) }, -]) +export const Error = proto3.makeMessageType( + "ares.Error", + () => [ + { no: 1, name: "code", kind: "enum", T: proto3.getEnumType(ErrorCode) }, + ], +); /** * @generated from message ares.EntitySpawn */ -export const EntitySpawn = proto3.makeMessageType('ares.EntitySpawn', () => [ - { no: 1, name: 'entities', kind: 'message', T: Entity, repeated: true }, -]) +export const EntitySpawn = proto3.makeMessageType( + "ares.EntitySpawn", + () => [ + { no: 1, name: "entities", kind: "message", T: Entity, repeated: true }, + ], +); /** * @generated from message ares.EntityDespawn */ export const EntityDespawn = proto3.makeMessageType( - 'ares.EntityDespawn', + "ares.EntityDespawn", () => [ - { - no: 1, - name: 'ids', - kind: 'scalar', - T: 9 /* ScalarType.STRING */, - repeated: true, - }, + { no: 1, name: "ids", kind: "scalar", T: 9 /* ScalarType.STRING */, repeated: true }, ], -) +); + +/** + * @generated from message ares.ServerInfo + */ +export const ServerInfo = proto3.makeMessageType( + "ares.ServerInfo", + () => [ + { no: 1, name: "player_count", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, + ], +); /** * @generated from message ares.SignatureResponse */ export const SignatureResponse = proto3.makeMessageType( - 'ares.SignatureResponse', + "ares.SignatureResponse", () => [ - { no: 1, name: 'bytes', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, - { no: 2, name: 'signature', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, + { no: 1, name: "bytes", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "signature", kind: "scalar", T: 9 /* ScalarType.STRING */ }, ], -) +); /** * @generated from message ares.CharacterAction */ export const CharacterAction = proto3.makeMessageType( - 'ares.CharacterAction', + "ares.CharacterAction", () => [ - { no: 1, name: 'id', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, - { no: 2, name: 'action', kind: 'enum', T: proto3.getEnumType(Action) }, + { no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "action", kind: "enum", T: proto3.getEnumType(Action) }, ], -) +); /** * @generated from message ares.CharacterPosition */ export const CharacterPosition = proto3.makeMessageType( - 'ares.CharacterPosition', + "ares.CharacterPosition", () => [ - { no: 1, name: 'id', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, - { no: 2, name: 'position', kind: 'message', T: Position }, + { no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "position", kind: "message", T: Position }, ], -) +); /** * @generated from message ares.Position */ -export const Position = proto3.makeMessageType('ares.Position', () => [ - { no: 1, name: 'x', kind: 'scalar', T: 2 /* ScalarType.FLOAT */ }, - { no: 2, name: 'y', kind: 'scalar', T: 2 /* ScalarType.FLOAT */ }, - { no: 3, name: 'z', kind: 'scalar', T: 2 /* ScalarType.FLOAT */ }, -]) +export const Position = proto3.makeMessageType( + "ares.Position", + () => [ + { no: 1, name: "x", kind: "scalar", T: 2 /* ScalarType.FLOAT */ }, + { no: 2, name: "y", kind: "scalar", T: 2 /* ScalarType.FLOAT */ }, + { no: 3, name: "z", kind: "scalar", T: 2 /* ScalarType.FLOAT */ }, + ], +); /** * @generated from message ares.SiblingEntity */ export const SiblingEntity = proto3.makeMessageType( - 'ares.SiblingEntity', + "ares.SiblingEntity", () => [ - { no: 1, name: 'name', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, - { no: 2, name: 'level', kind: 'scalar', T: 13 /* ScalarType.UINT32 */ }, + { no: 1, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "level", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, ], -) +); /** * @generated from message ares.Entity */ -export const Entity = proto3.makeMessageType('ares.Entity', () => [ - { no: 1, name: 'id', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, - { no: 2, name: 'name', kind: 'scalar', T: 9 /* ScalarType.STRING */ }, - { no: 3, name: 'position', kind: 'message', T: Position }, - { no: 4, name: 'type', kind: 'enum', T: proto3.getEnumType(EntityType) }, - { no: 5, name: 'level', kind: 'scalar', T: 13 /* ScalarType.UINT32 */ }, - { - no: 8, - name: 'siblings', - kind: 'message', - T: SiblingEntity, - repeated: true, - }, -]) +export const Entity = proto3.makeMessageType( + "ares.Entity", + () => [ + { no: 1, name: "id", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 2, name: "name", kind: "scalar", T: 9 /* ScalarType.STRING */ }, + { no: 3, name: "position", kind: "message", T: Position }, + { no: 4, name: "type", kind: "enum", T: proto3.getEnumType(EntityType) }, + { no: 5, name: "level", kind: "scalar", T: 13 /* ScalarType.UINT32 */ }, + { no: 8, name: "siblings", kind: "message", T: SiblingEntity, repeated: true }, + ], +); + diff --git a/proto/ares.proto b/proto/ares.proto index 5948af0..aa9b34b 100644 --- a/proto/ares.proto +++ b/proto/ares.proto @@ -10,6 +10,7 @@ message Packet { CharacterPosition characterPosition = 5; EntitySpawn entitySpawn = 6; EntityDespawn entityDespawn = 7; + ServerInfo serverInfo = 8; } } @@ -32,6 +33,10 @@ message EntityDespawn { repeated string ids = 1; } +message ServerInfo { + uint32 player_count = 1; +} + // ======================================== [CLIENT -> SERVER] // Packets sent from the client to the server diff --git a/src/chunk.js b/src/chunk.js index 2f81a50..54a192e 100644 --- a/src/chunk.js +++ b/src/chunk.js @@ -3,7 +3,6 @@ import spiral from 'spiralloop' export const CHUNK_SIZE = 500 export function to_chunk_position(position) { - if (isNaN(position.x) || isNaN(position.z)) return null const x = Math.floor(position.x / CHUNK_SIZE) const z = Math.floor(position.z / CHUNK_SIZE) diff --git a/src/index.js b/src/index.js index 2a118b1..0c363ef 100644 --- a/src/index.js +++ b/src/index.js @@ -4,7 +4,6 @@ import * as Packets from '../generated/ares_pb.js' export * from './chunk.js' -/** @type {typeof import("./types").create_client} */ export function create_client({ socket_write, socket_end }) { const controller = new AbortController() const stream = new PassThrough({ diff --git a/src/types.d.ts b/src/types.d.ts index 53c512c..0bfe204 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -71,8 +71,6 @@ export module 'events' { } } -export function create_client({ socket_write, socket_end }): create_client - interface create_client { controller: AbortController stream: NodeJS.ReadWriteStream @@ -111,7 +109,8 @@ export type Packets = { 'packet/entitySpawn': { entities: Entity[] } // server -> client 'packet/entityDespawn': { ids: string[] } // server -> client 'packet/characterAction': { id: string; action: string } // both ways - 'packet/characterMove': { id: string; position: Position } // both ways + 'packet/characterPosition': { id: string; position: Position } // both ways + 'packet/serverInfo': { player_count: number } } type Packet = {