feat:V3.0.1
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
import fs from "node:fs";
|
||||
import p from "node:path"
|
||||
import websocket, { WebSocketServer } from "ws";
|
||||
import { yauzl_promise } from "./utils/yauzl.promise.js";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { platform, what_platform } from "./platform/index.js";
|
||||
import { DeEarth } from "./utils/DeEarth.js";
|
||||
import { mlsetup } from "./modloader/index.js";
|
||||
import { console } from "node:inspector";
|
||||
|
||||
interface Iinfo{
|
||||
name:string
|
||||
buffer:Buffer
|
||||
}
|
||||
import { dinstall, mlsetup } from "./modloader/index.js";
|
||||
import config from "./utils/config.js";
|
||||
import { execPromise } from "./utils/utils.js";
|
||||
|
||||
export class Dex {
|
||||
wsx!: WebSocketServer;
|
||||
@@ -18,79 +15,128 @@ export class Dex {
|
||||
ws!: websocket;
|
||||
constructor(ws: WebSocketServer) {
|
||||
this.wsx = ws;
|
||||
this.wsx.on('connection',(e)=>{
|
||||
this.ws = e
|
||||
})
|
||||
this.in = {}
|
||||
}
|
||||
this.wsx.on("connection", (e) => {
|
||||
this.ws = e;
|
||||
});
|
||||
this.in = {};
|
||||
}
|
||||
|
||||
public async Main(buffer: Buffer) {
|
||||
const first = Date.now()
|
||||
const info = await this._getinfo(buffer)
|
||||
const plat = what_platform(info)
|
||||
const mpname = this.in.name
|
||||
const unpath = `./instance/${mpname}`
|
||||
public async Main(buffer: Buffer, dser: boolean) {
|
||||
const first = Date.now();
|
||||
const info = await this._getinfo(buffer);
|
||||
const plat = what_platform(info);
|
||||
const mpname = this.in.name;
|
||||
const unpath = `./instance/${mpname}`;
|
||||
await Promise.all([
|
||||
this._unzip(buffer,mpname),
|
||||
await platform(plat).downloadfile(this.in,unpath,this.ws)
|
||||
]) // 解压和下载
|
||||
this.ws.send(JSON.stringify({
|
||||
status: "changed",
|
||||
result: undefined
|
||||
})); //改变状态
|
||||
await new DeEarth(`${unpath}/mods`,`./.rubbish/${mpname}`).Main()
|
||||
this.ws.send(JSON.stringify({
|
||||
status: "changed",
|
||||
result: undefined
|
||||
})); //改变状态(DeEarth筛选模组完毕)
|
||||
const mlinfo = await platform(plat).getinfo(this.in)
|
||||
await mlsetup(mlinfo.loader,mlinfo.minecraft,mlinfo.loader_version,unpath) //安装服务端
|
||||
const latest = Date.now()
|
||||
this.ws.send(JSON.stringify({
|
||||
status: "finish",
|
||||
result: latest - first
|
||||
}))
|
||||
this._unzip(buffer, mpname),
|
||||
await platform(plat).downloadfile(this.in, unpath, this.ws),
|
||||
]); // 解压和下载
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
status: "changed",
|
||||
result: undefined,
|
||||
})
|
||||
); //改变状态
|
||||
await new DeEarth(`${unpath}/mods`, `./.rubbish/${mpname}`).Main();
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
status: "changed",
|
||||
result: undefined,
|
||||
})
|
||||
); //改变状态(DeEarth筛选模组完毕)
|
||||
const mlinfo = await platform(plat).getinfo(this.in);
|
||||
if (dser) {
|
||||
await mlsetup(
|
||||
mlinfo.loader,
|
||||
mlinfo.minecraft,
|
||||
mlinfo.loader_version,
|
||||
unpath
|
||||
); //安装服务端
|
||||
}
|
||||
if (!dser) {
|
||||
dinstall(mlinfo.loader, mlinfo.minecraft, mlinfo.loader_version, unpath);
|
||||
}
|
||||
const latest = Date.now();
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
status: "finish",
|
||||
result: latest - first,
|
||||
})
|
||||
);
|
||||
if (config.oaf) {
|
||||
await execPromise(`start ${p.join("./instance")}`);
|
||||
}
|
||||
//await this._unzip(buffer);
|
||||
}
|
||||
|
||||
private async _getinfo(buffer: Buffer){
|
||||
const important_name = ["manifest.json","modrinth.index.json"]
|
||||
let contain:string = ""
|
||||
private async _getinfo(buffer: Buffer) {
|
||||
const important_name = ["manifest.json", "modrinth.index.json"];
|
||||
let contain: string = "";
|
||||
const zip = await yauzl_promise(buffer);
|
||||
zip.forEach(async e=>{
|
||||
if (important_name.includes(e.fileName)){
|
||||
contain = e.fileName
|
||||
this.in = JSON.parse((e.ReadEntrySync).toString())
|
||||
return;
|
||||
zip.forEach(async (e) => {
|
||||
if (important_name.includes(e.fileName)) {
|
||||
contain = e.fileName;
|
||||
this.in = JSON.parse(e.ReadEntrySync.toString());
|
||||
return;
|
||||
}
|
||||
})
|
||||
});
|
||||
return contain;
|
||||
}
|
||||
|
||||
private async _unzip(buffer: Buffer,instancename:string) {
|
||||
private async _unzip(buffer: Buffer, instancename: string) {
|
||||
/* 解压Zip */
|
||||
const zip = await yauzl_promise(buffer);
|
||||
let index = 1;
|
||||
for await (const entry of zip) {
|
||||
const ew = entry.fileName.endsWith("/");
|
||||
if (ew) {
|
||||
await fs.promises.mkdir(`./instance/${instancename}/${entry.fileName}`, {
|
||||
recursive: true,
|
||||
});
|
||||
await fs.promises.mkdir(
|
||||
`./instance/${instancename}/${entry.fileName}`,
|
||||
{
|
||||
recursive: true,
|
||||
}
|
||||
);
|
||||
}
|
||||
if (!ew&&entry.fileName.startsWith("overrides/")) {
|
||||
const dirPath = `./instance/${instancename}/${entry.fileName.substring(
|
||||
0,
|
||||
entry.fileName.lastIndexOf("/")
|
||||
).replace("overrides/","")}`;
|
||||
if (!ew && entry.fileName.startsWith("overrides/")) {
|
||||
const dirPath = `./instance/${instancename}/${entry.fileName
|
||||
.substring(0, entry.fileName.lastIndexOf("/"))
|
||||
.replace("overrides/", "")}`;
|
||||
if (this._ublack(entry.fileName)) {
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
await fs.promises.mkdir(dirPath, { recursive: true });
|
||||
const stream = await entry.openReadStream;
|
||||
const write = fs.createWriteStream(`./instance/${instancename}/${entry.fileName.replace("overrides/","")}`);
|
||||
const write = fs.createWriteStream(
|
||||
`./instance/${instancename}/${entry.fileName.replace(
|
||||
"overrides/",
|
||||
""
|
||||
)}`
|
||||
);
|
||||
await pipeline(stream, write);
|
||||
}
|
||||
this.ws.send(JSON.stringify({ status: "unzip", result: { name: entry.fileName,total: zip.length, current:index } }));
|
||||
index++
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
status: "unzip",
|
||||
result: { name: entry.fileName, total: zip.length, current: index },
|
||||
})
|
||||
);
|
||||
index++;
|
||||
}
|
||||
/* 解压完成 */
|
||||
}
|
||||
|
||||
private _ublack(filename: string) {
|
||||
if (filename === "overrides/") {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
filename.includes("shaderpacks") ||
|
||||
filename.includes("essential") ||
|
||||
filename.includes("resourcepacks") ||
|
||||
filename === "overrides/options.txt"
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,9 @@ import multer from "multer";
|
||||
import cors from "cors"
|
||||
import websocket, { WebSocketServer } from "ws"
|
||||
import { createServer, Server } from "node:http";
|
||||
import fs from "node:fs"
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { Config, IConfig } from "./utils/config.js";
|
||||
import { yauzl_promise } from "./utils/yauzl.promise.js";
|
||||
import { Dex } from "./Dex.js";
|
||||
import { mlsetup } from "./modloader/index.js";
|
||||
import { exec } from "node:child_process";
|
||||
export class Core {
|
||||
private config: IConfig;
|
||||
private readonly app: Application;
|
||||
@@ -30,14 +27,36 @@ export class Core {
|
||||
this.dex = new Dex(this.ws)
|
||||
}
|
||||
|
||||
javachecker(){
|
||||
exec("java -version",(err,stdout,stderr)=>{
|
||||
if(err){
|
||||
this.wsx.send(JSON.stringify({
|
||||
type:"error",
|
||||
message:"jini"
|
||||
}))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
express() {
|
||||
this.app.use(cors());
|
||||
this.app.use(express.json());
|
||||
this.app.get('/',(req,res)=>{
|
||||
res.json({
|
||||
status:200,
|
||||
by:"DeEarthX.Core",
|
||||
qqg:"559349662",
|
||||
bilibili:"https://space.bilibili.com/1728953419"
|
||||
})
|
||||
})
|
||||
this.app.post("/start", this.upload.single("file"), (req, res) => {
|
||||
if (!req.file) {
|
||||
return;
|
||||
}
|
||||
this.dex.Main(req.file.buffer) //Dex
|
||||
if (!req.query.mode){
|
||||
return;
|
||||
}
|
||||
this.dex.Main(req.file.buffer,req.query.mode == "server") //Dex
|
||||
//this.dex.Main(req.file.buffer)
|
||||
res.json({
|
||||
status:200,
|
||||
|
||||
@@ -31,7 +31,7 @@ export class Fabric{
|
||||
}
|
||||
|
||||
async setup():Promise<void>{
|
||||
await this.getLaestLoader()
|
||||
await this.installer()
|
||||
await this.libraries()
|
||||
await this.install()
|
||||
await this.wshell()
|
||||
@@ -59,7 +59,7 @@ export class Fabric{
|
||||
await xfastdownload(_downlist)
|
||||
}
|
||||
|
||||
async getLaestLoader(){
|
||||
async installer(){
|
||||
let downurl = ""
|
||||
const res = await this.got.get("fabric-meta/v2/versions/installer").json<ILatestLoader[]>()
|
||||
res.forEach(e=>{
|
||||
|
||||
@@ -4,7 +4,8 @@ import { Minecraft } from "./minecraft.js";
|
||||
import { NeoForge } from "./neoforge.js";
|
||||
|
||||
interface XModloader {
|
||||
setup(): Promise<void>
|
||||
setup(): Promise<void>;
|
||||
installer(): Promise<void>;
|
||||
}
|
||||
export function modloader(ml:string,mcv:string,mlv:string,path:string){
|
||||
let modloader:XModloader
|
||||
@@ -33,4 +34,8 @@ export async function mlsetup(ml:string,mcv:string,mlv:string,path:string){
|
||||
//console.log(ml)
|
||||
await modloader(ml,mcv,mlv,path).setup()
|
||||
await minecraft.setup()
|
||||
}
|
||||
|
||||
export async function dinstall(ml:string,mcv:string,mlv:string,path:string){
|
||||
await modloader(ml,mcv,mlv,path).installer();
|
||||
}
|
||||
@@ -109,6 +109,10 @@ export class Minecraft {
|
||||
// 依赖解压
|
||||
}
|
||||
|
||||
async installer(){ //占位
|
||||
|
||||
}
|
||||
|
||||
async eula(){
|
||||
const context = `#By changing the setting below to TRUE you are indicating your agreement to our EULA (https://aka.ms/MinecraftEULA).\n#Spawn by DeEarthX(QQgroup:559349662) Tianpao:(https://space.bilibili.com/1728953419)\neula=true`
|
||||
await fs.promises.writeFile(`${this.path}/eula.txt`,context)
|
||||
|
||||
@@ -9,6 +9,7 @@ export interface IConfig {
|
||||
dexpub: boolean;
|
||||
mixins: boolean;
|
||||
};
|
||||
oaf: boolean
|
||||
}
|
||||
|
||||
export class Config {
|
||||
@@ -22,6 +23,7 @@ export class Config {
|
||||
dexpub: false,
|
||||
mixins: true,
|
||||
},
|
||||
oaf:true
|
||||
};
|
||||
config(): IConfig {
|
||||
if (!fs.existsSync("./config.json")) {
|
||||
|
||||
@@ -49,7 +49,7 @@ export function version_compare(v1: string, v2: string) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function execPromise(cmd:string,options:ExecOptions){
|
||||
export function execPromise(cmd:string,options?:ExecOptions){
|
||||
return new Promise((resolve,reject)=>{
|
||||
exec(cmd,options,(err,stdout,stderr)=>{
|
||||
if(err){
|
||||
|
||||
Reference in New Issue
Block a user