1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! # factorio-rcon
//!
//! Async RCON client for Factorio with proper multi-packet response handling.
//!
//! Factorio can return large responses (>64KB) that get fragmented across
//! multiple TCP segments. This crate correctly handles that by reading the
//! length-prefixed packet header first, then using `read_exact()` to buffer
//! the complete packet body before parsing.
//!
//! ## Features
//!
//! - ✅ Async/await with Tokio
//! - ✅ Correct multi-packet fragmentation handling
//! - ✅ Strong error types with thiserror
//! - ✅ Configurable timeouts
//! - ✅ Lua execution support with serpent serialization
//!
//! ## Usage
//!
//! ```no_run
//! use factorio_rcon::RconClient;
//! use std::time::Duration;
//!
//! #[tokio::main]
//! async fn main() -> factorio_rcon::Result<()> {
//! // Connect and authenticate
//! let mut client = RconClient::connect("127.0.0.1:27015", "password").await?;
//!
//! // Execute basic commands
//! let version = client.execute("/version").await?;
//! println!("Server version: {}", version);
//!
//! // Execute Lua code
//! let tick = client.execute("/c rcon.print(game.tick)").await?;
//! println!("Current tick: {}", tick);
//!
//! // Query with serpent serialization (for structured data)
//! let _inventory = client.execute(
//! "/c rcon.print(serpent.line(game.connected_players[1].get_main_inventory()))"
//! ).await?;
//!
//! // Custom timeout for slow queries
//! let _result = client.execute_with_timeout(
//! "/c rcon.print(serpent.line(game.surfaces))",
//! Duration::from_secs(10)
//! ).await?;
//!
//! // Configure default timeout
//! client.set_timeout(Duration::from_secs(15));
//!
//! Ok(())
//! }
//! ```
//!
//! ## Prerequisites
//!
//! Factorio must run as a multiplayer host for RCON to work:
//!
//! 1. Launch Factorio
//! 2. Multiplayer → Host New Game
//! 3. RCON is automatically enabled (check `config.ini` for port and password)
//!
//! Default RCON configuration:
//! - Port: 27015
//! - Password: Check `config/config.ini` in your Factorio installation
//!
//! ## Error Handling
//!
//! The crate provides strongly-typed errors for different failure scenarios:
//!
//! ```no_run
//! use factorio_rcon::{RconClient, RconError};
//!
//! # async fn example() {
//! match RconClient::connect("127.0.0.1:27015", "wrong_password").await {
//! Ok(_client) => println!("Connected!"),
//! Err(RconError::ConnectionFailed(e)) => println!("Can't reach server: {}", e),
//! Err(RconError::AuthFailed) => println!("Wrong password"),
//! Err(RconError::Timeout(ms)) => println!("Timed out after {}ms", ms),
//! Err(e) => println!("Other error: {}", e),
//! }
//! # }
//! ```
pub use RconClient;
pub use ;