insim

Crates.ioinsim
lib.rsinsim
version2.1.0
sourcesrc
created_at2024-02-06 18:04:41.577665
updated_at2024-09-03 10:01:46.189291
descriptionLiveForSpeed Insim implementation that focuses on ergonomics and strong typing
homepagehttps://github.com/theangryangel/insim.rs
repository
max_upload_size
id1129262
size233,724
Karl (theangryangel)

documentation

README

insim

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).

Supported Features

  • insim over TCP or UDP
  • insim over TCP and Websocket via LFS World Relay

Feature flags

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

Making a TCP connection (using tokio)

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!")
        },
        _ => {},
    }
}

Making a TCP connection (using blocking)

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!")
        },
        _ => {},
    }
}

Making a LFS World Relay connection (using tokio)

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!")
        },
        _ => {},
    }
}

Making a UDP connection (using tokio)

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!")
        },
        _ => {},
    }
}

Additional examples

For further examples see https://github.com/theangryangel/insim.rs/tree/main/examples

Commit count: 0

cargo fmt