From 6952fbec35cb635694c805419737fe27ee7be3d4 Mon Sep 17 00:00:00 2001 From: blackspherefollower Date: Wed, 3 Jan 2024 12:38:18 +0000 Subject: [PATCH] feat: Match BTLE protocols from the WSDM without additional config --- .../server/device/configuration/specifier.rs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/buttplug/src/server/device/configuration/specifier.rs b/buttplug/src/server/device/configuration/specifier.rs index 3b6ab837..e29bcb60 100644 --- a/buttplug/src/server/device/configuration/specifier.rs +++ b/buttplug/src/server/device/configuration/specifier.rs @@ -153,6 +153,37 @@ impl PartialEq for BluetoothLESpecifier { } } +impl PartialEq for BluetoothLESpecifier { + fn eq(&self, other: &WebsocketSpecifier) -> bool { + // If names or manufacturer data are found, use those automatically. + if self.names.intersection(&other.names).count() > 0 { + return true; + } + // Otherwise, try wildcarded names. + for name in &self.names { + for other_name in &other.names { + let compare_name: &String; + let mut wildcard: String; + if name.ends_with('*') { + wildcard = name.clone(); + compare_name = other_name; + } else if other_name.ends_with('*') { + wildcard = other_name.clone(); + compare_name = name; + } else { + continue; + } + // Remove asterisk from the end of the wildcard + wildcard.pop(); + if compare_name.starts_with(&wildcard) { + return true; + } + } + } + false + } +} + impl BluetoothLESpecifier { pub fn new( names: HashSet, @@ -385,6 +416,7 @@ impl PartialEq for ProtocolCommunicationSpecifier { (HID(self_spec), HID(other_spec)) => self_spec == other_spec, (XInput(self_spec), XInput(other_spec)) => self_spec == other_spec, (Websocket(self_spec), Websocket(other_spec)) => self_spec == other_spec, + (BluetoothLE(self_spec), Websocket(other_spec)) => self_spec == other_spec, (LovenseConnectService(self_spec), LovenseConnectService(other_spec)) => { self_spec == other_spec }