Skip to content

Commit 198013d

Browse files
feat: Added login state protocol version check
1 parent b111729 commit 198013d

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ server_ip = "localhost"
9797
support_1_19 = false
9898

9999
[server.config]
100-
# Minecraft server name
100+
# Minecraft server name (used for internal auth; can be empty)
101101
server_name = "mc-oauth-rs"
102102

103103
# Protocol version (`0` for auto)
104-
# Used only during the server ping and is ignored when trying to connect. If set to 0, the protocol version that the client uses will be applied.
104+
# If set to 0, the protocol version that the client uses will be applied.
105105
protocol = 0
106106

107-
# Minecraft version string
107+
# Minecraft version string (In fact, it's just a stub)
108108
version = "1.21"
109109

110110
# Session Auth URL
@@ -141,6 +141,9 @@ using_proxy = "§cYou are using a proxy!"
141141

142142
# Message for internal server error
143143
internal_error = "§cSorry, internal server error occurred"
144+
145+
# Message for unsupported client version
146+
unsupported_client_version = "§cYou are using unsupported version of client!"
144147
```
145148

146149

config.example.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ success = "Hello, §6{{NAME}}§r! Your code is: §a{{CODE}}"
2828
bad_session = "§cFailed to login: Invalid session (Try restarting your game and the launcher)"
2929
using_proxy = "§cYou are using a proxy!"
3030
internal_error = "§cSorry, internal server error occurred"
31+
unsupported_client_version = "§cYou are using unsupported version of client!"

src/config/types.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,7 @@ pub struct Messages {
103103

104104
/// Message for internal server error
105105
pub internal_error: String,
106+
107+
/// Message for unsupported client version
108+
pub unsupported_client_version: String,
106109
}

src/handlers/handshake.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ impl MinecraftServer {
3030
}
3131
}
3232

33+
// Check client's protocol version
34+
let server_proto_ver = self.config.server.config.protocol;
35+
if let NextStateEnum::Login = self.session.next_state {
36+
if server_proto_ver.ne(&0) && self.session.proto_ver.ne(&server_proto_ver) {
37+
self.send_disconnect(self.config.messages.unsupported_client_version.clone())
38+
.await?;
39+
return Err(Error::msg(format!(
40+
"Unsupported client version! Server: {}, client: {}",
41+
server_proto_ver, self.session.proto_ver
42+
)));
43+
}
44+
}
45+
3346
Ok(())
3447
}
3548
}

0 commit comments

Comments
 (0)