mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
start adding clientbound_login_packet
This commit is contained in:
parent
498077e09f
commit
8e3ba097b4
9 changed files with 100 additions and 19 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -76,6 +76,7 @@ dependencies = [
|
|||
name = "azalea-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"azalea-chat",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
60
azalea-core/src/game_type.rs
Normal file
60
azalea-core/src/game_type.rs
Normal file
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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>(
|
|
@ -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>) {}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue