Initial commit

This commit is contained in:
2026-08-24 22:20:36 +02:00
commit 62f7b1278a
251 changed files with 16670 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
// const Game = require("../../../Game/Game");
// const isAuthenticated = require("../../../Utility/isAuthenticated");
const ShopEntryPacket = require("../../../Packets/ShopEntry");
const BASE_SHOP = require("../../../Data/shop");
const { SHOP } = BASE_SHOP;
module.exports = (res, req) => {
res.onAborted(() => res.isAborted = true);
console.info("hit")
let buffer = Buffer.alloc(0);
res.onData(async (chunk, isLast) => {
buffer = Buffer.concat([buffer, Buffer.from(chunk)]);
if (isLast) {
const body = buffer.toString("utf8");
let data = {};
try {
data = JSON.parse(body);
} catch {
console.info("error")
res
.writeStatus("400 Bad Request")
.end();
};
console.info(data);
const shopEntryAddQuery = await execute("INSERT INTO shop (itemID, categoryID, currencyType, currencyAmount, unit) VALUES (?, ?, ?, ?, ?)", [data.itemID, data.categoryID, data.currencyType, data.currencyAmount, data.unit]);
if (!shopEntryAddQuery.data) {
return res
.writeStatus("400 Bad Request")
.end();
};
const shopEntry = {
id: shopEntryAddQuery.data.insertId,
itemID: parseInt(data.itemID),
categoryID: parseInt(data.categoryID),
currencyType: parseInt(data.currencyType),
currencyAmount: parseInt(data.currencyAmount),
unit: parseInt(data.unit),
shopCategoryID: 2,
isAvailable: () => true
};
console.info(shopEntryAddQuery.data);
SHOP.push(shopEntry);
const shopEntryPacket = ShopEntryPacket(shopEntry);
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20].forEach(mapID => app.publish(mapID.toString(), shopEntryPacket, true, true));
res.cork(() => res
.writeStatus("200")
.end("OK"));
};
});
};
+38
View File
@@ -0,0 +1,38 @@
// const Game = require("../../../Game/Game");
// const isAuthenticated = require("../../../Utility/isAuthenticated");
const ShopEntryRemovedPacket = require("../../../Packets/ShopEntryRemoved");
const BASE_SHOP = require("../../../Data/shop");
const { SHOP } = BASE_SHOP;
module.exports = async (res, req) => {
res.onAborted(() => res.isAborted = true);
const shopEntryID = req.getParameter(0);
if (!shopEntryID) return;
const shopEntryRemoveQuery = await execute("DELETE FROM shop WHERE id = ?", [shopEntryID]);
if (!shopEntryRemoveQuery.data) return;
const shopEntryIndex = SHOP.findIndex(entry => entry.id === parseInt(shopEntryID));
if (shopEntryIndex === -1) return;
const { shopCategoryID, itemID } = SHOP[shopEntryIndex];
SHOP.splice(shopEntryIndex, 1);
const shopEntryRemoved = {
shopCategoryID: 4,
id: itemID
};
const shopEntryRemovedPacket = ShopEntryRemovedPacket(shopEntryRemoved);
[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20].forEach(mapID => app.publish(mapID.toString(), shopEntryRemovedPacket, true, true));
res.cork(() => res
.writeStatus("200")
.end("OK"));
};