mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-11 07:11:30 +11:00
Check protocol version during login
This commit is contained in:
parent
7fac522a8e
commit
793a795732
|
@ -71,6 +71,7 @@ impl Config for Game {
|
|||
&self,
|
||||
_server: &SharedServer<Self>,
|
||||
_remote_addr: SocketAddr,
|
||||
_protocol_version: i32,
|
||||
) -> ServerListPing {
|
||||
ServerListPing::Respond {
|
||||
online_players: self.player_count.load(Ordering::SeqCst) as i32,
|
||||
|
|
|
@ -84,6 +84,7 @@ impl Config for Game {
|
|||
&self,
|
||||
_server: &SharedServer<Self>,
|
||||
_remote_addr: SocketAddr,
|
||||
_protocol_version: i32,
|
||||
) -> ServerListPing {
|
||||
ServerListPing::Respond {
|
||||
online_players: self.player_count.load(Ordering::SeqCst) as i32,
|
||||
|
|
|
@ -64,6 +64,7 @@ impl Config for Game {
|
|||
&self,
|
||||
_server: &SharedServer<Self>,
|
||||
_remote_addr: SocketAddr,
|
||||
_protocol_version: i32,
|
||||
) -> ServerListPing {
|
||||
ServerListPing::Respond {
|
||||
online_players: self.player_count.load(Ordering::SeqCst) as i32,
|
||||
|
|
|
@ -59,6 +59,7 @@ impl Config for Game {
|
|||
&self,
|
||||
_server: &SharedServer<Self>,
|
||||
_remote_addr: SocketAddr,
|
||||
_protocol_version: i32,
|
||||
) -> ServerListPing {
|
||||
ServerListPing::Respond {
|
||||
online_players: self.player_count.load(Ordering::SeqCst) as i32,
|
||||
|
|
|
@ -69,6 +69,7 @@ impl Config for Game {
|
|||
&self,
|
||||
_server: &SharedServer<Self>,
|
||||
_remote_addr: SocketAddr,
|
||||
_protocol_version: i32,
|
||||
) -> ServerListPing {
|
||||
ServerListPing::Respond {
|
||||
online_players: self.player_count.load(Ordering::SeqCst) as i32,
|
||||
|
|
|
@ -177,6 +177,7 @@ pub trait Config: 'static + Sized + Send + Sync + UnwindSafe + RefUnwindSafe {
|
|||
&self,
|
||||
shared: &SharedServer<Self>,
|
||||
remote_addr: SocketAddr,
|
||||
protocol_version: i32,
|
||||
) -> ServerListPing {
|
||||
ServerListPing::Ignore
|
||||
}
|
||||
|
|
|
@ -391,10 +391,16 @@ pub(crate) mod test {
|
|||
use super::*;
|
||||
|
||||
def_struct! {
|
||||
TestPacket 0xfff {
|
||||
TestPacket {
|
||||
first: String,
|
||||
second: Vec<u16>,
|
||||
third: u64
|
||||
}
|
||||
}
|
||||
|
||||
def_packet_group! {
|
||||
TestPacketGroup {
|
||||
TestPacket = 12345,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -547,11 +547,13 @@ async fn handle_connection<C: Config>(
|
|||
|
||||
// TODO: peek stream for 0xFE legacy ping
|
||||
|
||||
match c.dec.read_packet::<Handshake>().await?.next_state {
|
||||
HandshakeNextState::Status => handle_status(server, &mut c, remote_addr)
|
||||
let handshake = c.dec.read_packet::<Handshake>().await?;
|
||||
|
||||
match handshake.next_state {
|
||||
HandshakeNextState::Status => handle_status(server, &mut c, remote_addr, handshake)
|
||||
.await
|
||||
.context("error during status"),
|
||||
HandshakeNextState::Login => match handle_login(&server, &mut c, remote_addr)
|
||||
HandshakeNextState::Login => match handle_login(&server, &mut c, remote_addr, handshake)
|
||||
.await
|
||||
.context("error during login")?
|
||||
{
|
||||
|
@ -567,10 +569,16 @@ async fn handle_status<C: Config>(
|
|||
server: SharedServer<C>,
|
||||
c: &mut Codec,
|
||||
remote_addr: SocketAddr,
|
||||
handshake: Handshake,
|
||||
) -> anyhow::Result<()> {
|
||||
c.dec.read_packet::<QueryRequest>().await?;
|
||||
|
||||
match server.0.cfg.server_list_ping(&server, remote_addr).await {
|
||||
match server
|
||||
.0
|
||||
.cfg
|
||||
.server_list_ping(&server, remote_addr, handshake.protocol_version.0)
|
||||
.await
|
||||
{
|
||||
ServerListPing::Respond {
|
||||
online_players,
|
||||
max_players,
|
||||
|
@ -619,7 +627,13 @@ async fn handle_login<C: Config>(
|
|||
server: &SharedServer<C>,
|
||||
c: &mut Codec,
|
||||
remote_addr: SocketAddr,
|
||||
handshake: Handshake,
|
||||
) -> anyhow::Result<Option<NewClientData>> {
|
||||
if handshake.protocol_version.0 != PROTOCOL_VERSION {
|
||||
// TODO: send translated disconnect msg?
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let LoginStart {
|
||||
username: BoundedString(username),
|
||||
sig_data: _, // TODO
|
||||
|
|
Loading…
Reference in a new issue