Compare commits
No commits in common. "a49079e270957737d3408d84e3c9f86aebc932bc" and "f46577c355c27bd252642674ec321192dd0d1124" have entirely different histories.
a49079e270
...
f46577c355
16 changed files with 770 additions and 975 deletions
24
Cargo.lock
generated
24
Cargo.lock
generated
|
@ -257,26 +257,17 @@ dependencies = [
|
|||
"async-trait",
|
||||
"async-tungstenite",
|
||||
"clap",
|
||||
"e4mc-common",
|
||||
"env_logger",
|
||||
"futures",
|
||||
"futures-util",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "e4mc-common"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"async-tungstenite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "e4mc-server"
|
||||
version = "0.1.0"
|
||||
|
@ -284,12 +275,12 @@ dependencies = [
|
|||
"anyhow",
|
||||
"async-trait",
|
||||
"async-tungstenite",
|
||||
"e4mc-common",
|
||||
"env_logger",
|
||||
"futures",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"rand",
|
||||
"nanoid",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
|
@ -591,6 +582,15 @@ dependencies = [
|
|||
"windows-sys 0.45.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nanoid"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ffa00dec017b5b1a8b7cf5e2c008bfda1aa7e0697ac1508b491fdf2622fb4d8"
|
||||
dependencies = [
|
||||
"rand",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.15.0"
|
||||
|
|
|
@ -3,5 +3,4 @@
|
|||
members = [
|
||||
"server",
|
||||
"client",
|
||||
"common"
|
||||
]
|
||||
|
|
|
@ -17,7 +17,7 @@ futures = "0.3.28"
|
|||
futures-util = { version = "0.3.28", features = ["io"] }
|
||||
lazy_static = "1.4.0"
|
||||
log = "0.4.17"
|
||||
serde = { version = "1.0.159", features = ["derive"] }
|
||||
serde_json = "1.0.95"
|
||||
thiserror = "1.0.40"
|
||||
tokio = { version = "1.27.0", features = ["rt-multi-thread", "sync", "macros", "net", "io-util"] }
|
||||
e4mc-common = { path = "../common"}
|
|
@ -1,26 +1,166 @@
|
|||
use std::collections::HashMap;
|
||||
use std::{collections::HashMap, net::SocketAddr};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use async_tungstenite::tokio::connect_async;
|
||||
use async_tungstenite::tungstenite::Message;
|
||||
use async_tungstenite::{tokio::connect_async, WebSocketStream};
|
||||
use clap::Parser;
|
||||
use e4mc_common::ClientboundControlMessage;
|
||||
use futures::stream::{SplitSink, SplitStream};
|
||||
use futures::{AsyncRead, AsyncWrite};
|
||||
use futures_util::{SinkExt, StreamExt};
|
||||
use lazy_static::lazy_static;
|
||||
use log::{error, info, trace, warn};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::TcpStream;
|
||||
use tokio::net::tcp::{WriteHalf, ReadHalf};
|
||||
use log::{error, info, trace};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tokio::{
|
||||
io::{AsyncReadExt, AsyncWriteExt},
|
||||
net::{
|
||||
tcp::{OwnedReadHalf, OwnedWriteHalf},
|
||||
TcpStream,
|
||||
},
|
||||
sync::mpsc::{UnboundedReceiver, UnboundedSender},
|
||||
sync::RwLock,
|
||||
task,
|
||||
};
|
||||
|
||||
enum ChannelHandlerMessage {
|
||||
Data(Vec<u8>),
|
||||
Shutdown,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref CHANNEL_MAP: RwLock<HashMap<u8, UnboundedSender<ChannelTaskMessage>>> =
|
||||
static ref CHANNEL_MAP: RwLock<HashMap<u8, UnboundedSender<ChannelHandlerMessage>>> =
|
||||
RwLock::new(HashMap::new());
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let _ = env_logger::try_init();
|
||||
let args = Args::parse();
|
||||
let server = args.server.unwrap_or("wss://e4mc.skyevg.systems".to_string());
|
||||
let (ws_conn, _) = connect_async(server).await?;
|
||||
let (mut send, mut recv) = ws_conn.split();
|
||||
let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel();
|
||||
let sender = &*Box::leak(Box::new(sender)); // the task::spawn below requires 'static and this is main
|
||||
tokio::try_join!(
|
||||
async move {
|
||||
while let Some(Ok(message)) = recv.next().await {
|
||||
match message {
|
||||
Message::Text(message) => {
|
||||
info!("{}", message);
|
||||
let message: ClientboundControlMessage = serde_json::from_str(&message)?;
|
||||
match message {
|
||||
ClientboundControlMessage::DomainAssigned(domain) => {
|
||||
println!("Domain assigned: {}", domain);
|
||||
}
|
||||
ClientboundControlMessage::ChannelOpen(id, _) => {
|
||||
match TcpStream::connect(("127.0.0.1", args.port)).await {
|
||||
Ok(conn) => {
|
||||
let (send, recv) = tokio::sync::mpsc::unbounded_channel();
|
||||
CHANNEL_MAP.write().await.insert(id, send);
|
||||
task::spawn(async move {
|
||||
if let Err(e) =
|
||||
handle_channel(id, sender.clone(), conn, recv).await
|
||||
{
|
||||
error!("Error handling channel: {}", e);
|
||||
}
|
||||
CHANNEL_MAP.write().await.remove(&id);
|
||||
info!("Sending close request for channel: {}", id);
|
||||
sender
|
||||
.send(Message::Text(
|
||||
serde_json::to_string(
|
||||
&ServerboundControlMessage::ChannelClosed(
|
||||
id,
|
||||
),
|
||||
)
|
||||
.unwrap(),
|
||||
))
|
||||
.unwrap();
|
||||
});
|
||||
}
|
||||
Err(e) => {
|
||||
error!("Error creating channel: {}", e);
|
||||
sender
|
||||
.send(Message::Text(
|
||||
serde_json::to_string(
|
||||
&ServerboundControlMessage::ChannelClosed(
|
||||
id,
|
||||
),
|
||||
)
|
||||
.unwrap(),
|
||||
))
|
||||
.unwrap();
|
||||
}
|
||||
};
|
||||
}
|
||||
ClientboundControlMessage::ChannelClosed(id) => {
|
||||
let mut channel_map = CHANNEL_MAP.write().await;
|
||||
if let Some(send) = channel_map.remove(&id) {
|
||||
if let Err(e) = send.send(ChannelHandlerMessage::Shutdown) {
|
||||
error!("Error closing channel: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::Binary(buf) => {
|
||||
trace!("recv: {:?}", buf);
|
||||
if let Some(send) = CHANNEL_MAP.write().await.get_mut(&buf[0]) {
|
||||
if let Err(e) = send.send(ChannelHandlerMessage::Data(buf[1..].to_vec())) {
|
||||
error!("Error transferring data: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(()) as anyhow::Result<()>
|
||||
},
|
||||
async move {
|
||||
while let Some(message) = receiver.recv().await {
|
||||
send.send(message.clone()).await?;
|
||||
}
|
||||
Ok(()) as anyhow::Result<()>
|
||||
}
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_channel(
|
||||
id: u8,
|
||||
sender: UnboundedSender<Message>,
|
||||
mut conn: TcpStream,
|
||||
mut recv: UnboundedReceiver<ChannelHandlerMessage>,
|
||||
) -> anyhow::Result<()> {
|
||||
let (mut read, mut write) = conn.split();
|
||||
tokio::select!(_ = async move {
|
||||
let mut buf = [0u8; 1024];
|
||||
loop {
|
||||
let ready = read.ready(tokio::io::Interest::READABLE).await?;
|
||||
if ready.is_read_closed() {
|
||||
return Ok(())
|
||||
}
|
||||
let len = read.read(&mut buf).await?;
|
||||
if len == 0 {
|
||||
continue;
|
||||
}
|
||||
let mut packet = Vec::from(&buf[..len]);
|
||||
packet.insert(0, id);
|
||||
trace!("send: {:?}", packet);
|
||||
sender.send(Message::Binary(packet))?;
|
||||
}
|
||||
Ok(()) as anyhow::Result<()>
|
||||
} => {},
|
||||
_ = async move {
|
||||
while let Some(message) = recv.recv().await {
|
||||
match message {
|
||||
ChannelHandlerMessage::Data(buf) => write.write_all(&buf).await?,
|
||||
ChannelHandlerMessage::Shutdown => return Ok(()),
|
||||
}
|
||||
}
|
||||
Ok(()) as anyhow::Result<()>
|
||||
} => {});
|
||||
conn.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
/// Simple program to greet a person
|
||||
#[derive(Parser, Debug)]
|
||||
struct Args {
|
||||
|
@ -33,130 +173,14 @@ struct Args {
|
|||
server: Option<String>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
let _ = env_logger::try_init();
|
||||
let args = Args::parse();
|
||||
let server = args
|
||||
.server
|
||||
.unwrap_or("wss://e4mc.skyevg.systems".to_string());
|
||||
let (ws_conn, _) = connect_async(server).await?;
|
||||
let (send, recv) = ws_conn.split();
|
||||
let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
|
||||
tokio::select! {
|
||||
res = handle_send(send, receiver) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error in send loop: {}", e);
|
||||
}
|
||||
},
|
||||
res = handle_recv(recv, sender, args.port) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error in recv loop: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
#[derive(Deserialize)]
|
||||
enum ClientboundControlMessage {
|
||||
DomainAssigned(String),
|
||||
ChannelOpen(u8, SocketAddr),
|
||||
ChannelClosed(u8),
|
||||
}
|
||||
|
||||
async fn handle_send<T: AsyncRead + AsyncWrite + Unpin>(
|
||||
mut send: SplitSink<WebSocketStream<T>, Message>,
|
||||
mut receiver: UnboundedReceiver<Message>,
|
||||
) -> anyhow::Result<()> {
|
||||
while let Some(message) = receiver.recv().await {
|
||||
send.send(message).await?;
|
||||
}
|
||||
Ok(())
|
||||
#[derive(Serialize)]
|
||||
enum ServerboundControlMessage {
|
||||
ChannelClosed(u8),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
enum ChannelTaskMessage {
|
||||
Close,
|
||||
Data(Vec<u8>),
|
||||
}
|
||||
|
||||
async fn handle_recv<T: AsyncRead + AsyncWrite + Unpin>(
|
||||
mut recv: SplitStream<WebSocketStream<T>>,
|
||||
sender: UnboundedSender<Message>,
|
||||
port: u16,
|
||||
) -> anyhow::Result<()> {
|
||||
while let Some(message) = recv.next().await {
|
||||
let message = message?;
|
||||
match message {
|
||||
Message::Text(message) => {
|
||||
info!("{}", message);
|
||||
let message: ClientboundControlMessage = serde_json::from_str(&message)?;
|
||||
match message {
|
||||
ClientboundControlMessage::DomainAssigned(domain) => {
|
||||
println!("Domain assigned: {}", domain);
|
||||
}
|
||||
ClientboundControlMessage::ChannelOpen(channel, _) => {
|
||||
let conn = TcpStream::connect(("127.0.0.1", port)).await?;
|
||||
let (send, recv) = tokio::sync::mpsc::unbounded_channel();
|
||||
CHANNEL_MAP.write().await.insert(channel, send);
|
||||
tokio::spawn(handle_channel(conn, sender.clone(), channel, recv));
|
||||
}
|
||||
ClientboundControlMessage::ChannelClosed(channel) => {
|
||||
if let Some(sender) = CHANNEL_MAP.write().await.remove(&channel) {
|
||||
sender.send(ChannelTaskMessage::Close)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::Binary(buf) => {
|
||||
let channel = buf[0];
|
||||
if let Some(sender) = CHANNEL_MAP.read().await.get(&channel) {
|
||||
sender.send(ChannelTaskMessage::Data(buf[1..].to_vec()))?;
|
||||
} else {
|
||||
warn!("Message sent to unknown Channel");
|
||||
}
|
||||
},
|
||||
_ => continue,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_channel(mut stream: TcpStream, sender: UnboundedSender<Message>, channel: u8, recv: UnboundedReceiver<ChannelTaskMessage>) {
|
||||
let (read, write) = stream.split();
|
||||
tokio::select! {
|
||||
res = handle_channel_send(write, recv) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error in send loop: {}", e);
|
||||
}
|
||||
},
|
||||
res = handle_channel_recv(read, sender, channel) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error in recv loop: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
CHANNEL_MAP.write().await.remove(&channel);
|
||||
}
|
||||
|
||||
async fn handle_channel_send(mut write: WriteHalf<'_>, mut recv: UnboundedReceiver<ChannelTaskMessage>) -> anyhow::Result<()> {
|
||||
while let Some(message) = recv.recv().await {
|
||||
match message {
|
||||
ChannelTaskMessage::Close => return Ok(()),
|
||||
ChannelTaskMessage::Data(buf) => write.write_all(&buf).await?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_channel_recv(mut read: ReadHalf<'_>, sender: UnboundedSender<Message>, channel: u8) -> anyhow::Result<()> {
|
||||
let mut buf = [0u8; 1024];
|
||||
loop {
|
||||
let ready = read.ready(tokio::io::Interest::READABLE).await?;
|
||||
if ready.is_read_closed() {
|
||||
return Ok(());
|
||||
}
|
||||
let len = read.read(&mut buf).await?;
|
||||
if len == 0 {
|
||||
continue;
|
||||
}
|
||||
let mut packet = Vec::from(&buf[..len]);
|
||||
packet.insert(0, channel);
|
||||
trace!("send: {:?}", packet);
|
||||
sender.send(Message::Binary(packet))?;
|
||||
}
|
||||
}
|
233
client/src/netty.rs
Normal file
233
client/src/netty.rs
Normal file
|
@ -0,0 +1,233 @@
|
|||
use async_std::io::{ReadExt, WriteExt};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::{info, error};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
pub enum NettyReadError {
|
||||
#[error("{0}")]
|
||||
IoError(std::io::Error),
|
||||
#[error("Was not a netty packet, but a Legacy ServerListPing")]
|
||||
LegacyServerListPing,
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for NettyReadError {
|
||||
fn from(value: std::io::Error) -> Self {
|
||||
Self::IoError(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<std::io::ErrorKind> for NettyReadError {
|
||||
fn from(value: std::io::ErrorKind) -> Self {
|
||||
Self::IoError(value.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait ReadExtNetty: ReadExt + Unpin {
|
||||
async fn read_bool(&mut self) -> Result<bool, NettyReadError> {
|
||||
let mut buf = [0u8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
match buf[0] {
|
||||
0 => Ok(false),
|
||||
1 => Ok(true),
|
||||
_ => Err(std::io::ErrorKind::InvalidData.into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_byte(&mut self) -> Result<i8, NettyReadError> {
|
||||
let mut buf = [0u8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i8::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_unsigned_byte(&mut self) -> Result<u8, NettyReadError> {
|
||||
let mut buf = [0u8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(buf[0])
|
||||
}
|
||||
|
||||
async fn read_short(&mut self) -> Result<i16, NettyReadError> {
|
||||
let mut buf = [0u8; 2];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i16::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_unsigned_short(&mut self) -> Result<u16, NettyReadError> {
|
||||
let mut buf = [0u8; 2];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(u16::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_int(&mut self) -> Result<i32, NettyReadError> {
|
||||
let mut buf = [0u8; 4];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i32::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_long(&mut self) -> Result<i64, NettyReadError> {
|
||||
let mut buf = [0u8; 8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i64::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_float(&mut self) -> Result<f32, NettyReadError> {
|
||||
let mut buf = [0u8; 4];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(f32::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_double(&mut self) -> Result<f64, NettyReadError> {
|
||||
let mut buf = [0u8; 8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(f64::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_string(&mut self) -> Result<String, NettyReadError> {
|
||||
let len = self.read_varint().await?;
|
||||
let mut buf = vec![0u8; len as usize];
|
||||
self.read_exact(&mut buf).await?;
|
||||
String::from_utf8(buf).map_err(|_| std::io::ErrorKind::InvalidData.into())
|
||||
}
|
||||
|
||||
async fn read_varint(&mut self) -> Result<i32, NettyReadError> {
|
||||
let mut res = 0i32;
|
||||
for i in 0..5 {
|
||||
let part = self.read_unsigned_byte().await?;
|
||||
res |= (part as i32 & 0x7F) << (7 * i);
|
||||
if part & 0x80 == 0 {
|
||||
return Ok(res);
|
||||
}
|
||||
}
|
||||
error!("Varint is invalid");
|
||||
Err(std::io::ErrorKind::InvalidData.into())
|
||||
}
|
||||
|
||||
// async fn read_varint(&mut self) -> Result<i32, NettyReadError> {
|
||||
// let mut value = 0i32;
|
||||
// let mut buf = [0u8; 1];
|
||||
// let mut pos = 0u8;
|
||||
// loop {
|
||||
// self.read_exact(&mut buf).await?;
|
||||
// println!("{}", buf[0]);
|
||||
// value |= ((buf[0] & 0b01111111) << pos) as i32;
|
||||
// if (buf[0] & 0b10000000) == 0 {
|
||||
// break;
|
||||
// };
|
||||
// pos += 7;
|
||||
// if pos >= 32 {
|
||||
// return Err(std::io::ErrorKind::InvalidData.into());
|
||||
// };
|
||||
// }
|
||||
// Ok(value)
|
||||
// }
|
||||
|
||||
async fn read_varlong(&mut self) -> Result<i64, NettyReadError> {
|
||||
let mut value = 0i64;
|
||||
let mut buf = [0u8; 1];
|
||||
let mut position = 0u8;
|
||||
loop {
|
||||
self.read_exact(&mut buf).await?;
|
||||
value |= ((buf[0] & 0b01111111) << position) as i64;
|
||||
if (buf[0] & 0b10000000) == 0 {
|
||||
break;
|
||||
};
|
||||
position += 7;
|
||||
if position >= 64 {
|
||||
return Err(std::io::ErrorKind::InvalidData.into());
|
||||
};
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
async fn read_vec3(&mut self) -> Result<(i32, i16, i32), NettyReadError> {
|
||||
let mut buf = [0u8; 8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
let packed = u64::from_be_bytes(buf);
|
||||
let x: i32 = ((packed & 0xffffffc000000000) >> 38) as _;
|
||||
let y: i16 = (packed & 0xfff) as _;
|
||||
let z: i32 = ((packed & 0x3ffffff000) >> 12) as _;
|
||||
Ok((
|
||||
match x {
|
||||
i32::MIN..=0x1ffffff => x,
|
||||
0x2000000.. => x - 0x2000000,
|
||||
},
|
||||
match y {
|
||||
i16::MIN..=0x7ff => y,
|
||||
0x800.. => y - 0x800,
|
||||
},
|
||||
match z {
|
||||
i32::MIN..=0x1ffffff => z,
|
||||
0x2000000.. => z - 0x2000000,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
async fn read_uuid(&mut self) -> Result<u128, NettyReadError> {
|
||||
let mut buf = [0u8; 16];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(u128::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_packet(&mut self) -> Result<Vec<u8>, NettyReadError> {
|
||||
let len = self.read_varint().await?;
|
||||
let mut buf = vec![0u8; len as usize];
|
||||
if len == 254 {
|
||||
let mut temp = [0u8];
|
||||
self.read_exact(&mut temp).await?;
|
||||
if temp[0] == 0xFA {
|
||||
// FE 01 FA: Legacy ServerListPing
|
||||
return Err(NettyReadError::LegacyServerListPing);
|
||||
}
|
||||
buf[0] = temp[0];
|
||||
self.read_exact(&mut buf[1..]).await?;
|
||||
} else {
|
||||
self.read_exact(&mut buf).await?;
|
||||
}
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
// fn read_packet_compressed(&mut self) -> Result<Vec<u8>, NettyReadError> {
|
||||
// let len = self.read_varint()?;
|
||||
// let len_decompressed = self.read_varint()?;
|
||||
// let mut buf = vec![0u8; len as usize];
|
||||
// self.read_exact(&mut buf)?;
|
||||
// if len_decompressed == 0 {
|
||||
// return Ok(buf);
|
||||
// }
|
||||
// let mut buf_decompressed = vec![0u8; len_decompressed as usize];
|
||||
// if flate2::Decompress::new(true)
|
||||
// .decompress(&buf, &mut buf_decompressed, flate2::FlushDecompress::Finish)
|
||||
// .is_err()
|
||||
// {
|
||||
// return Err(std::io::ErrorKind::InvalidData.into());
|
||||
// };
|
||||
// Ok(buf_decompressed)
|
||||
// }
|
||||
}
|
||||
|
||||
impl<T: ReadExt + Unpin> ReadExtNetty for T {}
|
||||
|
||||
#[async_trait]
|
||||
pub trait WriteExtNetty: WriteExt + Unpin {
|
||||
async fn write_varint(&mut self, mut val: i32) -> std::io::Result<()> {
|
||||
for _ in 0..5 {
|
||||
if val & !0x7F == 0 {
|
||||
self.write_all(&[val as u8]).await?;
|
||||
return Ok(());
|
||||
}
|
||||
self.write_all(&[(val & 0x7F | 0x80) as u8]).await?;
|
||||
val >>= 7;
|
||||
}
|
||||
Err(std::io::ErrorKind::InvalidData.into())
|
||||
}
|
||||
|
||||
async fn write_string(&mut self, s: &str) -> std::io::Result<()> {
|
||||
self.write_varint(s.len() as i32).await?;
|
||||
self.write_all(s.as_bytes()).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: WriteExt + Unpin> WriteExtNetty for T {}
|
|
@ -1,11 +0,0 @@
|
|||
[package]
|
||||
name = "e4mc-common"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.159", features = ["derive"] }
|
||||
serde_json = "1.0.95"
|
||||
async-tungstenite = "0.20.0"
|
|
@ -1,27 +0,0 @@
|
|||
use std::net::SocketAddr;
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ClientboundControlMessage {
|
||||
DomainAssigned(String),
|
||||
ChannelOpen(u8, SocketAddr),
|
||||
ChannelClosed(u8),
|
||||
}
|
||||
|
||||
impl From<ClientboundControlMessage> for async_tungstenite::tungstenite::Message {
|
||||
fn from(val: ClientboundControlMessage) -> Self {
|
||||
async_tungstenite::tungstenite::Message::Text(serde_json::to_string(&val).unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ServerboundControlMessage {
|
||||
ChannelClosed(u8),
|
||||
}
|
||||
|
||||
impl From<ServerboundControlMessage> for async_tungstenite::tungstenite::Message {
|
||||
fn from(val: ServerboundControlMessage) -> Self {
|
||||
async_tungstenite::tungstenite::Message::Text(serde_json::to_string(&val).unwrap())
|
||||
}
|
||||
}
|
2
node/.gitignore
vendored
2
node/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
*.js
|
||||
node_modules/
|
115
node/client.ts
115
node/client.ts
|
@ -1,115 +0,0 @@
|
|||
import WebSocket from 'ws';
|
||||
import net from 'net';
|
||||
|
||||
const DEFAULT_REMOTE_SERVER = 'wss://e4mc.skyevg.systems';
|
||||
const DEFAULT_TCP_ADDRESS = 'localhost';
|
||||
const DEFAULT_TCP_PORT = 25565;
|
||||
|
||||
interface DomainAssignedMessage {
|
||||
DomainAssigned: string;
|
||||
}
|
||||
|
||||
interface ChannelOpenMessage {
|
||||
ChannelOpen: [number, string];
|
||||
}
|
||||
|
||||
interface ChannelClosedMessage {
|
||||
ChannelClosed: number;
|
||||
}
|
||||
|
||||
type ServerMessage = DomainAssignedMessage | ChannelOpenMessage | ChannelClosedMessage;
|
||||
|
||||
class e4mcClient {
|
||||
private tcpAddress: string;
|
||||
private tcpPort: number;
|
||||
private channels: Map<number, net.Socket>;
|
||||
private pendingData: Map<number, Buffer[]>;
|
||||
private ws: WebSocket;
|
||||
private onDomainAssigned: ((domain: string) => void) | undefined;
|
||||
|
||||
constructor(onDomainAssigned?: (domain: string) => void, tcpPort?: number, tcpAddress?: string, remoteServer?: string) {
|
||||
this.tcpAddress = tcpAddress ?? DEFAULT_TCP_ADDRESS;
|
||||
this.tcpPort = tcpPort ?? DEFAULT_TCP_PORT;
|
||||
this.channels = new Map();
|
||||
this.pendingData = new Map();
|
||||
this.onDomainAssigned = onDomainAssigned;
|
||||
|
||||
this.ws = new WebSocket(remoteServer ?? DEFAULT_REMOTE_SERVER);
|
||||
this.ws.on('open', () => this.onOpen());
|
||||
this.ws.on('message', (data: Buffer, isBinary: boolean) => this.onMessage(data, isBinary));
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
console.log('Connected to the remote server.');
|
||||
}
|
||||
|
||||
onMessage(data: Buffer, isBinary: boolean) {
|
||||
if (!isBinary) {
|
||||
const message: ServerMessage = JSON.parse(data.toString());
|
||||
|
||||
if ('DomainAssigned' in message) {
|
||||
console.log('Domain assigned:', message.DomainAssigned);
|
||||
if (this.onDomainAssigned) {
|
||||
this.onDomainAssigned(message.DomainAssigned);
|
||||
}
|
||||
} else if ('ChannelOpen' in message) {
|
||||
this.onChannelOpen(...message.ChannelOpen);
|
||||
} else if ('ChannelClosed' in message) {
|
||||
this.onChannelClosed(message.ChannelClosed);
|
||||
}
|
||||
} else {
|
||||
this.onBinaryMessage(data);
|
||||
}
|
||||
}
|
||||
|
||||
onChannelOpen(channelId: number, clientInfo: string) {
|
||||
console.log(`Opening channel ${channelId} for ${clientInfo}`);
|
||||
|
||||
const tcpSocket = net.createConnection({ host: this.tcpAddress, port: this.tcpPort }, () => {
|
||||
console.log(`TCP connection established for channel ${channelId}`);
|
||||
});
|
||||
|
||||
tcpSocket.on('data', (chunk) => {
|
||||
const data = Buffer.concat([Buffer.from([channelId]), chunk]);
|
||||
this.ws.send(data);
|
||||
});
|
||||
|
||||
tcpSocket.on('close', () => {
|
||||
console.log(`TCP connection closed for channel ${channelId}`);
|
||||
this.ws.send(JSON.stringify({ ChannelClosed: channelId }));
|
||||
this.channels.delete(channelId);
|
||||
});
|
||||
|
||||
this.channels.set(channelId, tcpSocket);
|
||||
|
||||
if (this.pendingData.has(channelId)) {
|
||||
this.pendingData.get(channelId)?.forEach((chunk) => {
|
||||
tcpSocket.write(chunk);
|
||||
});
|
||||
this.pendingData.delete(channelId);
|
||||
}
|
||||
}
|
||||
|
||||
onChannelClosed(channelId: number) {
|
||||
console.log(`Closing channel ${channelId}`);
|
||||
if (this.channels.has(channelId)) {
|
||||
this.channels.get(channelId)?.end();
|
||||
this.channels.delete(channelId);
|
||||
}
|
||||
}
|
||||
|
||||
onBinaryMessage(data: Buffer) {
|
||||
const channelId = data.readUInt8(0);
|
||||
const payload = data.slice(1);
|
||||
if (this.channels.has(channelId)) {
|
||||
this.channels.get(channelId)?.write(payload);
|
||||
} else {
|
||||
if (!this.pendingData.has(channelId)) {
|
||||
this.pendingData.set(channelId, []);
|
||||
}
|
||||
this.pendingData.get(channelId)?.push(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default e4mcClient;
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"name": "e4mc-client-node",
|
||||
"version": "1.0.0",
|
||||
"main": "client.js",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.15.11",
|
||||
"@types/ws": "^8.5.4",
|
||||
"typescript": "^5.0.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"ws": "^8.13.0"
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/node@*", "@types/node@^18.15.11":
|
||||
version "18.15.11"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-18.15.11.tgz#b3b790f09cb1696cffcec605de025b088fa4225f"
|
||||
integrity sha512-E5Kwq2n4SbMzQOn6wnmBjuK9ouqlURrcZDVfbo9ftDDTFt3nk7ZKK4GMOzoYgnpQJKcxwQw+lGaBvvlMo0qN/Q==
|
||||
|
||||
"@types/ws@^8.5.4":
|
||||
version "8.5.4"
|
||||
resolved "https://registry.yarnpkg.com/@types/ws/-/ws-8.5.4.tgz#bb10e36116d6e570dd943735f86c933c1587b8a5"
|
||||
integrity sha512-zdQDHKUgcX/zBc4GrwsE/7dVdAD8JR4EuiAXiiUhhfyIJXXb2+PrGshFyeXWQPMmmZ2XxgaqclgpIC7eTXc1mg==
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
typescript@^5.0.3:
|
||||
version "5.0.3"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.3.tgz#fe976f0c826a88d0a382007681cbb2da44afdedf"
|
||||
integrity sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==
|
||||
|
||||
ws@^8.13.0:
|
||||
version "8.13.0"
|
||||
resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0"
|
||||
integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA==
|
|
@ -15,8 +15,8 @@ env_logger = "0.10.0"
|
|||
futures = "0.3.28"
|
||||
lazy_static = "1.4.0"
|
||||
log = "0.4.17"
|
||||
nanoid = "0.4.0"
|
||||
serde = { version = "1.0.159", features = ["derive"] }
|
||||
serde_json = "1.0.95"
|
||||
thiserror = "1.0.40"
|
||||
tokio = { version = "1.27.0", features = ["rt-multi-thread", "sync", "macros", "net", "io-util"] }
|
||||
e4mc-common = { path = "../common"}
|
||||
rand = "0.8.5"
|
||||
|
|
|
@ -1,29 +1,24 @@
|
|||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap};
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_tungstenite::tokio::TokioAdapter;
|
||||
use async_tungstenite::tungstenite::Message;
|
||||
use async_tungstenite::WebSocketStream;
|
||||
use e4mc_common::{ClientboundControlMessage, ServerboundControlMessage};
|
||||
use futures::stream::{SplitSink, SplitStream};
|
||||
use futures::{Sink, SinkExt, Stream, StreamExt};
|
||||
use lazy_static::lazy_static;
|
||||
use log::{error, info, trace, warn};
|
||||
use netty::ReadExtNetty;
|
||||
use rand::seq::SliceRandom;
|
||||
use futures::{SinkExt, StreamExt};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::tcp::{ReadHalf, WriteHalf};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
|
||||
use tokio::sync::{Mutex, RwLock};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::sync::RwLock;
|
||||
use tokio::task;
|
||||
use async_tungstenite::tungstenite::Message;
|
||||
use lazy_static::lazy_static;
|
||||
use log::{error, info};
|
||||
use nanoid::nanoid;
|
||||
use netty::ReadExtNetty;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::netty::{NettyReadError, WriteExtNetty};
|
||||
|
||||
mod netty;
|
||||
mod wordlist;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct Handshake {
|
||||
|
@ -33,7 +28,7 @@ struct Handshake {
|
|||
next_state: HandshakeType,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone)]
|
||||
#[repr(i32)]
|
||||
enum HandshakeType {
|
||||
Status = 1,
|
||||
|
@ -48,7 +43,7 @@ impl Handshake {
|
|||
} else {
|
||||
let protocol_version = packet.read_varint().await?;
|
||||
let server_address = packet.read_string().await?;
|
||||
let server_port = packet.read_u16().await?;
|
||||
let server_port = packet.read_unsigned_short().await?;
|
||||
let next_state = match packet.read_varint().await? {
|
||||
1 => HandshakeType::Status,
|
||||
2 => HandshakeType::Login,
|
||||
|
@ -62,38 +57,10 @@ impl Handshake {
|
|||
})
|
||||
}
|
||||
}
|
||||
async fn send(&self, mut writer: impl AsyncWriteExt + Unpin + Send) -> tokio::io::Result<()> {
|
||||
let mut buf = vec![];
|
||||
buf.write_varint(0).await?;
|
||||
buf.write_varint(self.protocol_version).await?;
|
||||
buf.write_string(&self.server_address).await?;
|
||||
buf.write_all(&self.server_port.to_be_bytes()).await?;
|
||||
buf.write_varint(self.next_state as i32).await?;
|
||||
writer.write_varint(buf.len() as i32).await?;
|
||||
writer.write_all(&buf).await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
enum WebsocketHandlerMessage {
|
||||
ChannelOpen {
|
||||
id_callback: tokio::sync::oneshot::Sender<Option<u8>>,
|
||||
backchannel: UnboundedSender<MinecraftHandlerMessage>,
|
||||
addr: SocketAddr,
|
||||
},
|
||||
ChannelClose(u8),
|
||||
Data(Vec<u8>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
enum MinecraftHandlerMessage {
|
||||
ChannelClose,
|
||||
Data(Vec<u8>),
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref ROUTING_MAP: RwLock<HashMap<String, UnboundedSender<WebsocketHandlerMessage>>> =
|
||||
static ref EXPOSER_MAP: RwLock<HashMap<String, UnboundedSender<(Handshake, TcpStream, SocketAddr)>>> =
|
||||
RwLock::new(HashMap::new());
|
||||
static ref BASE_DOMAIN: String = env::var("BASE_DOMAIN").expect("BASE_DOMAIN missing");
|
||||
}
|
||||
|
@ -110,7 +77,7 @@ async fn main() -> Result<()> {
|
|||
info!("WebSocket Listening on: {}", ws_bind_addr);
|
||||
while let Ok((stream, _)) = listener.accept().await {
|
||||
task::spawn(async {
|
||||
if let Err(e) = accept_websocket_connection(stream).await {
|
||||
if let Err(e) = accept_ws_connection(stream).await {
|
||||
error!("Error handling WebSocket connection: {}", e);
|
||||
}
|
||||
});
|
||||
|
@ -122,7 +89,7 @@ async fn main() -> Result<()> {
|
|||
info!("Minecraft Listening on: {}", mc_bind_addr);
|
||||
while let Ok((stream, _)) = listener.accept().await {
|
||||
task::spawn(async {
|
||||
if let Err(e) = accept_minecraft_connection(stream).await {
|
||||
if let Err(e) = accept_mc_connection(stream).await {
|
||||
error!("Error handling Minecraft connection: {}", e);
|
||||
}
|
||||
});
|
||||
|
@ -134,256 +101,254 @@ async fn main() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
struct RoutingHandle {
|
||||
receiver: UnboundedReceiver<WebsocketHandlerMessage>,
|
||||
domain: String,
|
||||
#[derive(Serialize)]
|
||||
enum ClientboundControlMessage {
|
||||
DomainAssigned(String),
|
||||
ChannelOpen(u8, SocketAddr),
|
||||
ChannelClosed(u8),
|
||||
}
|
||||
|
||||
impl RoutingHandle {
|
||||
#[derive(Deserialize)]
|
||||
enum ServerboundControlMessage {
|
||||
ChannelClosed(u8),
|
||||
}
|
||||
|
||||
struct ExposerMapHandle(String, UnboundedReceiver<(Handshake, TcpStream, SocketAddr)>);
|
||||
|
||||
impl ExposerMapHandle {
|
||||
async fn new(domain: String) -> Self {
|
||||
let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
|
||||
ROUTING_MAP.write().await.insert(domain.clone(), sender);
|
||||
Self { receiver, domain }
|
||||
EXPOSER_MAP.write().await.insert(domain.clone(), sender);
|
||||
Self(domain, receiver)
|
||||
}
|
||||
|
||||
async fn recv(&mut self) -> Option<WebsocketHandlerMessage> {
|
||||
self.receiver.recv().await
|
||||
async fn recv(&mut self) -> Option<(Handshake, TcpStream, SocketAddr)> {
|
||||
self.1.recv().await
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for RoutingHandle {
|
||||
impl Drop for ExposerMapHandle {
|
||||
fn drop(&mut self) {
|
||||
let domain = self.domain.clone();
|
||||
tokio::spawn(async move {
|
||||
ROUTING_MAP.write().await.remove(&domain);
|
||||
let domain = self.0.clone();
|
||||
task::spawn(async move {
|
||||
EXPOSER_MAP.write().await.remove(&domain);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async fn accept_websocket_connection(stream: TcpStream) -> Result<()> {
|
||||
let addr = stream.peer_addr()?;
|
||||
info!("WebSocket Peer address: {}", addr);
|
||||
|
||||
let mut ws_stream = async_tungstenite::tokio::accept_async(stream).await?;
|
||||
|
||||
info!("New WebSocket connection: {}", addr);
|
||||
|
||||
let domain = get_random_domain().await;
|
||||
|
||||
ws_stream
|
||||
.send(ClientboundControlMessage::DomainAssigned(domain.clone()).into())
|
||||
.await?;
|
||||
|
||||
let handle = RoutingHandle::new(domain.clone()).await;
|
||||
|
||||
let channel_table = Mutex::new(HashMap::new());
|
||||
|
||||
let (mut write, mut read) = ws_stream.split();
|
||||
|
||||
tokio::select! {
|
||||
res = handle_websocket_send(&mut write, &channel_table, handle) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error on WebSocket send loop: {}", e);
|
||||
}
|
||||
},
|
||||
res = handle_websocket_recv(&mut read, &channel_table) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error on WebSocket recv loop: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let _ = write.reunite(read)?.close(None).await; // if this errors, why bother?
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_websocket_send(
|
||||
write: &mut SplitSink<WebSocketStream<TokioAdapter<TcpStream>>, Message>,
|
||||
channel_table: &Mutex<HashMap<u8, UnboundedSender<MinecraftHandlerMessage>>>,
|
||||
mut handle: RoutingHandle,
|
||||
) -> Result<()> {
|
||||
while let Some(data) = handle.recv().await {
|
||||
match data {
|
||||
WebsocketHandlerMessage::ChannelOpen {
|
||||
id_callback,
|
||||
backchannel,
|
||||
addr,
|
||||
} => {
|
||||
let mut table = channel_table.lock().await;
|
||||
let channel = get_available_channel(table.keys().copied().collect());
|
||||
if id_callback.send(channel).is_err() {
|
||||
warn!("ID callback died before we could send the assigned ID");
|
||||
} else if let Some(channel) = channel {
|
||||
table.insert(channel, backchannel);
|
||||
|
||||
write
|
||||
.send(ClientboundControlMessage::ChannelOpen(channel, addr).into())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
WebsocketHandlerMessage::ChannelClose(channel) => {
|
||||
write
|
||||
.send(ClientboundControlMessage::ChannelClosed(channel).into())
|
||||
.await?;
|
||||
channel_table.lock().await.remove(&channel);
|
||||
}
|
||||
WebsocketHandlerMessage::Data(buf) => {
|
||||
write.send(Message::Binary(buf)).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_websocket_recv(
|
||||
read: &mut SplitStream<WebSocketStream<TokioAdapter<TcpStream>>>,
|
||||
channel_table: &Mutex<HashMap<u8, UnboundedSender<MinecraftHandlerMessage>>>,
|
||||
) -> Result<()> {
|
||||
while let Some(message) = read.next().await {
|
||||
if let Err(async_tungstenite::tungstenite::Error::ConnectionClosed) = message {
|
||||
info!("Connection closed normally");
|
||||
return Ok(());
|
||||
}
|
||||
let message = message?;
|
||||
match message {
|
||||
Message::Text(message) => {
|
||||
let message: ServerboundControlMessage = serde_json::from_str(&message)?;
|
||||
match message {
|
||||
ServerboundControlMessage::ChannelClosed(channel) => {
|
||||
if let Some(sender) = channel_table.lock().await.remove(&channel) {
|
||||
sender.send(MinecraftHandlerMessage::ChannelClose)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::Binary(buf) => {
|
||||
let channel = buf[0];
|
||||
if let Some(sender) = channel_table.lock().await.get(&channel) {
|
||||
sender.send(MinecraftHandlerMessage::Data(buf[1..].to_vec()))?;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
struct ChannelHandle {
|
||||
receiver: UnboundedReceiver<MinecraftHandlerMessage>,
|
||||
sender: UnboundedSender<WebsocketHandlerMessage>,
|
||||
channel: u8,
|
||||
}
|
||||
struct ChannelHandle(
|
||||
u8,
|
||||
UnboundedReceiver<MinecraftConnectionMessage>,
|
||||
UnboundedSender<WebsocketConnectionMessage>,
|
||||
);
|
||||
|
||||
impl ChannelHandle {
|
||||
async fn new(
|
||||
sender: &UnboundedSender<WebsocketHandlerMessage>,
|
||||
id: u8,
|
||||
addr: SocketAddr,
|
||||
send: UnboundedSender<WebsocketConnectionMessage>,
|
||||
) -> Result<Self> {
|
||||
let (mc_sender, mc_receiver) = tokio::sync::mpsc::unbounded_channel();
|
||||
let (id_sender, id_receiver) = tokio::sync::oneshot::channel();
|
||||
sender.send(WebsocketHandlerMessage::ChannelOpen {
|
||||
id_callback: id_sender,
|
||||
backchannel: mc_sender,
|
||||
addr,
|
||||
})?;
|
||||
if let Some(channel) = id_receiver.await? {
|
||||
Ok(Self {
|
||||
receiver: mc_receiver,
|
||||
sender: sender.clone(),
|
||||
channel,
|
||||
})
|
||||
} else {
|
||||
Err(anyhow!("Websocket handler couldn't give channel"))
|
||||
}
|
||||
let (sender, receiver) = tokio::sync::mpsc::unbounded_channel();
|
||||
send.send(WebsocketConnectionMessage::Open(id, addr, sender))
|
||||
.map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
Ok(Self(id, receiver, send))
|
||||
}
|
||||
|
||||
fn send(&self, mut buf: Vec<u8>) -> Result<()> {
|
||||
buf.insert(0, self.channel);
|
||||
self.sender.send(WebsocketHandlerMessage::Data(buf))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn recv(&mut self) -> Option<MinecraftHandlerMessage> {
|
||||
self.receiver.recv().await
|
||||
}
|
||||
|
||||
fn split(&mut self) -> (ChannelHandleSend, ChannelHandleRecv) {
|
||||
(
|
||||
ChannelHandleSend {
|
||||
sender: &mut self.sender,
|
||||
channel: self.channel,
|
||||
},
|
||||
ChannelHandleRecv {
|
||||
receiver: &mut self.receiver,
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
struct ChannelHandleSend<'a> {
|
||||
sender: &'a mut UnboundedSender<WebsocketHandlerMessage>,
|
||||
channel: u8,
|
||||
}
|
||||
|
||||
impl ChannelHandleSend<'_> {
|
||||
fn send(&self, mut buf: Vec<u8>) -> Result<()> {
|
||||
buf.insert(0, self.channel);
|
||||
self.sender.send(WebsocketHandlerMessage::Data(buf))?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct ChannelHandleRecv<'a> {
|
||||
receiver: &'a mut UnboundedReceiver<MinecraftHandlerMessage>,
|
||||
}
|
||||
|
||||
impl ChannelHandleRecv<'_> {
|
||||
async fn recv(&mut self) -> Option<MinecraftHandlerMessage> {
|
||||
self.receiver.recv().await
|
||||
async fn recv(&mut self) -> Option<MinecraftConnectionMessage> {
|
||||
self.1.recv().await
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for ChannelHandle {
|
||||
fn drop(&mut self) {
|
||||
self.sender
|
||||
.send(WebsocketHandlerMessage::ChannelClose(self.channel))
|
||||
.unwrap();
|
||||
self.2.send(WebsocketConnectionMessage::Close(self.0)).map_err(|e| anyhow::anyhow!("{}", e)).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
async fn accept_minecraft_connection(mut stream: TcpStream) -> Result<()> {
|
||||
enum MinecraftConnectionMessage {
|
||||
Data(Vec<u8>),
|
||||
Close,
|
||||
}
|
||||
|
||||
enum WebsocketConnectionMessage {
|
||||
Data(Vec<u8>),
|
||||
Close(u8),
|
||||
Open(u8, SocketAddr, UnboundedSender<MinecraftConnectionMessage>),
|
||||
}
|
||||
|
||||
async fn accept_ws_connection(stream: TcpStream) -> Result<()> {
|
||||
let addr = stream.peer_addr()?;
|
||||
info!("Minecraft Peer address: {}", addr);
|
||||
info!("WebSocker Peer address: {}", addr);
|
||||
|
||||
let mut ws_stream = async_tungstenite::tokio::accept_async(stream).await?;
|
||||
|
||||
info!("New WebSocket connection: {}", addr);
|
||||
|
||||
let mut domain = get_random_domain();
|
||||
|
||||
let exposer_map = EXPOSER_MAP.read().await;
|
||||
while exposer_map.contains_key(&domain) {
|
||||
domain = get_random_domain();
|
||||
}
|
||||
let domain = domain;
|
||||
info!("Connection {} was assigned domain {}", addr, domain);
|
||||
|
||||
ws_stream
|
||||
.send(Message::Text(serde_json::to_string(
|
||||
&ClientboundControlMessage::DomainAssigned(domain.clone()),
|
||||
)?))
|
||||
.await?;
|
||||
|
||||
drop(exposer_map);
|
||||
|
||||
let mut exposer_handle = ExposerMapHandle::new(domain.clone()).await;
|
||||
|
||||
let channel_map = &RwLock::new(HashMap::new());
|
||||
|
||||
let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel();
|
||||
let (mut send, mut recv) = ws_stream.split();
|
||||
|
||||
futures::try_join!(
|
||||
async move {
|
||||
while let Some(message) = receiver.recv().await {
|
||||
match message {
|
||||
WebsocketConnectionMessage::Data(buf) => {
|
||||
send.send(Message::Binary(buf)).await?
|
||||
}
|
||||
WebsocketConnectionMessage::Close(id) => {
|
||||
send.send(Message::Text(serde_json::to_string(
|
||||
&ClientboundControlMessage::ChannelClosed(id),
|
||||
)?))
|
||||
.await?;
|
||||
channel_map.write().await.remove(&id);
|
||||
}
|
||||
WebsocketConnectionMessage::Open(id, addr, channel) => {
|
||||
send.send(Message::Text(serde_json::to_string(
|
||||
&ClientboundControlMessage::ChannelOpen(id, addr),
|
||||
)?))
|
||||
.await?;
|
||||
channel_map.write().await.insert(id, channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(()) as Result<()>
|
||||
},
|
||||
async move {
|
||||
while let Some(Ok(message)) = recv.next().await {
|
||||
match message {
|
||||
Message::Text(message) => {
|
||||
let message: ServerboundControlMessage = serde_json::from_str(&message)?;
|
||||
match message {
|
||||
ServerboundControlMessage::ChannelClosed(id) => {
|
||||
if let Some(channel) = channel_map.write().await.remove(&id) {
|
||||
info!("Closing channel id: {}", id);
|
||||
channel.send(MinecraftConnectionMessage::Close).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::Binary(buf) => {
|
||||
if let Some(channel) = channel_map.read().await.get(&buf[0]) {
|
||||
channel
|
||||
.send(MinecraftConnectionMessage::Data(buf[1..].to_vec())).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(()) as Result<()>
|
||||
},
|
||||
async move {
|
||||
while let Some((handshake, mc_stream, addr)) = exposer_handle.recv().await {
|
||||
if let Some(channel_id) =
|
||||
get_available_channel(channel_map.read().await.keys().copied().collect())
|
||||
{
|
||||
task::spawn(handle_sent_connection(
|
||||
handshake,
|
||||
mc_stream,
|
||||
addr,
|
||||
sender.clone(),
|
||||
channel_id,
|
||||
));
|
||||
}
|
||||
}
|
||||
Ok(()) as Result<()>
|
||||
}
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_sent_connection(
|
||||
handshake: Handshake,
|
||||
mut mc_stream: TcpStream,
|
||||
addr: SocketAddr,
|
||||
send: UnboundedSender<WebsocketConnectionMessage>,
|
||||
channel_id: u8,
|
||||
) -> Result<()> {
|
||||
let mut handle = ChannelHandle::new(channel_id, addr, send.clone()).await?;
|
||||
let mut buf = vec![];
|
||||
buf.write_varint(0).await?;
|
||||
buf.write_varint(handshake.protocol_version).await?;
|
||||
buf.write_string(&handshake.server_address).await?;
|
||||
buf.write_all(&handshake.server_port.to_be_bytes()).await?;
|
||||
buf.write_varint(handshake.next_state as i32).await?;
|
||||
let mut len_buf = vec![channel_id];
|
||||
len_buf.write_varint(buf.len() as i32).await?;
|
||||
len_buf.append(&mut buf);
|
||||
send.send(WebsocketConnectionMessage::Data(len_buf)).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
let (mut read, mut write) = mc_stream.split();
|
||||
tokio::select!(_ =
|
||||
#[allow(unreachable_code)]
|
||||
async move {
|
||||
let mut buf = [0u8; 1024];
|
||||
loop {
|
||||
read.readable().await?;
|
||||
let len = read.read(&mut buf).await?;
|
||||
if len == 0 {
|
||||
continue;
|
||||
}
|
||||
let mut packet = Vec::from(&buf[..len]);
|
||||
packet.insert(0, channel_id);
|
||||
send.send(WebsocketConnectionMessage::Data(packet)).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
}
|
||||
Ok(()) as anyhow::Result<()>
|
||||
} => {},
|
||||
_ = async move {
|
||||
while let Some(message) = handle.recv().await {
|
||||
match message {
|
||||
MinecraftConnectionMessage::Data(buf) => {
|
||||
write.write_all(&buf).await?;
|
||||
}
|
||||
MinecraftConnectionMessage::Close => {
|
||||
return Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(()) as anyhow::Result<()>
|
||||
} => {}
|
||||
);
|
||||
mc_stream.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn accept_mc_connection(mut stream: TcpStream) -> Result<()> {
|
||||
let addr = stream.peer_addr()?;
|
||||
info!("New Minecraft connection: {}", addr);
|
||||
|
||||
let packet = stream.read_packet().await;
|
||||
|
||||
if let Err(NettyReadError::LegacyServerListPing) = packet {
|
||||
stream
|
||||
.write_all(include_bytes!("legacy_serverlistping_response.bin"))
|
||||
.write_all(include_bytes!("./legacy_serverlistping_response.bin"))
|
||||
.await?;
|
||||
return Ok(());
|
||||
}
|
||||
let handshake = Handshake::new(&packet?).await?;
|
||||
if let Some(sender) = ROUTING_MAP.read().await.get(&handshake.server_address) {
|
||||
let mut handle = ChannelHandle::new(sender, addr).await?;
|
||||
let mut buf = vec![];
|
||||
handshake.send(&mut buf).await?;
|
||||
handle.send(buf)?;
|
||||
let (send, recv) = handle.split();
|
||||
let (read, write) = stream.split();
|
||||
tokio::select! {
|
||||
res = handle_minecraft_send(write, recv) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error on Minecraft send loop: {}", e);
|
||||
}
|
||||
},
|
||||
res = handle_minecraft_recv(read, send) => {
|
||||
if let Err(e) = res {
|
||||
error!("Error on Minecraft recv loop: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
stream.shutdown().await?;
|
||||
|
||||
let packet = packet?;
|
||||
|
||||
let handshake = Handshake::new(&packet).await?;
|
||||
if let Some(sender) = EXPOSER_MAP.read().await.get(&handshake.server_address) {
|
||||
sender.send((handshake, stream, addr)).map_err(|e| anyhow::anyhow!("{}", e))?;
|
||||
} else {
|
||||
match handshake.next_state {
|
||||
HandshakeType::Status => {
|
||||
|
@ -408,53 +373,18 @@ async fn accept_minecraft_connection(mut stream: TcpStream) -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_minecraft_send(
|
||||
mut write: WriteHalf<'_>,
|
||||
mut recv: ChannelHandleRecv<'_>,
|
||||
) -> Result<()> {
|
||||
while let Some(data) = recv.recv().await {
|
||||
match data {
|
||||
MinecraftHandlerMessage::ChannelClose => return Ok(()),
|
||||
MinecraftHandlerMessage::Data(buf) => write.write_all(&buf).await?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
const ID_ALPHABET: [char; 36] = [
|
||||
'1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
|
||||
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
||||
];
|
||||
const ID_LENGTH: usize = 8;
|
||||
|
||||
async fn handle_minecraft_recv(mut read: ReadHalf<'_>, send: ChannelHandleSend<'_>) -> Result<()> {
|
||||
let mut buf = [0u8; 1024];
|
||||
loop {
|
||||
let ready = read.ready(tokio::io::Interest::READABLE).await?;
|
||||
if ready.is_read_closed() {
|
||||
return Ok(());
|
||||
}
|
||||
let len = read.read(&mut buf).await?;
|
||||
if len == 0 {
|
||||
continue;
|
||||
}
|
||||
let packet = Vec::from(&buf[..len]);
|
||||
trace!("send: {:?}", packet);
|
||||
send.send(packet)?;
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_random_domain() -> String {
|
||||
let mut domain = format!(
|
||||
"{}-{}.{}",
|
||||
wordlist::ID_WORDS.choose(&mut rand::thread_rng()).unwrap(),
|
||||
wordlist::ID_WORDS.choose(&mut rand::thread_rng()).unwrap(),
|
||||
fn get_random_domain() -> String {
|
||||
format!(
|
||||
"{}.{}",
|
||||
nanoid!(ID_LENGTH, &ID_ALPHABET),
|
||||
BASE_DOMAIN.as_str()
|
||||
);
|
||||
let map = ROUTING_MAP.read().await;
|
||||
while map.contains_key(&domain) {
|
||||
domain = format!(
|
||||
"{}-{}.{}",
|
||||
wordlist::ID_WORDS.choose(&mut rand::thread_rng()).unwrap(),
|
||||
wordlist::ID_WORDS.choose(&mut rand::thread_rng()).unwrap(),
|
||||
BASE_DOMAIN.as_str()
|
||||
);
|
||||
}
|
||||
domain
|
||||
)
|
||||
}
|
||||
|
||||
fn get_available_channel(used: Vec<u8>) -> Option<u8> {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
use async_trait::async_trait;
|
||||
use log::error;
|
||||
use log::{error};
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Error, Debug)]
|
||||
|
@ -26,6 +26,64 @@ impl From<std::io::ErrorKind> for NettyReadError {
|
|||
|
||||
#[async_trait]
|
||||
pub trait ReadExtNetty: AsyncReadExt + Unpin {
|
||||
async fn read_bool(&mut self) -> Result<bool, NettyReadError> {
|
||||
let mut buf = [0u8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
match buf[0] {
|
||||
0 => Ok(false),
|
||||
1 => Ok(true),
|
||||
_ => Err(std::io::ErrorKind::InvalidData.into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn read_byte(&mut self) -> Result<i8, NettyReadError> {
|
||||
let mut buf = [0u8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i8::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_unsigned_byte(&mut self) -> Result<u8, NettyReadError> {
|
||||
let mut buf = [0u8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(buf[0])
|
||||
}
|
||||
|
||||
async fn read_short(&mut self) -> Result<i16, NettyReadError> {
|
||||
let mut buf = [0u8; 2];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i16::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_unsigned_short(&mut self) -> Result<u16, NettyReadError> {
|
||||
let mut buf = [0u8; 2];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(u16::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_int(&mut self) -> Result<i32, NettyReadError> {
|
||||
let mut buf = [0u8; 4];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i32::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_long(&mut self) -> Result<i64, NettyReadError> {
|
||||
let mut buf = [0u8; 8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(i64::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_float(&mut self) -> Result<f32, NettyReadError> {
|
||||
let mut buf = [0u8; 4];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(f32::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_double(&mut self) -> Result<f64, NettyReadError> {
|
||||
let mut buf = [0u8; 8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(f64::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_string(&mut self) -> Result<String, NettyReadError> {
|
||||
let len = self.read_varint().await?;
|
||||
let mut buf = vec![0u8; len as usize];
|
||||
|
@ -33,10 +91,11 @@ pub trait ReadExtNetty: AsyncReadExt + Unpin {
|
|||
String::from_utf8(buf).map_err(|_| std::io::ErrorKind::InvalidData.into())
|
||||
}
|
||||
|
||||
|
||||
async fn read_varint(&mut self) -> Result<i32, NettyReadError> {
|
||||
let mut res = 0i32;
|
||||
for i in 0..5 {
|
||||
let part = self.read_u8().await?;
|
||||
let part = self.read_unsigned_byte().await?;
|
||||
res |= (part as i32 & 0x7F) << (7 * i);
|
||||
if part & 0x80 == 0 {
|
||||
return Ok(res);
|
||||
|
@ -46,6 +105,72 @@ pub trait ReadExtNetty: AsyncReadExt + Unpin {
|
|||
Err(std::io::ErrorKind::InvalidData.into())
|
||||
}
|
||||
|
||||
// async fn read_varint(&mut self) -> Result<i32, NettyReadError> {
|
||||
// let mut value = 0i32;
|
||||
// let mut buf = [0u8; 1];
|
||||
// let mut pos = 0u8;
|
||||
// loop {
|
||||
// self.read_exact(&mut buf).await?;
|
||||
// println!("{}", buf[0]);
|
||||
// value |= ((buf[0] & 0b01111111) << pos) as i32;
|
||||
// if (buf[0] & 0b10000000) == 0 {
|
||||
// break;
|
||||
// };
|
||||
// pos += 7;
|
||||
// if pos >= 32 {
|
||||
// return Err(std::io::ErrorKind::InvalidData.into());
|
||||
// };
|
||||
// }
|
||||
// Ok(value)
|
||||
// }
|
||||
|
||||
async fn read_varlong(&mut self) -> Result<i64, NettyReadError> {
|
||||
let mut value = 0i64;
|
||||
let mut buf = [0u8; 1];
|
||||
let mut position = 0u8;
|
||||
loop {
|
||||
self.read_exact(&mut buf).await?;
|
||||
value |= ((buf[0] & 0b01111111) << position) as i64;
|
||||
if (buf[0] & 0b10000000) == 0 {
|
||||
break;
|
||||
};
|
||||
position += 7;
|
||||
if position >= 64 {
|
||||
return Err(std::io::ErrorKind::InvalidData.into());
|
||||
};
|
||||
}
|
||||
Ok(value)
|
||||
}
|
||||
|
||||
async fn read_vec3(&mut self) -> Result<(i32, i16, i32), NettyReadError> {
|
||||
let mut buf = [0u8; 8];
|
||||
self.read_exact(&mut buf).await?;
|
||||
let packed = u64::from_be_bytes(buf);
|
||||
let x: i32 = ((packed & 0xffffffc000000000) >> 38) as _;
|
||||
let y: i16 = (packed & 0xfff) as _;
|
||||
let z: i32 = ((packed & 0x3ffffff000) >> 12) as _;
|
||||
Ok((
|
||||
match x {
|
||||
i32::MIN..=0x1ffffff => x,
|
||||
0x2000000.. => x - 0x2000000,
|
||||
},
|
||||
match y {
|
||||
i16::MIN..=0x7ff => y,
|
||||
0x800.. => y - 0x800,
|
||||
},
|
||||
match z {
|
||||
i32::MIN..=0x1ffffff => z,
|
||||
0x2000000.. => z - 0x2000000,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
async fn read_uuid(&mut self) -> Result<u128, NettyReadError> {
|
||||
let mut buf = [0u8; 16];
|
||||
self.read_exact(&mut buf).await?;
|
||||
Ok(u128::from_be_bytes(buf))
|
||||
}
|
||||
|
||||
async fn read_packet(&mut self) -> Result<Vec<u8>, NettyReadError> {
|
||||
let len = self.read_varint().await?;
|
||||
let mut buf = vec![0u8; len as usize];
|
||||
|
|
|
@ -1,213 +0,0 @@
|
|||
pub const ID_WORDS: [&str; 2048] = [
|
||||
"abandon", "ability", "able", "about", "above", "absent", "absorb", "abstract", "absurd",
|
||||
"abuse", "access", "accident", "account", "accuse", "achieve", "acid", "acoustic", "acquire",
|
||||
"across", "act", "action", "actor", "actress", "actual", "adapt", "add", "addict", "address",
|
||||
"adjust", "admit", "adult", "advance", "advice", "aerobic", "affair", "afford", "afraid",
|
||||
"again", "age", "agent", "agree", "ahead", "aim", "air", "airport", "aisle", "alarm", "album",
|
||||
"alcohol", "alert", "alien", "all", "alley", "allow", "almost", "alone", "alpha", "already",
|
||||
"also", "alter", "always", "amateur", "amazing", "among", "amount", "amused", "analyst",
|
||||
"anchor", "ancient", "anger", "angle", "angry", "animal", "ankle", "announce", "annual",
|
||||
"another", "answer", "antenna", "antique", "anxiety", "any", "apart", "apology", "appear",
|
||||
"apple", "approve", "april", "arch", "arctic", "area", "arena", "argue", "arm", "armed",
|
||||
"armor", "army", "around", "arrange", "arrest", "arrive", "arrow", "art", "artefact", "artist",
|
||||
"artwork", "ask", "aspect", "assault", "asset", "assist", "assume", "asthma", "athlete",
|
||||
"atom", "attack", "attend", "attitude", "attract", "auction", "audit", "august", "aunt",
|
||||
"author", "auto", "autumn", "average", "avocado", "avoid", "awake", "aware", "away", "awesome",
|
||||
"awful", "awkward", "axis", "baby", "bachelor", "bacon", "badge", "bag", "balance", "balcony",
|
||||
"ball", "bamboo", "banana", "banner", "bar", "barely", "bargain", "barrel", "base", "basic",
|
||||
"basket", "battle", "beach", "bean", "beauty", "because", "become", "beef", "before", "begin",
|
||||
"behave", "behind", "believe", "below", "belt", "bench", "benefit", "best", "betray", "better",
|
||||
"between", "beyond", "bicycle", "bid", "bike", "bind", "biology", "bird", "birth", "bitter",
|
||||
"black", "blade", "blame", "blanket", "blast", "bleak", "bless", "blind", "blood", "blossom",
|
||||
"blouse", "blue", "blur", "blush", "board", "boat", "body", "boil", "bomb", "bone", "bonus",
|
||||
"book", "boost", "border", "boring", "borrow", "boss", "bottom", "bounce", "box", "boy",
|
||||
"bracket", "brain", "brand", "brass", "brave", "bread", "breeze", "brick", "bridge", "brief",
|
||||
"bright", "bring", "brisk", "broccoli", "broken", "bronze", "broom", "brother", "brown",
|
||||
"brush", "bubble", "buddy", "budget", "buffalo", "build", "bulb", "bulk", "bullet", "bundle",
|
||||
"bunker", "burden", "burger", "burst", "bus", "business", "busy", "butter", "buyer", "buzz",
|
||||
"cabbage", "cabin", "cable", "cactus", "cage", "cake", "call", "calm", "camera", "camp", "can",
|
||||
"canal", "cancel", "candy", "cannon", "canoe", "canvas", "canyon", "capable", "capital",
|
||||
"captain", "car", "carbon", "card", "cargo", "carpet", "carry", "cart", "case", "cash",
|
||||
"casino", "castle", "casual", "cat", "catalog", "catch", "category", "cattle", "caught",
|
||||
"cause", "caution", "cave", "ceiling", "celery", "cement", "census", "century", "cereal",
|
||||
"certain", "chair", "chalk", "champion", "change", "chaos", "chapter", "charge", "chase",
|
||||
"chat", "cheap", "check", "cheese", "chef", "cherry", "chest", "chicken", "chief", "child",
|
||||
"chimney", "choice", "choose", "chronic", "chuckle", "chunk", "churn", "cigar", "cinnamon",
|
||||
"circle", "citizen", "city", "civil", "claim", "clap", "clarify", "claw", "clay", "clean",
|
||||
"clerk", "clever", "click", "client", "cliff", "climb", "clinic", "clip", "clock", "clog",
|
||||
"close", "cloth", "cloud", "clown", "club", "clump", "cluster", "clutch", "coach", "coast",
|
||||
"coconut", "code", "coffee", "coil", "coin", "collect", "color", "column", "combine", "come",
|
||||
"comfort", "comic", "common", "company", "concert", "conduct", "confirm", "congress",
|
||||
"connect", "consider", "control", "convince", "cook", "cool", "copper", "copy", "coral",
|
||||
"core", "corn", "correct", "cost", "cotton", "couch", "country", "couple", "course", "cousin",
|
||||
"cover", "coyote", "crack", "cradle", "craft", "cram", "crane", "crash", "crater", "crawl",
|
||||
"crazy", "cream", "credit", "creek", "crew", "cricket", "crime", "crisp", "critic", "crop",
|
||||
"cross", "crouch", "crowd", "crucial", "cruel", "cruise", "crumble", "crunch", "crush", "cry",
|
||||
"crystal", "cube", "culture", "cup", "cupboard", "curious", "current", "curtain", "curve",
|
||||
"cushion", "custom", "cute", "cycle", "dad", "damage", "damp", "dance", "danger", "daring",
|
||||
"dash", "daughter", "dawn", "day", "deal", "debate", "debris", "decade", "december", "decide",
|
||||
"decline", "decorate", "decrease", "deer", "defense", "define", "defy", "degree", "delay",
|
||||
"deliver", "demand", "demise", "denial", "dentist", "deny", "depart", "depend", "deposit",
|
||||
"depth", "deputy", "derive", "describe", "desert", "design", "desk", "despair", "destroy",
|
||||
"detail", "detect", "develop", "device", "devote", "diagram", "dial", "diamond", "diary",
|
||||
"dice", "diesel", "diet", "differ", "digital", "dignity", "dilemma", "dinner", "dinosaur",
|
||||
"direct", "dirt", "disagree", "discover", "disease", "dish", "dismiss", "disorder", "display",
|
||||
"distance", "divert", "divide", "divorce", "dizzy", "doctor", "document", "dog", "doll",
|
||||
"dolphin", "domain", "donate", "donkey", "donor", "door", "dose", "double", "dove", "draft",
|
||||
"dragon", "drama", "drastic", "draw", "dream", "dress", "drift", "drill", "drink", "drip",
|
||||
"drive", "drop", "drum", "dry", "duck", "dumb", "dune", "during", "dust", "dutch", "duty",
|
||||
"dwarf", "dynamic", "eager", "eagle", "early", "earn", "earth", "easily", "east", "easy",
|
||||
"echo", "ecology", "economy", "edge", "edit", "educate", "effort", "egg", "eight", "either",
|
||||
"elbow", "elder", "electric", "elegant", "element", "elephant", "elevator", "elite", "else",
|
||||
"embark", "embody", "embrace", "emerge", "emotion", "employ", "empower", "empty", "enable",
|
||||
"enact", "end", "endless", "endorse", "enemy", "energy", "enforce", "engage", "engine",
|
||||
"enhance", "enjoy", "enlist", "enough", "enrich", "enroll", "ensure", "enter", "entire",
|
||||
"entry", "envelope", "episode", "equal", "equip", "era", "erase", "erode", "erosion", "error",
|
||||
"erupt", "escape", "essay", "essence", "estate", "eternal", "ethics", "evidence", "evil",
|
||||
"evoke", "evolve", "exact", "example", "excess", "exchange", "excite", "exclude", "excuse",
|
||||
"execute", "exercise", "exhaust", "exhibit", "exile", "exist", "exit", "exotic", "expand",
|
||||
"expect", "expire", "explain", "expose", "express", "extend", "extra", "eye", "eyebrow",
|
||||
"fabric", "face", "faculty", "fade", "faint", "faith", "fall", "false", "fame", "family",
|
||||
"famous", "fan", "fancy", "fantasy", "farm", "fashion", "fat", "fatal", "father", "fatigue",
|
||||
"fault", "favorite", "feature", "february", "federal", "fee", "feed", "feel", "female",
|
||||
"fence", "festival", "fetch", "fever", "few", "fiber", "fiction", "field", "figure", "file",
|
||||
"film", "filter", "final", "find", "fine", "finger", "finish", "fire", "firm", "first",
|
||||
"fiscal", "fish", "fit", "fitness", "fix", "flag", "flame", "flash", "flat", "flavor", "flee",
|
||||
"flight", "flip", "float", "flock", "floor", "flower", "fluid", "flush", "fly", "foam",
|
||||
"focus", "fog", "foil", "fold", "follow", "food", "foot", "force", "forest", "forget", "fork",
|
||||
"fortune", "forum", "forward", "fossil", "foster", "found", "fox", "fragile", "frame",
|
||||
"frequent", "fresh", "friend", "fringe", "frog", "front", "frost", "frown", "frozen", "fruit",
|
||||
"fuel", "fun", "funny", "furnace", "fury", "future", "gadget", "gain", "galaxy", "gallery",
|
||||
"game", "gap", "garage", "garbage", "garden", "garlic", "garment", "gas", "gasp", "gate",
|
||||
"gather", "gauge", "gaze", "general", "genius", "genre", "gentle", "genuine", "gesture",
|
||||
"ghost", "giant", "gift", "giggle", "ginger", "giraffe", "girl", "give", "glad", "glance",
|
||||
"glare", "glass", "glide", "glimpse", "globe", "gloom", "glory", "glove", "glow", "glue",
|
||||
"goat", "goddess", "gold", "good", "goose", "gorilla", "gospel", "gossip", "govern", "gown",
|
||||
"grab", "grace", "grain", "grant", "grape", "grass", "gravity", "great", "green", "grid",
|
||||
"grief", "grit", "grocery", "group", "grow", "grunt", "guard", "guess", "guide", "guilt",
|
||||
"guitar", "gun", "gym", "habit", "hair", "half", "hammer", "hamster", "hand", "happy",
|
||||
"harbor", "hard", "harsh", "harvest", "hat", "have", "hawk", "hazard", "head", "health",
|
||||
"heart", "heavy", "hedgehog", "height", "hello", "helmet", "help", "hen", "hero", "hidden",
|
||||
"high", "hill", "hint", "hip", "hire", "history", "hobby", "hockey", "hold", "hole", "holiday",
|
||||
"hollow", "home", "honey", "hood", "hope", "horn", "horror", "horse", "hospital", "host",
|
||||
"hotel", "hour", "hover", "hub", "huge", "human", "humble", "humor", "hundred", "hungry",
|
||||
"hunt", "hurdle", "hurry", "hurt", "husband", "hybrid", "ice", "icon", "idea", "identify",
|
||||
"idle", "ignore", "ill", "illegal", "illness", "image", "imitate", "immense", "immune",
|
||||
"impact", "impose", "improve", "impulse", "inch", "include", "income", "increase", "index",
|
||||
"indicate", "indoor", "industry", "infant", "inflict", "inform", "inhale", "inherit",
|
||||
"initial", "inject", "injury", "inmate", "inner", "innocent", "input", "inquiry", "insane",
|
||||
"insect", "inside", "inspire", "install", "intact", "interest", "into", "invest", "invite",
|
||||
"involve", "iron", "island", "isolate", "issue", "item", "ivory", "jacket", "jaguar", "jar",
|
||||
"jazz", "jealous", "jeans", "jelly", "jewel", "job", "join", "joke", "journey", "joy", "judge",
|
||||
"juice", "jump", "jungle", "junior", "junk", "just", "kangaroo", "keen", "keep", "ketchup",
|
||||
"key", "kick", "kid", "kidney", "kind", "kingdom", "kiss", "kit", "kitchen", "kite", "kitten",
|
||||
"kiwi", "knee", "knife", "knock", "know", "lab", "label", "labor", "ladder", "lady", "lake",
|
||||
"lamp", "language", "laptop", "large", "later", "latin", "laugh", "laundry", "lava", "law",
|
||||
"lawn", "lawsuit", "layer", "lazy", "leader", "leaf", "learn", "leave", "lecture", "left",
|
||||
"leg", "legal", "legend", "leisure", "lemon", "lend", "length", "lens", "leopard", "lesson",
|
||||
"letter", "level", "liar", "liberty", "library", "license", "life", "lift", "light", "like",
|
||||
"limb", "limit", "link", "lion", "liquid", "list", "little", "live", "lizard", "load", "loan",
|
||||
"lobster", "local", "lock", "logic", "lonely", "long", "loop", "lottery", "loud", "lounge",
|
||||
"love", "loyal", "lucky", "luggage", "lumber", "lunar", "lunch", "luxury", "lyrics", "machine",
|
||||
"mad", "magic", "magnet", "maid", "mail", "main", "major", "make", "mammal", "man", "manage",
|
||||
"mandate", "mango", "mansion", "manual", "maple", "marble", "march", "margin", "marine",
|
||||
"market", "marriage", "mask", "mass", "master", "match", "material", "math", "matrix",
|
||||
"matter", "maximum", "maze", "meadow", "mean", "measure", "meat", "mechanic", "medal", "media",
|
||||
"melody", "melt", "member", "memory", "mention", "menu", "mercy", "merge", "merit", "merry",
|
||||
"mesh", "message", "metal", "method", "middle", "midnight", "milk", "million", "mimic", "mind",
|
||||
"minimum", "minor", "minute", "miracle", "mirror", "misery", "miss", "mistake", "mix", "mixed",
|
||||
"mixture", "mobile", "model", "modify", "mom", "moment", "monitor", "monkey", "monster",
|
||||
"month", "moon", "moral", "more", "morning", "mosquito", "mother", "motion", "motor",
|
||||
"mountain", "mouse", "move", "movie", "much", "muffin", "mule", "multiply", "muscle", "museum",
|
||||
"mushroom", "music", "must", "mutual", "myself", "mystery", "myth", "naive", "name", "napkin",
|
||||
"narrow", "nasty", "nation", "nature", "near", "neck", "need", "negative", "neglect",
|
||||
"neither", "nephew", "nerve", "nest", "net", "network", "neutral", "never", "news", "next",
|
||||
"nice", "night", "noble", "noise", "nominee", "noodle", "normal", "north", "nose", "notable",
|
||||
"note", "nothing", "notice", "novel", "now", "nuclear", "number", "nurse", "nut", "oak",
|
||||
"obey", "object", "oblige", "obscure", "observe", "obtain", "obvious", "occur", "ocean",
|
||||
"october", "odor", "off", "offer", "office", "often", "oil", "okay", "old", "olive", "olympic",
|
||||
"omit", "once", "one", "onion", "online", "only", "open", "opera", "opinion", "oppose",
|
||||
"option", "orange", "orbit", "orchard", "order", "ordinary", "organ", "orient", "original",
|
||||
"orphan", "ostrich", "other", "outdoor", "outer", "output", "outside", "oval", "oven", "over",
|
||||
"own", "owner", "oxygen", "oyster", "ozone", "pact", "paddle", "page", "pair", "palace",
|
||||
"palm", "panda", "panel", "panic", "panther", "paper", "parade", "parent", "park", "parrot",
|
||||
"party", "pass", "patch", "path", "patient", "patrol", "pattern", "pause", "pave", "payment",
|
||||
"peace", "peanut", "pear", "peasant", "pelican", "pen", "penalty", "pencil", "people",
|
||||
"pepper", "perfect", "permit", "person", "pet", "phone", "photo", "phrase", "physical",
|
||||
"piano", "picnic", "picture", "piece", "pig", "pigeon", "pill", "pilot", "pink", "pioneer",
|
||||
"pipe", "pistol", "pitch", "pizza", "place", "planet", "plastic", "plate", "play", "please",
|
||||
"pledge", "pluck", "plug", "plunge", "poem", "poet", "point", "polar", "pole", "police",
|
||||
"pond", "pony", "pool", "popular", "portion", "position", "possible", "post", "potato",
|
||||
"pottery", "poverty", "powder", "power", "practice", "praise", "predict", "prefer", "prepare",
|
||||
"present", "pretty", "prevent", "price", "pride", "primary", "print", "priority", "prison",
|
||||
"private", "prize", "problem", "process", "produce", "profit", "program", "project", "promote",
|
||||
"proof", "property", "prosper", "protect", "proud", "provide", "public", "pudding", "pull",
|
||||
"pulp", "pulse", "pumpkin", "punch", "pupil", "puppy", "purchase", "purity", "purpose",
|
||||
"purse", "push", "put", "puzzle", "pyramid", "quality", "quantum", "quarter", "question",
|
||||
"quick", "quit", "quiz", "quote", "rabbit", "raccoon", "race", "rack", "radar", "radio",
|
||||
"rail", "rain", "raise", "rally", "ramp", "ranch", "random", "range", "rapid", "rare", "rate",
|
||||
"rather", "raven", "raw", "razor", "ready", "real", "reason", "rebel", "rebuild", "recall",
|
||||
"receive", "recipe", "record", "recycle", "reduce", "reflect", "reform", "refuse", "region",
|
||||
"regret", "regular", "reject", "relax", "release", "relief", "rely", "remain", "remember",
|
||||
"remind", "remove", "render", "renew", "rent", "reopen", "repair", "repeat", "replace",
|
||||
"report", "require", "rescue", "resemble", "resist", "resource", "response", "result",
|
||||
"retire", "retreat", "return", "reunion", "reveal", "review", "reward", "rhythm", "rib",
|
||||
"ribbon", "rice", "rich", "ride", "ridge", "rifle", "right", "rigid", "ring", "riot", "ripple",
|
||||
"risk", "ritual", "rival", "river", "road", "roast", "robot", "robust", "rocket", "romance",
|
||||
"roof", "rookie", "room", "rose", "rotate", "rough", "round", "route", "royal", "rubber",
|
||||
"rude", "rug", "rule", "run", "runway", "rural", "sad", "saddle", "sadness", "safe", "sail",
|
||||
"salad", "salmon", "salon", "salt", "salute", "same", "sample", "sand", "satisfy", "satoshi",
|
||||
"sauce", "sausage", "save", "say", "scale", "scan", "scare", "scatter", "scene", "scheme",
|
||||
"school", "science", "scissors", "scorpion", "scout", "scrap", "screen", "script", "scrub",
|
||||
"sea", "search", "season", "seat", "second", "secret", "section", "security", "seed", "seek",
|
||||
"segment", "select", "sell", "seminar", "senior", "sense", "sentence", "series", "service",
|
||||
"session", "settle", "setup", "seven", "shadow", "shaft", "shallow", "share", "shed", "shell",
|
||||
"sheriff", "shield", "shift", "shine", "ship", "shiver", "shock", "shoe", "shoot", "shop",
|
||||
"short", "shoulder", "shove", "shrimp", "shrug", "shuffle", "shy", "sibling", "sick", "side",
|
||||
"siege", "sight", "sign", "silent", "silk", "silly", "silver", "similar", "simple", "since",
|
||||
"sing", "siren", "sister", "situate", "six", "size", "skate", "sketch", "ski", "skill", "skin",
|
||||
"skirt", "skull", "slab", "slam", "sleep", "slender", "slice", "slide", "slight", "slim",
|
||||
"slogan", "slot", "slow", "slush", "small", "smart", "smile", "smoke", "smooth", "snack",
|
||||
"snake", "snap", "sniff", "snow", "soap", "soccer", "social", "sock", "soda", "soft", "solar",
|
||||
"soldier", "solid", "solution", "solve", "someone", "song", "soon", "sorry", "sort", "soul",
|
||||
"sound", "soup", "source", "south", "space", "spare", "spatial", "spawn", "speak", "special",
|
||||
"speed", "spell", "spend", "sphere", "spice", "spider", "spike", "spin", "spirit", "split",
|
||||
"spoil", "sponsor", "spoon", "sport", "spot", "spray", "spread", "spring", "spy", "square",
|
||||
"squeeze", "squirrel", "stable", "stadium", "staff", "stage", "stairs", "stamp", "stand",
|
||||
"start", "state", "stay", "steak", "steel", "stem", "step", "stereo", "stick", "still",
|
||||
"sting", "stock", "stomach", "stone", "stool", "story", "stove", "strategy", "street",
|
||||
"strike", "strong", "struggle", "student", "stuff", "stumble", "style", "subject", "submit",
|
||||
"subway", "success", "such", "sudden", "suffer", "sugar", "suggest", "suit", "summer", "sun",
|
||||
"sunny", "sunset", "super", "supply", "supreme", "sure", "surface", "surge", "surprise",
|
||||
"surround", "survey", "suspect", "sustain", "swallow", "swamp", "swap", "swarm", "swear",
|
||||
"sweet", "swift", "swim", "swing", "switch", "sword", "symbol", "symptom", "syrup", "system",
|
||||
"table", "tackle", "tag", "tail", "talent", "talk", "tank", "tape", "target", "task", "taste",
|
||||
"tattoo", "taxi", "teach", "team", "tell", "ten", "tenant", "tennis", "tent", "term", "test",
|
||||
"text", "thank", "that", "theme", "then", "theory", "there", "they", "thing", "this",
|
||||
"thought", "three", "thrive", "throw", "thumb", "thunder", "ticket", "tide", "tiger", "tilt",
|
||||
"timber", "time", "tiny", "tip", "tired", "tissue", "title", "toast", "tobacco", "today",
|
||||
"toddler", "toe", "together", "toilet", "token", "tomato", "tomorrow", "tone", "tongue",
|
||||
"tonight", "tool", "tooth", "top", "topic", "topple", "torch", "tornado", "tortoise", "toss",
|
||||
"total", "tourist", "toward", "tower", "town", "toy", "track", "trade", "traffic", "tragic",
|
||||
"train", "transfer", "trap", "trash", "travel", "tray", "treat", "tree", "trend", "trial",
|
||||
"tribe", "trick", "trigger", "trim", "trip", "trophy", "trouble", "truck", "true", "truly",
|
||||
"trumpet", "trust", "truth", "try", "tube", "tuition", "tumble", "tuna", "tunnel", "turkey",
|
||||
"turn", "turtle", "twelve", "twenty", "twice", "twin", "twist", "two", "type", "typical",
|
||||
"ugly", "umbrella", "unable", "unaware", "uncle", "uncover", "under", "undo", "unfair",
|
||||
"unfold", "unhappy", "uniform", "unique", "unit", "universe", "unknown", "unlock", "until",
|
||||
"unusual", "unveil", "update", "upgrade", "uphold", "upon", "upper", "upset", "urban", "urge",
|
||||
"usage", "use", "used", "useful", "useless", "usual", "utility", "vacant", "vacuum", "vague",
|
||||
"valid", "valley", "valve", "van", "vanish", "vapor", "various", "vast", "vault", "vehicle",
|
||||
"velvet", "vendor", "venture", "venue", "verb", "verify", "version", "very", "vessel",
|
||||
"veteran", "viable", "vibrant", "vicious", "victory", "video", "view", "village", "vintage",
|
||||
"violin", "virtual", "virus", "visa", "visit", "visual", "vital", "vivid", "vocal", "voice",
|
||||
"void", "volcano", "volume", "vote", "voyage", "wage", "wagon", "wait", "walk", "wall",
|
||||
"walnut", "want", "warfare", "warm", "warrior", "wash", "wasp", "waste", "water", "wave",
|
||||
"way", "wealth", "weapon", "wear", "weasel", "weather", "web", "wedding", "weekend", "weird",
|
||||
"welcome", "west", "wet", "whale", "what", "wheat", "wheel", "when", "where", "whip",
|
||||
"whisper", "wide", "width", "wife", "wild", "will", "win", "window", "wine", "wing", "wink",
|
||||
"winner", "winter", "wire", "wisdom", "wise", "wish", "witness", "wolf", "woman", "wonder",
|
||||
"wood", "wool", "word", "work", "world", "worry", "worth", "wrap", "wreck", "wrestle", "wrist",
|
||||
"write", "wrong", "yard", "year", "yellow", "you", "young", "youth", "zebra", "zero", "zone",
|
||||
"zoo",
|
||||
];
|
Loading…
Reference in a new issue