Crates.io | insim |
lib.rs | insim |
version | 2.1.0 |
source | src |
created_at | 2024-02-06 18:04:41.577665 |
updated_at | 2024-09-03 10:01:46.189291 |
description | LiveForSpeed Insim implementation that focuses on ergonomics and strong typing |
homepage | https://github.com/theangryangel/insim.rs |
repository | |
max_upload_size | |
id | 1129262 |
size | 233,724 |
insim is a Rust library for working with the Racing Simulator Live For Speed.
It's primary use case is to communicate with LFS via Insim, however it also provides additional utilities for working with LFS as a whole through feature flags and it's sibling crates.
The intention is to provide a strongly typed, native rust implementation, rather than a thin layer over a series of bytes.
Many of the core types, such as Vehicle, Track, etc. have been housed within
the crate insim_core
, which is re-exported.
You will probably want to use https://en.lfsmanual.net/wiki/InSim.txt as a detailed reference for what each packet describes and can do. Where possible this crate aligns the naming of fields in packets to match the original spec. In a handful of circumstances we have needed to rename, or separate some fields (most notably thrbrk and cluhan in the Con packet).
The following are a list of [Cargo features][cargo-features] that can be enabled or disabled:
Name | Description | Default? |
---|---|---|
serde | Enable serde support | No |
pth | Pull in insim_pth and re-export | No |
smx | Pull in insim_smx and re-export | No |
tokio | Enable tokio support | Yes |
blocking | Enable blocking/sync support | Yes |
websocket | Enable LFSW Relay support over websocket using Tungstenite (requires tokio) | Yes |
let conn = insim::tcp("127.0.0.1:29999").connect_async().await?;
loop {
let packet = conn.read().await?;
println!("{:?}", packet);
match packet {
insim::Packet::Mci(_) => {
println!("Got a MCI packet!")
},
_ => {},
}
}
let conn = insim::tcp("127.0.0.1:29999").connect()?;
loop {
let packet = conn.read()?;
println!("{:?}", packet);
match packet {
insim::Packet::Mci(_) => {
println!("Got a MCI packet!")
},
_ => {},
}
}
let conn = insim::relay()
.relay_select_host("Nubbins AU Demo")
.connect_async()
.await?;
loop {
let packet = conn.read().await?;
println!("{:?}", packet);
match packet {
insim::Packet::Mci(_) => {
println!("Got a MCI packet!")
},
_ => {},
}
}
let conn = insim::tcp("127.0.0.1:29999", None).connect_async().await?;
loop {
let packet = conn.read().await?;
println!("{:?}", packet);
match packet {
insim::Packet::Mci(_) => {
println!("Got a MCI packet!")
},
_ => {},
}
}
For further examples see https://github.com/theangryangel/insim.rs/tree/main/examples