Skip to content

Commit

Permalink
Resolve some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
timvisee committed Nov 11, 2021
1 parent 51ab0c6 commit 8c5f483
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
1 change: 0 additions & 1 deletion src/action/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub fn invoke(matches: &ArgMatches) -> Result<(), ()> {
rewrite_server_properties(&config);

// Start server service
// TODO: start tokio runtime here?
let config = Arc::new(config);
service::server::service(config)
}
Expand Down
13 changes: 7 additions & 6 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ pub const STATUS_PACKET_ID_PING: i32 = 1;
pub const LOGIN_PACKET_ID_LOGIN_START: i32 = 0;

/// 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)]
pub struct Client {
/// Current client state.
Expand All @@ -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)]
pub enum ClientState {
/// Initial client state.
Expand All @@ -60,9 +66,6 @@ pub enum ClientState {

/// State to login to server.
Login,

/// State for playing.
Play,
}

impl ClientState {
Expand All @@ -72,7 +75,6 @@ impl ClientState {
0 => Some(Self::Handshake),
1 => Some(Self::Status),
2 => Some(Self::Login),
3 => Some(Self::Play),
_ => None,
}
}
Expand All @@ -83,7 +85,6 @@ impl ClientState {
Self::Handshake => 0,
Self::Status => 1,
Self::Login => 2,
Self::Play => 3,
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/service/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub async fn service(config: Arc<Config>) -> Result<(), ()> {
let server = Arc::new(Server::default());

// Listen for new connections
// TODO: do not drop error here
let listener = TcpListener::bind(config.public.address)
.await
.map_err(|err| {
Expand Down
16 changes: 11 additions & 5 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,17 @@ pub async fn serve(
if client_state == ClientState::Handshake && packet.id == proto::STATUS_PACKET_ID_STATUS {
// Parse handshake, grab new state
let new_state = match Handshake::decode(&mut packet.data.as_slice()) {
Ok(handshake) => {
// TODO: do not panic here
ClientState::from_id(handshake.next_state).expect("unknown next client state")
Ok(handshake) => match ClientState::from_id(handshake.next_state) {
Some(state) => 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
Expand Down Expand Up @@ -159,7 +165,7 @@ pub async fn hold<'a>(
let timeout = config.time.hold_client_for as u64;

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;

trace!("Polling server state for holding client...");
Expand Down

0 comments on commit 8c5f483

Please sign in to comment.