Skip to content

Commit

Permalink
fix: types error
Browse files Browse the repository at this point in the history
  • Loading branch information
JadlionHD committed Nov 15, 2023
1 parent 2eff5e7 commit bf9f485
Show file tree
Hide file tree
Showing 8 changed files with 742 additions and 600 deletions.
1,096 changes: 617 additions & 479 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "growtopia.js",
"version": "1.3.0",
"version": "1.3.1",
"description": "A package to create a growtopia private servers.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -35,11 +35,12 @@
},
"dependencies": {
"@mapbox/node-pre-gyp": "^1.0.10",
"@types/express": "^4.17.21",
"@types/node": "^20.1.5",
"eventemitter3": "^5.0.1",
"express": "^4.18.2",
"node-addon-api": "^6.1.0",
"node-gyp": "^9.4.0",
"node-gyp": "^10.0.1",
"typescript": "^5.0.4"
},
"devDependencies": {
Expand Down
36 changes: 18 additions & 18 deletions src/structures/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@ class Client extends EventEmitter {
super();

this.config = {
plugins: options.plugins ?? [],
plugins: options?.plugins ?? [],
https: {
ip: options.https?.ip ?? "127.0.0.1",
port: options.https?.port ?? 17091,
enable: options.https?.enable ?? true,
type2: options.https?.type2 ?? false
ip: options?.https?.ip ?? "127.0.0.1",
port: options?.https?.port ?? 17091,
enable: options?.https?.enable ?? true,
type2: options?.https?.type2 ?? false
},
enet: {
ip: options.enet?.ip ?? "127.0.0.1",
port: options.enet?.port ?? 17091,
maxPeers: options.enet?.maxPeers ?? 1024,
ip: options?.enet?.ip ?? "127.0.0.1",
port: options?.enet?.port ?? 17091,
maxPeers: options?.enet?.maxPeers ?? 1024,
useNewPacket: {
asClient: options.enet?.useNewPacket?.asClient ?? false
asClient: options?.enet?.useNewPacket?.asClient ?? false
}
}
};

this.config.plugins;

this._client = new Native(this.config.enet.ip, this.config.enet.port) as ClientType;
this._client = new Native(this.config.enet?.ip, this.config.enet?.port) as ClientType;

this.cache = {
players: new Map<number, number>()
Expand Down Expand Up @@ -73,7 +73,7 @@ class Client extends EventEmitter {

public listen() {
try {
this._client.create(this.config.enet.maxPeers, this.config.enet.useNewPacket.asClient);
this._client.create(this.config?.enet?.maxPeers!, this.config?.enet?.useNewPacket?.asClient!);

this.emitter(this.emit.bind(this));

Expand All @@ -96,25 +96,25 @@ class Client extends EventEmitter {
private _startWeb() {
if (!this.config.https) return;
if (this.config.https.enable)
WebServer(this.config.https.ip, this.config.https.port, this.config.https.type2);
WebServer(this.config?.https?.ip!, this.config?.https?.port!, this.config.https.type2);
}

private _handleEvent() {
// Initialize plugins
if (this.config.plugins.length) this.config.plugins.forEach((v) => v.init(this));
if (this.config?.plugins?.length) this.config.plugins.forEach((v) => v.init(this));

this.on("connect", (netID) => {
this.cache.players.set(netID, netID);
if (this.config.plugins.length) this.config.plugins.forEach((v) => v.onConnect(netID));
this.cache.players?.set(netID, netID);
if (this.config.plugins?.length) this.config.plugins.forEach((v) => v.onConnect(netID));
});

this.on("disconnect", (netID) => {
this.cache.players.delete(netID);
if (this.config.plugins.length) this.config.plugins.forEach((v) => v.onDisconnect(netID));
this.cache.players?.delete(netID);
if (this.config.plugins?.length) this.config.plugins.forEach((v) => v.onDisconnect(netID));
});

this.on("raw", (netID, data) => {
if (this.config.plugins.length) this.config.plugins.forEach((v) => v.onRaw(netID, data));
if (this.config.plugins?.length) this.config.plugins.forEach((v) => v.onRaw(netID, data));
const type = data.readInt32LE();
const peer = new Peer(this, netID);

Expand Down
2 changes: 1 addition & 1 deletion src/structures/GrowApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Caching } from "../../types";
import { Client } from "./Client";

class GrowApi {
public client: Client;
public client?: Client;

constructor() {}

Expand Down
Loading

0 comments on commit bf9f485

Please sign in to comment.