File tree Expand file tree Collapse file tree 10 files changed +17
-18
lines changed Expand file tree Collapse file tree 10 files changed +17
-18
lines changed Original file line number Diff line number Diff line change @@ -79,6 +79,10 @@ pub fn read_unsigned_short(buf: &mut BytesMut) -> io::Result<u16> {
79
79
Ok ( buf. get_u16 ( ) )
80
80
}
81
81
82
+ /*
83
+ For some reason, not all Minecraft clients send their UUID correctly,
84
+ so you have to return Result, since parsing is not always possible.
85
+ */
82
86
pub fn try_get_uuid ( buf : & mut BytesMut ) -> anyhow:: Result < Uuid > {
83
87
let len = buf. len ( ) ;
84
88
if len < 16 {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ pub async fn handle_handshake(client: &mut MinecraftClient) -> Result<()> {
15
15
_ => NextStateEnum :: Unknown ,
16
16
} ;
17
17
18
+ // Check client's connecting hostname
18
19
client. session . proto_ver = Some ( handshake. proto_ver ) ;
19
20
if let Some ( server_ip) = & client. config . server . server_ip {
20
21
if server_ip. ne ( & handshake. server_addr ) {
Original file line number Diff line number Diff line change
1
+ use crate :: byte_buf_utils:: { read_unsigned_short, read_utf8, read_varint} ;
1
2
use bytes:: BytesMut ;
2
3
use tokio:: io;
3
4
4
- use crate :: byte_buf_utils:: { read_unsigned_short, read_utf8, read_varint} ;
5
-
6
5
#[ allow( dead_code) ]
7
6
pub struct HandshakePacket {
8
7
pub proto_ver : usize ,
@@ -17,7 +16,7 @@ impl HandshakePacket {
17
16
proto_ver : read_varint ( buff) ?,
18
17
server_addr : read_utf8 ( buff) ?,
19
18
port : read_unsigned_short ( buff) ?,
20
- next_state : read_varint ( buff) ?
19
+ next_state : read_varint ( buff) ?,
21
20
} )
22
21
}
23
22
}
Original file line number Diff line number Diff line change
1
+ use crate :: byte_buf_utils:: { read_utf8, try_get_uuid} ;
1
2
use bytes:: BytesMut ;
2
3
use uuid:: Uuid ;
3
4
4
- use crate :: byte_buf_utils:: { read_utf8, try_get_uuid} ;
5
-
6
5
pub struct LoginStartPacket {
7
6
pub name : String ,
8
7
pub uuid : Option < Uuid > ,
Original file line number Diff line number Diff line change
1
+ use crate :: byte_buf_utils:: { add_size, write_varint} ;
1
2
use anyhow:: Result ;
2
3
use bytes:: { BufMut , BytesMut } ;
3
4
4
- use crate :: byte_buf_utils:: { add_size, write_varint} ;
5
-
6
-
7
- #[ allow( dead_code) ]
8
5
pub struct PingPacket {
9
- pub payload : i64
6
+ pub payload : i64 ,
10
7
}
11
8
12
9
impl PingPacket {
Original file line number Diff line number Diff line change
1
+ use crate :: byte_buf_utils:: { add_size, write_utf8, write_varint} ;
1
2
use anyhow:: Result ;
2
3
use bytes:: BytesMut ;
3
4
use serde:: Serialize ;
4
5
use serde_json:: Value ;
5
6
6
- use crate :: byte_buf_utils:: { add_size, write_utf8, write_varint} ;
7
-
8
7
pub struct StatusPacket { }
9
8
10
9
impl StatusPacket {
Original file line number Diff line number Diff line change @@ -13,10 +13,13 @@ pub async fn send_disconnect(
13
13
}
14
14
. build ( ) ?;
15
15
16
+ // Passing a session object allows sending a disconnect packet with or without encryption.
16
17
encrypt_packet ( & mut disconnect_packet, session) ;
17
18
18
19
stream. writable ( ) . await ?;
19
20
stream. write_all ( & disconnect_packet) . await ?;
21
+
22
+ // Minecraft clients expect that after sending a disconnect packet there should be a disconnect
20
23
stream. shutdown ( ) . await ?;
21
24
22
25
debug ! ( "Disconnected client with reason: {}" , reason) ;
Original file line number Diff line number Diff line change
1
+ use crate :: { client:: Session , packets:: encryption_request:: EncryptionRequestPacket } ;
1
2
use anyhow:: Result ;
2
3
use rsa:: pkcs8:: EncodePublicKey ;
3
4
use std:: sync:: Arc ;
4
5
use tokio:: { io:: AsyncWriteExt , net:: TcpStream } ;
5
6
6
- use crate :: { client:: Session , packets:: encryption_request:: EncryptionRequestPacket } ;
7
-
8
7
pub async fn send_encryption (
9
8
stream : & mut TcpStream ,
10
9
keys : Arc < rsa:: RsaPrivateKey > ,
Original file line number Diff line number Diff line change 1
1
use anyhow:: Result ;
2
2
3
+ use crate :: packets:: ping:: PingPacket ;
3
4
use bytes:: { Buf , BytesMut } ;
4
5
use tokio:: { io:: AsyncWriteExt , net:: TcpStream } ;
5
6
6
- use crate :: packets:: ping:: PingPacket ;
7
-
8
7
pub async fn handle_ping ( stream : & mut TcpStream , buff : & mut BytesMut ) -> Result < ( ) > {
9
8
let payload = buff. get_i64 ( ) ;
10
9
let packet = PingPacket { payload } ;
Original file line number Diff line number Diff line change 1
1
use anyhow:: Result ;
2
2
3
+ use crate :: { client:: Session , config:: get_config, packets:: status} ;
3
4
use serde_json:: json;
4
5
use tokio:: { io:: AsyncWriteExt , net:: TcpStream } ;
5
6
6
- use crate :: { client:: Session , config:: get_config, packets:: status} ;
7
-
8
7
pub async fn send_status ( stream : & mut TcpStream , session : & mut Session ) -> Result < ( ) > {
9
8
let config = get_config ( ) . await ;
10
9
let proto_ver = if config. server . config . protocol == 0 {
You can’t perform that action at this time.
0 commit comments