Files
ZYZ/game-server/app/components/UpdateComponent.ts
2026-03-13 01:38:40 +00:00

50 lines
1.7 KiB
TypeScript

import { Application, IComponent, manualReloadCrons, manualReloadHandlers, manualReloadRemoters } from "pinus";
export class UpdateComponent implements IComponent {
name = "UpdateComponent";
app: Application;
constructor(app: Application) {
this.app = app;
this.app.set(this.name, this);
}
start(cb: () => void) {
console.log("UpdateComponent start", this.app.getServerId());
cb();
}
stop(force: boolean, cb: () => void) {
console.log("UpdateComponent stop", force, this.app.getServerId());
cb();
}
hotupdate(files: string, cb: (err, res?) => void) {
try {
const filelist = files.split(",");
for (let i = 0; i < filelist.length; i++) {
const file = this.app.getBase() + filelist[i];
if (!file || !require.cache[file]) {
console.log("UpdateComponent hotupdate", this.app.getServerId(), "file not exist", file);
cb("file not exist");
return;
}
}
for (let i = 0; i < filelist.length; i++) {
const file = this.app.getBase() + filelist[i];
delete require.cache[file];
console.log("UpdateComponent hotupdate", this.app.getServerId(), file)
}
manualReloadHandlers(this.app);
manualReloadRemoters(this.app);
manualReloadCrons(this.app);
cb(null, "success");
} catch (error) {
console.log("UpdateComponent hotupdate", this.app.getServerId(), error)
cb(error);
return;
}
}
}