b23r0 / rust-raknet Goto Github PK
View Code? Open in Web Editor NEWRakNet Protocol implementation by Rust.
License: MIT License
RakNet Protocol implementation by Rust.
License: MIT License
Created simple packet listener, my code:
#[tokio::main]
async fn main() {
tracing_subscriber::fmt::init();
let mut socket = rust_raknet::RaknetListener::bind("0.0.0.0:19132".parse().unwrap()).await.unwrap();
socket.listen().await;
while let Ok(mut s) = socket.accept().await {
tracing::info!("Accepted connection from {:?}", s.local_addr());
let mut connection = rust_raknet::RaknetSocket::connect(&"51.210.143.233:19132".parse().unwrap()).await.unwrap();
loop {
if let Ok(buf) = s.recv().await {
tracing::info!("FROM CLIENT: {:?}", &buf);
connection.send(buf.as_slice(), Reliability::Reliable).await;
}
if let Ok(buf) = connection.recv().await {
tracing::info!("FROM SERVER: {:?}", &buf);
s.send(buf.as_slice(), Reliability::Reliable).await;
}
}
}
}
Error:
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: ReadPacketBufferError', C:\Users\dolabaeb\.cargo\registry\src\github.com-1ecc6299db9ec823\rust-raknet-0.3.1\src\socket.rs:357:137
On line https://github.com/b23r0/rust-raknet/blob/main/src/socket.rs#L371
Cloning library directly from master
branch, building proxy.exe
with --release
on Windows 10 21H2 (19044.1645) and connecting to it through PC version Minecraft 1.18.12 and getting this error:
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: ReadPacketBufferError', C:\Users\dolabaeb\CLionProjects\rust-raknet\src\socket.rs:371:137
stack backtrace:
0: 0x7ff7082c2fff - std::backtrace_rs::backtrace::dbghelp::trace
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:98
1: 0x7ff7082c2fff - std::backtrace_rs::backtrace::trace_unsynchronized
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
2: 0x7ff7082c2fff - std::sys_common::backtrace::_print_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:67
3: 0x7ff7082c2fff - std::sys_common::backtrace::_print::impl$0::fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:46
4: 0x7ff7082d5c2a - core::fmt::write
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\fmt\mod.rs:1168
5: 0x7ff7082bccb8 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\io\mod.rs:1660
6: 0x7ff7082c5b5b - std::sys_common::backtrace::_print
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:49
7: 0x7ff7082c5b5b - std::sys_common::backtrace::print
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:36
8: 0x7ff7082c5b5b - std::panicking::default_hook::closure$1
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:211
9: 0x7ff7082c5654 - std::panicking::default_hook
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:228
10: 0x7ff7082c605c - std::panicking::rust_panic_with_hook
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:606
11: 0x7ff7082c5f1b - std::panicking::begin_panic_handler::closure$0
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:502
12: 0x7ff7082c3947 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure$0,never$>
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys_common\backtrace.rs:139
13: 0x7ff7082c5c19 - std::panicking::begin_panic_handler
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\panicking.rs:498
14: 0x7ff7082e0520 - core::panicking::panic_fmt
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\panicking.rs:116
15: 0x7ff7082e05c3 - core::result::unwrap_failed
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\core\src\result.rs:1690
16: 0x7ff70827bf58 - rust_raknet::socket::RaknetSocket::start_receiver::{{closure}}::hdf180a56c8e969e1
17: 0x7ff70826bd5a - std::panicking::try::hc206c013b6ddaf57
18: 0x7ff7082713c8 - tokio::runtime::task::harness::Harness<T,S>::complete::hdd4b53e814e17a2e
19: 0x7ff70826f180 - tokio::runtime::task::harness::Harness<T,S>::poll::h4b79a9f0313f8bda
20: 0x7ff7082899e7 - std::thread::local::LocalKey<T>::with::hee90645ce63d04a6
21: 0x7ff7082a7867 - tokio::runtime::thread_pool::worker::Context::run::hf532ea944e9ceb7b
22: 0x7ff7082a659f - tokio::runtime::thread_pool::worker::Context::run::hf532ea944e9ceb7b
23: 0x7ff70828f878 - tokio::macros::scoped_tls::ScopedKey<T>::set::h9c078d3da8ad3cf1
24: 0x7ff7082a5f6a - tokio::runtime::thread_pool::worker::run::h7190bbc6b2ab57df
25: 0x7ff70828a565 - tokio::runtime::task::core::CoreStage<T>::poll::h8158559ae3fc7af7
26: 0x7ff708286616 - std::panicking::try::h285da934742423c5
27: 0x7ff70829df00 - tokio::runtime::task::harness::Harness<T,S>::poll::he531c6aa5d8b0e33
28: 0x7ff708299d7c - tokio::runtime::blocking::pool::Inner::run::hc60e1a36e26a7d78
29: 0x7ff70829c7e5 - std::sys_common::backtrace::__rust_begin_short_backtrace::h471c0fb8d6991f35
30: 0x7ff708288ca3 - <tokio::io::driver::scheduled_io::Readiness as core::ops::drop::Drop>::drop::h9c7660bf59f3dba4
31: 0x7ff7082c9b5c - alloc::boxed::impl$44::call_once
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\alloc\src\boxed.rs:1854
32: 0x7ff7082c9b5c - alloc::boxed::impl$44::call_once
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\library\alloc\src\boxed.rs:1854
33: 0x7ff7082c9b5c - std::sys::windows::thread::impl$0::new::thread_start
at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a\/library\std\src\sys\windows\thread.rs:58
34: 0x7ffe55f57034 - BaseThreadInitThunk
35: 0x7ffe56522651 - RtlUserThreadStart
proxy.exe -l 0.0.0.0:19132 -r 146.59.254.235:19132
IP address is Europe HiveMC server
In order to be compatible with minecraft, the raknet protocol version has to be configurable. It changed in various minecraft versions (without changes to raknet level). In 1.19.30 the latest raknet version is 11.
If we update the motd after the raknet listener starts to listen it isn't send to the client
In files server.rs
, socket.rs
and error.rs
there are typos BindAdreesError that should be BindAddressError I guess
I've made normal client server application that uses rust-raknet, but once the first client is accepted by the RaknetListener, the listener stop accepting new connections.
So I made a test program that binds a RaknetListener and accepts clients in a loop and reads data from them and prints it. And i've added loop that connects clients to the listener. This test program also stop accepting new connections after few clients that got accepted. Code below:
let mut server = rust_raknet::RaknetListener::bind(&"0.0.0.0:1337".parse().unwrap()).await.unwrap();
server.listen().await;
log::info!("Listening on {}", server.local_addr().unwrap());
tokio::spawn(async move {
loop {
log::info!("Accepting...");
let client = server.accept().await.unwrap();
log::info!("Accepted: {}", client.peer_addr().unwrap());
tokio::spawn(async move {
loop {
let msg = client.recv().await;
log::info!("Received: {:?}", msg);
if msg.is_err() {
break; // Stop the task
}
}
});
}
});
tokio::time::sleep(std::time::Duration::from_secs(2)).await; // Wait some time for the server to start accepting connections
loop {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
tokio::spawn(async move {
log::info!("Connecting new client...");
let client = rust_raknet::RaknetSocket::connect(&"127.0.0.1:1337".parse().unwrap()).await.unwrap();
log::info!("Connected to {}", client.peer_addr().unwrap());
client.send(&[0xFE, 0x02, 0x03, 0x04], rust_raknet::Reliability::ReliableOrdered).await.unwrap();
let _ = client.close().await;
});
}
To use this socket within codecs in tokio utility crate, the socket must implement AsyncRead
and AsyncWrite
. Is this possible to implement?
My last commit was never published, so I have to use a git submodule.
RaknetError does not currently implement std::error::Error, which means I can't return it from my error source method or read a human-readable message from it.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.