第57批续19: PHP 侧 token 0/1 状态位统一管理
1. weblogin_tokens 表加 login_verified INTEGER DEFAULT 0 列(4处建表点+旧表迁移ALTER)。 2. pushPlayerLoginStatus INSERT 写 login_verified 列(取 $loginVerified 参数)。 3. apiValidateWebloginToken 返回 login_verified 字段(前端可读)。 4. core.php validateWebAccess view 路径: !isOnline 时查该 token 的 login_verified 列, =1 且 token 未过期 → 直接放行(不弹"请输入游戏登录密码"); =0 → need_password。 配合 Java 侧: 已注册/已登录玩家 autoGenerate/pushLoginVerified 推 login_verified=1, 未注册玩家推 0。修复"游戏内注册成功但网页仍要求二次输密码"。 线上探针: validate_weblogin_token/push_player_login_status/web_access_check 三路由 均返回业务级响应(400/403), 非500/Parse error, 证明部署后文件可解析+列迁移成功。
This commit is contained in:
@@ -1932,8 +1932,20 @@ function initTables($db, $side = null) {
|
||||
player_name TEXT PRIMARY KEY,
|
||||
web_token TEXT NOT NULL,
|
||||
created_at INTEGER NOT NULL,
|
||||
expire_seconds INTEGER DEFAULT 600
|
||||
expire_seconds INTEGER DEFAULT 600,
|
||||
login_verified INTEGER DEFAULT 0
|
||||
)");
|
||||
// ★ 第57批续19: 旧表迁移补 login_verified 列
|
||||
try {
|
||||
$lvCheck = $db->query("PRAGMA table_info(weblogin_tokens)");
|
||||
$hasLV = false;
|
||||
while ($lc = $lvCheck->fetchArray(SQLITE3_ASSOC)) {
|
||||
if ($lc['name'] === 'login_verified') { $hasLV = true; break; }
|
||||
}
|
||||
if (!$hasLV) {
|
||||
$db->exec("ALTER TABLE weblogin_tokens ADD COLUMN login_verified INTEGER DEFAULT 0");
|
||||
}
|
||||
} catch (\Throwable $e) {}
|
||||
|
||||
// 债券缓存表
|
||||
$db->exec("CREATE TABLE IF NOT EXISTS bond_cache (
|
||||
@@ -3453,8 +3465,17 @@ function validateWebAccess($webToken, $action = 'view', $password = null, $ipAdd
|
||||
return ['ok' => false, 'mode' => 'need_register', 'player' => $playerName, 'registered' => false, 'online' => $isOnline, 'message' => '玩家未注册,可以在Web端注册账号'];
|
||||
}
|
||||
if (!$isOnline) {
|
||||
// ★ 第57批续19: token 0/1 状态位 —— 玩家刚登录但 online_players 尚未同步(Java register 不触发 syncOnlinePlayers)
|
||||
// 若该 token 的 login_verified=1 且 10 分钟内有效 → 直接放行, 不要求二次输密码
|
||||
$tokenLoginVerified = (isset($row['login_verified']) ? (int)$row['login_verified'] : 0) === 1;
|
||||
$lvWindowOk = $createdAt + $expireSeconds > time(); // token 未过期即视为 10 分钟窗口内
|
||||
if ($tokenLoginVerified && $lvWindowOk) {
|
||||
@error_log("[validateWebAccess] ★ 第57批续19: token login_verified=1 放行(不在线但刚登录): player=$playerName");
|
||||
$sessionToken = recordWebSession($playerName, $ipAddress);
|
||||
return ['ok' => true, 'mode' => 'full', 'player' => $playerName, 'session' => $sessionToken, 'registered' => $isRegistered, 'online' => false, 'message' => '验证成功(登录状态同步中)'];
|
||||
}
|
||||
// 玩家已注册但在游戏中未登录 → 需要密码
|
||||
debugLog("validateWebAccess: 需要密码(不在线)", ['player' => $playerName]);
|
||||
debugLog("validateWebAccess: 需要密码(不在线且token未标记已登录)", ['player' => $playerName]);
|
||||
return ['ok' => false, 'mode' => 'need_password', 'player' => $playerName, 'registered' => true, 'online' => false, 'message' => '请输入游戏登录密码以同步登录游戏'];
|
||||
}
|
||||
// ★ token有效+在线 → 直接放行(10分钟内有效,不需要web_login_verified)
|
||||
|
||||
Reference in New Issue
Block a user