aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol
diff options
context:
space:
mode:
authorHonbra <honbraofficial@gmail.com>2022-11-14 20:25:59 +0100
committerGitHub <noreply@github.com>2022-11-14 13:25:59 -0600
commit9f78b3f4a7229033a3f5acaad6c8fffbe24e3e75 (patch)
tree48bc658358a0b23316ad62b83685f56d1a59f922 /azalea-protocol
parent6eee543a3367d38a6f0e9bffb457a2bd76a8f9cc (diff)
downloadazalea-drasl-9f78b3f4a7229033a3f5acaad6c8fffbe24e3e75.tar.xz
Military-grade server implementation (#40)
* Military-grade server implementation * Add doc comments
Diffstat (limited to 'azalea-protocol')
-rwxr-xr-xazalea-protocol/src/connect.rs24
1 files changed, 23 insertions, 1 deletions
diff --git a/azalea-protocol/src/connect.rs b/azalea-protocol/src/connect.rs
index 37df0f08..00685d3c 100755
--- a/azalea-protocol/src/connect.rs
+++ b/azalea-protocol/src/connect.rs
@@ -302,7 +302,8 @@ where
R1: ProtocolPacket + Debug,
W1: ProtocolPacket + Debug,
{
- fn from<R2, W2>(connection: Connection<R1, W1>) -> Connection<R2, W2>
+ /// Creates a `Connection` of a type from a `Connection` of another type. Useful for servers or custom packets.
+ pub fn from<R2, W2>(connection: Connection<R1, W1>) -> Connection<R2, W2>
where
R2: ProtocolPacket + Debug,
W2: ProtocolPacket + Debug,
@@ -323,4 +324,25 @@ where
},
}
}
+
+ /// Convert an existing `TcpStream` into a `Connection`. Useful for servers.
+ pub fn wrap(stream: TcpStream) -> Connection<R1, W1> {
+ let (read_stream, write_stream) = stream.into_split();
+
+ Connection {
+ reader: ReadConnection {
+ read_stream,
+ buffer: BytesMut::new(),
+ compression_threshold: None,
+ dec_cipher: None,
+ _reading: PhantomData,
+ },
+ writer: WriteConnection {
+ write_stream,
+ compression_threshold: None,
+ enc_cipher: None,
+ _writing: PhantomData,
+ },
+ }
+ }
}