mirror of
https://github.com/WorldEditAxe/eaglerproxy.git
synced 2024-11-13 17:16:04 -08:00
25 lines
944 B
JavaScript
25 lines
944 B
JavaScript
|
import { dirname, join } from "path";
|
||
|
import { fileURLToPath, pathToFileURL } from "url";
|
||
|
import { Util } from "./Util.js";
|
||
|
export async function loadPackets(dir) {
|
||
|
const files = (await Util.recursiveFileSearch(dir ?? join(dirname(fileURLToPath(import.meta.url)), "packets"))).filter((f) => f.endsWith(".js") && !f.endsWith(".disabled.js"));
|
||
|
const packetRegistry = new Map();
|
||
|
for (const file of files) {
|
||
|
const imp = await import(process.platform == "win32" ? pathToFileURL(file).toString() : file);
|
||
|
for (const val of Object.values(imp)) {
|
||
|
if (val != null) {
|
||
|
let e;
|
||
|
try {
|
||
|
e = new val();
|
||
|
}
|
||
|
catch { }
|
||
|
if (e != null && e.type == "packet") {
|
||
|
e.class = val;
|
||
|
packetRegistry.set(e.packetId, e);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return packetRegistry;
|
||
|
}
|