添加登录功能

This commit is contained in:
zpx committed 2026-11-20 15:13:11 +08:00
commit a3f61a29d0
120 files changed
+3974

No files matched your search

@@ -0,0 +1,2 @@
[InternetShortcut]
URL=https://docs.cocos.com/creator/manual/en/scripting/setup.html#custom-script-template
+27
View File
@@ -0,0 +1,27 @@
#///////////////////////////
# Cocos Creator Project
#///////////////////////////
/library/
/temp/
/local/
/build/
/profiles/
/common-key/
/native/engine/android/**/*/assets
/美术资源/source-res/
#//////////////////////////
# NPM
#//////////////////////////
node_modules/
#//////////////////////////
# VSCode
#//////////////////////////
.vscode/
#//////////////////////////
# WebStorm
#//////////////////////////
.idea/
+55
View File
@@ -0,0 +1,55 @@
# 项目开发规则
## 协作状态机
- 每个新需求默认进入“需求理解、讨论阶段”,不是实施阶段。
- 需求理解阶段允许读取代码、配置、Git 状态、场景数据和资源信息,以便理解需求并制定可靠方案。
- 讨论阶段允许读取代码、配置、Git 状态、场景数据和资源信息,以便理解需求并制定可靠方案。
- 讨论阶段禁止修改、创建、删除、移动或格式化文件;禁止复制资源、安装依赖、保存场景、启动构建以及调用任何会改变项目状态的工具。
- 收到需求后,先完整理解需求和边界,再说明实现方案、取舍、风险、预计修改范围和验证方式。
- 讨论回复结尾必须标记:`当前状态:等待“开始实施”授权`。
- 只有当用户发送一条去除首尾空白后完全等于 `开始实施` 的单独消息时,才进入实施阶段。
- `可以`、`没问题`、`没有异议`、`继续`、`按这个方案`、`确认方案` 等表达都不构成实施授权。
- 不得根据语气、上下文或方案已达成一致而推断用户授权实施。
- 进入实施阶段后,只执行已讨论并获准的范围。需求范围发生实质变化时,重新回到讨论阶段。
- 用户说“先分析”“先讨论”“不要修改”时,始终保持讨论阶段。
## 项目范围
- 这是一个 PinK 工程,使用 TypeScript 和 2D 竖屏界面;项目元数据中的 3d 类型不代表玩法使用 3D。
- 修改必须限定在已获准的功能范围内。
- 除非任务确实需要,否则不要扫描 `node_modules`、`dist` 或大型资源目录。
- 只加载当前任务需要的 Skill,不要预先读取整套 Skill。
- 永久禁止加载、读取或执行 `skill-game-factory` 及任何 Factory 命令或状态工作流;此前已加载的 Factory 指令不适用于本项目。
- `E:\ProjectPhaser\ricochet-circuit` 严格只读:仅可读取源码、包配置或执行只读 Git 命令;禁止修改文件、安装依赖、构建、测试、同步及任何可能写入该目录的命令。
- 保留用户已有修改,不清理或覆盖无关工作区内容。
## PinK 场景与资源
- 使用 PinK 场景、资源及构建工具;场景编辑前明确绑定目标场景。
- 场景通过领域工具创建、修改与保存,不手工编辑 `.scene` 文件。
- 脚本资源通过资源工具创建,后续 TypeScript 逻辑使用文本补丁维护。
- 占位版界面由场景组件生成,符号 ID 与显示分离,后续可替换美术。
- 查询后再修改节点或组件属性,完整写入值类型;完成一批场景修改后保存并复核。
- 操作结果不确定时先查询状态,不盲目重试。保留用户已有场景修改。
- 如果工程连接失效或目标项目错误,停止相关操作并报告阻塞。
## Token 与工具调用控制
- 先形成批量修改计划,再执行工具调用;不要为每个对象分别开启一个工具回合。
- 能通过对象数据、坐标和场景尺寸验证时,不获取截图。
- 每个功能阶段默认最多获取两次截图:必要的修改前基准图和最终验收图。
- 同一张截图最多读取一次,不要重复使用 `view_image` 查看相同图片。
- 不要把图片二进制、Base64、大型完整 JSON 或无关终端输出带入上下文。
- 使用定向搜索和有限输出,不要重复读取已经掌握且没有变化的内容。
- 如果任务明显变成多个独立阶段,完成当前阶段后先总结,再建议新建会话继续。
## 验证
- 依赖和脚本命令统一使用 `pnpm@11.17.0`,根目录维护唯一的 `pnpm-lock.yaml`;当前没有原生子工程,不要创建 npm/yarn 锁文件。
- 首次运行先在当前项目根目录执行 `pnpm install`;依赖构建脚本仅允许 `pnpm-workspace.yaml` 中明确批准的 `esbuild`。
- 本地运行使用 PinK 场景预览;不要假设当前工程包含独立 Web 开发服务器。
- 修改 TypeScript 后运行 `pnpm typecheck`。
- 修改行为逻辑后运行 `pnpm test`。
- 可能影响编译或资源的修改完成后通过 PinK 构建工具构建,未指定平台时使用 `web-mobile`。
- 只执行与本次修改风险相匹配的验证,并报告未执行的命令及原因。
View File
Whitespace-only changes.
+1854
View File
File diff suppressed because it is too large. Load diff
+11
View File
@@ -0,0 +1,11 @@
{
"ver": "1.1.50",
"importer": "scene",
"imported": true,
"uuid": "478fdf39-37fe-4d07-9770-f088728b9215",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "a7d4d258-9358-4240-acf9-74b73e71cd0c",
"files": [],
"subMetas": {},
"userData": {}
}
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "4a204ac2-aeae-49b2-91f2-cf05cab13ef5",
"files": [],
"subMetas": {},
"userData": {}
}
+40
View File
@@ -0,0 +1,40 @@
/** 登录边界与可注入端口。 / Login contracts and injectable ports. */
export interface GuestSettings {
origin: string;
product: string;
deviceType: 'iphone' | 'ipad';
registerDevice: string;
timeoutMs: number;
}
export interface GuestSession { guestId: string; token: string; expires: number }
export interface TextStorage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
}
export interface GuestAccountStore {
identity(create: () => string): string;
save(session: GuestSession): void;
}
export interface GuestPayload {
guest_id: string;
pkg: string;
device_type: 'iphone' | 'ipad';
register_device: string;
install_fb: boolean;
gyroscope_not_spinning: boolean;
}
export interface GuestSigner {
headers(payload: GuestPayload): Record<string, string>;
}
export interface GuestTransport {
post(path: string, body: object, headers: Record<string, string>, signal?: AbortSignal): Promise<Record<string, unknown>>;
}
export interface GuestLogin { signIn(signal?: AbortSignal): Promise<GuestSession> }
export type GuestFailure = 'configuration' | 'identity' | 'storage' | 'network' | 'timeout' | 'cancelled' | 'response' | 'verification' | 'rejected';
/** 只向界面提供固定消息,避免泄漏服务器原文或凭据。 / Expose fixed messages, never raw server data or credentials. */
export class GuestError extends Error {
constructor(readonly kind: GuestFailure, message: string) { super(message); this.name = 'GuestError'; }
}
export function assertNotCancelled(signal?: AbortSignal): void {
if (signal?.aborted) throw new GuestError('cancelled', 'Sign-in cancelled.');
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "a16fec42-51b1-45d6-b6c0-8746ded67408",
"files": [],
"subMetas": {},
"userData": {}
}
+49
View File
@@ -0,0 +1,49 @@
import { assertNotCancelled, GuestError, GuestTransport } from './GuestContracts';
/** 请求与响应读取共用期限,取消后隔离迟到结果。 / One deadline covers fetch and response parsing; ignore late results after cancellation. */
export class GuestHttpClient implements GuestTransport {
constructor(private readonly origin: string, private readonly timeoutMs: number, private readonly fetcher: typeof fetch) {
if (!/^https:\/\/[^\s/@?#:\\]+(?::\d+)?$/.test(origin) || !Number.isFinite(timeoutMs) || timeoutMs <= 0) {
throw new GuestError('configuration', 'Guest service configuration is unavailable.');
}
}
async post(path: string, body: object, headers: Record<string, string>, signal?: AbortSignal): Promise<Record<string, unknown>> {
assertNotCancelled(signal);
const request = new AbortController();
let timer: ReturnType<typeof setTimeout> | undefined;
let cancel = () => {};
const interruption = new Promise<never>((_, reject) => {
cancel = () => { reject(new GuestError('cancelled', 'Sign-in cancelled.')); request.abort(); };
signal?.addEventListener('abort', cancel, { once: true });
timer = setTimeout(() => { reject(new GuestError('timeout', 'Sign-in timed out. Please retry.')); request.abort(); }, this.timeoutMs);
});
try {
return await Promise.race([interruption, this.exchange(path, body, headers, request.signal)]);
} catch (error) {
if (error instanceof GuestError) throw error;
throw new GuestError('network', 'Unable to connect. Please check your connection and retry.');
} finally {
if (timer !== undefined) clearTimeout(timer);
signal?.removeEventListener('abort', cancel);
}
}
private async exchange(path: string, body: object, headers: Record<string, string>, signal: AbortSignal): Promise<Record<string, unknown>> {
const response = await this.fetcher(this.origin + path, {
method: 'POST', headers: { 'Content-Type': 'application/json', ...headers },
credentials: 'omit', body: JSON.stringify(body), signal,
});
if (!response.ok) throw new GuestError('network', 'Guest service is unavailable. Please retry.');
let data: unknown;
try { data = await response.json(); }
catch { throw new GuestError('response', 'Invalid sign-in response. Please retry.'); }
if (!data || typeof data !== 'object' || Array.isArray(data)) throw new GuestError('response', 'Invalid sign-in response. Please retry.');
const result = data as Record<string, unknown>;
if (result.code !== 0) {
if (result.code === 401 && typeof result.msg === 'string' && /\brequest_sign_invalid\b/.test(result.msg)) {
throw new GuestError('verification', 'Sign-in verification failed. Check the device clock or signing configuration.');
}
throw new GuestError('rejected', 'Guest sign-in was rejected. Please retry.');
}
return result;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "9ca9729a-e1df-45ea-81b2-ef11b40f297f",
"files": [],
"subMetas": {},
"userData": {}
}
+27
View File
@@ -0,0 +1,27 @@
import { _decorator, Button, Component, Label, sys } from 'cc';
const { ccclass, property } = _decorator;
/** 法律链接单独绑定,不混入认证服务;缺地址时显示真实状态。 / Bind legal links separately from authentication and report missing URLs honestly. */
@ccclass('GuestLegalLinks')
export class GuestLegalLinks extends Component {
@property({ type: Button }) privacyButton: Button | null = null;
@property({ type: Button }) termsButton: Button | null = null;
@property({ type: Label }) notice: Label | null = null;
@property privacyUrl = '';
@property termsUrl = '';
onLoad(): void {
this.privacyButton?.node.on(Button.EventType.CLICK, this.openPrivacy, this);
this.termsButton?.node.on(Button.EventType.CLICK, this.openTerms, this);
}
private openPrivacy(): void { this.open(this.privacyUrl, 'Privacy policy is not available yet.'); }
private openTerms(): void { this.open(this.termsUrl, 'Terms of service are not available yet.'); }
private open(url: string, unavailable: string): void {
if (/^https:\/\/[^\s]+$/i.test(url)) { sys.openURL(url); return; }
// 未配置不伪造页面,也不启动登录或覆盖游客会话。 / Never invent a page, trigger login or overwrite the guest session when unconfigured.
if (this.notice) { this.notice.string = unavailable; this.notice.node.active = true; }
}
onDestroy(): void {
if (this.privacyButton?.isValid) this.privacyButton.node.off(Button.EventType.CLICK, this.openPrivacy, this);
if (this.termsButton?.isValid) this.termsButton.node.off(Button.EventType.CLICK, this.openTerms, this);
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "7f182094-3816-4409-b492-771b059cc23b",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,53 @@
import { GuestError, GuestLogin, GuestSession } from './GuestContracts';
export type LoginPhase = 'idle' | 'signing-in' | 'authenticated' | 'failed';
export interface LoginState { phase: LoginPhase; message: string; enabled: boolean }
export interface LoginViewPort { render(state: LoginState): void }
/** 独立于引擎的交互状态机,方便测试连点与销毁。 / Engine-independent interaction state machine for repeated-click and lifecycle tests. */
export class GuestLoginPresenter {
private operation: AbortController | null = null;
private disposed = false;
private authenticated = false;
constructor(private readonly view: LoginViewPort, private readonly service: () => GuestLogin,
private readonly completed: (session: GuestSession) => void) {}
async submit(): Promise<void> {
if (this.disposed || this.operation || this.authenticated) return;
if (typeof AbortController === 'undefined') {
this.view.render({ phase: 'failed', message: 'Secure sign-in is unavailable on this platform.', enabled: true });
return;
}
const operation = new AbortController();
this.operation = operation;
let authenticated: GuestSession | null = null;
try {
this.view.render({ phase: 'signing-in', message: 'Signing in...', enabled: false });
const session = await this.service().signIn(operation.signal);
if (!this.isCurrent(operation)) return;
this.authenticated = true;
authenticated = session;
} catch (error) {
if (!this.isCurrent(operation)) return;
const message = error instanceof GuestError ? error.message : 'Unable to sign in. Please retry.';
this.view.render({ phase: 'failed', message, enabled: true });
} finally {
if (this.operation === operation) this.operation = null;
}
if (authenticated) {
// 成功通知异常不能回滚已保存的认证状态。 / Presentation failures must not turn committed authentication into a login failure.
try {
this.view.render({ phase: 'authenticated', message: 'Signed in successfully.', enabled: false });
this.completed(authenticated);
} catch { /* 保留已认证状态且不输出会话。 / Retain authentication without logging the session. */ }
}
}
cancel(): void {
const operation = this.operation;
this.operation = null;
operation?.abort();
if (!this.disposed && !this.authenticated) this.view.render({ phase: 'idle', message: '', enabled: true });
}
dispose(): void { this.disposed = true; this.cancel(); }
private isCurrent(operation: AbortController): boolean {
return !this.disposed && this.operation === operation && !operation.signal.aborted;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "4f3bdd87-5f8e-4b02-8fcf-1f852e5170c1",
"files": [],
"subMetas": {},
"userData": {}
}
+43
View File
@@ -0,0 +1,43 @@
import { assertNotCancelled, GuestAccountStore, GuestError, GuestLogin, GuestPayload, GuestSession, GuestSettings, GuestSigner, GuestTransport } from './GuestContracts';
import { GUEST_REGISTRATION_PATH } from './GuestSignature';
/** 两步认证的应用服务;不依赖场景或平台全局对象。 / Two-step authentication service independent of scenes and platform globals. */
export class GuestLoginService implements GuestLogin {
private current: Promise<GuestSession> | null = null;
constructor(private readonly settings: GuestSettings, private readonly accounts: GuestAccountStore,
private readonly signer: GuestSigner, private readonly transport: GuestTransport, private readonly makeIdentity: () => string) {}
signIn(signal?: AbortSignal): Promise<GuestSession> {
// 合并请求由首次调用者拥有;已取消的新调用者不加入等待。 / The first caller owns a coalesced request; an already-cancelled caller never joins.
if (signal?.aborted) return Promise.reject(new GuestError('cancelled', 'Sign-in cancelled.'));
if (this.current) return this.current;
const operation = this.authenticate(signal);
this.current = operation;
const release = () => { if (this.current === operation) this.current = null; };
void operation.then(release, release);
return operation;
}
private async authenticate(signal?: AbortSignal): Promise<GuestSession> {
assertNotCancelled(signal);
if (!this.settings.product.trim() || !['iphone', 'ipad'].includes(this.settings.deviceType) ||
!['web', 'android-google', 'ios'].includes(this.settings.registerDevice)) {
throw new GuestError('configuration', 'Guest service configuration is unavailable.');
}
const guestId = this.accounts.identity(this.makeIdentity);
const body: GuestPayload = {
guest_id: guestId, pkg: this.settings.product, device_type: this.settings.deviceType,
register_device: this.settings.registerDevice, install_fb: false, gyroscope_not_spinning: false,
};
await this.transport.post(GUEST_REGISTRATION_PATH, body, this.signer.headers(body), signal);
assertNotCancelled(signal);
// 换 token 不携带签名或认证头;始终使用同一游客身份。 / Exchange without signature/auth headers using the same identity.
const response = await this.transport.post('/account/login', { guest_id: guestId, pkg: this.settings.product }, {}, signal);
assertNotCancelled(signal);
const value = response.data;
if (!value || typeof value !== 'object' || Array.isArray(value)) throw new GuestError('response', 'Invalid sign-in response. Please retry.');
const data = value as Record<string, unknown>;
if (typeof data.token !== 'string' || !data.token.trim()) throw new GuestError('response', 'Invalid sign-in response. Please retry.');
const session: GuestSession = { guestId, token: data.token, expires: typeof data.expires === 'number' && Number.isFinite(data.expires) ? data.expires : 0 };
this.accounts.save(session);
return session;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "d1086204-c49f-4b6a-b552-41c197bc2c48",
"files": [],
"subMetas": {},
"userData": {}
}
+40
View File
@@ -0,0 +1,40 @@
import { _decorator, Button, Component, Label } from 'cc';
import type { GuestSession } from './GuestContracts';
import { GuestLoginPresenter, LoginState, LoginViewPort } from './GuestLoginPresenter';
import { createGuestLogin } from './GuestRuntime';
const { ccclass, property } = _decorator;
/** 场景适配组件,只负责控件绑定与状态展示。 / Scene adapter responsible only for control bindings and rendering state. */
@ccclass('GuestLoginView')
export class GuestLoginView extends Component implements LoginViewPort {
static readonly AUTHENTICATED = 'guest-authenticated';
@property({ type: Button }) guestButton: Button | null = null;
@property({ type: Label }) statusLabel: Label | null = null;
private presenter: GuestLoginPresenter | null = null;
private session: GuestSession | null = null;
get signedIn(): boolean { return this.session !== null; }
onLoad(): void {
if (!this.guestButton || !this.statusLabel) return;
this.presenter = new GuestLoginPresenter(this, createGuestLogin, session => {
this.session = session;
// 事件不包含 token,后续流程按需读取受控会话存储。 / Do not expose the token in UI events; future flow can read the session store.
this.node.emit(GuestLoginView.AUTHENTICATED);
});
this.guestButton.node.on(Button.EventType.CLICK, this.submit, this);
this.render({ phase: 'idle', message: '', enabled: true });
}
private submit(): void { void this.presenter?.submit(); }
render(state: LoginState): void {
if (this.guestButton) this.guestButton.interactable = state.enabled;
if (this.statusLabel) {
this.statusLabel.string = state.message;
this.statusLabel.node.active = state.message.length > 0;
}
}
onDisable(): void { this.presenter?.cancel(); }
onDestroy(): void {
this.presenter?.dispose();
if (this.guestButton?.isValid) this.guestButton.node.off(Button.EventType.CLICK, this.submit, this);
this.session = null;
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "e7144023-5b32-4c59-89e8-be661c99fe09",
"files": [],
"subMetas": {},
"userData": {}
}
+36
View File
@@ -0,0 +1,36 @@
import { sys } from 'cc';
import signing from '../../../common-key/common_key.json';
import { GuestError, GuestLogin, GuestSettings } from './GuestContracts';
import { GuestHttpClient } from './GuestHttpClient';
import { GuestLoginService } from './GuestLoginService';
import { GuestSessionStore } from './GuestSessionStore';
import { HmacGuestSigner } from './GuestSignature';
/** 沿用已确认的服务配置,本地身份使用 Fruit Pop 命名空间。 / Reuse the approved service configuration with a Fruit Pop storage namespace. */
export const GUEST_SERVICE = { origin: 'https://gate.vivarisdigitalgate.com', product: 'VeryWellSlots', timeoutMs: 30000 } as const;
export function guestDeviceType(userAgent: string, touchPoints: number): 'iphone' | 'ipad' {
return /iPad|Tablet/i.test(userAgent) || (/Macintosh/i.test(userAgent) && touchPoints > 1) ? 'ipad' : 'iphone';
}
/** 只能使用安全随机源,不降级到 Math.random。 / Require secure randomness; never fall back to Math.random. */
export function secureGuestId(): string {
if (!globalThis.crypto || typeof globalThis.crypto.getRandomValues !== 'function') {
throw new GuestError('configuration', 'Secure sign-in is unavailable on this platform.');
}
const bytes = new Uint8Array(16);
globalThis.crypto.getRandomValues(bytes);
return Array.from(bytes, value => value.toString(16).padStart(2, '0')).join('');
}
/** 组合根:在这里连接配置、平台能力与独立领域服务。 / Composition root connecting configuration, platform ports and the independent service. */
export function createGuestLogin(): GuestLogin {
if (typeof globalThis.fetch !== 'function' || typeof AbortController === 'undefined') {
throw new GuestError('configuration', 'Network sign-in is unavailable on this platform.');
}
const settings: GuestSettings = {
...GUEST_SERVICE,
deviceType: typeof navigator === 'undefined' ? 'iphone' : guestDeviceType(navigator.userAgent, navigator.maxTouchPoints || 0),
registerDevice: sys.isNative ? (sys.os === sys.OS.ANDROID ? 'android-google' : 'ios') : 'web',
};
return new GuestLoginService(settings, new GuestSessionStore(sys.localStorage, settings.origin, settings.product),
new HmacGuestSigner(signing.key, secureGuestId),
new GuestHttpClient(settings.origin, settings.timeoutMs, globalThis.fetch.bind(globalThis)), secureGuestId);
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "bd61a17b-2d5d-4c42-b294-56d7d1faa08c",
"files": [],
"subMetas": {},
"userData": {}
}
+34
View File
@@ -0,0 +1,34 @@
import { GuestAccountStore, GuestError, GuestSession, TextStorage } from './GuestContracts';
/** 按产品和服务隔离身份,成功会话单独提交。 / Isolate identities by product/service and commit successful sessions separately. */
export class GuestSessionStore implements GuestAccountStore {
readonly identityKey: string;
readonly sessionKey: string;
constructor(private readonly storage: TextStorage, origin: string, product: string) {
const scope = encodeURIComponent(`${origin.replace(/\/+$/, '')}|${product}`);
this.identityKey = `fruit-pop.auth.identity.v1.${scope}`;
this.sessionKey = `fruit-pop.auth.session.v1.${scope}`;
}
identity(create: () => string): string {
try {
const existing = this.storage.getItem(this.identityKey);
const identity = existing ?? create();
if (typeof identity !== 'string' || !/^[a-zA-Z0-9-]{16,128}$/.test(identity)) {
throw new GuestError('identity', 'Unable to restore a secure guest identity.');
}
if (existing === null) this.writeVerified(this.identityKey, identity);
return identity;
} catch (error) { throw this.storageError(error); }
}
save(session: GuestSession): void {
try { this.writeVerified(this.sessionKey, JSON.stringify(session)); }
catch (error) { throw this.storageError(error); }
}
private writeVerified(key: string, text: string): void {
this.storage.setItem(key, text);
if (this.storage.getItem(key) !== text) throw new GuestError('storage', 'Unable to save guest data. Please retry.');
}
private storageError(error: unknown): GuestError {
return error instanceof GuestError ? error : new GuestError('storage', 'Guest storage is unavailable. Please retry.');
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "4c8e112f-a077-4804-8336-a8e2fb14fbf3",
"files": [],
"subMetas": {},
"userData": {}
}
+28
View File
@@ -0,0 +1,28 @@
import { hmac } from '@noble/hashes/hmac';
import { sha256 } from '@noble/hashes/sha2';
import { GuestError, GuestPayload, GuestSigner } from './GuestContracts';
export const GUEST_REGISTRATION_PATH = '/account/v2/guest/login';
/** 协议签名,不负责发送请求或读取配置。 / Protocol signing without transport or configuration access. */
export class HmacGuestSigner implements GuestSigner {
constructor(private readonly secret: string, private readonly nonce: () => string, private readonly clock: () => number = Date.now) {
if (typeof secret !== 'string' || !secret.trim()) throw new GuestError('configuration', 'Guest signing configuration is unavailable.');
}
headers(payload: GuestPayload): Record<string, string> {
const timestamp = String(Math.floor(this.clock() / 1000));
const nonce = this.nonce();
if (!/^\d+$/.test(timestamp) || !Number.isSafeInteger(Number(timestamp)) || Number(timestamp) <= 0 || !/^[a-zA-Z0-9-]{16,128}$/.test(nonce)) {
throw new GuestError('configuration', 'Unable to prepare a secure sign-in request.');
}
// 仅签白名单;false 必须参与,空 uid 是第五行。 / Sign only allowed fields; include false and the empty fifth uid line.
const fields: Record<string, string> = {
guest_id: payload.guest_id, pkg: payload.pkg, device_type: payload.device_type,
register_device: payload.register_device, install_fb: String(payload.install_fb),
gyroscope_not_spinning: String(payload.gyroscope_not_spinning),
};
const canonical = Object.keys(fields).filter(key => fields[key] !== '').sort().map(key => `${key}=${fields[key]}`).join('&');
const message = ['POST', GUEST_REGISTRATION_PATH, timestamp, nonce, '', canonical].join('\n');
const signature = Array.from(hmac(sha256, this.secret, message), value => value.toString(16).padStart(2, '0')).join('');
return { 'X-Timestamp': timestamp, 'X-Nonce': nonce, 'X-Sign': signature };
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "ba15ae6b-94f5-454f-a584-b5decaa0f66e",
"files": [],
"subMetas": {},
"userData": {}
}
@@ -0,0 +1,71 @@
import { _decorator, Button, Canvas, Color, Component, Label, Node, Sprite, UITransform, Widget } from 'cc';
import { EDITOR } from 'cc/env';
const { ccclass, executeInEditMode, property } = _decorator;
/** 仅按显式开关校准已存在节点,不在运行时重建界面。 / Explicit editor-only calibration of existing nodes; never rebuild UI at runtime. */
@ccclass('WelcomeLayoutAuthoring')
@executeInEditMode
export class WelcomeLayoutAuthoring extends Component {
@property
get applyReferenceLayout(): boolean { return false; }
set applyReferenceLayout(value: boolean) {
if (!EDITOR || !value) return;
const canvas = this.node;
const group = this.child(canvas, 'WelcomeComposition');
const widget = canvas.getComponent(Widget);
if (widget) { widget.alignFlags = 0; widget.enabled = false; }
// 保存的设计画布与项目设置保持一致,运行适配仍由独立组件负责。 / Persist the design canvas; the viewport component owns runtime adaptation.
canvas.getComponent(UITransform)!.setContentSize(1080, 1920);
canvas.setPosition(540, 960, 0);
const camera = canvas.getChildByName('Camera');
if (!canvas.getComponent(Canvas) || !camera) throw new Error('Welcome canvas is unavailable.');
const backdrop = this.child(canvas, 'OrchardBackdrop');
this.box(backdrop, 0, 0, 1080, 1920);
backdrop.setSiblingIndex(1);
this.sprite(backdrop);
this.box(this.child(group, 'BrandMark'), 4, 466.5, 982, 643);
this.box(this.child(group, 'FruitArrangement'), -7.5, -78, 991, 456);
this.box(this.child(group, 'GuestAccess'), -1.5, -460, 1027, 268);
for (const name of ['BrandMark', 'FruitArrangement', 'GuestAccess']) this.sprite(this.child(group, name));
const button = this.child(group, 'GuestAccess').getComponent(Button);
if (button) { button.transition = Button.Transition.SCALE; button.zoomScale = .97; }
this.text(this.child(group, 'GuestReassurance'), 'No account needed', 0, -618, 780, 90, 56);
this.text(this.child(group, 'PrivacyLink'), 'Privacy Policy', -190, -765, 300, 88, 38, true);
this.text(this.child(group, 'TermsLink'), 'Terms of Service', 179, -765, 340, 88, 38, true);
this.text(this.child(group, 'LegalDivider'), '|', -10, -765, 28, 76, 56);
this.child(group, 'LegalDivider').getComponent(Label)!.color = new Color(236, 0, 136, 255);
const status = this.child(group, 'AuthenticationStatus');
this.text(status, '', 0, -692, 960, 50, 25);
status.active = false;
}
private child(parent: Node, name: string): Node {
const node = parent.getChildByName(name);
if (!node) throw new Error(`Missing welcome node: ${name}`);
return node;
}
private box(node: Node, x: number, y: number, width: number, height: number): void {
node.setPosition(x, y, 0);
node.setScale(1, 1, 1);
node.getComponent(UITransform)!.setContentSize(width, height);
}
private sprite(node: Node): void {
const sprite = node.getComponent(Sprite)!;
sprite.sizeMode = Sprite.SizeMode.CUSTOM;
sprite.trim = false;
}
private text(node: Node, text: string, x: number, y: number, width: number, height: number, font: number, underline = false): void {
const label = node.getComponent(Label)!;
label.overflow = Label.Overflow.SHRINK;
label.string = text;
label.fontFamily = 'Arial';
label.fontSize = font;
label.lineHeight = font + 8;
label.horizontalAlign = Label.HorizontalAlign.CENTER;
label.verticalAlign = Label.VerticalAlign.CENTER;
label.enableWrapText = true;
label.isBold = false;
label.isUnderline = underline;
label.color = new Color(250, 250, 250, 255);
this.box(node, x, y, width, height);
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "c8bc8aab-88e5-478f-af07-00f32bd66a3a",
"files": [],
"subMetas": {},
"userData": {}
}
+24
View File
@@ -0,0 +1,24 @@
import { _decorator, Component, ResolutionPolicy, UITransform, view } from 'cc';
const { ccclass } = _decorator;
/** 保持完整设计画布;装饰背景等比覆盖额外区域。 / Preserve the entire design canvas and cover extra space with the decorative backdrop. */
@ccclass('WelcomeViewport')
export class WelcomeViewport extends Component {
private frameKey = '';
onEnable(): void { this.fit(); }
update(): void { this.fit(); }
private fit(): void {
const frame = view.getFrameSize();
if (frame.width <= 0 || frame.height <= 0) return;
const key = `${frame.width}:${frame.height}`;
if (key === this.frameKey) return;
this.frameKey = key;
const short = frame.height / frame.width < 1920 / 1080;
view.setDesignResolutionSize(1080, 1920, short ? ResolutionPolicy.FIXED_HEIGHT : ResolutionPolicy.FIXED_WIDTH);
const visible = view.getVisibleSize();
// 主体切图保持原设计坐标,只有背景按覆盖比例放大。 / Keep foreground design coordinates and scale only the background to cover.
this.node.getComponent(UITransform)?.setContentSize(visible);
const cover = Math.max(visible.width / 1080, visible.height / 1920);
this.node.getChildByName('OrchardBackdrop')?.setScale(cover, cover, 1);
}
}
@@ -0,0 +1,9 @@
{
"ver": "4.0.24",
"importer": "typescript",
"imported": true,
"uuid": "340496d0-474c-4678-9ee1-b7751a920e05",
"files": [],
"subMetas": {},
"userData": {}
}
+9
View File
@@ -0,0 +1,9 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "7a77c3d9-8836-41ca-a555-ef1c92144aae",
"files": [],
"subMetas": {},
"userData": {}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

+134
View File
@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "6d00a053-6087-49e8-8dd2-41de217646ae",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "6d00a053-6087-49e8-8dd2-41de217646ae@6c48a",
"displayName": "brand-lockup",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "6d00a053-6087-49e8-8dd2-41de217646ae",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "6d00a053-6087-49e8-8dd2-41de217646ae@f9941",
"displayName": "brand-lockup",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimThreshold": 1,
"rotated": false,
"offsetX": -0.5,
"offsetY": 0,
"trimX": 14,
"trimY": 4,
"width": 941,
"height": 627,
"rawWidth": 970,
"rawHeight": 635,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-470.5,
-313.5,
0,
470.5,
-313.5,
0,
-470.5,
313.5,
0,
470.5,
313.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
14,
631,
955,
631,
14,
4,
955,
4
],
"nuv": [
0.01443298969072165,
0.006299212598425197,
0.9845360824742269,
0.006299212598425197,
0.01443298969072165,
0.9937007874015747,
0.9845360824742269,
0.9937007874015747
],
"minPos": [
-470.5,
-313.5,
0
],
"maxPos": [
470.5,
313.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "6d00a053-6087-49e8-8dd2-41de217646ae@6c48a",
"atlasUuid": "",
"trimType": "auto"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": false,
"hasAlpha": true,
"redirect": "6d00a053-6087-49e8-8dd2-41de217646ae@6c48a"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "68253d33-6386-4047-aa78-8fed637aac12",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "68253d33-6386-4047-aa78-8fed637aac12@6c48a",
"displayName": "guest-access-pill",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "68253d33-6386-4047-aa78-8fed637aac12",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "68253d33-6386-4047-aa78-8fed637aac12@f9941",
"displayName": "guest-access-pill",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimThreshold": 1,
"rotated": false,
"offsetX": 0.5,
"offsetY": -0.5,
"trimX": 34,
"trimY": 4,
"width": 893,
"height": 243,
"rawWidth": 960,
"rawHeight": 250,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-446.5,
-121.5,
0,
446.5,
-121.5,
0,
-446.5,
121.5,
0,
446.5,
121.5,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
34,
246,
927,
246,
34,
3,
927,
3
],
"nuv": [
0.035416666666666666,
0.012,
0.965625,
0.012,
0.035416666666666666,
0.984,
0.965625,
0.984
],
"minPos": [
-446.5,
-121.5,
0
],
"maxPos": [
446.5,
121.5,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "68253d33-6386-4047-aa78-8fed637aac12@6c48a",
"atlasUuid": "",
"trimType": "auto"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": false,
"hasAlpha": true,
"redirect": "68253d33-6386-4047-aa78-8fed637aac12@6c48a"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "f2e507ec-c69a-4484-82df-bf893aca4975",
"files": [
".jpg",
".json"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "f2e507ec-c69a-4484-82df-bf893aca4975@6c48a",
"displayName": "orchard-backdrop",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "f2e507ec-c69a-4484-82df-bf893aca4975",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "f2e507ec-c69a-4484-82df-bf893aca4975@f9941",
"displayName": "orchard-backdrop",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1080,
"height": 1920,
"rawWidth": 1080,
"rawHeight": 1920,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-540,
-960,
0,
540,
-960,
0,
-540,
960,
0,
540,
960,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
1920,
1080,
1920,
0,
0,
1080,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-540,
-960,
0
],
"maxPos": [
540,
960,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "f2e507ec-c69a-4484-82df-bf893aca4975@6c48a",
"atlasUuid": "",
"trimType": "auto"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": false,
"hasAlpha": false,
"redirect": "f2e507ec-c69a-4484-82df-bf893aca4975@6c48a"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "eb8cef2e-799f-4599-ad1a-ce004b28dbc8",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "eb8cef2e-799f-4599-ad1a-ce004b28dbc8@6c48a",
"displayName": "orchard-cluster",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "eb8cef2e-799f-4599-ad1a-ce004b28dbc8",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "eb8cef2e-799f-4599-ad1a-ce004b28dbc8@f9941",
"displayName": "orchard-cluster",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": -0.5,
"trimX": 7,
"trimY": 3,
"width": 976,
"height": 450,
"rawWidth": 990,
"rawHeight": 455,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-488,
-225,
0,
488,
-225,
0,
-488,
225,
0,
488,
225,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
7,
452,
983,
452,
7,
2,
983,
2
],
"nuv": [
0.007070707070707071,
0.004395604395604396,
0.9929292929292929,
0.004395604395604396,
0.007070707070707071,
0.9934065934065934,
0.9929292929292929,
0.9934065934065934
],
"minPos": [
-488,
-225,
0
],
"maxPos": [
488,
225,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "eb8cef2e-799f-4599-ad1a-ce004b28dbc8@6c48a",
"atlasUuid": "",
"trimType": "auto"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": false,
"hasAlpha": true,
"redirect": "eb8cef2e-799f-4599-ad1a-ce004b28dbc8@6c48a"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

@@ -0,0 +1,134 @@
{
"ver": "1.0.27",
"importer": "image",
"imported": true,
"uuid": "a84750b2-a709-417c-8980-fa56cab27d2c",
"files": [
".json",
".png"
],
"subMetas": {
"6c48a": {
"importer": "texture",
"uuid": "a84750b2-a709-417c-8980-fa56cab27d2c@6c48a",
"displayName": "welcome-layout-guide",
"id": "6c48a",
"name": "texture",
"userData": {
"wrapModeS": "clamp-to-edge",
"wrapModeT": "clamp-to-edge",
"imageUuidOrDatabaseUri": "a84750b2-a709-417c-8980-fa56cab27d2c",
"isUuid": true,
"visible": false,
"minfilter": "linear",
"magfilter": "linear",
"mipfilter": "none",
"anisotropy": 0
},
"ver": "1.0.22",
"imported": true,
"files": [
".json"
],
"subMetas": {}
},
"f9941": {
"importer": "sprite-frame",
"uuid": "a84750b2-a709-417c-8980-fa56cab27d2c@f9941",
"displayName": "welcome-layout-guide",
"id": "f9941",
"name": "spriteFrame",
"userData": {
"trimThreshold": 1,
"rotated": false,
"offsetX": 0,
"offsetY": 0,
"trimX": 0,
"trimY": 0,
"width": 1080,
"height": 1920,
"rawWidth": 1080,
"rawHeight": 1920,
"borderTop": 0,
"borderBottom": 0,
"borderLeft": 0,
"borderRight": 0,
"packable": true,
"pixelsToUnit": 100,
"pivotX": 0.5,
"pivotY": 0.5,
"meshType": 0,
"vertices": {
"rawPosition": [
-540,
-960,
0,
540,
-960,
0,
-540,
960,
0,
540,
960,
0
],
"indexes": [
0,
1,
2,
2,
1,
3
],
"uv": [
0,
1920,
1080,
1920,
0,
0,
1080,
0
],
"nuv": [
0,
0,
1,
0,
0,
1,
1,
1
],
"minPos": [
-540,
-960,
0
],
"maxPos": [
540,
960,
0
]
},
"isUuid": true,
"imageUuidOrDatabaseUri": "a84750b2-a709-417c-8980-fa56cab27d2c@6c48a",
"atlasUuid": "",
"trimType": "auto"
},
"ver": "1.0.12",
"imported": true,
"files": [
".json"
],
"subMetas": {}
}
},
"userData": {
"type": "sprite-frame",
"fixAlphaTransparencyArtifacts": false,
"hasAlpha": false,
"redirect": "a84750b2-a709-417c-8980-fa56cab27d2c@6c48a"
}
}
+68
View File
@@ -0,0 +1,68 @@
# Fruit Pop 游客登录
本阶段仅实现登录场景、两步游客认证及本地会话保存,不包含加载页或游戏主界面。
## 场景与美术
- 启动场景为 assets/Welcome.scene;项目设计分辨率为 1080×1920。
- WelcomeComposition 下的 BrandMark、FruitArrangement、GuestAccess 是独立可编辑节点。
- 使用未裁剪透明切图,位置和尺寸来自新版 1080×1920 参考图的多尺度像素匹配。
- OrchardBackdrop 使用装饰背景,位于主体之后;长短屏等比覆盖,不拉伸前景。
- Canvas 保存尺寸为 1080×1920,位置为 (540, 960),根 Widget 已取消旧屏幕尺寸对齐。
- GuestReassurance、PrivacyLink、TermsLink 和 LegalDivider 为独立可编辑文字;链接带下划线。
- 导入后的目录和图片已重新命名;原始美术文件保持不变。
- WelcomeViewport 对长屏固定宽度、短屏固定高度,完整保留画布并避免切图变形。
## 模块职责 / Module responsibilities
- GuestContracts:类型、端口与固定错误消息 / Types, ports and fixed error messages.
- GuestSignature:白名单字段的 HMAC-SHA256 签名 / HMAC-SHA256 signing of allowed fields.
- GuestHttpClient:请求、响应、超时和取消 / Requests, responses, deadlines and cancellation.
- GuestSessionStore:独立身份命名空间及会话提交 / Isolated identity namespace and session persistence.
- GuestLoginService:两步认证编排 / Two-step authentication orchestration.
- GuestLoginPresenter:交互状态、防连点及生命周期 / Interaction state, duplicate-click prevention and lifecycle.
- GuestRuntime:连接平台、配置与依赖 / Connect platform capabilities, configuration and dependencies.
- GuestLoginView:场景控件绑定与展示 / Scene bindings and state rendering.
- GuestLegalLinks:法律链接独立交互,未配置网址时仅提示 / Independent legal links with honest missing-URL feedback.
- WelcomeLayoutAuthoring:显式编辑校准,不在运行时生成界面 / Explicit editor calibration without runtime UI generation.
- WelcomeViewport:画布适配 / Viewport adaptation.
## 协议与配置
按已确认要求沿用参考项目 HTTPS 服务、VeryWellSlots 服务端 pkg 与本机签名配置。
本机 common-key/common_key.json 已复制至本项目并加入忽略规则;测试不读取该文件。
1. POST /account/v2/guest/login:携带 X-Timestamp、X-Nonce、X-Sign,不携带 Authorization。
2. POST /account/login:使用同一个 guest_id 与 pkg,不携带签名头,取得完整 token 后保存。
签名使用 LF 分隔的六行,空 uid 为第五行;字段按键排序、false 参与签名、无额外 URL 编码。
每次按钮登录重新认证;游客身份保持不变,nonce 重新生成,不复用缓存 token 作为认证成功。
本地存储前缀为 fruit-pop.auth,按服务地址与产品隔离。重登失败不覆盖旧成功会话。
首次调用者拥有同一服务实例的合并请求及其取消信号;界面层禁止并发提交。
认证成功后显示 Signed in successfully. 并发出不含 token 的 guest-authenticated 事件,供后续加载功能衔接。
当前不添加加载场景,也不自动跳转。
## 验证记录
- pnpm@11.17.0 安装;类型检查、离线行为测试与布局契约测试。
- web-mobile 发布构建成功,输出 build/web-mobile-guest-login。
- 发布页真实游客认证:两步接口均 HTTP 200,界面进入认证成功状态,身份与保存会话一致。
- 真实服务存在响应波动,后续一次请求达到超时;按钮恢复可重试,不把失败显示为成功。
- 发布页注入验签失败响应:固定提示、恢复按钮、旧会话保留;测试完成恢复真实网络实现。
- 540×960、390×844、390×640 及横向窗口完成运行时结构检查,切图不拉伸且完整可见。
当前验收范围为网页发布版。没有生成原生子工程或 Android 安装包;原生安全随机、网络适配及真机验证留到对应阶段。
客户端签名材料会进入编译产物;忽略本机文件只防止误提交,不表示客户端密钥不可提取。
## 新版参考图修复
- 改用完整装饰背景,重新校准 Logo、水果和更宽的游客按钮。
- 加入 No account needed 和法律链接;尚无真实政策网址时显示固定提示,不虚构跳转。
- 登录状态提示移至说明文字与法律链接之间。
- 已同步保存画布与项目设计分辨率;类型、布局和行为验证在本轮重新执行。
- 最终发布目录为 build/web-mobile-welcome-revised;类型检查和 15 项测试全部通过。
- 新版发布页两步真实游客认证均返回 HTTP 200,认证完成状态和会话保存通过核对。
- 540×960、390×844、390×640 核对前景完整、不变形、背景覆盖完整;法律链接点击提示正确。
- 自动验收页处于隐藏状态时会暂停帧回调,仅测试页面临时恢复调度;该处理未进入项目代码或构建产物。
- 旧输出目录重建曾因 ENOTEMPTY 失败;改用新的最终目录成功构建,未删除旧产物。
+45
View File
@@ -0,0 +1,45 @@
# Fruit Pop — Slots 规则初版 v1.0
这是一份待确认的玩法设计与数学模型,并非已实现游戏。规则与 UI 视觉稿存在差异时,以本文为准;赔率和概率需上线前复核。
## 玩法与货币
- 仅有一种虚拟金币,不可提现、转让或兑换现实物品。
- 初始赠送 100,000 金币;每个 UTC 自然日可免费领取 20,000 金币一次,重置时间为 00:00 UTC;领取后显示下一次重置倒计时。旋转中奖可赢取金币;不设连续签到、广告视频或充值。
- 5 列 × 3 行,固定 20 条有效赔付线,每条线从左到右各经过每列一个格子。总下注为 1,000 / 2,000 / 5,000 / 10,000 / 20,000 / 50,000,单线下注 = 总下注 ÷ 20。每次普通旋转扣除一次总下注。
- 普通符号在一条线上从最左列起连续出现 3、4 或 5 个时中奖。每条线只支付最高的一组;所有中奖线的金额相加。同一个位置可以参与多条不同的线。
## 10 种符号与支付表
下列 8 种普通符号的数字是单线下注倍数。每个可见格独立按下表权重抽取,任何转动或余额不会改变权重,合计 100。
| 普通符号 | 3 连 | 4 连 | 5 连 | 每格权重 |
|---|---:|---:|---:|---:|
| 7 | 45 | 158 | 675 | 3 |
| 铃铛 | 36 | 113 | 450 | 5 |
| BAR | 27 | 90 | 360 | 7 |
| 草莓 | 18 | 54 | 203 | 10 |
| 蓝莓 | 14 | 45 | 158 | 11 |
| 李子 | 9 | 27 | 90 | 13 |
| 樱桃 | 5 | 18 | 68 | 15 |
| 西瓜 | 5 | 14 | 45 | 30 |
另有 WILD 权重 2、SCATTER 权重 4。WILD 可代替上述 8 种普通符号,不能代替 SCATTER;本身没有独立赔付。若同一条线可形成多个符号组合,取该线最高赔付;全 WILD 时按 7 的相应倍数结算。SCATTER 不属于普通樱桃,使用带 SCATTER 标识的樱桃图标,无普通线赔付。
示例:总下注 2,000,则单线下注 100。某线从左起有 5 个樱桃,该线赢取 100 × 68 = 6,800 金币;其他中奖线另行相加。
## 20 条赔付线
T=上排、M=中排、B=下排;每组从左到右表示 5 列。
1. MMMMM 2. TTTTT 3. BBBBB 4. TMBMT 5. BMTMB
6. MTTTM 7. MBBBM 8. MTBTM 9. MBTBM 10. TMMMT
11. BMMMB 12. TTMMB 13. BBMMT 14. TMMBB 15. BMMTT
16. MTMMM 17. MBMMM 18. MMMTM 19. MMMBM 20. MTMBM
## SCATTER 与免费旋转
- 一次普通旋转的 15 个格子任意位置出现 3 个 SCATTER 得 8 次、4 个得 12 次、5 个及以上得 16 次免费旋转;免费旋转不会额外扣除金币,沿用触发时总下注和赔付线。
- 每次免费旋转,从 5 列中等概率选择 1 列;该列的非 SCATTER 符号全部变为 WILD,SCATTER 保持原样。展示变化后的结果并按常规赔付线结算。
- 免费旋转内的 SCATTER 不再次触发免费旋转;免费旋转完成后展示累计赢取金币。免费旋转期间锁定下注,不可调整。
## 自动旋转
玩家可选择 10、25、50 或 100 次;每次普通旋转照常扣除总下注。主按钮显示 STOP,点击后完成当前旋转并停止。余额不足、离开游戏或触发免费旋转时停止自动旋转;免费旋转结束后不会自动恢复,玩家可重新开启。
## 概率核算
按上述每格独立权重、20 条固定线、赔率表及免费旋转规则精确枚举单线结果并计算 SCATTER 分布:普通旋转基础线赔付期望为总下注的约 58.0661%;免费旋转贡献约 37.2746%;合计理论 RTP 约 95.3407%。这是长期数学期望,不是单次或短期承诺。每次普通旋转触发免费旋转的概率约为 2.0292%。所有数字是设计初版,需独立复核和模拟后才可用于正式游戏。
+34
View File
@@ -0,0 +1,34 @@
{
"name": "fruit-pop-googleplay",
"type": "3d",
"version": "1.0.0",
"private": true,
"packageManager": "pnpm@11.17.0",
"scripts": {
"typecheck": "tsc --noEmit -p tsconfig.tests.json",
"test": "tsx --test tests/*.test.ts"
},
"dependencies": {
"@noble/hashes": "1.8.0"
},
"devDependencies": {
"@types/node": "22.15.30",
"tsx": "4.20.3",
"typescript": "5.8.3"
},
"uuid": "",
"creator": {
"version": "unknow"
},
"pink": {
"uuid": "39d627e8-7de7-41b7-80d7-bf7a0a58b628",
"version": "1.127.0",
"from": "pink"
},
"cocos": {
"version": "4.0.0-beta.1"
},
"cli": {
"version": "0.2.0-beta.1"
}
}
+352
View File
@@ -0,0 +1,352 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
dependencies:
'@noble/hashes':
specifier: 1.8.0
version: 1.8.0
devDependencies:
'@types/node':
specifier: 22.15.30
version: 22.15.30
tsx:
specifier: 4.20.3
version: 4.20.3
typescript:
specifier: 5.8.3
version: 5.8.3
packages:
'@esbuild/aix-ppc64@0.25.12':
resolution: {integrity: sha512-Hhmwd6CInZ3dwpuGTF8fJG6yoWmsToE+vYgD4nytZVxcu1ulHpUQRAB1UJ8+N1Am3Mz4+xOByoQoSZf4D+CpkA==}
engines: {node: '>=18'}
cpu: [ppc64]
os: [aix]
'@esbuild/android-arm64@0.25.12':
resolution: {integrity: sha512-6AAmLG7zwD1Z159jCKPvAxZd4y/VTO0VkprYy+3N2FtJ8+BQWFXU+OxARIwA46c5tdD9SsKGZ/1ocqBS/gAKHg==}
engines: {node: '>=18'}
cpu: [arm64]
os: [android]
'@esbuild/android-arm@0.25.12':
resolution: {integrity: sha512-VJ+sKvNA/GE7Ccacc9Cha7bpS8nyzVv0jdVgwNDaR4gDMC/2TTRc33Ip8qrNYUcpkOHUT5OZ0bUcNNVZQ9RLlg==}
engines: {node: '>=18'}
cpu: [arm]
os: [android]
'@esbuild/android-x64@0.25.12':
resolution: {integrity: sha512-5jbb+2hhDHx5phYR2By8GTWEzn6I9UqR11Kwf22iKbNpYrsmRB18aX/9ivc5cabcUiAT/wM+YIZ6SG9QO6a8kg==}
engines: {node: '>=18'}
cpu: [x64]
os: [android]
'@esbuild/darwin-arm64@0.25.12':
resolution: {integrity: sha512-N3zl+lxHCifgIlcMUP5016ESkeQjLj/959RxxNYIthIg+CQHInujFuXeWbWMgnTo4cp5XVHqFPmpyu9J65C1Yg==}
engines: {node: '>=18'}
cpu: [arm64]
os: [darwin]
'@esbuild/darwin-x64@0.25.12':
resolution: {integrity: sha512-HQ9ka4Kx21qHXwtlTUVbKJOAnmG1ipXhdWTmNXiPzPfWKpXqASVcWdnf2bnL73wgjNrFXAa3yYvBSd9pzfEIpA==}
engines: {node: '>=18'}
cpu: [x64]
os: [darwin]
'@esbuild/freebsd-arm64@0.25.12':
resolution: {integrity: sha512-gA0Bx759+7Jve03K1S0vkOu5Lg/85dou3EseOGUes8flVOGxbhDDh/iZaoek11Y8mtyKPGF3vP8XhnkDEAmzeg==}
engines: {node: '>=18'}
cpu: [arm64]
os: [freebsd]
'@esbuild/freebsd-x64@0.25.12':
resolution: {integrity: sha512-TGbO26Yw2xsHzxtbVFGEXBFH0FRAP7gtcPE7P5yP7wGy7cXK2oO7RyOhL5NLiqTlBh47XhmIUXuGciXEqYFfBQ==}
engines: {node: '>=18'}
cpu: [x64]
os: [freebsd]
'@esbuild/linux-arm64@0.25.12':
resolution: {integrity: sha512-8bwX7a8FghIgrupcxb4aUmYDLp8pX06rGh5HqDT7bB+8Rdells6mHvrFHHW2JAOPZUbnjUpKTLg6ECyzvas2AQ==}
engines: {node: '>=18'}
cpu: [arm64]
os: [linux]
'@esbuild/linux-arm@0.25.12':
resolution: {integrity: sha512-lPDGyC1JPDou8kGcywY0YILzWlhhnRjdof3UlcoqYmS9El818LLfJJc3PXXgZHrHCAKs/Z2SeZtDJr5MrkxtOw==}
engines: {node: '>=18'}
cpu: [arm]
os: [linux]
'@esbuild/linux-ia32@0.25.12':
resolution: {integrity: sha512-0y9KrdVnbMM2/vG8KfU0byhUN+EFCny9+8g202gYqSSVMonbsCfLjUO+rCci7pM0WBEtz+oK/PIwHkzxkyharA==}
engines: {node: '>=18'}
cpu: [ia32]
os: [linux]
'@esbuild/linux-loong64@0.25.12':
resolution: {integrity: sha512-h///Lr5a9rib/v1GGqXVGzjL4TMvVTv+s1DPoxQdz7l/AYv6LDSxdIwzxkrPW438oUXiDtwM10o9PmwS/6Z0Ng==}
engines: {node: '>=18'}
cpu: [loong64]
os: [linux]
'@esbuild/linux-mips64el@0.25.12':
resolution: {integrity: sha512-iyRrM1Pzy9GFMDLsXn1iHUm18nhKnNMWscjmp4+hpafcZjrr2WbT//d20xaGljXDBYHqRcl8HnxbX6uaA/eGVw==}
engines: {node: '>=18'}
cpu: [mips64el]
os: [linux]
'@esbuild/linux-ppc64@0.25.12':
resolution: {integrity: sha512-9meM/lRXxMi5PSUqEXRCtVjEZBGwB7P/D4yT8UG/mwIdze2aV4Vo6U5gD3+RsoHXKkHCfSxZKzmDssVlRj1QQA==}
engines: {node: '>=18'}
cpu: [ppc64]
os: [linux]
'@esbuild/linux-riscv64@0.25.12':
resolution: {integrity: sha512-Zr7KR4hgKUpWAwb1f3o5ygT04MzqVrGEGXGLnj15YQDJErYu/BGg+wmFlIDOdJp0PmB0lLvxFIOXZgFRrdjR0w==}
engines: {node: '>=18'}
cpu: [riscv64]
os: [linux]
'@esbuild/linux-s390x@0.25.12':
resolution: {integrity: sha512-MsKncOcgTNvdtiISc/jZs/Zf8d0cl/t3gYWX8J9ubBnVOwlk65UIEEvgBORTiljloIWnBzLs4qhzPkJcitIzIg==}
engines: {node: '>=18'}
cpu: [s390x]
os: [linux]
'@esbuild/linux-x64@0.25.12':
resolution: {integrity: sha512-uqZMTLr/zR/ed4jIGnwSLkaHmPjOjJvnm6TVVitAa08SLS9Z0VM8wIRx7gWbJB5/J54YuIMInDquWyYvQLZkgw==}
engines: {node: '>=18'}
cpu: [x64]
os: [linux]
'@esbuild/netbsd-arm64@0.25.12':
resolution: {integrity: sha512-xXwcTq4GhRM7J9A8Gv5boanHhRa/Q9KLVmcyXHCTaM4wKfIpWkdXiMog/KsnxzJ0A1+nD+zoecuzqPmCRyBGjg==}
engines: {node: '>=18'}
cpu: [arm64]
os: [netbsd]
'@esbuild/netbsd-x64@0.25.12':
resolution: {integrity: sha512-Ld5pTlzPy3YwGec4OuHh1aCVCRvOXdH8DgRjfDy/oumVovmuSzWfnSJg+VtakB9Cm0gxNO9BzWkj6mtO1FMXkQ==}
engines: {node: '>=18'}
cpu: [x64]
os: [netbsd]
'@esbuild/openbsd-arm64@0.25.12':
resolution: {integrity: sha512-fF96T6KsBo/pkQI950FARU9apGNTSlZGsv1jZBAlcLL1MLjLNIWPBkj5NlSz8aAzYKg+eNqknrUJ24QBybeR5A==}
engines: {node: '>=18'}
cpu: [arm64]
os: [openbsd]
'@esbuild/openbsd-x64@0.25.12':
resolution: {integrity: sha512-MZyXUkZHjQxUvzK7rN8DJ3SRmrVrke8ZyRusHlP+kuwqTcfWLyqMOE3sScPPyeIXN/mDJIfGXvcMqCgYKekoQw==}
engines: {node: '>=18'}
cpu: [x64]
os: [openbsd]
'@esbuild/openharmony-arm64@0.25.12':
resolution: {integrity: sha512-rm0YWsqUSRrjncSXGA7Zv78Nbnw4XL6/dzr20cyrQf7ZmRcsovpcRBdhD43Nuk3y7XIoW2OxMVvwuRvk9XdASg==}
engines: {node: '>=18'}
cpu: [arm64]
os: [openharmony]
'@esbuild/sunos-x64@0.25.12':
resolution: {integrity: sha512-3wGSCDyuTHQUzt0nV7bocDy72r2lI33QL3gkDNGkod22EsYl04sMf0qLb8luNKTOmgF/eDEDP5BFNwoBKH441w==}
engines: {node: '>=18'}
cpu: [x64]
os: [sunos]
'@esbuild/win32-arm64@0.25.12':
resolution: {integrity: sha512-rMmLrur64A7+DKlnSuwqUdRKyd3UE7oPJZmnljqEptesKM8wx9J8gx5u0+9Pq0fQQW8vqeKebwNXdfOyP+8Bsg==}
engines: {node: '>=18'}
cpu: [arm64]
os: [win32]
'@esbuild/win32-ia32@0.25.12':
resolution: {integrity: sha512-HkqnmmBoCbCwxUKKNPBixiWDGCpQGVsrQfJoVGYLPT41XWF8lHuE5N6WhVia2n4o5QK5M4tYr21827fNhi4byQ==}
engines: {node: '>=18'}
cpu: [ia32]
os: [win32]
'@esbuild/win32-x64@0.25.12':
resolution: {integrity: sha512-alJC0uCZpTFrSL0CCDjcgleBXPnCrEAhTBILpeAp7M/OFgoqtAetfBzX0xM00MUsVVPpVjlPuMbREqnZCXaTnA==}
engines: {node: '>=18'}
cpu: [x64]
os: [win32]
'@noble/hashes@1.8.0':
resolution: {integrity: sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==}
engines: {node: ^14.21.3 || >=16}
'@types/node@22.15.30':
resolution: {integrity: sha512-6Q7lr06bEHdlfplU6YRbgG1SFBdlsfNC4/lX+SkhiTs0cpJkOElmWls8PxDFv4yY/xKb8Y6SO0OmSX4wgqTZbA==}
esbuild@0.25.12:
resolution: {integrity: sha512-bbPBYYrtZbkt6Os6FiTLCTFxvq4tt3JKall1vRwshA3fdVztsLAatFaZobhkBC8/BrPetoa0oksYoKXoG4ryJg==}
engines: {node: '>=18'}
hasBin: true
fsevents@2.3.3:
resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
get-tsconfig@4.14.3:
resolution: {integrity: sha512-++QEw4DIY7WGoukz+/+A/8dGYPT9l9yIadnmSgZ8Rjr3YVSVDipQSO9CdnJo9ePqFqUUqh+wk9uIaoiAwsiPkA==}
resolve-pkg-maps@1.0.0:
resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==}
tsx@4.20.3:
resolution: {integrity: sha512-qjbnuR9Tr+FJOMBqJCW5ehvIo/buZq7vH7qD7JziU98h6l3qGy0a/yPFjwO+y0/T7GFpNgNAvEcPPVfyT8rrPQ==}
engines: {node: '>=18.0.0'}
hasBin: true
typescript@5.8.3:
resolution: {integrity: sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==}
engines: {node: '>=14.17'}
hasBin: true
undici-types@6.21.0:
resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==}
snapshots:
'@esbuild/aix-ppc64@0.25.12':
optional: true
'@esbuild/android-arm64@0.25.12':
optional: true
'@esbuild/android-arm@0.25.12':
optional: true
'@esbuild/android-x64@0.25.12':
optional: true
'@esbuild/darwin-arm64@0.25.12':
optional: true
'@esbuild/darwin-x64@0.25.12':
optional: true
'@esbuild/freebsd-arm64@0.25.12':
optional: true
'@esbuild/freebsd-x64@0.25.12':
optional: true
'@esbuild/linux-arm64@0.25.12':
optional: true
'@esbuild/linux-arm@0.25.12':
optional: true
'@esbuild/linux-ia32@0.25.12':
optional: true
'@esbuild/linux-loong64@0.25.12':
optional: true
'@esbuild/linux-mips64el@0.25.12':
optional: true
'@esbuild/linux-ppc64@0.25.12':
optional: true
'@esbuild/linux-riscv64@0.25.12':
optional: true
'@esbuild/linux-s390x@0.25.12':
optional: true
'@esbuild/linux-x64@0.25.12':
optional: true
'@esbuild/netbsd-arm64@0.25.12':
optional: true
'@esbuild/netbsd-x64@0.25.12':
optional: true
'@esbuild/openbsd-arm64@0.25.12':
optional: true
'@esbuild/openbsd-x64@0.25.12':
optional: true
'@esbuild/openharmony-arm64@0.25.12':
optional: true
'@esbuild/sunos-x64@0.25.12':
optional: true
'@esbuild/win32-arm64@0.25.12':
optional: true
'@esbuild/win32-ia32@0.25.12':
optional: true
'@esbuild/win32-x64@0.25.12':
optional: true
'@noble/hashes@1.8.0': {}
'@types/node@22.15.30':
dependencies:
undici-types: 6.21.0
esbuild@0.25.12:
optionalDependencies:
'@esbuild/aix-ppc64': 0.25.12
'@esbuild/android-arm': 0.25.12
'@esbuild/android-arm64': 0.25.12
'@esbuild/android-x64': 0.25.12
'@esbuild/darwin-arm64': 0.25.12
'@esbuild/darwin-x64': 0.25.12
'@esbuild/freebsd-arm64': 0.25.12
'@esbuild/freebsd-x64': 0.25.12
'@esbuild/linux-arm': 0.25.12
'@esbuild/linux-arm64': 0.25.12
'@esbuild/linux-ia32': 0.25.12
'@esbuild/linux-loong64': 0.25.12
'@esbuild/linux-mips64el': 0.25.12
'@esbuild/linux-ppc64': 0.25.12
'@esbuild/linux-riscv64': 0.25.12
'@esbuild/linux-s390x': 0.25.12
'@esbuild/linux-x64': 0.25.12
'@esbuild/netbsd-arm64': 0.25.12
'@esbuild/netbsd-x64': 0.25.12
'@esbuild/openbsd-arm64': 0.25.12
'@esbuild/openbsd-x64': 0.25.12
'@esbuild/openharmony-arm64': 0.25.12
'@esbuild/sunos-x64': 0.25.12
'@esbuild/win32-arm64': 0.25.12
'@esbuild/win32-ia32': 0.25.12
'@esbuild/win32-x64': 0.25.12
fsevents@2.3.3:
optional: true
get-tsconfig@4.14.3:
dependencies:
resolve-pkg-maps: 1.0.0
resolve-pkg-maps@1.0.0: {}
tsx@4.20.3:
dependencies:
esbuild: 0.25.12
get-tsconfig: 4.14.3
optionalDependencies:
fsevents: 2.3.3
typescript@5.8.3: {}
undici-types@6.21.0: {}
+2
View File
@@ -0,0 +1,2 @@
allowBuilds:
esbuild: true
+18
View File
@@ -0,0 +1,18 @@
{
"scene": {
"tick": false
},
"version": "1.0.0",
"$schema": "../temp/cocos.config.schema.json",
"engine": {
"designResolution": {
"width": 1080,
"height": 1920
}
},
"builder": {
"common": {
"startScene": "478fdf39-37fe-4d07-9770-f088728b9215"
}
}
}
+149
View File
@@ -0,0 +1,149 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { createHmac } from 'node:crypto';
import { GuestError, GuestPayload, GuestSession, GuestSettings } from '../assets/login/scripts/GuestContracts';
import { GuestHttpClient } from '../assets/login/scripts/GuestHttpClient';
import { GuestLoginPresenter, LoginState } from '../assets/login/scripts/GuestLoginPresenter';
import { GuestLoginService } from '../assets/login/scripts/GuestLoginService';
import { GuestSessionStore } from '../assets/login/scripts/GuestSessionStore';
import { HmacGuestSigner } from '../assets/login/scripts/GuestSignature';
// 测试只使用公开假数据,不加载本机签名配置。 / Use public fixtures only; never load the local signing configuration.
const settings: GuestSettings = { origin: 'https://example.test', product: 'FruitFixture', deviceType: 'iphone', registerDevice: 'web', timeoutMs: 50 };
const identity = '0123456789abcdef0123456789abcdef';
const session: GuestSession = { guestId: identity, token: 'Bearer fixture.token', expires: 1234 };
const payload: GuestPayload = { guest_id: identity, pkg: '测试&game', device_type: 'iphone', register_device: 'web', install_fb: false, gyroscope_not_spinning: false };
function memory() {
const values = new Map<string, string>();
return { values, getItem: (key: string) => values.get(key) ?? null, setItem: (key: string, value: string) => { values.set(key, value); } };
}
function response(value: unknown): Response { return { ok: true, json: async () => value } as Response; }
function deferred<T>() {
let resolve!: (value: T) => void;
const promise = new Promise<T>(yes => { resolve = yes; });
return { promise, resolve };
}
const failure = (kind: string) => (error: unknown) => error instanceof GuestError && error.kind === kind;
test('signature matches independent HMAC with UTF-8, LF, empty uid and false fields', () => {
const signer = new HmacGuestSigner('public-test-key', () => identity, () => 1700000000000);
const fields = `device_type=iphone&guest_id=${identity}&gyroscope_not_spinning=false&install_fb=false&pkg=测试&game&register_device=web`;
const text = `POST\n/account/v2/guest/login\n1700000000\n${identity}\n\n${fields}`;
const expected = createHmac('sha256', 'public-test-key').update(text, 'utf8').digest('hex');
assert.deepEqual(signer.headers(payload), { 'X-Timestamp': '1700000000', 'X-Nonce': identity, 'X-Sign': expected });
assert.throws(() => new HmacGuestSigner('', () => identity), failure('configuration'));
assert.throws(() => new HmacGuestSigner('test', () => 'short').headers(payload), failure('configuration'));
});
test('identity is stable and isolated from other products and origins', () => {
const storage = memory();
const first = new GuestSessionStore(storage, settings.origin, settings.product);
assert.equal(first.identity(() => identity), identity);
assert.equal(first.identity(() => { throw Error('must not regenerate'); }), identity);
const another = new GuestSessionStore(storage, settings.origin, 'OtherProduct');
assert.notEqual(first.identityKey, another.identityKey);
assert.notEqual(first.identityKey, new GuestSessionStore(storage, 'https://other.test', settings.product).identityKey);
first.save(session);
assert.deepEqual(JSON.parse(storage.getItem(first.sessionKey)!), session);
});
test('storage corruption and silent write failures stop authentication', () => {
const storage = memory();
const accounts = new GuestSessionStore(storage, settings.origin, settings.product);
storage.setItem(accounts.identityKey, 'corrupt');
assert.throws(() => accounts.identity(() => identity), failure('identity'));
const unavailable = new GuestSessionStore({ getItem: () => null, setItem: () => {} }, settings.origin, settings.product);
assert.throws(() => unavailable.identity(() => identity), failure('storage'));
});
test('two-step login signs only registration and preserves the complete token', async () => {
const storage = memory();
const accounts = new GuestSessionStore(storage, settings.origin, settings.product);
const calls: { url: string; init: RequestInit }[] = [];
let nonce = 0;
const transport = new GuestHttpClient(settings.origin, 100, (async (url, init) => {
calls.push({ url: String(url), init: init! });
return response(calls.length % 2 === 1 ? { code: 0 } : { code: 0, data: session });
}) as typeof fetch);
const service = new GuestLoginService(settings, accounts, new HmacGuestSigner('fixture', () => identity + ++nonce), transport, () => identity);
assert.deepEqual(await service.signIn(), session);
assert.equal(calls[0].url, settings.origin + '/account/v2/guest/login');
assert.equal(calls[1].url, settings.origin + '/account/login');
assert.deepEqual(JSON.parse(String(calls[0].init.body)), { ...payload, pkg: settings.product });
assert.deepEqual(JSON.parse(String(calls[1].init.body)), { guest_id: identity, pkg: settings.product });
assert.ok((calls[0].init.headers as Record<string, string>)['X-Sign']);
assert.deepEqual(calls[1].init.headers, { 'Content-Type': 'application/json' });
assert.equal(calls[0].init.credentials, 'omit');
await service.signIn();
assert.notEqual((calls[0].init.headers as Record<string, string>)['X-Nonce'], (calls[2].init.headers as Record<string, string>)['X-Nonce']);
assert.equal(JSON.parse(storage.getItem(accounts.sessionKey)!).token, session.token);
});
test('concurrent calls coalesce; cancelled caller never joins', async () => {
const waiting = deferred<Record<string, unknown>>();
let calls = 0;
const service = new GuestLoginService(settings, new GuestSessionStore(memory(), settings.origin, settings.product),
new HmacGuestSigner('fixture', () => identity), { post: async () => ++calls === 1 ? waiting.promise : { data: session } }, () => identity);
const first = service.signIn();
assert.equal(first, service.signIn());
const cancelled = new AbortController(); cancelled.abort();
await assert.rejects(service.signIn(cancelled.signal), failure('cancelled'));
waiting.resolve({ code: 0 });
assert.deepEqual(await first, session); assert.equal(calls, 2);
});
test('business failures and missing token preserve the previous saved session', async () => {
for (const value of [{ code: 17, msg: 'private message' }, { code: 0, data: {} }]) {
const storage = memory(); const accounts = new GuestSessionStore(storage, settings.origin, settings.product); accounts.save(session);
const service = new GuestLoginService(settings, accounts, new HmacGuestSigner('fixture', () => identity),
new GuestHttpClient(settings.origin, 100, (async () => response(value)) as typeof fetch), () => identity);
await assert.rejects(service.signIn(), error => error instanceof GuestError && !error.message.includes('private message'));
assert.deepEqual(JSON.parse(storage.getItem(accounts.sessionKey)!), session);
}
});
test('timeout covers response body parsing and cancellation ignores late registration', async () => {
const body = deferred<unknown>();
const timeout = new GuestHttpClient(settings.origin, 5, (async () => ({ ok: true, json: () => body.promise } as Response)) as typeof fetch);
await assert.rejects(timeout.post('/fixture', {}, {}), failure('timeout'));
body.resolve({ code: 0 });
const waiting = deferred<Response>(); let calls = 0;
const storage = memory(); const accounts = new GuestSessionStore(storage, settings.origin, settings.product);
const service = new GuestLoginService(settings, accounts, new HmacGuestSigner('fixture', () => identity),
new GuestHttpClient(settings.origin, 100, (() => { calls++; return waiting.promise; }) as typeof fetch), () => identity);
const abort = new AbortController(); const login = service.signIn(abort.signal); abort.abort();
await assert.rejects(login, failure('cancelled'));
waiting.resolve(response({ code: 0 })); await Promise.resolve();
assert.equal(calls, 1); assert.equal(storage.getItem(accounts.sessionKey), null);
});
test('invalid JSON is a response error and verification errors hide server text', async () => {
const malformed = new GuestHttpClient(settings.origin, 100, (async () => new Response('invalid JSON')) as typeof fetch);
await assert.rejects(malformed.post('/fixture', {}, {}), failure('response'));
const rejected = new GuestHttpClient(settings.origin, 100, (async () => response({ code: 401, msg: 'request_sign_invalid secret details' })) as typeof fetch);
await assert.rejects(rejected.post('/fixture', {}, {}), error => error instanceof GuestError && error.kind === 'verification' && !error.message.includes('secret details'));
});
test('presenter ignores repeated clicks and keeps committed success if a listener throws', async () => {
const waiting = deferred<GuestSession>(); const states: LoginState[] = []; let calls = 0;
const presenter = new GuestLoginPresenter({ render: state => states.push(state) },
() => ({ signIn: () => { calls++; return waiting.promise; } }), () => { throw Error('listener'); });
const login = presenter.submit(); await presenter.submit();
assert.equal(calls, 1); assert.equal(states[0].enabled, false);
waiting.resolve(session); await login;
assert.equal(states.at(-1)?.phase, 'authenticated');
await presenter.submit(); assert.equal(calls, 1);
});
test('presenter destruction prevents late success and failure allows retry', async () => {
const waiting = deferred<GuestSession>(); const states: LoginState[] = []; let completed = 0;
const presenter = new GuestLoginPresenter({ render: state => states.push(state) }, () => ({ signIn: () => waiting.promise }), () => completed++);
const login = presenter.submit(); presenter.dispose(); waiting.resolve(session); await login;
assert.equal(completed, 0); assert.equal(states.length, 1);
let calls = 0;
const retry = new GuestLoginPresenter({ render: state => states.push(state) }, () => ({ signIn: async () => {
if (++calls === 1) throw new GuestError('network', 'Try again.'); return session;
} }), () => completed++);
await retry.submit(); assert.equal(states.at(-1)?.enabled, true);
await retry.submit(); assert.equal(completed, 1);
});
+73
View File
@@ -0,0 +1,73 @@
import { test } from 'node:test';
import { strict as assert } from 'node:assert';
import { readFileSync, readdirSync } from 'node:fs';
// 校验保存后的场景契约,不通过手工修改场景来修正测试。 / Verify the saved scene contract; never rewrite scenes to satisfy tests.
type Entry = Record<string, any>;
const scene: Entry[] = JSON.parse(readFileSync('assets/Welcome.scene', 'utf8'));
const node = (name: string): Entry => scene.find(value => value.__type__ === 'cc.Node' && value._name === name)!;
const component = (name: string, type: string): Entry => node(name)._components.map((ref: Entry) => scene[ref.__id__]).find((value: Entry) => value.__type__ === type)!;
test('project design resolution and start scene use the portrait login scene', () => {
const settings = JSON.parse(readFileSync('settings/cocos.config.json', 'utf8'));
assert.equal(settings.engine.designResolution.width, 1080);
assert.equal(settings.engine.designResolution.height, 1920);
assert.equal(settings.builder.common.startScene, JSON.parse(readFileSync('assets/Welcome.scene.meta', 'utf8')).uuid);
assert.equal(component('Canvas', 'cc.UITransform')._contentSize.width, 1080);
assert.equal(component('Canvas', 'cc.UITransform')._contentSize.height, 1920);
assert.equal(node('Canvas')._lpos.x, 540);
assert.equal(node('Canvas')._lpos.y, 960);
assert.equal(component('Canvas', 'cc.Widget')._alignFlags, 0);
});
test('reference artwork retains independent editable sprites, exact positions and proportions', () => {
for (const [name, x, y, width, height] of [
['BrandMark', 4, 466.5, 982, 643],
['FruitArrangement', -7.5, -78, 991, 456],
['GuestAccess', -1.5, -460, 1027, 268],
] as const) {
const item = node(name), transform = component(name, 'cc.UITransform'), sprite = component(name, 'cc.Sprite');
assert.ok(item, name);
assert.equal(item._lpos.x, x); assert.equal(item._lpos.y, y);
assert.equal(transform._contentSize.width, width); assert.equal(transform._contentSize.height, height);
assert.equal(sprite._isTrimmedMode, false); assert.equal(sprite._sizeMode, 0);
assert.ok(sprite._spriteFrame.__uuid__);
assert.equal(item._lscale.x, 1); assert.equal(item._lscale.y, 1);
}
assert.equal(node('AuthenticationStatus')._active, false);
assert.deepEqual(component('Camera', 'cc.Camera')._color, { __type__: 'cc.Color', r: 55, g: 0, b: 34, a: 255 });
});
test('decorative backdrop is independent and behind the editable foreground', () => {
const children = node('Canvas')._children.map((ref: Entry) => scene[ref.__id__]._name);
assert.ok(children.indexOf('OrchardBackdrop') < children.indexOf('WelcomeComposition'));
const meta = JSON.parse(readFileSync('assets/login/visuals/orchard-backdrop.jpg.meta', 'utf8'));
assert.equal(component('OrchardBackdrop', 'cc.Sprite')._spriteFrame.__uuid__, meta.uuid + '@f9941');
assert.equal(component('OrchardBackdrop', 'cc.UITransform')._contentSize.width, 1080);
assert.equal(component('OrchardBackdrop', 'cc.UITransform')._contentSize.height, 1920);
});
test('reference footer is editable, underlined and separated from authentication notices', () => {
assert.equal(component('GuestReassurance', 'cc.Label')._string, 'No account needed');
assert.equal(component('PrivacyLink', 'cc.Label')._string, 'Privacy Policy');
assert.equal(component('TermsLink', 'cc.Label')._string, 'Terms of Service');
assert.equal(component('PrivacyLink', 'cc.Label')._isUnderline, true);
assert.equal(component('TermsLink', 'cc.Label')._isUnderline, true);
const controller = node('WelcomeComposition')._components.map((ref: Entry) => scene[ref.__id__]).find((value: Entry) => value.privacyButton);
assert.equal(scene[controller.privacyButton.__id__].__type__, 'cc.Button');
assert.equal(scene[controller.termsButton.__id__].__type__, 'cc.Button');
assert.equal(scene[controller.notice.__id__].__type__, 'cc.Label');
assert.equal(controller.privacyUrl, ''); assert.equal(controller.termsUrl, '');
const status = node('AuthenticationStatus'), height = component('AuthenticationStatus', 'cc.UITransform')._contentSize.height;
assert.ok(status._lpos.y + height / 2 < node('GuestReassurance')._lpos.y - 45);
assert.ok(status._lpos.y - height / 2 > node('PrivacyLink')._lpos.y + 44);
});
test('login view has explicit button/status bindings and no source artwork filenames', () => {
const controller = node('WelcomeComposition')._components.map((ref: Entry) => scene[ref.__id__]).find((value: Entry) => value.guestButton);
assert.equal(scene[controller.guestButton.__id__].__type__, 'cc.Button');
assert.equal(scene[controller.statusLabel.__id__].__type__, 'cc.Label');
const names = readdirSync('assets/login/visuals').filter(name => !name.endsWith('.meta')).sort();
assert.deepEqual(names, ['brand-lockup.png', 'guest-access-pill.png', 'orchard-backdrop.jpg', 'orchard-cluster.png', 'welcome-layout-guide.png']);
assert.ok(readFileSync('.gitignore', 'utf8').includes('/common-key/'));
});
+6
View File
@@ -0,0 +1,6 @@
{
/* Base configuration. Do not edit this field. */
"extends": "./temp/tsconfig.cocos.json"
/* Add your custom configuration here. */
}
+20
View File
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"moduleResolution": "node",
"strict": true,
"strictNullChecks": true,
"noImplicitAny": true,
"strictPropertyInitialization": true,
"skipLibCheck": true,
"lib": ["ES2020", "DOM"],
"types": ["node", "./temp/declarations/cc", "./temp/declarations/cc.env"],
"resolveJsonModule": true,
"esModuleInterop": true,
"noEmit": true
},
"include": ["assets/**/*.ts", "tests/**/*.ts"],
"exclude": ["node_modules", "library", "temp/programming", "build"]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 123 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 325 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 189 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Loaded 100 of 120 files, more files were not shown because too many files have changed in this diff. Show more