Buttplug sex toy control library

chore: Autoincrement user device indexes if they collide

Not a great way to do this but it works.

Fixes #693 (I guess. It's not great. It needs tests.)

+14 -3
+2 -2
crates/buttplug_server_device_config/src/device_definitions.rs
··· 97 97 } 98 98 } 99 99 100 - #[derive(Serialize, Deserialize, Debug, Getters, CopyGetters, Default, Clone)] 100 + #[derive(Serialize, Deserialize, Debug, Getters, CopyGetters, Default, Clone, MutGetters)] 101 101 pub struct UserDeviceCustomization { 102 102 #[serde( 103 103 rename = "display-name", ··· 112 112 #[serde(default)] 113 113 #[getset(get_copy = "pub")] 114 114 deny: bool, 115 - #[getset(get_copy = "pub")] 115 + #[getset(get_copy = "pub", get_mut = "pub")] 116 116 index: u32, 117 117 #[getset(get_copy = "pub")] 118 118 #[serde(
+12 -1
crates/buttplug_server_device_config/src/lib.rs
··· 350 350 definition: &DeviceDefinition, 351 351 ) -> Result<(), ButtplugDeviceError> { 352 352 //self.protocol_map.contains_key(identifier.protocol()); 353 + // Check validity of device 354 + let mut index = definition.user_config().index(); 355 + let indexes: Vec<u32> = self.user_device_definitions().iter().map(|x| x.value().user_config().index()).collect(); 356 + // If we just added 1 to the maximum value of the current indexes, someone decides to set an 357 + // index to u32::MAX-1, then we'd have a problem. This is kind of a shit solution but it'll work 358 + // quickly for anyone that's not actively fucking with us by manually playing with user config files. 359 + while indexes.contains(&index) { 360 + index = index.wrapping_add(1); 361 + } 362 + let mut def = definition.clone(); 363 + *def.user_device_mut().user_config_mut().index_mut() = index; 353 364 self 354 365 .user_device_definitions 355 366 .entry(identifier.clone()) 356 - .insert(definition.clone()); 367 + .insert(def); 357 368 Ok(()) 358 369 } 359 370