From 841ab83836dcab64dbdbd2a83e444d7310aebfc0 Mon Sep 17 00:00:00 2001 From: JadlionHD <48410066+JadlionHD@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:47:05 +0700 Subject: [PATCH] fix peer data type --- package.json | 2 +- src/structures/Peer.ts | 22 +++++++++++----------- types/index.d.ts | 4 ++++ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 8350639..72dd282 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "growtopia.js", - "version": "1.3.3", + "version": "1.3.4", "description": "A package to create a growtopia private servers.", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/structures/Peer.ts b/src/structures/Peer.ts index d805067..eedd029 100644 --- a/src/structures/Peer.ts +++ b/src/structures/Peer.ts @@ -1,14 +1,14 @@ -import { ClientType } from "../../types"; +import { ClientType, PeerData } from "../../types"; import { Sendable } from "../../types/packets"; import { Variant } from "../packets/Variant"; import { Client } from "./Client"; -class Peer { - public data?: T; +class Peer { + public data: T; constructor(private client: Client, netID: number) { - (this.data as any) = { netID }; - // this.netID = netID; + this.data = {} as T; + this.data.netID = netID; this.client = client; } @@ -17,14 +17,14 @@ class Peer { * Get ENetPeer Round Trip Time (RTT). */ public get ping() { - return this.client._client.getPeerRTT((this.data as any).netID); + return this.client._client.getPeerRTT(this.data.netID); } /** * Get [ENetPeerState](http://enet.bespin.org/enet_8h.html#a058bc368c507eb86cb47f3946f38d558). */ public get state() { - return this.client._client.getPeerState((this.data as any).netID); + return this.client._client.getPeerState(this.data.netID); } /** @@ -32,7 +32,7 @@ class Peer { * @param data An argument of packets that contains the `parse()` function or just an array of Buffers. */ public send(...data: Sendable[]) { - Peer.send(this.client._client, (this.data as any).netID, ...data); + Peer.send(this.client._client, this.data.netID, ...data); } /** @@ -72,15 +72,15 @@ class Peer { public disconnect(type: "now" | "later" | "normal" = "later") { switch (type) { case "normal": { - this.client._client.disconnect((this.data as any).netID); + this.client._client.disconnect(this.data.netID); break; } case "later": { - this.client._client.disconnectLater((this.data as any).netID); + this.client._client.disconnectLater(this.data.netID); break; } case "now": { - this.client._client.disconnectNow((this.data as any).netID); + this.client._client.disconnectNow(this.data.netID); break; } } diff --git a/types/index.d.ts b/types/index.d.ts index af50465..8382f2c 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -2,6 +2,10 @@ export interface DataObject { [key: string]: string | number; } +export interface PeerData { + netID: number; +} + export * from "./client"; export * from "./packets"; export * from "./events";