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

Implemented optional parameters for universe/place-id #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
58 changes: 54 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ struct Options {
#[structopt(long("place"))]
place_path: Option<PathBuf>,

/// The universe of the place id to open in Roblox Studio. If not specified,
/// the place-id will not be used
#[structopt(long("universe-id"))]
universe_id: Option<u64>,

/// The place id to open in Roblox Studio. If not specified, the place-id
/// will not be used
#[structopt(long("place-id"))]
place_id: Option<u64>,

/// A path to the script to run in Roblox Studio.
///
/// The script will be run at plugin-level security.
Expand All @@ -30,11 +40,13 @@ struct Options {
}

fn run(options: Options) -> Result<i32, anyhow::Error> {
// Additional parameters that we may want to pass to roblox Studio
let mut params = vec![];

// Create a temp directory to house our place, even if a path is given from
// the command line. This helps ensure Studio won't hang trying to tell the
// user that the place is read-only because of a .lock file.
let temp_place_folder = tempdir()?;
let temp_place_path;

match &options.place_path {
Some(place_path) => {
Expand All @@ -44,17 +56,55 @@ fn run(options: Options) -> Result<i32, anyhow::Error> {
.to_str()
.ok_or_else(|| anyhow!("Place file extension had invalid Unicode"))?;

temp_place_path = temp_place_folder
let temp_place_path = temp_place_folder
.path()
.join(format!("run-in-roblox-place.{}", extension));

fs::copy(place_path, &temp_place_path)?;

params.push(format!("{}", temp_place_path.display()));
}
None => {
unimplemented!("run-in-roblox with no place argument");
// Default baseplate place: https://www.roblox.com/games/95206881/Baseplate
let mut place_id = "95206881".to_string();
let mut universe_id = Some("28220420".to_string());

// Fall back to testing universe and place-id
// If we have both a universe and place id, we need to pass them to Studio
match (&options.universe_id, &options.place_id) {
(Some(input_universe_id), Some(input_place_id)) => {
place_id = format!("{}", input_place_id);
universe_id = Some(format!("{}", input_universe_id));
},
(None, Some(input_place_id)) => {
place_id = format!("{}", input_place_id);
universe_id = None;
},
(Some(_), None) => {
unimplemented!("You must specify a place-id if you specify a universe-id");
},
_ => {}
};

params.extend_from_slice(&vec![
// This tells studio to open the place
"-task".to_string(),
"EditPlace".to_string(),
"-placeId".to_string(),
place_id,
]);

if let Some(universe_id) = universe_id {
params.extend_from_slice(&vec![
"-universeId".to_string(),
universe_id,
]);
}
}
}



let script_contents = fs::read_to_string(&options.script_path)?;

// Generate a random, unique ID for this session. The plugin we inject will
Expand All @@ -64,9 +114,9 @@ fn run(options: Options) -> Result<i32, anyhow::Error> {

let place_runner = PlaceRunner {
port: 50312,
place_path: temp_place_path.clone(),
server_id: server_id.clone(),
lua_script: script_contents.clone(),
args: params,
};

let (sender, receiver) = mpsc::channel();
Expand Down
4 changes: 2 additions & 2 deletions src/place_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ impl Drop for KillOnDrop {

pub struct PlaceRunner {
pub port: u16,
pub place_path: PathBuf,
pub server_id: String,
pub args: Vec<String>,
pub lua_script: String,
}

Expand Down Expand Up @@ -56,7 +56,7 @@ impl PlaceRunner {

let _studio_process = KillOnDrop(
Command::new(studio_install.application_path())
.arg(format!("{}", self.place_path.display()))
.args(&self.args)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?,
Expand Down