From 934ca660c407aff583c070f5b1bd4bcccb8fd4ce Mon Sep 17 00:00:00 2001 From: MeexReay Date: Wed, 7 May 2025 18:54:00 +0300 Subject: [PATCH] fix brand reading and more debug messages --- src/play/mod.rs | 50 +++++++++++++++++++++-------------------- src/protocol/handler.rs | 7 ++++-- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/play/mod.rs b/src/play/mod.rs index 930fd84..70a9e66 100644 --- a/src/play/mod.rs +++ b/src/play/mod.rs @@ -239,18 +239,26 @@ pub fn get_offline_uuid(name: &str) -> Uuid { Uuid::new_v3(&namespace, (&name[2..]).as_bytes()) } +pub fn send_rainbow_message( + client: &Arc, + message: String, +) -> Result<(), ServerError> { + send_system_message(client.clone(), TextComponent::rainbow(message), false) +} + // Отдельная функция для работы с самой игрой pub fn handle_play_state( client: Arc, // Контекст клиента ) -> Result<(), ServerError> { - client.set_entity_info(EntityInfo::new( - client - .server - .world - .entity_id_counter - .fetch_add(1, Ordering::SeqCst), - get_offline_uuid(&client.player_info().unwrap().name), // TODO: authenticated uuid - )); + let player_name = client.player_info().unwrap().name; + let player_uuid = get_offline_uuid(&client.player_info().unwrap().name); // TODO: authenticated uuid + let entity_id = client + .server + .world + .entity_id_counter + .fetch_add(1, Ordering::SeqCst); + + client.set_entity_info(EntityInfo::new(entity_id, player_uuid)); client.entity_info().set_position((8.0, 0.0, 8.0)); // set 8 0 8 as position @@ -276,24 +284,18 @@ pub fn handle_play_state( // sync_player_pos(client.clone(), 8.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0)?; - send_system_message( - client.clone(), - TextComponent::rainbow(format!("Your Name: {}", client.player_info().unwrap().name)), - false, + send_rainbow_message(&client, format!("Your IP: {}", client.addr))?; + send_rainbow_message( + &client, + format!("Your brand: {}", client.client_info().unwrap().brand), )?; - send_system_message( - client.clone(), - TextComponent::rainbow(format!( - "Your Entity ID: {}", - client.entity_info().entity_id - )), - false, - )?; - send_system_message( - client.clone(), - TextComponent::rainbow(format!("Your UUID: {}", client.entity_info().uuid)), - false, + send_rainbow_message( + &client, + format!("Your locale: {}", client.client_info().unwrap().locale), )?; + send_rainbow_message(&client, format!("Your UUID: {}", client.entity_info().uuid))?; + send_rainbow_message(&client, format!("Your Name: {}", &player_name))?; + send_rainbow_message(&client, format!("Your Entity ID: {}", entity_id))?; for player in client.server.players() { if client.addr == player.addr { diff --git a/src/protocol/handler.rs b/src/protocol/handler.rs index 70301d5..71fdba2 100644 --- a/src/protocol/handler.rs +++ b/src/protocol/handler.rs @@ -1,4 +1,7 @@ -use std::{io::Read, sync::Arc}; +use std::{ + io::{Cursor, Read}, + sync::Arc, +}; use crate::{ ServerError, @@ -129,7 +132,7 @@ pub fn handle_connection( packet.get_mut().read_to_end(&mut data).unwrap(); if identifier == "minecraft:brand" { - break String::from_utf8_lossy(&data).to_string(); + break Cursor::new(data).read_string()?; } else { trigger_event!(client, plugin_message, &identifier, &data); }