|
|
|
@@ -0,0 +1,42 @@
|
|
|
|
|
import type { RemoteConfig } from '../config/remote-config.ts';
|
|
|
|
|
|
|
|
|
|
/** Defaults owned here reproduce 04_Data.js and Game_Surface_3 Debugger. */
|
|
|
|
|
const LOGIN_DEFAULTS = Object.freeze({ deviceLogin:0, showVisitor:0, qqLogin:0,
|
|
|
|
|
avatarUrl:'https://projectimage.tscce.cn/image_132/', avatarRange:[100,10000] as readonly number[],
|
|
|
|
|
hiddenVisitor:true });
|
|
|
|
|
export interface LoginPolicy {
|
|
|
|
|
deviceLogin:boolean; showVisitor:boolean; qqLogin:boolean; hiddenVisitor:boolean;
|
|
|
|
|
avatarUrl:string; avatarRange:readonly number[];
|
|
|
|
|
}
|
|
|
|
|
function flag(value:unknown, name:string):boolean {
|
|
|
|
|
if (![0,1,false,true].includes(value as number)) throw Error(`Invalid login config ${name}`);
|
|
|
|
|
return Boolean(value);
|
|
|
|
|
}
|
|
|
|
|
export function resolveLoginPolicy(remote:RemoteConfig):LoginPolicy {
|
|
|
|
|
const hallValue=remote.getValue('hall_config');
|
|
|
|
|
if (hallValue != null && (typeof hallValue!=='object' || Array.isArray(hallValue))) throw Error('Invalid hall_config');
|
|
|
|
|
const hall=hallValue as Record<string,unknown> | null;
|
|
|
|
|
// Legacy hall_config merge precedes hallConfigName top-level overrides.
|
|
|
|
|
const hallField=(name:'showVisitor'|'qqLogin')=> {
|
|
|
|
|
const override=remote.getValue(name);
|
|
|
|
|
if(override!=null) return override;
|
|
|
|
|
return hall && Object.prototype.hasOwnProperty.call(hall,name)?hall[name]:LOGIN_DEFAULTS[name];
|
|
|
|
|
};
|
|
|
|
|
const sourceField=(name:'deviceLogin'|'avatarUrl'|'avatarRange')=> {
|
|
|
|
|
const value=remote.getValue(name);return value==null?LOGIN_DEFAULTS[name]:value;
|
|
|
|
|
};
|
|
|
|
|
const avatarUrl=sourceField('avatarUrl'),range=sourceField('avatarRange');
|
|
|
|
|
if(typeof avatarUrl!=='string')throw Error('Invalid login config avatarUrl');
|
|
|
|
|
if(!Array.isArray(range)||range.length!==2||range.some(v=>!Number.isInteger(v))||range[1]<=range[0])throw Error('Invalid login config avatarRange');
|
|
|
|
|
return Object.freeze({deviceLogin:flag(sourceField('deviceLogin'),'deviceLogin'),
|
|
|
|
|
showVisitor:flag(hallField('showVisitor'),'showVisitor'),qqLogin:flag(hallField('qqLogin'),'qqLogin'),
|
|
|
|
|
hiddenVisitor:LOGIN_DEFAULTS.hiddenVisitor,avatarUrl,avatarRange:Object.freeze([...range])});
|
|
|
|
|
}
|
|
|
|
|
/** Assignment order is significant: JumpWxAuth applies showVisitor/QQ after cache hiding. */
|
|
|
|
|
export function loginButtons(policy:LoginPolicy, versionState:0|1, cached:boolean) {
|
|
|
|
|
const account=versionState===0&&cached;
|
|
|
|
|
let wechat=!policy.deviceLogin&&!account;
|
|
|
|
|
let visitor=!account;
|
|
|
|
|
if(versionState===0){visitor=false;if(policy.showVisitor){wechat=false;visitor=true;}}
|
|
|
|
|
return {wechat,visitor,phone:policy.deviceLogin&&!account,quick:false,qq:policy.qqLogin,account};
|
|
|
|
|
}
|