ratel-rust 0.1.1

A Rust implementation of Ratel the landlord game client.
Documentation
# 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

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

Example:
```bash
cargo run --release --example basic -- 192.252.182.94:9999
```

## Usage

### As a Library

Add this to your `Cargo.toml`:

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

Basic usage:

```rust
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

```bash
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

- **[PtyManager Guide]PtyManager.md** - Complete reference for PTY I/O management

## Development

### Building

```bash
cargo build
```

### Running Tests

```bash
cargo test
```

### Checking Code

```bash
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.