From e28b5fd65403038548f570426e17fe44ef9e1143 Mon Sep 17 00:00:00 2001 From: qiang-di Date: Sun, 18 May 2025 10:35:16 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/mcdcl/launcher/GameLauncher.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mcdcl/launcher/GameLauncher.java b/src/main/java/org/mcdcl/launcher/GameLauncher.java index e968591..2e81396 100644 --- a/src/main/java/org/mcdcl/launcher/GameLauncher.java +++ b/src/main/java/org/mcdcl/launcher/GameLauncher.java @@ -213,4 +213,13 @@ public void stopGame() { public boolean isRunning() { return gameProcess != null && gameProcess.isAlive(); } - } \ No newline at end of file + } + +// 在launchGame方法中添加更多的预检查 +// 例如检查磁盘空间是否足够 +File minecraftFolder = minecraftDir.getRoot(); +long freeSpace = minecraftFolder.getFreeSpace(); +long requiredSpace = 200 * 1024 * 1024; // 假设需要200MB空间 +if (freeSpace < requiredSpace) { + throw new LaunchException("磁盘空间不足,至少需要" + (requiredSpace / (1024 * 1024)) + "MB可用空间"); +} From 690f75f4c63950549f8b329e03d8f7a34b32c6d8 Mon Sep 17 00:00:00 2001 From: qiang-di Date: Sun, 18 May 2025 10:36:13 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E7=9A=84=E5=B8=AE=E5=8A=A9=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/mcdcl/ui/ErrorView.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/mcdcl/ui/ErrorView.java b/src/main/java/org/mcdcl/ui/ErrorView.java index 04a6514..4384c02 100644 --- a/src/main/java/org/mcdcl/ui/ErrorView.java +++ b/src/main/java/org/mcdcl/ui/ErrorView.java @@ -101,6 +101,20 @@ private void initUI() { scrollPane ); + // 在initUI方法中添加常见问题解决建议 + Label helpLabel = new Label("常见解决方法:"); + helpLabel.setFont(Font.font("System", FontWeight.BOLD, 14)); + + VBox helpBox = new VBox(5); + helpBox.getChildren().addAll( + new Label("1. 检查Java版本是否与游戏版本兼容"), + new Label("2. 确保网络连接正常"), + new Label("3. 检查是否有足够的磁盘空间"), + new Label("4. 尝试重新下载游戏文件") + ); + + // 将帮助信息添加到界面 + centerBox.getChildren().addAll(helpLabel, helpBox); setTop(topBox); setCenter(centerBox); setBottom(buttonBox); @@ -116,4 +130,4 @@ private String getStackTraceAsString(Throwable throwable) { throwable.printStackTrace(pw); return sw.toString(); } -} \ No newline at end of file +} From 1f2134ffb8bbf29d04b3911af1579ad1fef1cd67 Mon Sep 17 00:00:00 2001 From: qiang-di Date: Sun, 18 May 2025 10:37:17 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/mcdcl/util/ResourcePackManager.java | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/mcdcl/util/ResourcePackManager.java b/src/main/java/org/mcdcl/util/ResourcePackManager.java index e5809f2..5fe5503 100644 --- a/src/main/java/org/mcdcl/util/ResourcePackManager.java +++ b/src/main/java/org/mcdcl/util/ResourcePackManager.java @@ -34,15 +34,50 @@ public static void downloadResourcePack(String packName, Consumer progre // 确保目录存在 resourcePackDir.mkdirs(); - // TODO: 实现实际的资源包下载逻辑 - // 这里暂时使用模拟下载 - for (double progress = 0; progress <= 1; progress += 0.1) { - Thread.sleep(500); - progressCallback.accept(progress); + // 查找资源包下载链接 + URL url = new URL(RESOURCE_PACK_API); + JSONObject json = new JSONObject(new String(url.openStream().readAllBytes())); + JSONArray hits = json.getJSONArray("hits"); + + String downloadUrl = null; + for (int i = 0; i < hits.length(); i++) { + JSONObject pack = hits.getJSONObject(i); + if (pack.getString("title").equals(packName)) { + // 假设API返回的结构中包含下载链接 + downloadUrl = pack.getString("download_url"); + break; + } + } + + if (downloadUrl == null) { + throw new IOException("找不到资源包: " + packName); } + // 执行下载 + URL packUrl = new URL(downloadUrl); + String fileName = packName.replaceAll("[^a-zA-Z0-9.-]", "_") + ".zip"; + File outputFile = new File(resourcePackDir, fileName); + + try (InputStream in = packUrl.openStream(); + FileOutputStream out = new FileOutputStream(outputFile)) { + + byte[] buffer = new byte[8192]; + long totalBytes = 0; + int bytesRead; + long fileSize = packUrl.openConnection().getContentLengthLong(); + + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + totalBytes += bytesRead; + + if (fileSize > 0) { + double progress = (double) totalBytes / fileSize; + progressCallback.accept(progress); + } + } + } } catch (Exception e) { - throw new IOException("下载资源包失败: " + e.getMessage()); + throw new IOException("下载资源包失败: " + e.getMessage(), e); } } -} \ No newline at end of file +} From 476fba3ce2dd77d6f61f2c43825d571b0e4ed6a2 Mon Sep 17 00:00:00 2001 From: qiang-di Date: Sun, 18 May 2025 10:38:28 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=AF=86=E9=92=A5=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E5=8A=A0=E5=BC=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/mcdcl/ui/MultiplayerView.java | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/mcdcl/ui/MultiplayerView.java b/src/main/java/org/mcdcl/ui/MultiplayerView.java index e3ed6ca..8491aa0 100644 --- a/src/main/java/org/mcdcl/ui/MultiplayerView.java +++ b/src/main/java/org/mcdcl/ui/MultiplayerView.java @@ -345,9 +345,36 @@ private String generateRandomKey() { } private boolean validateKey(String key) { - // 简单验证密钥格式 - return key != null && key.length() == 16 && - key.matches("^[a-zA-Z0-9]+$"); + // 更强的密钥验证 + if (key == null || key.isEmpty()) { + return false; + } + + // 检查长度 + if (key.length() < 16 || key.length() > 32) { + return false; + } + + // 检查格式 - 要求包含字母和数字的组合 + boolean hasLetter = false; + boolean hasDigit = false; + + for (char c : key.toCharArray()) { + if (Character.isLetter(c)) { + hasLetter = true; + } else if (Character.isDigit(c)) { + hasDigit = true; + } else if (!Character.isLetterOrDigit(c)) { + // 不允许特殊字符 + return false; + } + + if (hasLetter && hasDigit) { + break; + } + } + + return hasLetter && hasDigit; } private String establishP2PConnection(String key) throws Exception { @@ -374,4 +401,4 @@ private void joinSelectedServer() { mainView.showAlert("未选择服务器", "请先从列表中选择一个服务器"); } } -} \ No newline at end of file +}