fix brand reading and more debug messages

This commit is contained in:
MeexReay 2025-05-07 18:54:00 +03:00
parent 0266958443
commit 934ca660c4
2 changed files with 31 additions and 26 deletions

View File

@ -239,18 +239,26 @@ pub fn get_offline_uuid(name: &str) -> Uuid {
Uuid::new_v3(&namespace, (&name[2..]).as_bytes()) Uuid::new_v3(&namespace, (&name[2..]).as_bytes())
} }
pub fn send_rainbow_message(
client: &Arc<ClientContext>,
message: String,
) -> Result<(), ServerError> {
send_system_message(client.clone(), TextComponent::rainbow(message), false)
}
// Отдельная функция для работы с самой игрой // Отдельная функция для работы с самой игрой
pub fn handle_play_state( pub fn handle_play_state(
client: Arc<ClientContext>, // Контекст клиента client: Arc<ClientContext>, // Контекст клиента
) -> Result<(), ServerError> { ) -> Result<(), ServerError> {
client.set_entity_info(EntityInfo::new( let player_name = client.player_info().unwrap().name;
client let player_uuid = get_offline_uuid(&client.player_info().unwrap().name); // TODO: authenticated uuid
.server let entity_id = client
.world .server
.entity_id_counter .world
.fetch_add(1, Ordering::SeqCst), .entity_id_counter
get_offline_uuid(&client.player_info().unwrap().name), // TODO: authenticated uuid .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 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)?; // 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( send_rainbow_message(&client, format!("Your IP: {}", client.addr))?;
client.clone(), send_rainbow_message(
TextComponent::rainbow(format!("Your Name: {}", client.player_info().unwrap().name)), &client,
false, format!("Your brand: {}", client.client_info().unwrap().brand),
)?; )?;
send_system_message( send_rainbow_message(
client.clone(), &client,
TextComponent::rainbow(format!( format!("Your locale: {}", client.client_info().unwrap().locale),
"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 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() { for player in client.server.players() {
if client.addr == player.addr { if client.addr == player.addr {

View File

@ -1,4 +1,7 @@
use std::{io::Read, sync::Arc}; use std::{
io::{Cursor, Read},
sync::Arc,
};
use crate::{ use crate::{
ServerError, ServerError,
@ -129,7 +132,7 @@ pub fn handle_connection(
packet.get_mut().read_to_end(&mut data).unwrap(); packet.get_mut().read_to_end(&mut data).unwrap();
if identifier == "minecraft:brand" { if identifier == "minecraft:brand" {
break String::from_utf8_lossy(&data).to_string(); break Cursor::new(data).read_string()?;
} else { } else {
trigger_event!(client, plugin_message, &identifier, &data); trigger_event!(client, plugin_message, &identifier, &data);
} }