13 Commits

Author SHA1 Message Date
zs-yg
ddc0d1d9e0 修改README.md 2025-11-13 21:10:45 +08:00
zs-yg
adaa360265 修改README.md 2025-11-13 21:09:09 +08:00
zs-yg
e2219d5042 修改README.md 2025-11-13 21:08:00 +08:00
zs-yg
8982aa9bcc 添加日志系统和gitignore 2025-11-09 14:48:42 +08:00
zs-yg
0b6f66304b 添加构建脚本 2025-11-09 08:27:54 +08:00
zsyg
d325676293 修改下载逻辑 2025-10-31 21:27:35 +08:00
zsyg
a8069c60b9 Fix formatting issues in README.md 2025-10-29 20:46:51 +08:00
zsyg
fbc4776eb8 Fix formatting issues in README.md 2025-10-29 20:44:47 +08:00
zsyg
9d87fd4bfb 修改README.md 2025-10-27 21:16:16 +08:00
zsyg
f46d169224 修改README.md 2025-10-27 21:14:31 +08:00
zsyg
866aa24686 Add files via upload 2025-10-27 21:12:10 +08:00
zsyg
453bf59eaa Add files via upload 2025-10-27 21:11:38 +08:00
zsyg
1d0f4d1631 Add files via upload 2025-10-27 21:10:25 +08:00
7 changed files with 178 additions and 8 deletions

4
.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
bin/
obj/
logs/
profiles/

View File

@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using MCSJ.Tools;
using MCSJ.Tools.LogSystem;
namespace MCSJ
{
@@ -8,8 +9,15 @@ namespace MCSJ
{
static async Task Main(string[] args)
{
// 验证日志目录
string logDir = LogCreator.GetLogDirectory();
Console.WriteLine($"日志目录: {logDir}");
LogMain.Debug($"日志文件: {LogCreator.GetLogFilePath()}");
LogMain.Info("MC服务器下载工具启动");
var versionManager = new VersionManager();
var downloadService = new DownloadService(versionManager);
LogMain.Debug("服务初始化完成");
while (true)
{
@@ -20,21 +28,27 @@ namespace MCSJ
Console.Write("请选择操作: ");
var input = Console.ReadLine();
LogMain.Debug($"用户选择操作: {input}");
switch (input)
{
case "1":
versionManager.DisplayAllVersions();
LogMain.Info("显示所有版本列表");
break;
case "2":
Console.Write("请输入要下载的版本名称: ");
var version = Console.ReadLine();
LogMain.Info($"开始下载版本: {version}");
await downloadService.DownloadVersion(version);
LogMain.Info($"版本下载完成: {version}");
break;
case "3":
LogMain.Info("程序正常退出");
return;
default:
Console.WriteLine("无效输入,请重新选择");
LogMain.Warn($"无效的用户输入: {input}");
break;
}

View File

@@ -1,2 +1,59 @@
# MCSJ
windows的命令行mc开服工具
# MCSJ 服务器管理工具
MCSJ 是一个开源的 Minecraft 服务器管理工具,旨在为用户提供极致便捷的服务器搭建与管理体验。
## 主要功能
- 一键下载 server.jar
- 一键生成启动脚本
- 一键启动服务器
- 一键下载 Java 环境
- 一些有趣实用的辅助功能
> 更多辅助功能请下载体验。
## 下载地址
[123网盘链接](https://www.123865.com/s/msALTd-L610d)
[github releases](https://github.com/zs-yg/MCSJ/releases)
## 开发环境
- Windows 10
- Visual Studio Code
- .net 8.0
## 运行环境
- Windows 10
- .net 8.0 runtime
## 运行方式
1. 下载并解压 MCSJ 压缩包。
2. 双击运行 MCSJ.exe 启动程序。
3. 或者命令行输入MCSJ.exe 启动程序。可以查看是否需要安装运行时
## 关于作者
MCSJ 项目由 [zs-yg](https://github.com/zs-yg) 开发,欢迎提交 issue 和 PR。
[discord](https://discord.gg/4mbqUzfg)
qq群:1043867176
b站号:https://space.bilibili.com/1698250734
## 开源协议
MIT协议
本项目已在 GitHub 开源,欢迎贡献代码与建议。
# 恰饭awa
不用捐款使用这个链接注册服务器就行了awa
性能不错,可以免费白嫖
服务器:https://www.rainyun.com/Nzk2NDEy_

View File

@@ -25,10 +25,34 @@ namespace MCSJ.Tools
return;
}
// 根目录 profiles 文件夹
var profilesRoot = Path.Combine(Directory.GetCurrentDirectory(), "profiles");
if (!Directory.Exists(profilesRoot))
Directory.CreateDirectory(profilesRoot);
string targetFolder = null;
string profilePath = null;
while (true)
{
Console.Write($"请输入存放文件夹名称(直接回车默认用版本名 '{version}'");
var input = Console.ReadLine();
targetFolder = string.IsNullOrWhiteSpace(input) ? version : input;
profilePath = Path.Combine(profilesRoot, targetFolder);
if (!Directory.Exists(profilePath))
break;
Console.WriteLine($"文件夹 '{targetFolder}' 已存在,请重新输入(直接回车则取消下载):");
}
if (Directory.Exists(profilePath))
{
Console.WriteLine("下载已取消。");
return;
}
Directory.CreateDirectory(profilePath);
string jarPath = Path.Combine(profilePath, "server.jar");
try
{
Console.WriteLine($"开始下载 {version}...");
Console.WriteLine($"开始下载 {version} 到 {profilePath} ...");
var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode();
@@ -38,7 +62,7 @@ namespace MCSJ.Tools
var isMoreToRead = true;
using (var stream = await response.Content.ReadAsStreamAsync())
using (var fileStream = new FileStream($"{version}.jar", FileMode.Create, FileAccess.Write))
using (var fileStream = new FileStream(jarPath, FileMode.Create, FileAccess.Write))
{
while (isMoreToRead)
{
@@ -50,7 +74,6 @@ namespace MCSJ.Tools
else
{
await fileStream.WriteAsync(buffer, 0, read);
downloadedBytes += read;
if (totalBytes > 0)
{
@@ -60,8 +83,7 @@ namespace MCSJ.Tools
}
}
}
Console.WriteLine($"\n{version} 下载完成!");
Console.WriteLine($"\n{version} 下载完成! 文件已保存到 {jarPath}");
}
catch (Exception ex)
{

View File

@@ -0,0 +1,29 @@
using System;
using System.IO;
namespace MCSJ.Tools.LogSystem
{
public static class LogCreator
{
public static string GenerateLogFileName()
{
DateTime now = DateTime.Now;
return $"{now:yyyy-MM-dd-HH-mm-ss}.log";
}
public static string GetLogDirectory()
{
string logDir = Path.Combine(Directory.GetCurrentDirectory(), "logs");
if (!Directory.Exists(logDir))
{
Directory.CreateDirectory(logDir);
}
return logDir;
}
public static string GetLogFilePath()
{
return Path.Combine(GetLogDirectory(), GenerateLogFileName());
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using System.IO;
using System.Threading;
namespace MCSJ.Tools.LogSystem
{
public static class LogMain
{
private static readonly object _lock = new object();
public enum LogLevel
{
DEBUG,
INFO,
WARN,
ERROR,
FATAL
}
public static void Log(LogLevel level, string message)
{
string logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{level}] {message}";
string logPath = LogCreator.GetLogFilePath();
lock (_lock)
{
File.AppendAllText(logPath, logEntry + Environment.NewLine);
}
}
public static void Debug(string message) => Log(LogLevel.DEBUG, message);
public static void Info(string message) => Log(LogLevel.INFO, message);
public static void Warn(string message) => Log(LogLevel.WARN, message);
public static void Error(string message) => Log(LogLevel.ERROR, message);
public static void Fatal(string message) => Log(LogLevel.FATAL, message);
}
}

7
build.bat Normal file
View File

@@ -0,0 +1,7 @@
dotnet publish MCSJ.csproj -c Release -r win-x86 --self-contained false /p:Optimize=true /p:DebugType=None
dotnet publish MCSJ.csproj -c Release -r win-x64 --self-contained false /p:Optimize=true /p:DebugType=None
cd bin\Release\net8.0
ren win-x64 MCSJ-x64
ren win-x86 MCSJ-x86
rmdir /s /q MCSJ-x64\publish
rmdir /s /q MCSJ-x86\publish