Skip to content

Commit 73bb607

Browse files
committed
fix(verify-server): format unsupported version disconnect
1 parent 7fba4e3 commit 73bb607

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

apps/verify-server/src/index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88

99
import * as Sentry from "@sentry/node";
1010
import { Logger } from "@statsify/logger";
11-
import { type ServerClient, createServer, states } from "minecraft-protocol";
11+
import {
12+
type ServerClient,
13+
createServer,
14+
states,
15+
supportedVersions,
16+
} from "minecraft-protocol";
1217
import { UserLogo, VerifyCode } from "@statsify/schemas";
1318
import { config, formatTime } from "@statsify/util";
1419
import { connect } from "mongoose";
@@ -41,6 +46,11 @@ const codeCreatedMessage = (code: string, time: Date) => {
4146
)}§r§7.`;
4247
};
4348

49+
const unsupportedProtocolMessage = (protocolVersion: number) =>
50+
`§9§lStatsify Verification Server\n\n§r§7Your Minecraft version is not supported yet.\n\n§r§7Please try again with §c§lMinecraft ${
51+
supportedVersions.at(-1) ?? "a supported version"
52+
}§r§7 or older.\n\n§r§8Protocol ${protocolVersion}`;
53+
4454
const supportsFeature = (client: ServerClient, feature: string) => {
4555
const supportFeature = (client as ServerClient & {
4656
supportFeature?: (feature: string) => boolean;
@@ -114,6 +124,16 @@ server.on("connection", (client) => {
114124
// instead of continuing into mismatched configuration registry data.
115125
client.state = states.LOGIN;
116126
client.removeAllListeners("login_start");
127+
128+
const end = client.end.bind(client);
129+
130+
client.end = (reason?: string) => {
131+
if (reason === `Protocol version ${packet.protocolVersion} is not supported`) {
132+
return end(unsupportedProtocolMessage(packet.protocolVersion));
133+
}
134+
135+
return end(reason);
136+
};
117137
});
118138

119139
client.on("state", (newState, oldState) => {

0 commit comments

Comments
 (0)