diff --git a/app/node_modules/dimensions/clearutils.ts b/app/node_modules/dimensions/clearutils.ts index 9d1a0e4..899c3ad 100644 --- a/app/node_modules/dimensions/clearutils.ts +++ b/app/node_modules/dimensions/clearutils.ts @@ -14,14 +14,15 @@ class ClearUtils { } public static clearPlayer(client: Client, playerIndex: number): void { - const playerActive = new PacketWriter() + const playerActiveData = new PacketWriter() .setType(PacketTypes.PlayerActive) .packByte(playerIndex) .packByte(0) // Active .data; - const packet = { packetType: PacketTypes.PlayerActive, data: playerActive }; - if (!client.server.getPacketHandler().handlePacket(client.server, packet)) { - client.socket.write(packet.data); + const playerActive = { packetType: PacketTypes.PlayerActive, data: playerActiveData }; + const playerActivePacket = client.server.getPacketHandler().handlePacket(client.server, playerActive); + if (playerActivePacket !== null) { + client.socket.write(playerActivePacket); } } @@ -50,7 +51,8 @@ class ClearUtils { .packByte(0) .data; const packet = { packetType: PacketTypes.NPCUpdate, data: updateNPC }; - if (!client.server.getPacketHandler().handlePacket(client.server, packet)) { + const finalPacket = client.server.getPacketHandler().handlePacket(client.server, packet); + if (finalPacket !== null) { client.socket.write(packet.data); } client.server.entityTracking.NPCs[npcIndex] = undefined; @@ -80,8 +82,9 @@ class ClearUtils { .data, packetType: PacketTypes.UpdateItemDrop, }; - if (!client.server.getPacketHandler().handlePacket(client.server, updateItemDrop)) { - client.socket.write(updateItemDrop.data); + const updateItemDropPacket = client.server.getPacketHandler().handlePacket(client.server, updateItemDrop); + if (updateItemDropPacket !== null) { + client.socket.write(updateItemDropPacket); } } } diff --git a/app/node_modules/dimensions/client.ts b/app/node_modules/dimensions/client.ts index d348253..c1d47e0 100644 --- a/app/node_modules/dimensions/client.ts +++ b/app/node_modules/dimensions/client.ts @@ -18,6 +18,7 @@ import ClientState from 'dimensions/clientstate'; import Logger from 'dimensions/logger'; import ClientArgs from 'dimensions/clientargs'; import ErrorHelper from 'dimensions/errorhelper'; +import ClearUtils from 'dimensions/clearutils'; /** * This class handles switching servers and passing data of a single client @@ -322,7 +323,7 @@ class Client { color = "00ff00" } - let chatMessage = new PacketWriter() + let chatMessageData = new PacketWriter() .setType(PacketTypes.LoadNetModule) .packUInt16(1) .packByte(255) @@ -330,9 +331,11 @@ class Client { .packHex(color) .data; - const packet = { packetType: PacketTypes.LoadNetModule, data: chatMessage }; - this.server.getPacketHandler().handlePacket(this.server, packet); - this.socket.write(packet.data); + const chatMessage = { packetType: PacketTypes.LoadNetModule, data: chatMessageData }; + const chatMessagePacket = this.server.getPacketHandler().handlePacket(this.server, chatMessage); + if (chatMessagePacket !== null) { + this.socket.write(chatMessagePacket); + } } } @@ -349,6 +352,10 @@ class Client { /* Handles switching from one server to another */ public changeServer(server: RoutingServer, options?: ChangeServerOptions): void { + ClearUtils.clearPlayers(this); + ClearUtils.clearNPCs(this); + ClearUtils.clearItems(this); + let ip: string = server.serverIP; let port: number = server.serverPort; let name: string = server.name; @@ -408,8 +415,9 @@ class Client { packetType: PacketTypes.AddPlayerBuff, }; - if (!this.server.getPacketHandler().handlePacket(this.server, stoned)) { - this.send(stoned.data); + const stonedPacket = this.server.getPacketHandler().handlePacket(this.server, stoned); + if (stonedPacket !== null) { + this.send(stonedPacket); } const webbed = { @@ -422,8 +430,9 @@ class Client { packetType: PacketTypes.AddPlayerBuff, }; - if (!this.server.getPacketHandler().handlePacket(this.server, webbed)) { - this.send(webbed.data); + const webbedPacket = this.server.getPacketHandler().handlePacket(this.server, webbed); + if (webbedPacket !== null) { + this.send(webbedPacket); } this.server.socket.on('data', this.ServerHandleData); diff --git a/app/node_modules/dimensions/clientcommandhandler.ts b/app/node_modules/dimensions/clientcommandhandler.ts index a3eed05..5479dd6 100644 --- a/app/node_modules/dimensions/clientcommandhandler.ts +++ b/app/node_modules/dimensions/clientcommandhandler.ts @@ -2,7 +2,6 @@ import PacketTypes from 'dimensions/packettypes'; import Client from 'dimensions/client'; import PacketWriter from 'dimensions/packets/packetwriter'; import ClientState from 'dimensions/clientstate'; -import ClearUtils from 'dimensions/clearutils'; export interface Command { name: string; @@ -45,9 +44,6 @@ export class ClientCommandHandler { if (client.state === ClientState.FullyConnected || client.state === ClientState.Disconnected) { client.sendChatMessage("Shifting to the " + client.servers[command.name].name + " Dimension", "FF0000"); - ClearUtils.clearPlayers(client); - ClearUtils.clearNPCs(client); - ClearUtils.clearItems(client); client.changeServer(client.servers[command.name]); } else { client.sendChatMessage("You need to wait until you have fully connected to your current Dimension."); diff --git a/app/node_modules/dimensions/terrariaserverpackethandler.ts b/app/node_modules/dimensions/terrariaserverpackethandler.ts index 025f188..bc54977 100644 --- a/app/node_modules/dimensions/terrariaserverpackethandler.ts +++ b/app/node_modules/dimensions/terrariaserverpackethandler.ts @@ -13,7 +13,6 @@ import Item from 'dimensions/item'; import Player from 'dimensions/player'; import ClientState from 'dimensions/clientstate'; import BitsByte from 'dimensions/datatypes/bitsbyte'; -import ClearUtils from 'dimensions/clearutils'; /** * This handles all packets coming from a Terraria Server, sometimes responding instead of the client @@ -381,9 +380,6 @@ class TerrariaServerPacketHandler { if (messageType === 2) { if (this.currentServer.client.servers[messageContent.toLowerCase()]) { this.currentServer.client.sendChatMessage("Shifting to the " + messageContent + " Dimension", "FF0000"); - ClearUtils.clearPlayers(this.currentServer.client); - ClearUtils.clearNPCs(this.currentServer.client); - ClearUtils.clearItems(this.currentServer.client); this.currentServer.client.changeServer(this.currentServer.client.servers[messageContent.toLowerCase()], { preventSpawnOnJoin: false }); @@ -393,9 +389,6 @@ class TerrariaServerPacketHandler { if (messageType === 3) { const ip = messageContent; const port: number = reader.readUInt16(); - ClearUtils.clearPlayers(this.currentServer.client); - ClearUtils.clearNPCs(this.currentServer.client); - ClearUtils.clearItems(this.currentServer.client); this.currentServer.client.changeServer({ name: `${ip}:${port}`, serverIP: ip,