Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for LFS 0.7F #170

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ default-members = ["insim", "insim_*"]
resolver = "2"

[workspace.package]
version = "1.1.1"
version = "2.0.0"
authors = ["Karl Southern <karl@theangryangel.co.uk>"]
edition = "2021"
rust-version = "1.75"
Expand Down
6 changes: 3 additions & 3 deletions insim/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ from_variants = { workspace = true }
futures-util = { workspace = true, optional = true }
if_chain = { workspace = true }
indexmap = { workspace = true }
insim_core = { path = "../insim_core", version = "1.1.1" }
insim_pth = { path = "../insim_pth", optional = true, version = "1.1.1" }
insim_smx = { path = "../insim_smx", optional = true, version = "1.1.1" }
insim_core = { path = "../insim_core", version = "2.0.0" }
insim_pth = { path = "../insim_pth", optional = true, version = "2.0.0" }
insim_smx = { path = "../insim_smx", optional = true, version = "2.0.0" }
serde = { workspace = true, features = ["derive"], optional = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["rt", "time", "net", "macros", "sync", "tracing"], optional = true }
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/acr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::identifiers::{ConnectionId, RequestId};
#[repr(u8)]
#[derive(Debug, Default, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub enum AcrResult {
/// Command was processed
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/axm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub struct ObjectInfo {
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
pub enum PmoAction {
#[default]
/// Sent by the layout loading system only
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/btn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ bitflags::bitflags! {
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Used within [Bfn] to specify the action to take.
pub enum BfnType {
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/cch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::identifiers::{PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Camera/view identifiers
pub enum CameraView {
/// Arcade "follow" view
Expand Down
4 changes: 4 additions & 0 deletions insim/src/insim/cim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::identifiers::{ConnectionId, RequestId};

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
/// Used within the [Cim] packet to indicate the mode.
pub enum CimMode {
/// Not in a special mode
Expand Down Expand Up @@ -48,6 +49,7 @@ impl Default for CimMode {
#[repr(u8)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
/// CimMode::Normal, submode
pub enum CimSubModeNormal {
#[default]
Expand Down Expand Up @@ -87,6 +89,7 @@ impl From<u8> for CimSubModeNormal {
#[repr(u8)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
/// CimMode::Garage, submode
pub enum CimSubModeGarage {
#[default]
Expand Down Expand Up @@ -142,6 +145,7 @@ impl From<u8> for CimSubModeGarage {
#[repr(u8)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
/// CimMode::ShiftU, submode
pub enum CimSubModeShiftU {
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/cnl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::identifiers::{ConnectionId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Used within [Cnl] to indicate the leave reason.
pub enum CnlReason {
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/csc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::identifiers::{PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Used within the [Csc] packet to indicate the type of state change.
pub enum CscAction {
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/flg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::identifiers::{PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
pub enum FlgType {
#[default]
/// Blue flag
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/hlv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::identifiers::{PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Used within [Hlv] to indicate the hotlap validity failure reason.
pub enum Hlvc {
/// Ground
Expand Down
120 changes: 120 additions & 0 deletions insim/src/insim/ipb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
use std::{default::Default, net::Ipv4Addr};

use indexmap::{set::Iter as IndexSetIter, IndexSet};
use insim_core::binrw::{self, binrw, BinRead, BinResult, BinWrite};

use crate::identifiers::RequestId;

const IPB_MAX_BANS: usize = 120;

#[binrw::parser(reader, endian)]
fn binrw_parse_ipb_bans(count: u8) -> BinResult<IndexSet<Ipv4Addr>> {
let mut data = IndexSet::new();
for _i in 0..count {
let ip = Ipv4Addr::from(u32::read_options(reader, endian, ())?);
let _ = data.insert(ip);
}
Ok(data)
}

#[binrw::writer(writer, endian)]
fn binrw_write_ipb_bans(input: &IndexSet<Ipv4Addr>) -> BinResult<()> {
for i in input.iter() {
u32::from(*i).write_options(writer, endian, ())?;
}

Ok(())
}

#[binrw]
#[bw(assert(banips.len() <= IPB_MAX_BANS))]
#[derive(Debug, Clone, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
/// Mods Allowed - restrict the mods that can be used
pub struct Ipb {
/// Non-zero if the packet is a packet request or a reply to a request
pub reqi: RequestId,

/// Number of bans in this packet, from the wire
/// This value is not to be trusted as we use an IndexSet to record the bans internally. It is technically
/// possible that LFS could return duplicate entries, but we have no way of verifying that.
#[bw(calc = banips.len() as u8)]
#[brw(pad_after = 4)]
numb: u8,

#[br(parse_with = binrw_parse_ipb_bans, args(numb))]
#[bw(write_with = binrw_write_ipb_bans)]
banips: IndexSet<Ipv4Addr>,
}

impl Ipb {
/// Returns `true` if a Vehicle is contained in this packet
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comments in this packet definition still refer to "vehicle" and "mods", that looks like an oversight after a copy&paste.

pub fn contains(&self, v: &Ipv4Addr) -> bool {
self.banips.contains(v)
}

/// Push a compressed form of a mod onto the list of allowed mods
/// and update the count.
pub fn insert(&mut self, ip: Ipv4Addr) -> bool {
self.banips.insert(ip)
}

/// Remove a Vehicle from this packet
pub fn remove(&mut self, ip: &Ipv4Addr) -> bool {
self.banips.shift_remove(ip)
}

/// Does this packet have no vehicles associated?
pub fn is_empty(&self) -> bool {
self.banips.is_empty()
}

/// Clear any previously allowed mods.
pub fn clear(&mut self) {
self.banips.clear()
}

/// Iterator for all allowed mods
pub fn iter(&self) -> IndexSetIter<'_, Ipv4Addr> {
self.banips.iter()
}

/// Returns the number of allowed mods
pub fn len(&self) -> usize {
self.banips.len()
}
}

#[cfg(test)]
mod tests {
use std::io::{Cursor, Seek};

use super::*;

#[test]
fn test_encoding() {
let mut bans = Ipb::default();
bans.reqi = RequestId(2);
let _ = bans.insert(Ipv4Addr::new(127, 0, 0, 1));

let mut buf = Cursor::new(Vec::new());
bans.write_le(&mut buf).unwrap();
buf.rewind().unwrap();

let buf2 = buf.clone().into_inner();
assert_eq!(
buf2,
[
2, // reqi
1, // numb
0, 0, 0, 0, // padding / unused
1, 0, 0, 127, // mod 1
]
);

let data2 = Ipb::read_le(&mut buf).unwrap();
assert_eq!(bans, data2);
assert_eq!(data2.len(), 1);
assert!(data2.contains(&Ipv4Addr::new(127, 0, 0, 1)));
}
}
1 change: 1 addition & 0 deletions insim/src/insim/jrr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::identifiers::{ConnectionId, PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Used within the [Jrr] packet.
pub enum JrrAction {
#[default]
Expand Down
2 changes: 2 additions & 0 deletions insim/src/insim/lap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::identifiers::{PlayerId, RequestId};

#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
/// When /showfuel yes: double fuel percent / no: 255
pub enum Fuel200 {
/// Double fuel percent
Expand Down Expand Up @@ -62,6 +63,7 @@ impl BinRead for Fuel200 {

#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[derive(Debug, Default, Clone)]
#[non_exhaustive]
/// When /showfuel yes: fuel added percent / no: 255
pub enum Fuel {
/// Double fuel percent
Expand Down
2 changes: 2 additions & 0 deletions insim/src/insim/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod flg;
mod hcp;
mod hlv;
mod iii;
mod ipb;
mod isi;
mod ism;
mod jrr;
Expand Down Expand Up @@ -82,6 +83,7 @@ pub use flg::{Flg, FlgType};
pub use hcp::{Hcp, HcpCarHandicap};
pub use hlv::{Hlv, Hlvc};
pub use iii::Iii;
pub use ipb::Ipb;
pub use isi::{Isi, IsiFlags};
pub use ism::Ism;
pub use jrr::{Jrr, JrrAction};
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/msl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::identifiers::RequestId;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
pub enum SoundType {
#[default]
/// Silent
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/mso.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::identifiers::{ConnectionId, PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
pub enum MsoUserType {
/// System message.
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/npl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::identifiers::{ConnectionId, PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Tyre compounds/types
pub enum TyreCompound {
/// R1
Expand Down
2 changes: 2 additions & 0 deletions insim/src/insim/oco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::identifiers::RequestId;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Object Control action to take. Used within [Oco].
pub enum OcoAction {
#[default]
Expand All @@ -26,6 +27,7 @@ pub enum OcoAction {
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Which lights to manipulate. See [Oco].
pub enum OcoIndex {
/// Layout lights 1
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/pen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::identifiers::{PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Penalty types
pub enum PenaltyInfo {
/// None, or cleared
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/pit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub struct Psf {
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Pit lane fact, or info. Used in [Pla].
pub enum PitLaneFact {
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/racelaps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use insim_core::binrw::{self, BinRead, BinWrite};
/// Handles the rules around how RaceLaps are described within Insim automatically for you.
#[derive(Debug, Default, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
pub enum RaceLaps {
/// This is a practise session
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/small.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ bitflags! {

#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[non_exhaustive]
/// [Small] packet subtype.
pub enum SmallType {
/// Nothing!
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::identifiers::RequestId;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Errors occurred during a [Ssh] request.
pub enum SshError {
#[default]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/sta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::identifiers::{PlayerId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// Game racing state
pub enum RaceInProgress {
/// No race in progress
Expand Down
4 changes: 4 additions & 0 deletions insim/src/insim/tiny.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::identifiers::RequestId;
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// [Tiny] Subtype
pub enum TinyType {
/// Keepalive request/response
Expand Down Expand Up @@ -96,6 +97,9 @@ pub enum TinyType {

/// Request a Plh packet
Plh = 28,

/// Request a Ipb packet
Ipb = 29,
}

#[binrw]
Expand Down
1 change: 1 addition & 0 deletions insim/src/insim/ttc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::identifiers::{ConnectionId, RequestId};
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[repr(u8)]
#[brw(repr(u8))]
#[non_exhaustive]
/// [Ttc] subtype.
pub enum TtcType {
/// Send Axm for the current layout editor selection
Expand Down
Loading
Loading