Skip to content

Commit

Permalink
Kick clients that declare an unsupported version (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
Protonull authored Aug 16, 2023
1 parent fc94b10 commit fb21f37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const SUPPORTED_VERSIONS = new Set([
'2.0.1-1.18.2-fabric',
'2.0.1-1.18.2-forge',
])
9 changes: 8 additions & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BufReader } from './protocol/BufReader'
import { BufWriter } from './protocol/BufWriter'
import { EncryptionResponsePacket } from './protocol/EncryptionResponsePacket'
import { HandshakePacket } from './protocol/HandshakePacket'
import { SUPPORTED_VERSIONS } from './constants'

const { PORT = '12312', HOST = '127.0.0.1' } = process.env

Expand Down Expand Up @@ -215,7 +216,13 @@ export class TcpClient {
if (this.cryptoPromise) throw new Error(`Already authenticated`)
if (this.verifyToken) throw new Error(`Encryption already started`)

this.modVersion = packet.modVersion
if (!SUPPORTED_VERSIONS.has(packet.modVersion)) {
this.kick(
'Connected with unsupported version [' + packet.modVersion + ']',
)
return
}

this.gameAddress = packet.gameAddress
this.claimedMojangName = packet.mojangName
this.world = packet.world
Expand Down

0 comments on commit fb21f37

Please sign in to comment.