aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--azalea-client/src/connect.rs18
-rw-r--r--azalea-core/Cargo.toml1
-rw-r--r--azalea-core/src/game_type.rs60
-rw-r--r--azalea-core/src/lib.rs1
-rw-r--r--azalea-protocol/src/packets/game/clientbound_login_packet.rs (renamed from azalea-protocol/src/packets/game/ClientboundLoginPacket.rs)18
-rw-r--r--azalea-protocol/src/packets/game/mod.rs12
-rw-r--r--azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs1
-rw-r--r--azalea-protocol/src/packets/login/mod.rs7
9 files changed, 100 insertions, 19 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c91c963f..c4ecf771 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -76,6 +76,7 @@ dependencies = [
name = "azalea-core"
version = "0.1.0"
dependencies = [
+ "azalea-chat",
"uuid",
]
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs
index 07c2e0d0..94c800f6 100644
--- a/azalea-client/src/connect.rs
+++ b/azalea-client/src/connect.rs
@@ -56,7 +56,23 @@ pub async fn join_server(address: &ServerAddress) -> Result<(), String> {
};
// game
- panic!("ok i haven't implemented game yet");
+ loop {
+ let packet_result = conn.read().await;
+ match packet_result {
+ Ok(packet) => match packet {
+ GamePacket::ClientboundKeepAlivePacket(p) => {
+ println!("Got keep alive packet {:?}", p.keep_alive_id);
+ }
+ GamePacket::ClientboundChatMessagePacket(p) => {
+ println!("Got chat message packet {:?}", p.message);
+ }
+ _ => panic!("unhandled packet"),
+ },
+ Err(e) => {
+ println!("Error: {:?}", e);
+ }
+ }
+ }
Ok(())
}
diff --git a/azalea-core/Cargo.toml b/azalea-core/Cargo.toml
index 1aa59fe9..b0139999 100644
--- a/azalea-core/Cargo.toml
+++ b/azalea-core/Cargo.toml
@@ -6,4 +6,5 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+azalea-chat = {path = "../azalea-chat"}
uuid = "^0.8.2"
diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs
new file mode 100644
index 00000000..b0ca6a2d
--- /dev/null
+++ b/azalea-core/src/game_type.rs
@@ -0,0 +1,60 @@
+use azalea_chat;
+
+#[derive(Hash, Clone, Debug)]
+pub enum GameType {
+ SURVIVAL,
+ CREATIVE,
+ ADVENTURE,
+ SPECTATOR,
+}
+
+impl GameType {
+ fn to_id(&self) -> u8 {
+ match self {
+ GameType::SURVIVAL => 0,
+ GameType::CREATIVE => 1,
+ GameType::ADVENTURE => 2,
+ GameType::SPECTATOR => 3,
+ }
+ }
+
+ fn from_id(id: u8) -> GameType {
+ match id {
+ 0 => GameType::SURVIVAL,
+ 1 => GameType::CREATIVE,
+ 2 => GameType::ADVENTURE,
+ 3 => GameType::SPECTATOR,
+ _ => panic!("Unknown game type id: {}", id),
+ }
+ }
+
+ fn short_name(&self) -> &'static str {
+ // TODO: these should be translated TranslatableComponent("selectWorld.gameMode." + string2)
+ match self {
+ GameType::SURVIVAL => "Survival",
+ GameType::CREATIVE => "Creative",
+ GameType::ADVENTURE => "Adventure",
+ GameType::SPECTATOR => "Spectator",
+ }
+ }
+
+ fn long_name(&self) -> &'static str {
+ // TODO: These should be translated TranslatableComponent("gameMode." + string2);
+ match self {
+ GameType::SURVIVAL => "Survival Mode",
+ GameType::CREATIVE => "Creative Mode",
+ GameType::ADVENTURE => "Adventure Mode",
+ GameType::SPECTATOR => "Spectator Mode",
+ }
+ }
+
+ fn from_name(name: &str) -> GameType {
+ match name {
+ "survival" => GameType::SURVIVAL,
+ "creative" => GameType::CREATIVE,
+ "adventure" => GameType::ADVENTURE,
+ "spectator" => GameType::SPECTATOR,
+ _ => panic!("Unknown game type name: {}", name),
+ }
+ }
+}
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index dbe08afb..887d1686 100644
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -1,5 +1,6 @@
//! Random miscellaneous things like UUIDs that don't deserve their own crate.
+pub mod game_type;
pub mod resource_location;
pub mod serializable_uuid;
diff --git a/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs b/azalea-protocol/src/packets/game/clientbound_login_packet.rs
index ec869faa..fc701d9d 100644
--- a/azalea-protocol/src/packets/game/ClientboundLoginPacket.rs
+++ b/azalea-protocol/src/packets/game/clientbound_login_packet.rs
@@ -1,12 +1,11 @@
use super::GamePacket;
use crate::mc_buf::{Readable, Writable};
-use azalea_core::resource_location::ResourceLocation;
+use azalea_core::{game_type::GameType, resource_location::ResourceLocation};
use std::hash::Hash;
-use tokio::io::BufReader;
#[derive(Hash, Clone, Debug)]
pub struct ClientboundLoginPacket {
- // private final int playerId;
+ // private final int playerId;
// private final boolean hardcore;
// private final GameType gameType;
// @Nullable
@@ -23,7 +22,12 @@ pub struct ClientboundLoginPacket {
// private final boolean showDeathScreen;
// private final boolean isDebug;
// private final boolean isFlat;
-
+ pub player_id: i32,
+ pub hardcore: bool,
+ pub game_type: GameType,
+ pub previous_game_type: Option<GameType>,
+ pub levels: Vec<ResourceLocation>,
+ pub registry_holder: azalea_core::registry::RegistryAccess,
}
impl ClientboundLoginPacket {
@@ -32,9 +36,9 @@ impl ClientboundLoginPacket {
}
pub fn write(&self, buf: &mut Vec<u8>) {
- buf.write_varint(self.transaction_id as i32).unwrap();
- buf.write_utf(self.identifier.to_string().as_str()).unwrap();
- buf.write_bytes(&self.data).unwrap();
+ buf.write_int(self.player_id);
+ buf.write_bool(self.hardcore);
+ // buf.write_byte(self.game_type.
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
diff --git a/azalea-protocol/src/packets/game/mod.rs b/azalea-protocol/src/packets/game/mod.rs
index 0391a6b1..73f66c33 100644
--- a/azalea-protocol/src/packets/game/mod.rs
+++ b/azalea-protocol/src/packets/game/mod.rs
@@ -1,9 +1,9 @@
-use async_trait::async_trait;
-use tokio::io::BufReader;
-
-use crate::connect::PacketFlow;
+pub mod clientbound_login_packet;
use super::ProtocolPacket;
+use crate::connect::PacketFlow;
+use async_trait::async_trait;
+use tokio::io::BufReader;
#[derive(Clone, Debug)]
pub enum GamePacket
@@ -13,7 +13,9 @@ where
#[async_trait]
impl ProtocolPacket for GamePacket {
fn id(&self) -> u32 {
- 0x00
+ match self {
+ GamePacket::ClientboundLoginPacket(_packet) => 0x00,
+ }
}
fn write(&self, _buf: &mut Vec<u8>) {}
diff --git a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
index ed9820ef..2bc1fc1e 100644
--- a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
+++ b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs
@@ -2,7 +2,6 @@ use super::LoginPacket;
use crate::mc_buf::{Readable, Writable};
use azalea_core::resource_location::ResourceLocation;
use std::hash::Hash;
-use tokio::io::BufReader;
#[derive(Hash, Clone, Debug)]
pub struct ClientboundCustomQueryPacket {
diff --git a/azalea-protocol/src/packets/login/mod.rs b/azalea-protocol/src/packets/login/mod.rs
index 377a285a..65d94bed 100644
--- a/azalea-protocol/src/packets/login/mod.rs
+++ b/azalea-protocol/src/packets/login/mod.rs
@@ -4,12 +4,9 @@ pub mod clientbound_hello_packet;
pub mod clientbound_login_compression_packet;
pub mod serverbound_hello_packet;
-use async_trait::async_trait;
-use tokio::io::BufReader;
-
-use crate::connect::PacketFlow;
-
use super::ProtocolPacket;
+use crate::connect::PacketFlow;
+use async_trait::async_trait;
#[derive(Clone, Debug)]
pub enum LoginPacket