-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to create server #18
Comments
Yes, kind of. Instead of the server.read() method I am now using the server.read_packet() method. Here is some code: https://gist.github.com/ImuustMINE/0df1f1292b66c4b75575435791937fbf But I am not sure if this approach is the most efficient one. |
The It is possible it was just getting an invalid packet, but most likely it's a bug in ozelot. One change I'd like to make (or have made :-) ) is to add an option for lazy deserialization. Right now ozelot will try to deserialize every packet, but for most uses we aren't interested in fully implementing the protocol so that's not necessary. Also it'd be nice to improve the error messages (and move off error-chain) so it'd be easier to narrow down where the bug is. |
Hello! I've been looking into this lately and have identified the source of the problem. When a new This is the workaround I'm using: use std::thread;
use std::time::Duration;
use ozelot::{
Server,
serverbound::ServerboundPacket,
ClientState
};
use std::net::TcpListener;
static IP: &str = "0.0.0.0";
static PORT: &str = "223";
fn main() {
// bind to external port to listen
let listener = TcpListener::bind(format!("{}:{}", IP, PORT)).unwrap();
// for every new connection...
for stream in listener.incoming() {
// TODO: these unwraps should be dealt with better
let mut server_instance = Server::from_tcpstream(stream.unwrap()).unwrap();
loop {
// read new data from the network, if any
server_instance.update_inbuf().unwrap();
// check if we have a full packet
let potential_packet = server_instance.read_packet().unwrap();
if let Some(packet) = potential_packet {
// evaluate the packet if we have one
match packet {
ServerboundPacket::Handshake(data) => {
if data.get_next_state() == &1 {
// **THIS IS THE MAGIC THAT PREVENTS THE NASTY CRASH**
server_instance.set_clientstate(ClientState::Status);
}
}
}
}
// wait a little bit before checking again
thread::sleep(Duration::from_millis(50));
}
}
} I think I see two solutions to this:
I'd be happy to submit a PR with fixes for either of the soulutions, but I'd like to hear what @C4K3 thinks would be best. All the best, |
Hey,
I'm new to rust and I thought it would be a nice challenge to create some basic Minecraft server in Rust. Just with an implementation of authentication and chatting. However it failed at receiving a simple Handshake packet: 😄
Error when refreshing server list or connecting to the server:
Maybe someone nice can help me out. 🙂
Best
ImuustMINE
The text was updated successfully, but these errors were encountered: