mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(rockstar): preserve legacy launches when the SDK pipe is unused
This commit is contained in:
1 parent
9dfbc05933
commit
2974c2db92
3 files changed
+59
-2
No files matched your search
@@ -9,6 +9,17 @@ pub mod sdk;
|
||||
pub const MAX_FRAME_BYTES: usize = 64 * 1024;
|
||||
const OVERHEAD: usize = 4 + 4 + 1;
|
||||
|
||||
pub fn sdk_connection<T>(
|
||||
connection: io::Result<T>,
|
||||
legacy_authenticated: bool,
|
||||
) -> io::Result<Option<T>> {
|
||||
match connection {
|
||||
Ok(pipe) => Ok(Some(pipe)),
|
||||
Err(error) if legacy_authenticated && error.kind() == io::ErrorKind::TimedOut => Ok(None),
|
||||
Err(error) => Err(error),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn wait_for_game(
|
||||
child: &mut std::process::Child,
|
||||
handshake: std::sync::mpsc::Receiver<io::Result<()>>,
|
||||
@@ -162,6 +173,26 @@ mod tests {
|
||||
assert!(child.try_wait().unwrap().is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unused_sdk_connection_is_optional_only_after_legacy_authentication() {
|
||||
for authenticated in [false, true] {
|
||||
assert_eq!(sdk_connection(Ok(42), authenticated).unwrap(), Some(42));
|
||||
for kind in [
|
||||
io::ErrorKind::TimedOut,
|
||||
io::ErrorKind::PermissionDenied,
|
||||
io::ErrorKind::InvalidData,
|
||||
io::ErrorKind::BrokenPipe,
|
||||
] {
|
||||
let result = sdk_connection::<()>(Err(io::Error::from(kind)), authenticated);
|
||||
if authenticated && kind == io::ErrorKind::TimedOut {
|
||||
assert_eq!(result.unwrap(), None);
|
||||
} else {
|
||||
assert_eq!(result.unwrap_err().kind(), kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stopped_handshake_worker_terminates_and_reaps_the_game() {
|
||||
let mut child = sleeping_child();
|
||||
|
||||
@@ -26,7 +26,7 @@ fn run() -> Result<i32, Box<dyn std::error::Error>> {
|
||||
use droiddeck_rockstar_launcher::{
|
||||
pipe::Listener,
|
||||
sdk::{Message, Session},
|
||||
wait_for_game, Frame, Length,
|
||||
sdk_connection, wait_for_game, Frame, Length,
|
||||
};
|
||||
use std::io::{Read, Write};
|
||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
@@ -195,6 +195,7 @@ fn run() -> Result<i32, Box<dyn std::error::Error>> {
|
||||
let (result, handshake) = std::sync::mpsc::sync_channel(1);
|
||||
std::thread::spawn(move || {
|
||||
let serve = || -> std::io::Result<()> {
|
||||
let mut legacy_authenticated = false;
|
||||
if let Some((listener, material, terminated)) = legacy {
|
||||
let mut pipe = listener.accept()?;
|
||||
log("legacy launcher pipe connected");
|
||||
@@ -225,9 +226,14 @@ fn run() -> Result<i32, Box<dyn std::error::Error>> {
|
||||
},
|
||||
)?;
|
||||
log("legacy launcher handshake complete");
|
||||
legacy_authenticated = true;
|
||||
}
|
||||
if let (Some(listener), Some(session)) = (sdk_listener, session) {
|
||||
let mut pipe = listener.accept()?.with_deadline(Duration::from_secs(90));
|
||||
let Some(pipe) = sdk_connection(listener.accept(), legacy_authenticated)? else {
|
||||
log("SDK pipe unused after legacy launcher handshake");
|
||||
return Ok(());
|
||||
};
|
||||
let mut pipe = pipe.with_deadline(Duration::from_secs(90));
|
||||
if pipe.client_pid()? != pid {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::PermissionDenied,
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import pathlib
|
||||
import subprocess
|
||||
import unittest
|
||||
|
||||
|
||||
class RockstarLauncherTest(unittest.TestCase):
|
||||
def test_protocol_and_process_lifecycle(self):
|
||||
root = pathlib.Path(__file__).resolve().parents[2]
|
||||
subprocess.run(
|
||||
[
|
||||
"cargo",
|
||||
"test",
|
||||
"--locked",
|
||||
"--manifest-path",
|
||||
"tools/rockstar-launcher/Cargo.toml",
|
||||
],
|
||||
cwd=root,
|
||||
check=True,
|
||||
timeout=180,
|
||||
)
|
||||
Reference in new issue
Block a user