Skip to content
This repository was archived by the owner on Dec 14, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/org/mcdcl/launcher/GameLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,13 @@ public void stopGame() {
public boolean isRunning() {
return gameProcess != null && gameProcess.isAlive();
}
}
}

// 在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可用空间");
}
16 changes: 15 additions & 1 deletion src/main/java/org/mcdcl/ui/ErrorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -116,4 +130,4 @@ private String getStackTraceAsString(Throwable throwable) {
throwable.printStackTrace(pw);
return sw.toString();
}
}
}
35 changes: 31 additions & 4 deletions src/main/java/org/mcdcl/ui/MultiplayerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -374,4 +401,4 @@ private void joinSelectedServer() {
mainView.showAlert("未选择服务器", "请先从列表中选择一个服务器");
}
}
}
}
49 changes: 42 additions & 7 deletions src/main/java/org/mcdcl/util/ResourcePackManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,50 @@ public static void downloadResourcePack(String packName, Consumer<Double> 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);
}
}
}
}
Loading