-
-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
180 additions
and
8 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use pumpkin_macros::packet; | ||
use serde::Serialize; | ||
|
||
use crate::VarInt; | ||
|
||
#[derive(Serialize)] | ||
#[packet(0x04)] | ||
pub struct CLoginPluginRequest<'a> { | ||
message_id: VarInt, | ||
channel: &'a str, | ||
data: &'a [u8], | ||
} | ||
|
||
impl<'a> CLoginPluginRequest<'a> { | ||
pub fn new(message_id: VarInt, channel: &'a str, data: &'a [u8]) -> Self { | ||
Self { | ||
message_id, | ||
channel, | ||
data, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
mod c_encryption_request; | ||
mod c_login_disconnect; | ||
mod c_login_success; | ||
mod c_plugin_request; | ||
mod c_set_compression; | ||
|
||
pub use c_encryption_request::*; | ||
pub use c_login_disconnect::*; | ||
pub use c_login_success::*; | ||
pub use c_plugin_request::*; | ||
pub use c_set_compression::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Deserialize, Serialize, Default)] | ||
pub struct ProxyConfig { | ||
pub enabled: bool, | ||
pub velocity: VelocityConfig, | ||
} | ||
|
||
#[derive(Deserialize, Serialize)] | ||
pub struct VelocityConfig { | ||
pub enabled: bool, | ||
pub secret: String, | ||
} | ||
|
||
impl Default for VelocityConfig { | ||
fn default() -> Self { | ||
Self { | ||
enabled: false, | ||
secret: "".into(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod velocity; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use std::net::SocketAddr; | ||
|
||
use bytes::{BufMut, BytesMut}; | ||
use hmac::{Hmac, Mac}; | ||
use pumpkin_protocol::{ | ||
bytebuf::ByteBuffer, client::login::CLoginPluginRequest, server::login::SLoginPluginResponse, | ||
}; | ||
use sha2::Sha256; | ||
|
||
use crate::{client::Client, config::proxy::VelocityConfig}; | ||
|
||
type HmacSha256 = Hmac<Sha256>; | ||
|
||
const MAX_SUPPORTED_FORWARDING_VERSION: i32 = 4; | ||
const PLAYER_INFO_CHANNEL: &str = "velocity:player_info"; | ||
|
||
pub fn velocity_login(client: &mut Client) { | ||
let velocity_message_id: i32 = 0; | ||
|
||
let mut buf = BytesMut::new(); | ||
buf.put_u8(MAX_SUPPORTED_FORWARDING_VERSION as u8); | ||
client.send_packet(&CLoginPluginRequest::new( | ||
velocity_message_id.into(), | ||
PLAYER_INFO_CHANNEL, | ||
&buf, | ||
)); | ||
} | ||
|
||
pub fn check_integrity(data: (&[u8], &[u8]), secret: String) -> bool { | ||
let (signature, data_without_signature) = data; | ||
let mut mac = | ||
HmacSha256::new_from_slice(secret.as_bytes()).expect("HMAC can take key of any size"); | ||
mac.update(data_without_signature); | ||
mac.verify_slice(signature).is_ok() | ||
} | ||
|
||
pub fn receive_plugin_response( | ||
client: &mut Client, | ||
config: VelocityConfig, | ||
response: SLoginPluginResponse, | ||
) { | ||
dbg!("velocity response"); | ||
if let Some(data) = response.data { | ||
let (signature, data_without_signature) = data.split_at(32); | ||
|
||
if !check_integrity((signature, data_without_signature), config.secret) { | ||
client.kick("Unable to verify player details"); | ||
return; | ||
} | ||
let mut buf = ByteBuffer::new(BytesMut::new()); | ||
buf.put_slice(data_without_signature); | ||
|
||
// check velocity version | ||
let version = buf.get_var_int(); | ||
let version = version.0; | ||
if version > MAX_SUPPORTED_FORWARDING_VERSION { | ||
client.kick(&format!( | ||
"Unsupported forwarding version {version}, Max: {MAX_SUPPORTED_FORWARDING_VERSION}" | ||
)); | ||
return; | ||
} | ||
// TODO: no unwrap | ||
let addr: SocketAddr = buf.get_string().unwrap().parse().unwrap(); | ||
client.address = addr; | ||
todo!() | ||
} else { | ||
client.kick("This server requires you to connect with Velocity.") | ||
} | ||
} |