File tree Expand file tree Collapse file tree 7 files changed +49
-14
lines changed Expand file tree Collapse file tree 7 files changed +49
-14
lines changed Original file line number Diff line number Diff line change 2
2
/Cargo.lock
3
3
/out
4
4
/.vscode /settings.json
5
- /server_icon.png
5
+ /server_icon.png
6
+ /config.toml
Original file line number Diff line number Diff line change
1
+ [api ]
2
+ addr = " 0.0.0.0"
3
+ port = 8008
4
+ code_life_time = 300
5
+
6
+ [server ]
7
+ addr = " 0.0.0.0"
8
+ port = 25566
9
+ timeout = 20
10
+ server_ip = " localhost"
11
+
12
+ [server .config ]
13
+ server_name = " mc-oauth-rs"
14
+ protocol = 0
15
+ version = " 1.21"
16
+ auth_url = " https://sessionserver.mojang.com/session/minecraft/hasJoined?username={{NAME}}&serverId={{HASH}}"
17
+
18
+ [server .status ]
19
+ description = " §6mc-oauth.andcool.ru"
20
+ players_max = 0
21
+ players_online = 0
22
+ icon_path = " server_icon.png"
23
+
24
+ [messages ]
25
+ success = " Hello, §6{{NAME}}§r! Your code is: §a{{CODE}}"
26
+ bad_session = " §cFailed to login: Invalid session (Try restarting your game and the launcher)"
27
+ using_proxy = " §cYou are using a proxy!"
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ impl MinecraftServer {
14
14
pub async fn handle_handshake ( & mut self ) -> Result < ( ) > {
15
15
let handshake = HandshakePacket :: parse ( & mut self . buffer ) ?;
16
16
17
- self . session . proto_ver = Some ( handshake. proto_ver ) ;
17
+ self . session . proto_ver = handshake. proto_ver ;
18
18
self . session . next_state = match handshake. next_state {
19
19
1 => NextStateEnum :: Status ,
20
20
2 => NextStateEnum :: Login ,
Original file line number Diff line number Diff line change 1
1
use crate :: { packets:: login_start:: LoginStartPacket , server:: MinecraftServer } ;
2
+ use anyhow:: Error ;
2
3
3
4
impl MinecraftServer {
4
5
/**
5
6
Handle login start packet from client
6
7
*/
7
- pub fn handle_login_start ( & mut self ) -> anyhow:: Result < ( ) > {
8
+ pub async fn handle_login_start ( & mut self ) -> anyhow:: Result < ( ) > {
8
9
let packet = LoginStartPacket :: parse ( & mut self . buffer ) ?;
9
10
self . session . nickname = Some ( packet. name ) ;
10
11
self . session . uuid = packet. uuid ;
12
+
13
+ if self . session . proto_ver >= 759 && self . session . proto_ver <= 762 {
14
+ self . send_disconnect (
15
+ "Sorry, Minecraft 1.19.* clients not supported yet.\n Try using another version of client."
16
+ . to_string ( ) ,
17
+ )
18
+ . await ?;
19
+ return Err ( Error :: msg ( "Client using unsupported version!" ) ) ;
20
+ }
11
21
Ok ( ( ) )
12
22
}
13
23
}
Original file line number Diff line number Diff line change @@ -10,11 +10,11 @@ impl MinecraftServer {
10
10
pub async fn send_encryption ( & mut self ) -> Result < ( ) > {
11
11
let public_der = self . keys . to_public_key ( ) . to_public_key_der ( ) ?. into_vec ( ) ;
12
12
13
- let proto_ver = match self . session . proto_ver {
14
- Some ( x) => x,
15
- None => unreachable ! ( ) ,
13
+ let should_authenticate = if self . session . proto_ver >= 766 {
14
+ Some ( true )
15
+ } else {
16
+ None
16
17
} ;
17
- let should_authenticate = if proto_ver >= 766 { Some ( true ) } else { None } ;
18
18
19
19
let packet = EncryptionRequestPacket :: new (
20
20
self . session . server_id . clone ( ) ,
Original file line number Diff line number Diff line change @@ -14,10 +14,7 @@ impl MinecraftServer {
14
14
pub async fn send_status ( & mut self ) -> Result < ( ) > {
15
15
let config = get_config ( ) . await ;
16
16
let proto_ver = if config. server . config . protocol == 0 {
17
- match self . session . proto_ver {
18
- Some ( x) => x,
19
- None => unreachable ! ( ) ,
20
- }
17
+ self . session . proto_ver
21
18
} else {
22
19
config. server . config . protocol
23
20
} ;
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ pub enum NextStateEnum {
24
24
#[ derive( Debug ) ]
25
25
pub struct Session {
26
26
pub server_id : String ,
27
- pub proto_ver : Option < usize > ,
27
+ pub proto_ver : usize ,
28
28
pub next_state : NextStateEnum ,
29
29
pub nickname : Option < String > ,
30
30
pub uuid : Option < Uuid > ,
@@ -40,7 +40,7 @@ impl Session {
40
40
41
41
Self {
42
42
server_id : config. server . config . server_name . clone ( ) ,
43
- proto_ver : None ,
43
+ proto_ver : 0 ,
44
44
next_state : NextStateEnum :: Unknown ,
45
45
nickname : None ,
46
46
uuid : None ,
@@ -128,7 +128,7 @@ impl MinecraftServer {
128
128
NextStateEnum :: Status => self . send_status ( ) . await ?, // Send status response
129
129
NextStateEnum :: Login => {
130
130
// Handle login start
131
- self . handle_login_start ( ) ?;
131
+ self . handle_login_start ( ) . await ?;
132
132
self . send_encryption ( ) . await ?;
133
133
}
134
134
NextStateEnum :: Unknown => self . handle_handshake ( ) . await ?, // Handle handshake
You can’t perform that action at this time.
0 commit comments