| Crates.io | minechat-protocol |
| lib.rs | minechat-protocol |
| version | 0.3.0 |
| created_at | 2025-03-06 12:47:35.79831+00 |
| updated_at | 2025-03-07 09:18:35.251636+00 |
| description | The MineChat protocol, enabling you chat with people over on Minecraft |
| homepage | |
| repository | https://github.com/walker84837/minechat-protocol |
| max_upload_size | |
| id | 1581081 |
| size | 42,106 |
MineChat is a Rust library designed to facilitate communication with a Minecraft chat server. It provides asynchronous functions to send and receive messages, handle authentication, and manage connections.
tokio for asynchronous I/O operations.To send a message to the server, use the send_message function:
use minechat_protocol::{send_message, MineChatMessage};
use tokio::net::TcpStream;
#[tokio::main]
async fn main() {
let server_addr = "127.0.0.1:8080";
let mut stream = TcpStream::connect(server_addr).await.unwrap();
let (mut reader, mut writer) = stream.split();
let message = MineChatMessage::Chat {
payload: ChatPayload {
message: "Hello, server!".to_string(),
},
};
if let Err(e) = send_message(&mut writer, &message).await {
eprintln!("Failed to send message: {}", e);
}
}
To receive a message from the server, use the receive_message function:
use minechat_protocol::receive_message;
use tokio::net::TcpStream;
use tokio::io::BufReader;
#[tokio::main]
async fn main() {
let server_addr = "127.0.0.1:8080";
let mut stream = TcpStream::connect(server_addr).await.unwrap();
let (reader, _) = stream.split();
let mut reader = BufReader::new(reader);
match receive_message(&mut reader).await {
Ok(message) => println!("Received message: {:?}", message),
Err(e) => eprintln!("Failed to receive message: {}", e),
}
}
To handle linking with the server, use the handle_link function:
use minechat_protocol::handle_link;
#[tokio::main]
async fn main() {
let server_addr = "127.0.0.1:8080";
let link_code = "your_link_code";
match handle_link(server_addr, link_code).await {
Ok((server, client_uuid)) => {
println!("Linked successfully to server {} with client UUID {}", server, client_uuid);
}
Err(e) => eprintln!("Failed to link: {}", e),
}
}
This project is licensed under the MPL-2.0 License. See the LICENSE file for more details.
Contributions are welcome! Please open an issue or submit a pull request.
For any questions or support, please open an issue on the GitHub repository.