Resolve some TODOs
This commit is contained in:
@@ -25,7 +25,6 @@ pub fn invoke(matches: &ArgMatches) -> Result<(), ()> {
|
|||||||
rewrite_server_properties(&config);
|
rewrite_server_properties(&config);
|
||||||
|
|
||||||
// Start server service
|
// Start server service
|
||||||
// TODO: start tokio runtime here?
|
|
||||||
let config = Arc::new(config);
|
let config = Arc::new(config);
|
||||||
service::server::service(config)
|
service::server::service(config)
|
||||||
}
|
}
|
||||||
|
13
src/proto.rs
13
src/proto.rs
@@ -31,7 +31,9 @@ pub const STATUS_PACKET_ID_PING: i32 = 1;
|
|||||||
pub const LOGIN_PACKET_ID_LOGIN_START: i32 = 0;
|
pub const LOGIN_PACKET_ID_LOGIN_START: i32 = 0;
|
||||||
|
|
||||||
/// Client state.
|
/// Client state.
|
||||||
// TODO: add encryption/compression state?
|
///
|
||||||
|
/// Note: this does not keep track of compression/encryption states because packets are never
|
||||||
|
/// inspected when these modes are enabled.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Client {
|
pub struct Client {
|
||||||
/// Current client state.
|
/// Current client state.
|
||||||
@@ -50,6 +52,10 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Protocol state a client may be in.
|
||||||
|
///
|
||||||
|
/// Note: this does not include the `play` state, because this is never used anymore when a client
|
||||||
|
/// reaches this state.
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||||
pub enum ClientState {
|
pub enum ClientState {
|
||||||
/// Initial client state.
|
/// Initial client state.
|
||||||
@@ -60,9 +66,6 @@ pub enum ClientState {
|
|||||||
|
|
||||||
/// State to login to server.
|
/// State to login to server.
|
||||||
Login,
|
Login,
|
||||||
|
|
||||||
/// State for playing.
|
|
||||||
Play,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClientState {
|
impl ClientState {
|
||||||
@@ -72,7 +75,6 @@ impl ClientState {
|
|||||||
0 => Some(Self::Handshake),
|
0 => Some(Self::Handshake),
|
||||||
1 => Some(Self::Status),
|
1 => Some(Self::Status),
|
||||||
2 => Some(Self::Login),
|
2 => Some(Self::Login),
|
||||||
3 => Some(Self::Play),
|
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +85,6 @@ impl ClientState {
|
|||||||
Self::Handshake => 0,
|
Self::Handshake => 0,
|
||||||
Self::Status => 1,
|
Self::Status => 1,
|
||||||
Self::Login => 2,
|
Self::Login => 2,
|
||||||
Self::Play => 3,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,6 @@ pub async fn service(config: Arc<Config>) -> Result<(), ()> {
|
|||||||
let server = Arc::new(Server::default());
|
let server = Arc::new(Server::default());
|
||||||
|
|
||||||
// Listen for new connections
|
// Listen for new connections
|
||||||
// TODO: do not drop error here
|
|
||||||
let listener = TcpListener::bind(config.public.address)
|
let listener = TcpListener::bind(config.public.address)
|
||||||
.await
|
.await
|
||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
|
@@ -55,11 +55,17 @@ pub async fn serve(
|
|||||||
if client_state == ClientState::Handshake && packet.id == proto::STATUS_PACKET_ID_STATUS {
|
if client_state == ClientState::Handshake && packet.id == proto::STATUS_PACKET_ID_STATUS {
|
||||||
// Parse handshake, grab new state
|
// Parse handshake, grab new state
|
||||||
let new_state = match Handshake::decode(&mut packet.data.as_slice()) {
|
let new_state = match Handshake::decode(&mut packet.data.as_slice()) {
|
||||||
Ok(handshake) => {
|
Ok(handshake) => match ClientState::from_id(handshake.next_state) {
|
||||||
// TODO: do not panic here
|
Some(state) => state,
|
||||||
ClientState::from_id(handshake.next_state).expect("unknown next client state")
|
None => {
|
||||||
|
error!(target: "lazymc", "Client tried to switch into unknown protcol state ({}), disconnecting", handshake.next_state);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(_) => {
|
||||||
|
debug!(target: "lazymc", "Got malformed handshake from client, disconnecting");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
Err(_) => break,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update client state
|
// Update client state
|
||||||
@@ -159,7 +165,7 @@ pub async fn hold<'a>(
|
|||||||
let timeout = config.time.hold_client_for as u64;
|
let timeout = config.time.hold_client_for as u64;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// TODO: do not poll, wait for started signal instead (with timeout)
|
// TODO: wait for start signal over channel instead of polling
|
||||||
poll_interval.tick().await;
|
poll_interval.tick().await;
|
||||||
|
|
||||||
trace!("Polling server state for holding client...");
|
trace!("Polling server state for holding client...");
|
||||||
|
Reference in New Issue
Block a user