Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
* its token where nothing else reads it; the script then sees the app start the game but no new token, and the user is
* told to start Battle.net from the Start menu.
*
* <p>The wc3-e2e-harness does the same (docs/BattleNetSignIn.md there). Both hold the same localhost port as a lock
* from the renewal until the launched client has signed in.
* <p>Every tool that renews this sign-in holds the same localhost port as a lock from the renewal until the launched
* client has signed in.
*/
@SuppressWarnings("StringConcatToTextBlock") // Error Prone 2.50 crashes on this source under javac 27.
public final class BattleNetSignIn {
Expand Down Expand Up @@ -425,9 +425,9 @@ private static Path tempDir() {
return Path.of(System.getProperty("java.io.tmpdir"));
}

/** A copy of the wc3-e2e-harness {@code node/src/runner/battlenet-token.ps1}; keep them equal. */
/** The renewal script, run in the user's own registry view. */
static final String TOKEN_SCRIPT = "battlenet-token.ps1";
/** A copy of the wc3-e2e-harness {@code node/src/runner/battlenet-window.ps1}; keep them equal. */
/** The watcher that keeps the app's window out of sight during the renewal. */
static final String WINDOW_SCRIPT = "battlenet-window.ps1";
/** The watcher's limit without a client: every request the renewal may send, then a launch and a slow sign-in. */
static final long WINDOW_WATCH_SECONDS = TIMEOUT_SECONDS + 150;
Expand Down Expand Up @@ -540,7 +540,7 @@ private static Optional<String> readBinary(String key, String value) throws IOEx
return parseBinary(readCommand(new ProcessBuilder("reg.exe", "query", key, "/v", value)), value);
}

// The Node harness takes the same localhost port while it renews the sign-in.
// Every tool that renews this sign-in takes the same localhost port while it does.
static int gatePort(Path config) {
try {
String key = config.toAbsolutePath().normalize().toString().toLowerCase(Locale.ROOT);
Expand All @@ -558,7 +558,7 @@ private ServerSocket acquireGate(long waitSeconds, Runnable onWait) throws IOExc
while (true) {
ServerSocket socket = new ServerSocket();
try {
// 127.0.0.1 exactly, as the harness binds it; the loopback name could resolve to ::1
// 127.0.0.1 exactly, as every holder binds it; the loopback name could resolve to ::1
socket.bind(new InetSocketAddress(InetAddress.getByAddress(new byte[]{127, 0, 0, 1}), gatePort(config)));
return socket;
} catch (BindException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
* them started from inside such an app would keep it where the rest of the machine never sees it. A process created
* through WMI ({@code Win32_Process.Create}) starts in the user's own context instead, in the same session and on the
* same desktop.
*
* <p>The wc3-e2e-harness does the same ({@code startOutside} in node/src/runner/win32.cjs there).
*/
final class OutsideStart {
/** The {@code SW_} value WMI passes to the new process's first window. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ public void readsOnlyTheRequestedBinaryValueFromRegQuery() {
}

@Test
public void takesTheSameLockAsTheE2eHarness() {
public void takesTheSharedSignInLockPort() {
if (!Orient.isWindowsSystem()) throw new SkipException("Battle.net paths are Windows paths");
// node/src/runner/battlenet.cjs in wc3-e2e-harness: 33000 + sha256(lower-cased path) as uint32 BE % 10000
// 33000 + sha256(lower-cased path) as uint32 BE % 10000, the port every tool that renews this sign-in binds
assertEquals(BattleNetSignIn.gatePort(Path.of("C:\\Users\\tester\\AppData\\Roaming\\Battle.net\\Battle.net.config")), 36941);
}

Expand Down
Loading