refactor(repo)!: move apps, shared packages, and patch definitions
Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
This commit is contained in:
1 parent
9c813ccf7d
commit
930ea07630
476 files changed
+275
-251
No files matched your search
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Rewrite one configuration string that names a Gaijin server so that it names the local
|
||||
* service instead. Only values that clearly are server addresses are touched:
|
||||
*
|
||||
* http(s)://host[:port]/path -> http://127.0.0.1:<port>/host/path (host is a Gaijin domain or an external IP)
|
||||
* ws(s)://host[:port]/path -> ws://127.0.0.1:<port>/host/path
|
||||
* host:port -> 127.0.0.1:<port> (raw TCP endpoints: matching, chat)
|
||||
*
|
||||
* Bare Gaijin host names without a port (e.g. the event log host) are left as they are so the
|
||||
* client keeps their Host header and SNI; wto_ws.dll resolves them locally and sends their
|
||||
* connections to the local server port. Everything else (file patterns,
|
||||
* placeholders such as "https://not.used", DNS server IPs) is also left as it is.
|
||||
*/
|
||||
import { visitParams, type BlkBlock } from '@wto/blk';
|
||||
import { hostPort, localUrl, type LocalEndpoint } from './local-endpoint.ts';
|
||||
|
||||
export interface AddressChange {
|
||||
readonly path: string;
|
||||
readonly before: string;
|
||||
readonly after: string;
|
||||
}
|
||||
|
||||
/** Rewrite every server address among the string parameters of `root`, in place. */
|
||||
export function redirectAddresses(root: BlkBlock, endpoint: LocalEndpoint, pathPrefix: readonly string[] = []): AddressChange[] {
|
||||
const changes: AddressChange[] = [];
|
||||
visitParams(root, (param, path) => {
|
||||
if (param.value.type !== 'string') return;
|
||||
const rewritten = rewriteAddress(param.value.value, endpoint);
|
||||
if (rewritten === null || rewritten === param.value.value) return;
|
||||
changes.push({ path: [...pathPrefix, ...path, param.name].join('/'), before: param.value.value, after: rewritten });
|
||||
param.value = { type: 'string', value: rewritten };
|
||||
});
|
||||
return changes;
|
||||
}
|
||||
|
||||
/** gaijin.ops is Gaijin's internal domain, used by the internal test environments. */
|
||||
const GAIJIN_DOMAINS = ['gaijin.net', 'gaijinent.com', 'warthunder.com', 'gaijin.ops'];
|
||||
const URL_PATTERN = /^(https?|wss?):\/\/([^/:?#]+)(?::\d+)?([/?#].*)?$/i;
|
||||
const HOST_PORT_PATTERN = /^([a-z0-9.-]+):(\d{1,5})$/i;
|
||||
const IPV4_PATTERN = /^\d{1,3}(?:\.\d{1,3}){3}$/;
|
||||
|
||||
export function rewriteAddress(value: string, endpoint: LocalEndpoint): string | null {
|
||||
const url = URL_PATTERN.exec(value);
|
||||
if (url) {
|
||||
const host = url[2]!.toLowerCase();
|
||||
const scheme = url[1]!.toLowerCase().startsWith('ws') ? 'ws' : 'http';
|
||||
return isServerHost(host) ? localUrl(endpoint, host, url[3] ?? '/', scheme) : null;
|
||||
}
|
||||
const hostAndPort = HOST_PORT_PATTERN.exec(value);
|
||||
if (hostAndPort) return isServerHost(hostAndPort[1]!.toLowerCase()) ? hostPort(endpoint) : null;
|
||||
return null;
|
||||
}
|
||||
|
||||
function isServerHost(host: string): boolean {
|
||||
return isGaijinDomain(host) || (IPV4_PATTERN.test(host) && !host.startsWith('127.'));
|
||||
}
|
||||
|
||||
function isGaijinDomain(host: string): boolean {
|
||||
return GAIJIN_DOMAINS.some((domain) => host === domain || host.endsWith(`.${domain}`));
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/** Where the local server listens. The port is chosen at every launch. */
|
||||
export interface LocalEndpoint {
|
||||
readonly host: string;
|
||||
readonly port: number;
|
||||
}
|
||||
|
||||
export const LOOPBACK = '127.0.0.1';
|
||||
|
||||
export function localEndpoint(port: number): LocalEndpoint {
|
||||
if (!Number.isInteger(port) || port < 1 || port > 65535) throw new RangeError(`port must be an integer from 1 to 65535, got ${port}`);
|
||||
return { host: LOOPBACK, port };
|
||||
}
|
||||
|
||||
/** `host:port` of the local server. */
|
||||
export function hostPort(endpoint: LocalEndpoint): string {
|
||||
return `${endpoint.host}:${endpoint.port}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Local URL standing in for a Gaijin URL. The original host becomes the first path segment,
|
||||
* so the local server can tell which Gaijin service a request was meant for even when two
|
||||
* services use the same path (char and inventory both use "/char").
|
||||
*/
|
||||
export function localUrl(endpoint: LocalEndpoint, originalHost: string, originalPath: string, scheme: 'http' | 'ws' = 'http'): string {
|
||||
const path = originalPath.startsWith('/') ? originalPath : `/${originalPath}`;
|
||||
return `${scheme}://${hostPort(endpoint)}/${originalHost}${path}`;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Settings of an environment block's `yuplay` sub-block, which the game hands to its login
|
||||
* component.
|
||||
*
|
||||
* The URL keys get a local URL built from the login component's default address for that
|
||||
* key, so the local server sees which login request was meant. Only `loginURL`'s default is
|
||||
* certain (https://auth.gaijinent.com/login.php); the others are matched by name to the
|
||||
* addresses in the executable's string table.
|
||||
*
|
||||
* The host-only keys (authHost, ssoHost, storeApiHost, authFallbackHost) and `fallbackIP` are
|
||||
* intentionally not set: the host keys replace only the host name while keeping port 443, and
|
||||
* `fallbackIP` (yu_init.cpp) substitutes a bare IP literal on port 443 when DNS fails — both
|
||||
* strip the original Host/SNI domain and bypass wto_ws.dll's DNS-based routing. Leaving the
|
||||
* Gaijin host names in place lets wto_ws.dll resolve them to 127.0.0.2 and route their TLS
|
||||
* connections to the local server port with the original Host and SNI intact.
|
||||
*/
|
||||
import { localUrl, type LocalEndpoint } from './local-endpoint.ts';
|
||||
|
||||
const URL_DEFAULTS: ReadonlyArray<readonly [key: string, host: string, path: string]> = [
|
||||
['loginURL', 'auth.gaijinent.com', '/login.php'],
|
||||
['tagUserURL', 'auth.gaijinent.com', '/tag.php'],
|
||||
['userStokenURL', 'api.gaijinent.com', '/user_stoken.php'],
|
||||
['stokenLoginURL', 'api.gaijinent.com', '/login_stoken.php'],
|
||||
['versionURL', 'yupmaster.gaijinent.com', '/yuitem/get_version.php'],
|
||||
['yupURL', 'yupmaster.gaijinent.com', '/yuitem/get_yup.php'],
|
||||
];
|
||||
|
||||
export function loginOverrides(endpoint: LocalEndpoint): ReadonlyArray<readonly [key: string, value: string]> {
|
||||
return URL_DEFAULTS.map(([key, host, path]) => [key, localUrl(endpoint, host, path)] as const);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* The network hook library in the game copy: the exe patch
|
||||
* online/network-hook-library makes aces.exe load win64/wto_ws.dll, which reads the local
|
||||
* service port from win64/wto_ws.cfg. Both files are written next to the executable; the DLL is
|
||||
* built from native/wto-net (build.ps1).
|
||||
*/
|
||||
import type { LocalEndpoint } from './local-endpoint.ts';
|
||||
|
||||
export const NETWORK_HOOK_LIBRARY = 'wto_ws.dll';
|
||||
const SETTINGS = 'wto_ws.cfg';
|
||||
|
||||
export function networkHookSettings(endpoint: LocalEndpoint): { name: string; content: Uint8Array } {
|
||||
return { name: SETTINGS, content: new TextEncoder().encode(`port=${endpoint.port}\n`) };
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Point config/network.blk at the local server.
|
||||
*
|
||||
* The environment names stay as they are: the stock scripts branch on the environment name
|
||||
* (for example on whether it contains "production"), so renaming it would change client
|
||||
* behaviour. Instead:
|
||||
* - every server address in the file is rewritten to the local server (address-rewrite.ts);
|
||||
* - every environment block (a block with `charServer` entries) gets certificate checking
|
||||
* turned off and its login component settings pointed at the local server.
|
||||
*/
|
||||
import { ensureBlock, findParam, setParam, type BlkBlock } from '@wto/blk';
|
||||
import { redirectAddresses, type AddressChange } from './address-rewrite.ts';
|
||||
import type { LocalEndpoint } from './local-endpoint.ts';
|
||||
import { loginOverrides } from './login-overrides.ts';
|
||||
|
||||
export interface NetworkRedirectReport {
|
||||
readonly environments: readonly string[];
|
||||
readonly addresses: readonly AddressChange[];
|
||||
}
|
||||
|
||||
export function redirectNetworkConfig(root: BlkBlock, endpoint: LocalEndpoint): NetworkRedirectReport {
|
||||
const addresses = redirectAddresses(root, endpoint);
|
||||
const environments = root.blocks.filter((block) => findParam(block, 'charServer'));
|
||||
for (const environment of environments) configureEnvironment(environment, endpoint);
|
||||
return { environments: environments.map((block) => block.name), addresses };
|
||||
}
|
||||
|
||||
function configureEnvironment(environment: BlkBlock, endpoint: LocalEndpoint): void {
|
||||
setParam(environment, 'enableSslCertCheck', { type: 'bool', value: false });
|
||||
// The local store page. The stock value carries URL tags; here only
|
||||
// auto_local, so scripts/onlineShop/url.nut adds ?skin_lang=<game language> and opens it in
|
||||
// the built-in browser. No auto_login: that goes through Gaijin's login.gaijin.net.
|
||||
setParam(environment, 'webstoreURL', { type: 'string', value: `auto_local http://${endpoint.host}:${endpoint.port}/store` });
|
||||
const login = ensureBlock(environment, 'yuplay');
|
||||
for (const [key, value] of loginOverrides(endpoint)) setParam(login, key, { type: 'string', value });
|
||||
}
|
||||
Reference in new issue
Block a user