Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit c82fa5e

Browse files
committed
chore: Convert options to use ButtplugServerOptions
Read server options into the new argument struct, add more error checking on device/user config loading.
1 parent 4a7e848 commit c82fa5e

File tree

2 files changed

+30
-14
lines changed

2 files changed

+30
-14
lines changed

src/main.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use buttplug::{
3333
DeviceCommunicationManager, DeviceCommunicationManagerCreator,
3434
},
3535
ButtplugRemoteServer,
36+
ButtplugServerOptions,
3637
remote_server::ButtplugRemoteServerEvent,
3738
},
3839
util::logging::ChannelWriter
@@ -48,8 +49,7 @@ use std::{error::Error, fmt};
4849

4950
#[derive(Default, Clone)]
5051
pub struct ConnectorOptions {
51-
server_name: String,
52-
max_ping_time: u64,
52+
server_options: ButtplugServerOptions,
5353
stay_open: bool,
5454
use_frontend_pipe: bool,
5555
ws_listen_on_all_interfaces: bool,
@@ -254,7 +254,7 @@ async fn main() -> Result<(), IntifaceCLIErrorEnum> {
254254
if connector_opts.stay_open {
255255
task::block_on(async move {
256256
let (server, event_receiver) =
257-
ButtplugRemoteServer::new(&connector_opts.server_name, connector_opts.max_ping_time);
257+
ButtplugRemoteServer::new_with_options(&connector_opts.server_options).unwrap();
258258
if frontend_sender_clone.is_some() {
259259
let fscc = frontend_sender_clone.clone().unwrap();
260260
task::spawn(async move {
@@ -292,7 +292,7 @@ async fn main() -> Result<(), IntifaceCLIErrorEnum> {
292292
} else {
293293
task::block_on(async move {
294294
let (server, event_receiver) =
295-
ButtplugRemoteServer::new(&connector_opts.server_name, connector_opts.max_ping_time);
295+
ButtplugRemoteServer::new_with_options(&connector_opts.server_options).unwrap();
296296
let fscc = frontend_sender_clone.clone();
297297
if fscc.is_some() {
298298
task::spawn(async move {

src/options.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{utils::generate_certificate, ConnectorOptions, IntifaceCLIErrorEnum,
33
use super::frontend::{self, FrontendPBufChannel};
44
use argh::FromArgs;
55
use buttplug::device::configuration_manager::{
6-
set_external_device_config, set_user_device_config, DeviceConfigurationManager,
6+
DeviceConfigurationManager,
77
};
88
use std::fs;
99

@@ -85,6 +85,10 @@ struct IntifaceCLIArguments {
8585
#[allow(dead_code)]
8686
#[argh(option)]
8787
log: Option<String>,
88+
89+
/// allow raw messages (dangerous, only use for development)
90+
#[argh(switch)]
91+
allowraw: bool,
8892
}
8993

9094
pub fn check_options_and_pipe() -> Option<FrontendPBufChannel> {
@@ -186,8 +190,9 @@ pub fn parse_options() -> Result<Option<ConnectorOptions>, IntifaceCLIErrorEnum>
186190
);
187191
}
188192

189-
connector_info.server_name = args.servername;
190-
connector_info.max_ping_time = args.pingtime;
193+
connector_info.server_options.name = args.servername;
194+
connector_info.server_options.max_ping_time = args.pingtime;
195+
connector_info.server_options.allow_raw_messages = args.allowraw;
191196

192197
if args.frontendpipe {
193198
info!("Intiface CLI Options: Using frontend pipe");
@@ -206,20 +211,31 @@ pub fn parse_options() -> Result<Option<ConnectorOptions>, IntifaceCLIErrorEnum>
206211
"Intiface CLI Options: External Device Config {}",
207212
deviceconfig
208213
);
209-
let cfg = fs::read_to_string(deviceconfig).unwrap();
210-
set_external_device_config(Some(cfg));
211-
// Make an unused DeviceConfigurationManager here, as it'll panic if it's invalid.
212-
let _manager = DeviceConfigurationManager::default();
214+
match fs::read_to_string(deviceconfig) {
215+
Ok(cfg) => connector_info.server_options.device_configuration_json = Some(cfg),
216+
Err(err) => panic!("Error opening external device configuration: {:?}", err)
217+
};
213218
}
214219

215220
if let Some(userdeviceconfig) = &args.userdeviceconfig {
216221
info!(
217222
"Intiface CLI Options: User Device Config {}",
218223
userdeviceconfig
219224
);
220-
let cfg = fs::read_to_string(userdeviceconfig).unwrap();
221-
set_user_device_config(Some(cfg));
222-
let _manager = DeviceConfigurationManager::default();
225+
match fs::read_to_string(userdeviceconfig) {
226+
Ok(cfg) => connector_info.server_options.user_device_configuration_json = Some(cfg),
227+
Err(err) => panic!("Error opening user device configuration: {:?}", err)
228+
};
229+
}
230+
231+
// Make sure we can bring up a DeviceConfigurationManager before handing back
232+
// to the server to start the listener.
233+
234+
if let Err(err) = DeviceConfigurationManager::new_with_options(
235+
connector_info.server_options.allow_raw_messages,
236+
&connector_info.server_options.device_configuration_json,
237+
&connector_info.server_options.user_device_configuration_json) {
238+
panic!("Error in creation of Device Configuration Manager: {:?}", err);
223239
}
224240

225241
Ok(Some(connector_info))

0 commit comments

Comments
 (0)