From bbd0049602e7b13ea4101c32ecf5238e8d9f976b Mon Sep 17 00:00:00 2001 From: ypsdf1 Date: Sat, 27 Jun 2026 14:52:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A2=86=E5=9C=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F3=E4=B8=AAbug=EF=BC=9A=201.=20JSON=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=EF=BC=9AaddConvertEffectsForFrontend?= =?UTF-8?q?=E5=B0=86Java=E8=87=AA=E5=AE=9A=E4=B9=89=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E8=BD=ACJSON=E6=95=B0=E7=BB=84=20=20=20=20-=20give=5Feffects:?= =?UTF-8?q?=20=E5=A4=9C=E8=A7=86:1:99999|SPEED:2:60=20=E2=86=92=20[[?= =?UTF-8?q?=E5=A4=9C=E8=A7=86,1,99999],[SPEED,2,60]]=20=20=20=20-=20clear?= =?UTF-8?q?=5Feffects:=20POISON,WITHER=20=E2=86=92=20[POISON,WITHER]=202.?= =?UTF-8?q?=20admin.php=E9=85=8D=E7=BD=AEkey=E5=90=8D=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=EF=BC=9Aland=5Fprice=5Fper=5Fsqm=E2=86=92create=5Fprice=5Fper?= =?UTF-8?q?=5Fsqm,=20max=5Flands=E2=86=92max=5Flands=5Fper=5Fplayer=203.?= =?UTF-8?q?=20handleUpdateLandField=E5=AD=98=E5=82=A8=E6=97=B6=E5=B0=86JSO?= =?UTF-8?q?N=E6=95=B0=E7=BB=84=E8=BD=AC=E5=9B=9EJava=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin.php | 16 ++++++++----- api/land_api.php | 61 ++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 67 insertions(+), 10 deletions(-) diff --git a/admin.php b/admin.php index 3f5700d..fccf900 100644 --- a/admin.php +++ b/admin.php @@ -2277,6 +2277,7 @@ async function loadLands(el) { // 配置信息 const cfg = configRes.config || {}; + window._landCfgData = cfg; // 缓存供showLandConfig使用 html += `
`; const lands = landsRes.lands || []; html += `
@@ -2288,8 +2289,8 @@ async function loadLands(el) {
${shopItems.length}
在售权限
`; - const pricePerSqM = cfg.land_price_per_sqm || '10'; - const maxLands = cfg.max_lands || '5'; + const pricePerSqM = cfg.create_price_per_sqm || '10'; + const maxLands = cfg.max_lands_per_player || '5'; html += `
${pricePerSqM}
每平米价格(债券)
@@ -2362,15 +2363,18 @@ async function loadLands(el) { } function showLandConfig() { + const cfg = window._landCfgData || {}; + const price = cfg.create_price_per_sqm || '10'; + const maxLands = cfg.max_lands_per_player || '5'; const html = `

⚙️ 领地配置

- +
- +
`; @@ -2384,12 +2388,12 @@ async function saveLandConfig() { await fetch('api/land_api.php?action=update_config', { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - body: 'key=land_price_per_sqm&value=' + encodeURIComponent(price) + '&secret=sdf1_web_comm_2026_ypshidifu' + body: 'key=create_price_per_sqm&value=' + encodeURIComponent(price) + '&secret=sdf1_web_comm_2026_ypshidifu' }); await fetch('api/land_api.php?action=update_config', { method: 'POST', headers: {'Content-Type': 'application/x-www-form-urlencoded'}, - body: 'key=max_lands&value=' + encodeURIComponent(maxLands) + '&secret=sdf1_web_comm_2026_ypshidifu' + body: 'key=max_lands_per_player&value=' + encodeURIComponent(maxLands) + '&secret=sdf1_web_comm_2026_ypshidifu' }); document.querySelector('.modal-close')?.click(); loadLands(document.getElementById('C')); diff --git a/api/land_api.php b/api/land_api.php index 0ed9527..c71b782 100644 --- a/api/land_api.php +++ b/api/land_api.php @@ -7,6 +7,34 @@ header('Content-Type: application/json; charset=utf-8'); error_reporting(E_ERROR | E_PARSE); +/** + * ★ 将Java自定义格式转换为JSON数组 + * give_effects: "夜视:1:99999|SPEED:2:60" → [["夜视","1","99999"],["SPEED","2","60"]] + * clear_effects: "POISON,WITHER" → ["POISON","WITHER"] + */ +function convertEffectsForFrontend($row) { + if (!empty($row['give_effects']) && $row['give_effects'][0] !== '[') { + $parts = explode('|', $row['give_effects']); + $arr = []; + foreach ($parts as $p) { + $p = trim($p); + if (empty($p)) continue; + $pieces = explode(':', $p); + if (count($pieces) >= 2) { + $arr[] = $pieces; + } else { + $arr[] = [$pieces[0], '1', '99999']; + } + } + $row['give_effects'] = json_encode($arr); + } + if (!empty($row['clear_effects']) && $row['clear_effects'][0] !== '[') { + $names = array_filter(explode(',', $row['clear_effects']), function($n) { return !empty(trim($n)); }); + $row['clear_effects'] = json_encode(array_values(array_map('trim', $names))); + } + return $row; +} + try { // ★ 加载core.php(与sync.php相同的加载方式) $coreFile = dirname(__DIR__) . '/core.php'; @@ -546,7 +574,7 @@ function handleListLands($db) { $result = $db->query("SELECT * FROM web_area_lands ORDER BY synced_at DESC"); $lands = []; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { - $lands[] = $row; + $lands[] = convertEffectsForFrontend($row); } echo json_encode(['success' => true, 'lands' => $lands]); } @@ -714,7 +742,7 @@ function handleMyLands($db, $playerName) { $lands = []; while ($row = $result->fetchArray(SQLITE3_ASSOC)) { - $lands[] = $row; + $lands[] = convertEffectsForFrontend($row); } echo json_encode(['success' => true, 'lands' => $lands, 'player' => $playerName]); @@ -755,7 +783,7 @@ function handleLandDetail($db, $playerName, $landName) { $visitors[] = $row; } - echo json_encode(['success' => true, 'land' => $land, 'visitors' => $visitors]); + echo json_encode(['success' => true, 'land' => convertEffectsForFrontend($land), 'visitors' => $visitors]); } // ==================== 玩家端:添加访客 ==================== @@ -887,9 +915,34 @@ function handleUpdateLandField($db, $playerName, $post) { // 确保字段存在(容错) try { $db->exec("ALTER TABLE web_area_lands ADD COLUMN {$field} TEXT DEFAULT ''"); } catch (\Throwable $e) {} + // ★ 将JSON数组转回Java格式再存储 + $storeValue = $value; + if (($field === 'give_effects' || $field === 'clear_effects') && !empty($value) && $value[0] === '[') { + $arr = json_decode($value, true); + if (is_array($arr)) { + if ($field === 'give_effects') { + // [["夜视","1","99999"]] → "夜视:1:99999" + $parts = []; + foreach ($arr as $e) { + if (is_array($e)) { + $parts[] = implode(':', $e); + } else { + $parts[] = (string)$e; + } + } + $storeValue = implode('|', $parts); + } else { + // clear_effects: ["POISON","WITHER"] → "POISON,WITHER" + $storeValue = implode(',', array_map(function($e) { + return is_array($e) ? $e[0] : (string)$e; + }, $arr)); + } + } + } + // 更新 $stmt2 = $db->prepare("UPDATE web_area_lands SET {$field} = :value, admin_changed = 1 WHERE name = :name"); - $stmt2->bindValue(':value', $value, SQLITE3_TEXT); + $stmt2->bindValue(':value', $storeValue, SQLITE3_TEXT); $stmt2->bindValue(':name', $name, SQLITE3_TEXT); $stmt2->execute();