diff --git a/src/chunithm.ts b/src/chunithm.ts deleted file mode 100644 index a0932f2..0000000 --- a/src/chunithm.ts +++ /dev/null @@ -1,203 +0,0 @@ -import compression from "compression"; -import express from "express"; -import logger from "debug"; - -const debug = logger("app:chuni:io"); -const app = express(); - -// Thankfully we can use standard middleware for JSON I/O. We have to use a -// zlib middleware as well because compression is non-optional: the client will -// attempt to inflate whatever response we send to it whether there's a -// Transfer-Encoding header or not. - -app.use(function(req, res, next) { - // Chunithm client does not follow the HTTP spec: user agents must indicate - // that they are willing to accept a particular Transfer-Encoding for that - // T-E to be used (unless the T-E in question is "chunked" but w/e), and this - // indication is advisory anyway, the server is permitted to ignore it. - // - // Force this header into the request, since it is not present normally. - - req.headers["accept-encoding"] = "deflate"; - - return next(); -}); - -app.use(compression({ threshold: 0 })); -app.use(express.json()); - -// Trace requests and responses - -app.use(function(req, resp, next) { - debug(`\n--- Chunithm ${req.url} ---\n`); - debug(`Request: ${JSON.stringify(req.body)}\n`); - - const prevJson = resp.json; - - resp.json = function(obj) { - debug(`Response: ${JSON.stringify(obj)}`); - - resp.json = prevJson; - resp.json.apply(this, arguments); - - return resp; - }; - - next(); -}); - -app.post("/ChuniServlet/GetGameSettingApi", function(req, resp) { - resp.json({ - gameSetting: { - dataVersion: 1, - isMaintenance: false, - requestInterval: 10, - rebootStartTime: 0, - rebootEndTime: 0, - isBackgroundDistribute: false, - maxCountCharacter: 999, - maxCountItem: 999, - maxCountMusic: 999, - }, - isDumpUpload: false, - isAou: false, - }); -}); - -app.post("/ChuniServlet/UpsertClientSettingApi", function(req, resp) { - resp.json({ - returnCode: 1, - apiName: "UpsertClientSettingApi", - }); -}); - -app.post("/ChuniServlet/UpsertClientBookkeepingApi", function(req, resp) { - resp.json({ - returnCode: 1, - apiName: "UpsertClientBookkeepingApi", - }); -}); - -app.post("/ChuniServlet/UpsertClientTestmodeApi", function(req, resp) { - resp.json({ - returnCode: 1, - apiName: "UpsertClientTestmodeApi", - }); -}); - -app.post("/ChuniServlet/UpsertClientErrorApi", function(req, resp) { - resp.json({ - returnCode: 1, - apiName: "UpsertClientErrorApi", - }); -}); - -app.post("/ChuniServlet/UpsertClientDevelopApi", function(req, resp) { - resp.json({ - returnCode: 1, - apiName: "UpsertClientDevelopApi", - }); -}); - -app.post("/ChuniServlet/GetGameMessageApi", function(req, resp) { - resp.json({ - type: 1, - length: 0, - gameMessageList: [ - /* { - type: 2, - id: 1, - message: "true", - startDate: "0", - endDate: "0" - },*/ - ], - }); -}); - -app.post("/ChuniServlet/GetGameIdlistApi", function(req, resp) { - const { type } = req.body; - - resp.json({ - type, - length: 0, - gameIdlistList: [], - }); -}); - -app.post("/ChuniServlet/GetGameEventApi", function(req, resp) { - resp.json({ - type: 1, - length: 0, - gameEventList: [ - /* - { - type: 1, - id: 1102, // data/A000/event/event00001102 - startDate: 'STRINGIDK', - endDate: 'STRINGIDK', - }, - */ - ], - }); -}); - -app.post("/ChuniServlet/GetGameRankingApi", function(req, resp) { - const { type } = req.body; - - resp.json({ - type, - gameRankingList: [ - /* - // QWORD fields maybe? - { - id: 1, - point: 1, - } - */ - ], - }); -}); - -app.post("/ChuniServlet/GetGameSaleApi", function(req, resp) { - const { type } = req.body; - - resp.json({ - type, - length: 0, - gameSaleList: [ - /* - { - orderId: 1234, - type, - id: 4321, - rate: 5678, - startDate: 'STRINGIDK', - endDate: 'STRINGIDK', - }, - */ - ], - }); -}); - -app.post("/ChuniServlet/GetGameChargeApi", function(req, resp) { - resp.json({ - length: 0, - gameChargeList: [ - /* - { - orderId: 1, - chargeId: 1, - price: 1, - startDate: 'STRINGIDK', - endDate: 'STRINGIDK', - salePrice: - saleStartDate: 'STRINGIDK', - saleEndDate: 'STRINGIDK', - }, - */ - ], - }); -}); - -export default app; diff --git a/src/chunithm/getGameCharge.ts b/src/chunithm/getGameCharge.ts new file mode 100644 index 0000000..cdccf63 --- /dev/null +++ b/src/chunithm/getGameCharge.ts @@ -0,0 +1,21 @@ +import { Request, Response } from "express"; + +export default function getGameCharge(req: Request, res: Response) { + res.json({ + length: 0, + gameChargeList: [ + /* + { + orderId: 1, + chargeId: 1, + price: 1, + startDate: 'STRINGIDK', + endDate: 'STRINGIDK', + salePrice: + saleStartDate: 'STRINGIDK', + saleEndDate: 'STRINGIDK', + }, + */ + ], + }); +} diff --git a/src/chunithm/getGameEvent.ts b/src/chunithm/getGameEvent.ts new file mode 100644 index 0000000..e58cb8b --- /dev/null +++ b/src/chunithm/getGameEvent.ts @@ -0,0 +1,18 @@ +import { Request, Response } from "express"; + +export default function getGameEvent(req: Request, res: Response) { + res.json({ + type: 1, + length: 0, + gameEventList: [ + /* + { + type: 1, + id: 1102, // data/A000/event/event00001102 + startDate: 'STRINGIDK', + endDate: 'STRINGIDK', + }, + */ + ], + }); +} diff --git a/src/chunithm/getGameIdlist.ts b/src/chunithm/getGameIdlist.ts new file mode 100644 index 0000000..2d689cf --- /dev/null +++ b/src/chunithm/getGameIdlist.ts @@ -0,0 +1,11 @@ +import { Request, Response } from "express"; + +export default function getGameIdlist(req: Request, res: Response) { + const { type } = req.body; + + res.json({ + type, + length: 0, + gameIdlistList: [], + }); +} diff --git a/src/chunithm/getGameMessage.ts b/src/chunithm/getGameMessage.ts new file mode 100644 index 0000000..9fe5ca6 --- /dev/null +++ b/src/chunithm/getGameMessage.ts @@ -0,0 +1,17 @@ +import { Request, Response } from "express"; + +export default function getGameMessage(req: Request, res: Response) { + res.json({ + type: 1, + length: 0, + gameMessageList: [ + /* { + type: 2, + id: 1, + message: "true", + startDate: "0", + endDate: "0" + },*/ + ], + }); +} diff --git a/src/chunithm/getGameRanking.ts b/src/chunithm/getGameRanking.ts new file mode 100644 index 0000000..53c00d0 --- /dev/null +++ b/src/chunithm/getGameRanking.ts @@ -0,0 +1,18 @@ +import { Request, Response } from "express"; + +export default function getGameRanking(req: Request, res: Response) { + const { type } = req.body; + + res.json({ + type, + gameRankingList: [ + /* + // QWORD fields maybe? + { + id: 1, + point: 1, + } + */ + ], + }); +} diff --git a/src/chunithm/getGameSale.ts b/src/chunithm/getGameSale.ts new file mode 100644 index 0000000..72b533c --- /dev/null +++ b/src/chunithm/getGameSale.ts @@ -0,0 +1,22 @@ +import { Request, Response } from "express"; + +export default function getGameSale(req: Request, res: Response) { + const { type } = req.body; + + res.json({ + type, + length: 0, + gameSaleList: [ + /* + { + orderId: 1234, + type, + id: 4321, + rate: 5678, + startDate: 'STRINGIDK', + endDate: 'STRINGIDK', + }, + */ + ], + }); +} diff --git a/src/chunithm/getGameSetting.ts b/src/chunithm/getGameSetting.ts new file mode 100644 index 0000000..33377ae --- /dev/null +++ b/src/chunithm/getGameSetting.ts @@ -0,0 +1,19 @@ +import { Request, Response } from "express"; + +export default function getGameSetting(req: Request, res: Response) { + res.json({ + gameSetting: { + dataVersion: 1, + isMaintenance: false, + requestInterval: 10, + rebootStartTime: 0, + rebootEndTime: 0, + isBackgroundDistribute: false, + maxCountCharacter: 999, + maxCountItem: 999, + maxCountMusic: 999, + }, + isDumpUpload: false, + isAou: false, + }); +} diff --git a/src/chunithm/index.ts b/src/chunithm/index.ts new file mode 100644 index 0000000..5579f56 --- /dev/null +++ b/src/chunithm/index.ts @@ -0,0 +1,75 @@ +import compression from "compression"; +import express from "express"; +import logger from "debug"; + +import getGameCharge from "./getGameCharge"; +import getGameEvent from "./getGameEvent"; +import getGameIdlist from "./getGameIdlist"; +import getGameMessage from "./getGameMessage"; +import getGameRanking from "./getGameRanking"; +import getGameSale from "./getGameSale"; +import getGameSetting from "./getGameSetting"; +import upsertClientBookkeeping from "./upsertClientBookkeeping"; +import upsertClientDevelop from "./upsertClientDevelop"; +import upsertClientError from "./upsertClientError"; +import upsertClientSetting from "./upsertClientSetting"; +import upsertClientTestmode from "./upsertClientTestmode"; + +const debug = logger("app:chuni:io"); +const app = express(); + +// Thankfully we can use standard middleware for JSON I/O. We have to use a +// zlib middleware as well because compression is non-optional: the client will +// attempt to inflate whatever response we send to it whether there's a +// Transfer-Encoding header or not. + +app.use(function(req, res, next) { + // Chunithm client does not follow the HTTP spec: user agents must indicate + // that they are willing to accept a particular Transfer-Encoding for that + // T-E to be used (unless the T-E in question is "chunked" but w/e), and this + // indication is advisory anyway, the server is permitted to ignore it. + // + // Force this header into the request, since it is not present normally. + + req.headers["accept-encoding"] = "deflate"; + + return next(); +}); + +app.use(compression({ threshold: 0 })); +app.use(express.json()); + +// Trace requests and responses + +app.use(function(req, resp, next) { + debug(`\n--- Chunithm ${req.url} ---\n`); + debug(`Request: ${JSON.stringify(req.body)}\n`); + + const prevJson = resp.json; + + resp.json = function(obj) { + debug(`Response: ${JSON.stringify(obj)}`); + + resp.json = prevJson; + resp.json.apply(this, arguments); + + return resp; + }; + + next(); +}); + +app.post("/ChuniServlet/GetGameChargeApi", getGameCharge); +app.post("/ChuniServlet/GetGameEventApi", getGameEvent); +app.post("/ChuniServlet/GetGameIdlistApi", getGameIdlist); +app.post("/ChuniServlet/GetGameMessageApi", getGameMessage); +app.post("/ChuniServlet/GetGameRankingApi", getGameRanking); +app.post("/ChuniServlet/GetGameSaleApi", getGameSale); +app.post("/ChuniServlet/GetGameSettingApi", getGameSetting); +app.post("/ChuniServlet/UpsertClientBookkeepingApi", upsertClientBookkeeping); +app.post("/ChuniServlet/UpsertClientDevelopApi", upsertClientDevelop); +app.post("/ChuniServlet/UpsertClientErrorApi", upsertClientError); +app.post("/ChuniServlet/UpsertClientSettingApi", upsertClientSetting); +app.post("/ChuniServlet/UpsertClientTestmodeApi", upsertClientTestmode); + +export default app; diff --git a/src/chunithm/upsertClientBookkeeping.ts b/src/chunithm/upsertClientBookkeeping.ts new file mode 100644 index 0000000..9ed2053 --- /dev/null +++ b/src/chunithm/upsertClientBookkeeping.ts @@ -0,0 +1,8 @@ +import { Request, Response } from "express"; + +export default function upsertClientBookkeeping(req: Request, res: Response) { + res.json({ + returnCode: 1, + apiName: "UpsertClientBookkeepingApi", + }); +} diff --git a/src/chunithm/upsertClientDevelop.ts b/src/chunithm/upsertClientDevelop.ts new file mode 100644 index 0000000..2b92175 --- /dev/null +++ b/src/chunithm/upsertClientDevelop.ts @@ -0,0 +1,8 @@ +import { Request, Response } from "express"; + +export default function upsertClientDevelop(req: Request, res: Response) { + res.json({ + returnCode: 1, + apiName: "UpsertClientDevelopApi", + }); +} diff --git a/src/chunithm/upsertClientError.ts b/src/chunithm/upsertClientError.ts new file mode 100644 index 0000000..150fb7e --- /dev/null +++ b/src/chunithm/upsertClientError.ts @@ -0,0 +1,8 @@ +import { Request, Response } from "express"; + +export default function upsertClientError(req: Request, res: Response) { + res.json({ + returnCode: 1, + apiName: "UpsertClientErrorApi", + }); +} diff --git a/src/chunithm/upsertClientSetting.ts b/src/chunithm/upsertClientSetting.ts new file mode 100644 index 0000000..b27f27b --- /dev/null +++ b/src/chunithm/upsertClientSetting.ts @@ -0,0 +1,8 @@ +import { Request, Response } from "express"; + +export default function getGameSetting(req: Request, res: Response) { + res.json({ + returnCode: 1, + apiName: "UpsertClientSettingApi", + }); +} diff --git a/src/chunithm/upsertClientTestmode.ts b/src/chunithm/upsertClientTestmode.ts new file mode 100644 index 0000000..254578f --- /dev/null +++ b/src/chunithm/upsertClientTestmode.ts @@ -0,0 +1,8 @@ +import { Request, Response } from "express"; + +export default function upsertClientTestmode(req: Request, res: Response) { + res.json({ + returnCode: 1, + apiName: "UpsertClientTestmodeApi", + }); +}