|
8 | 8 |
|
9 | 9 | import * as Sentry from "@sentry/node"; |
10 | 10 | 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"; |
12 | 17 | import { UserLogo, VerifyCode } from "@statsify/schemas"; |
13 | 18 | import { config, formatTime } from "@statsify/util"; |
14 | 19 | import { connect } from "mongoose"; |
@@ -41,6 +46,11 @@ const codeCreatedMessage = (code: string, time: Date) => { |
41 | 46 | )}§r§7.`; |
42 | 47 | }; |
43 | 48 |
|
| 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 | + |
44 | 54 | const supportsFeature = (client: ServerClient, feature: string) => { |
45 | 55 | const supportFeature = (client as ServerClient & { |
46 | 56 | supportFeature?: (feature: string) => boolean; |
@@ -114,6 +124,16 @@ server.on("connection", (client) => { |
114 | 124 | // instead of continuing into mismatched configuration registry data. |
115 | 125 | client.state = states.LOGIN; |
116 | 126 | 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 | + }; |
117 | 137 | }); |
118 | 138 |
|
119 | 139 | client.on("state", (newState, oldState) => { |
|
0 commit comments