ratel-rust

Crates.ioratel-rust
lib.rsratel-rust
version0.1.1
created_at2026-01-20 16:10:35.44294+00
updated_at2026-01-20 17:22:01.932603+00
descriptionA Rust implementation of Ratel the landlord game client.
homepage
repository
max_upload_size
id2056927
size73,169
Abby (abbychau)

documentation

README

Ratel Rust Client

A Rust implementation of the Ratel client library, rewritten from Go to Rust with PTY interface support.

Features

  • TCP and WebSocket connections support
  • Interactive shell interface
  • PTY (pseudo-terminal) support for terminal I/O
  • Async/await with Tokio
  • User authentication
  • Random name generation

Quick Start

Running Example

cargo run --release --example basic -- <host:port>

Example:

cargo run --release --example basic -- 192.252.182.94:9999

Usage

As a Library

Add this to your Cargo.toml:

[dependencies]
ratel-rust = { path = "/path/to/ratel-rust" }

Basic usage:

use ratel_rust::RatelClient;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Create a new client with address and optional name
    let mut client = RatelClient::new(
        "127.0.0.1:9999".to_string(),
        Some("my_name".to_string())
    );
    
    // Start the client (will connect, authenticate, and listen)
    client.start().await?;
    
    Ok(())
}

Running the Example

cargo run --example basic

Project Structure

  • src/lib.rs - Main library entry point
  • src/model.rs - Data models (AuthInfo, Packet, etc.)
  • src/network.rs - Network connections (TCP and WebSocket)
  • src/shell.rs - Shell logic and listener
  • src/util.rs - Utility functions (random name generation, etc.)
  • src/pty.rs - PTY interface for terminal I/O

Network Types

The client automatically detects the network type based on the port:

  • Ports ending with 9998 → WebSocket
  • All other ports → TCP

Authentication

The client uses an AuthInfo structure containing:

  • id: Unique user ID (auto-generated timestamp)
  • name: Username (auto-generated if not provided)
  • score: User score (default: 100)

Documentation

Development

Building

cargo build

Running Tests

cargo test

Checking Code

cargo check

Dependencies

  • tokio - Async runtime
  • tokio-tungstenite - WebSocket support
  • serde - Serialization
  • anyhow - Error handling
  • crossterm - Terminal handling
  • pty-process - PTY support

License

This project is a Rust port of the original Go Ratel client.

Commit count: 0

cargo fmt