@@ -17,7 +17,7 @@ use aes::Aes128;
17
17
use anyhow:: { anyhow, Result } ;
18
18
use bytes:: { BufMut , BytesMut } ;
19
19
use cfb8:: Encryptor ;
20
- use std:: { sync:: Arc , time:: Duration } ;
20
+ use std:: { net :: SocketAddr , sync:: Arc , time:: Duration } ;
21
21
use tokio:: net:: TcpStream ;
22
22
use tracing:: { debug, error, info} ;
23
23
use uuid:: Uuid ;
@@ -39,10 +39,11 @@ pub struct Session {
39
39
pub secret : Option < Vec < u8 > > , // Shared secret,
40
40
pub verify_token : [ u8 ; 4 ] ,
41
41
pub cipher : Option < Encryptor < Aes128 > > ,
42
+ pub addr : SocketAddr ,
42
43
}
43
44
44
45
impl Session {
45
- pub async fn new ( ) -> Self {
46
+ pub async fn new ( addr : SocketAddr ) -> Self {
46
47
let config = get_config ( ) . await ;
47
48
48
49
Self {
@@ -54,6 +55,7 @@ impl Session {
54
55
secret : None ,
55
56
verify_token : generate_verify_token ( ) ,
56
57
cipher : None ,
58
+ addr,
57
59
}
58
60
}
59
61
}
@@ -69,7 +71,7 @@ pub struct MinecraftClient {
69
71
impl MinecraftClient {
70
72
pub async fn new ( stream : TcpStream , keys : Arc < rsa:: RsaPrivateKey > ) -> Self {
71
73
Self {
72
- session : Session :: new ( ) . await ,
74
+ session : Session :: new ( stream . peer_addr ( ) . unwrap ( ) ) . await ,
73
75
buffer : BytesMut :: new ( ) ,
74
76
config : get_config ( ) . await ,
75
77
stream,
@@ -81,7 +83,7 @@ impl MinecraftClient {
81
83
match self . _run ( ) . await {
82
84
Ok ( _) => info ! (
83
85
"Connection from {:?} closed successfully" ,
84
- self . stream . peer_addr ( ) . unwrap ( )
86
+ self . session . addr
85
87
) ,
86
88
Err ( e) => error ! ( "Internal error occurred: {}" , e) ,
87
89
}
0 commit comments