Skip to content

Commit

Permalink
Don't disconnect on unknown packet (#39)
Browse files Browse the repository at this point in the history
When an unknown packet is received instead of dropping the connection,
send a debug message with the connection state and packet payload.


![image](https://github.com/arciera/server/assets/66572326/d8a3b70a-e1f1-42d8-b8c8-fb39aa0e9ef8)
  • Loading branch information
zefir-git authored Aug 13, 2023
2 parents d62d1ec + 3ded0f1 commit 0943732
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Config from "./src/Config.js";
import Server from "./src/Server.js";
import LoginSuccessPacket from "./src/packet/server/LoginSuccessPacket.js";
import Connection from "./src/Connection.js";

const config: Config = await Config.fromFile("config.json");

Expand All @@ -9,8 +10,7 @@ server.start();
server.on("listening", (port) => server.logger.info(`Listening on port ${port}`));

server.on("unknownPacket", (packet, conn) => {
server.logger.warn("Unknown packet, disconnecting", packet.dataBuffer);
conn.disconnect().then();
server.logger.debug("Unknown packet", `{state=${Connection.State[conn.state]}}`, packet.dataBuffer);
});
server.on("packet", (packet, _conn) => {
server.logger.debug(packet.constructor.name, packet.data);
Expand Down

0 comments on commit 0943732

Please sign in to comment.