diff --git a/Cargo.lock b/Cargo.lock index a9db432..400e21d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,17 +257,26 @@ 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" @@ -275,12 +284,12 @@ dependencies = [ "anyhow", "async-trait", "async-tungstenite", + "e4mc-common", "env_logger", "futures", "lazy_static", "log", - "nanoid", - "serde", + "rand", "serde_json", "thiserror", "tokio", @@ -582,15 +591,6 @@ 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" diff --git a/Cargo.toml b/Cargo.toml index 830d036..c053b1f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,5 @@ members = [ "server", "client", + "common" ] diff --git a/client/Cargo.toml b/client/Cargo.toml index b921a42..d4df228 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -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"} \ No newline at end of file diff --git a/client/src/main.rs b/client/src/main.rs index 7eadbbb..7b0e036 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -1,186 +1,162 @@ -use std::{collections::HashMap, net::SocketAddr}; +use std::collections::HashMap; -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}; -use serde::{Deserialize, Serialize}; +use log::{error, info, trace, warn}; +use tokio::io::{AsyncReadExt, AsyncWriteExt}; +use tokio::net::TcpStream; +use tokio::net::tcp::{WriteHalf, ReadHalf}; use tokio::{ - io::{AsyncReadExt, AsyncWriteExt}, - net::{ - tcp::{OwnedReadHalf, OwnedWriteHalf}, - TcpStream, - }, sync::mpsc::{UnboundedReceiver, UnboundedSender}, sync::RwLock, - task, }; -enum ChannelHandlerMessage { - Data(Vec), - Shutdown, -} - lazy_static! { - static ref CHANNEL_MAP: RwLock>> = + static ref CHANNEL_MAP: RwLock>> = RwLock::new(HashMap::new()); } +/// Simple program to greet a person +#[derive(Parser, Debug)] +struct Args { + /// Port of Minecraft server + #[arg(short, long, default_value_t = 25565)] + port: u16, + + /// Address of e4mc-server instance + #[arg(short, long)] + server: Option, +} #[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 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); - } - } - } - _ => {} - } + 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); } - Ok(()) as anyhow::Result<()> }, - async move { - while let Some(message) = receiver.recv().await { - send.send(message.clone()).await?; + res = handle_recv(recv, sender, args.port) => { + if let Err(e) = res { + error!("Error in recv loop: {}", e); } - Ok(()) as anyhow::Result<()> } - )?; + } Ok(()) } -async fn handle_channel( - id: u8, - sender: UnboundedSender, - mut conn: TcpStream, - mut recv: UnboundedReceiver, +async fn handle_send( + mut send: SplitSink, Message>, + mut receiver: UnboundedReceiver, ) -> 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?; + while let Some(message) = receiver.recv().await { + send.send(message).await?; + } Ok(()) } -use clap::Parser; +#[derive(Debug, Clone, PartialEq, Eq)] +enum ChannelTaskMessage { + Close, + Data(Vec), +} -/// Simple program to greet a person -#[derive(Parser, Debug)] -struct Args { - /// Port of Minecraft server - #[arg(short, long, default_value_t = 25565)] +async fn handle_recv( + mut recv: SplitStream>, + sender: UnboundedSender, port: u16, - - /// Address of e4mc-server instance - #[arg(short, long)] - server: Option, +) -> 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(()) } -#[derive(Deserialize)] -enum ClientboundControlMessage { - DomainAssigned(String), - ChannelOpen(u8, SocketAddr), - ChannelClosed(u8), +async fn handle_channel(mut stream: TcpStream, sender: UnboundedSender, channel: u8, recv: UnboundedReceiver) { + 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); } -#[derive(Serialize)] -enum ServerboundControlMessage { - ChannelClosed(u8), +async fn handle_channel_send(mut write: WriteHalf<'_>, mut recv: UnboundedReceiver) -> 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, 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))?; + } +} \ No newline at end of file diff --git a/client/src/netty.rs b/client/src/netty.rs deleted file mode 100644 index e6a0206..0000000 --- a/client/src/netty.rs +++ /dev/null @@ -1,233 +0,0 @@ -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 for NettyReadError { - fn from(value: std::io::Error) -> Self { - Self::IoError(value) - } -} - -impl From 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 { - 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 { - let mut buf = [0u8]; - self.read_exact(&mut buf).await?; - Ok(i8::from_be_bytes(buf)) - } - - async fn read_unsigned_byte(&mut self) -> Result { - let mut buf = [0u8]; - self.read_exact(&mut buf).await?; - Ok(buf[0]) - } - - async fn read_short(&mut self) -> Result { - 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 { - let mut buf = [0u8; 2]; - self.read_exact(&mut buf).await?; - Ok(u16::from_be_bytes(buf)) - } - - async fn read_int(&mut self) -> Result { - let mut buf = [0u8; 4]; - self.read_exact(&mut buf).await?; - Ok(i32::from_be_bytes(buf)) - } - - async fn read_long(&mut self) -> Result { - let mut buf = [0u8; 8]; - self.read_exact(&mut buf).await?; - Ok(i64::from_be_bytes(buf)) - } - - async fn read_float(&mut self) -> Result { - let mut buf = [0u8; 4]; - self.read_exact(&mut buf).await?; - Ok(f32::from_be_bytes(buf)) - } - - async fn read_double(&mut self) -> Result { - let mut buf = [0u8; 8]; - self.read_exact(&mut buf).await?; - Ok(f64::from_be_bytes(buf)) - } - - async fn read_string(&mut self) -> Result { - 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 { - 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 { - // 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 { - 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 { - let mut buf = [0u8; 16]; - self.read_exact(&mut buf).await?; - Ok(u128::from_be_bytes(buf)) - } - - async fn read_packet(&mut self) -> Result, 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, 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 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 WriteExtNetty for T {} diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000..0ce6952 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,11 @@ +[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" \ No newline at end of file diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000..67d0c70 --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,27 @@ +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 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 for async_tungstenite::tungstenite::Message { + fn from(val: ServerboundControlMessage) -> Self { + async_tungstenite::tungstenite::Message::Text(serde_json::to_string(&val).unwrap()) + } +} diff --git a/server/Cargo.toml b/server/Cargo.toml index 9dd4603..39111e8 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -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" diff --git a/server/src/main.rs b/server/src/main.rs index 26ad940..f630fb2 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -1,24 +1,29 @@ -use std::collections::{HashMap}; +use std::collections::HashMap; use std::env; use std::net::SocketAddr; use anyhow::{anyhow, Result}; -use futures::{SinkExt, StreamExt}; -use tokio::io::{AsyncReadExt, AsyncWriteExt}; -use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender}; -use tokio::net::{TcpListener, TcpStream}; -use tokio::sync::RwLock; -use tokio::task; +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}; -use nanoid::nanoid; +use log::{error, info, trace, warn}; use netty::ReadExtNetty; -use serde::{Deserialize, Serialize}; +use rand::seq::SliceRandom; +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::task; use crate::netty::{NettyReadError, WriteExtNetty}; mod netty; +mod wordlist; #[derive(Debug, Clone)] struct Handshake { @@ -28,7 +33,7 @@ struct Handshake { next_state: HandshakeType, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Copy)] #[repr(i32)] enum HandshakeType { Status = 1, @@ -43,7 +48,7 @@ impl Handshake { } else { let protocol_version = packet.read_varint().await?; let server_address = packet.read_string().await?; - let server_port = packet.read_unsigned_short().await?; + let server_port = packet.read_u16().await?; let next_state = match packet.read_varint().await? { 1 => HandshakeType::Status, 2 => HandshakeType::Login, @@ -57,10 +62,38 @@ 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>, + backchannel: UnboundedSender, + addr: SocketAddr, + }, + ChannelClose(u8), + Data(Vec), +} + +#[derive(Debug, Clone, PartialEq, Eq)] +enum MinecraftHandlerMessage { + ChannelClose, + Data(Vec), } lazy_static! { - static ref EXPOSER_MAP: RwLock>> = + static ref ROUTING_MAP: RwLock>> = RwLock::new(HashMap::new()); static ref BASE_DOMAIN: String = env::var("BASE_DOMAIN").expect("BASE_DOMAIN missing"); } @@ -77,7 +110,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_ws_connection(stream).await { + if let Err(e) = accept_websocket_connection(stream).await { error!("Error handling WebSocket connection: {}", e); } }); @@ -89,7 +122,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_mc_connection(stream).await { + if let Err(e) = accept_minecraft_connection(stream).await { error!("Error handling Minecraft connection: {}", e); } }); @@ -101,254 +134,256 @@ async fn main() -> Result<()> { Ok(()) } -#[derive(Serialize)] -enum ClientboundControlMessage { - DomainAssigned(String), - ChannelOpen(u8, SocketAddr), - ChannelClosed(u8), +struct RoutingHandle { + receiver: UnboundedReceiver, + domain: String, } -#[derive(Deserialize)] -enum ServerboundControlMessage { - ChannelClosed(u8), -} - -struct ExposerMapHandle(String, UnboundedReceiver<(Handshake, TcpStream, SocketAddr)>); - -impl ExposerMapHandle { +impl RoutingHandle { async fn new(domain: String) -> Self { let (sender, receiver) = tokio::sync::mpsc::unbounded_channel(); - EXPOSER_MAP.write().await.insert(domain.clone(), sender); - Self(domain, receiver) + ROUTING_MAP.write().await.insert(domain.clone(), sender); + Self { receiver, domain } } - async fn recv(&mut self) -> Option<(Handshake, TcpStream, SocketAddr)> { - self.1.recv().await + async fn recv(&mut self) -> Option { + self.receiver.recv().await } } -impl Drop for ExposerMapHandle { +impl Drop for RoutingHandle { fn drop(&mut self) { - let domain = self.0.clone(); - task::spawn(async move { - EXPOSER_MAP.write().await.remove(&domain); + let domain = self.domain.clone(); + tokio::spawn(async move { + ROUTING_MAP.write().await.remove(&domain); }); } } -struct ChannelHandle( - u8, - UnboundedReceiver, - UnboundedSender, -); - -impl ChannelHandle { - async fn new( - id: u8, - addr: SocketAddr, - send: UnboundedSender, - ) -> Result { - 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)) - } - - async fn recv(&mut self) -> Option { - self.1.recv().await - } -} - -impl Drop for ChannelHandle { - fn drop(&mut self) { - self.2.send(WebsocketConnectionMessage::Close(self.0)).map_err(|e| anyhow::anyhow!("{}", e)).unwrap(); - } -} - -enum MinecraftConnectionMessage { - Data(Vec), - Close, -} - -enum WebsocketConnectionMessage { - Data(Vec), - Close(u8), - Open(u8, SocketAddr, UnboundedSender), -} - -async fn accept_ws_connection(stream: TcpStream) -> Result<()> { +async fn accept_websocket_connection(stream: TcpStream) -> Result<()> { let addr = stream.peer_addr()?; - info!("WebSocker Peer address: {}", addr); + info!("WebSocket 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); + let domain = get_random_domain().await; ws_stream - .send(Message::Text(serde_json::to_string( - &ClientboundControlMessage::DomainAssigned(domain.clone()), - )?)) + .send(ClientboundControlMessage::DomainAssigned(domain.clone()).into()) .await?; - drop(exposer_map); + let handle = RoutingHandle::new(domain.clone()).await; - let mut exposer_handle = ExposerMapHandle::new(domain.clone()).await; + let channel_table = Mutex::new(HashMap::new()); - let channel_map = &RwLock::new(HashMap::new()); + let (mut write, mut read) = ws_stream.split(); - let (sender, mut receiver) = tokio::sync::mpsc::unbounded_channel(); - let (mut send, mut recv) = 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); + } + } + } - 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), - )?)) + let _ = write.reunite(read)?.close(None).await; // if this errors, why bother? + + Ok(()) +} + +async fn handle_websocket_send( + write: &mut SplitSink>, Message>, + channel_table: &Mutex>>, + 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?; - 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))?; - } - } - _ => {} - } + WebsocketHandlerMessage::ChannelClose(channel) => { + write + .send(ClientboundControlMessage::ChannelClosed(channel).into()) + .await?; + channel_table.lock().await.remove(&channel); } - 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, - )); - } + WebsocketHandlerMessage::Data(buf) => { + write.send(Message::Binary(buf)).await?; } - Ok(()) as Result<()> } - )?; + } Ok(()) } -async fn handle_sent_connection( - handshake: Handshake, - mut mc_stream: TcpStream, - addr: SocketAddr, - send: UnboundedSender, - channel_id: u8, +async fn handle_websocket_recv( + read: &mut SplitStream>>, + channel_table: &Mutex>>, ) -> 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 { + 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 { - MinecraftConnectionMessage::Data(buf) => { - write.write_all(&buf).await?; - } - MinecraftConnectionMessage::Close => { - return Ok(()) + ServerboundControlMessage::ChannelClosed(channel) => { + if let Some(sender) = channel_table.lock().await.remove(&channel) { + sender.send(MinecraftHandlerMessage::ChannelClose)?; + } } } } - Ok(()) as anyhow::Result<()> - } => {} - ); - mc_stream.shutdown().await?; + 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(()) } -async fn accept_mc_connection(mut stream: TcpStream) -> Result<()> { +struct ChannelHandle { + receiver: UnboundedReceiver, + sender: UnboundedSender, + channel: u8, +} + +impl ChannelHandle { + async fn new( + sender: &UnboundedSender, + addr: SocketAddr, + ) -> Result { + 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")) + } + } + + fn send(&self, mut buf: Vec) -> Result<()> { + buf.insert(0, self.channel); + self.sender.send(WebsocketHandlerMessage::Data(buf))?; + Ok(()) + } + + async fn recv(&mut self) -> Option { + 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, + channel: u8, +} + +impl ChannelHandleSend<'_> { + fn send(&self, mut buf: Vec) -> Result<()> { + buf.insert(0, self.channel); + self.sender.send(WebsocketHandlerMessage::Data(buf))?; + Ok(()) + } +} + +struct ChannelHandleRecv<'a> { + receiver: &'a mut UnboundedReceiver, +} + +impl ChannelHandleRecv<'_> { + async fn recv(&mut self) -> Option { + self.receiver.recv().await + } +} + +impl Drop for ChannelHandle { + fn drop(&mut self) { + self.sender + .send(WebsocketHandlerMessage::ChannelClose(self.channel)) + .unwrap(); + } +} + +async fn accept_minecraft_connection(mut stream: TcpStream) -> Result<()> { let addr = stream.peer_addr()?; - info!("New Minecraft connection: {}", addr); + info!("Minecraft Peer address: {}", 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 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))?; + 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?; } else { match handshake.next_state { HandshakeType::Status => { @@ -373,18 +408,53 @@ async fn accept_mc_connection(mut stream: TcpStream) -> Result<()> { 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_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(()) +} + +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)?; + } +} -fn get_random_domain() -> String { - format!( - "{}.{}", - nanoid!(ID_LENGTH, &ID_ALPHABET), +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(), 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) -> Option { diff --git a/server/src/netty.rs b/server/src/netty.rs index 334e526..a4f2627 100644 --- a/server/src/netty.rs +++ b/server/src/netty.rs @@ -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,64 +26,6 @@ impl From for NettyReadError { #[async_trait] pub trait ReadExtNetty: AsyncReadExt + Unpin { - async fn read_bool(&mut self) -> Result { - 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 { - let mut buf = [0u8]; - self.read_exact(&mut buf).await?; - Ok(i8::from_be_bytes(buf)) - } - - async fn read_unsigned_byte(&mut self) -> Result { - let mut buf = [0u8]; - self.read_exact(&mut buf).await?; - Ok(buf[0]) - } - - async fn read_short(&mut self) -> Result { - 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 { - let mut buf = [0u8; 2]; - self.read_exact(&mut buf).await?; - Ok(u16::from_be_bytes(buf)) - } - - async fn read_int(&mut self) -> Result { - let mut buf = [0u8; 4]; - self.read_exact(&mut buf).await?; - Ok(i32::from_be_bytes(buf)) - } - - async fn read_long(&mut self) -> Result { - let mut buf = [0u8; 8]; - self.read_exact(&mut buf).await?; - Ok(i64::from_be_bytes(buf)) - } - - async fn read_float(&mut self) -> Result { - let mut buf = [0u8; 4]; - self.read_exact(&mut buf).await?; - Ok(f32::from_be_bytes(buf)) - } - - async fn read_double(&mut self) -> Result { - let mut buf = [0u8; 8]; - self.read_exact(&mut buf).await?; - Ok(f64::from_be_bytes(buf)) - } - async fn read_string(&mut self) -> Result { let len = self.read_varint().await?; let mut buf = vec![0u8; len as usize]; @@ -91,11 +33,10 @@ pub trait ReadExtNetty: AsyncReadExt + Unpin { String::from_utf8(buf).map_err(|_| std::io::ErrorKind::InvalidData.into()) } - async fn read_varint(&mut self) -> Result { let mut res = 0i32; for i in 0..5 { - let part = self.read_unsigned_byte().await?; + let part = self.read_u8().await?; res |= (part as i32 & 0x7F) << (7 * i); if part & 0x80 == 0 { return Ok(res); @@ -105,72 +46,6 @@ pub trait ReadExtNetty: AsyncReadExt + Unpin { Err(std::io::ErrorKind::InvalidData.into()) } - // async fn read_varint(&mut self) -> Result { - // 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 { - 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 { - let mut buf = [0u8; 16]; - self.read_exact(&mut buf).await?; - Ok(u128::from_be_bytes(buf)) - } - async fn read_packet(&mut self) -> Result, NettyReadError> { let len = self.read_varint().await?; let mut buf = vec![0u8; len as usize]; diff --git a/server/src/wordlist.rs b/server/src/wordlist.rs new file mode 100644 index 0000000..ef23aba --- /dev/null +++ b/server/src/wordlist.rs @@ -0,0 +1,213 @@ +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", +];