Crack Chunithm handlers

This commit is contained in:
Tau 2019-10-06 20:57:10 -04:00
parent 9697b4b06e
commit cc0cd06c92
14 changed files with 241 additions and 203 deletions

View File

@ -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;

View File

@ -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',
},
*/
],
});
}

View File

@ -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',
},
*/
],
});
}

View File

@ -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: [],
});
}

View File

@ -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"
},*/
],
});
}

View File

@ -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,
}
*/
],
});
}

View File

@ -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',
},
*/
],
});
}

View File

@ -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,
});
}

75
src/chunithm/index.ts Normal file
View File

@ -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;

View File

@ -0,0 +1,8 @@
import { Request, Response } from "express";
export default function upsertClientBookkeeping(req: Request, res: Response) {
res.json({
returnCode: 1,
apiName: "UpsertClientBookkeepingApi",
});
}

View File

@ -0,0 +1,8 @@
import { Request, Response } from "express";
export default function upsertClientDevelop(req: Request, res: Response) {
res.json({
returnCode: 1,
apiName: "UpsertClientDevelopApi",
});
}

View File

@ -0,0 +1,8 @@
import { Request, Response } from "express";
export default function upsertClientError(req: Request, res: Response) {
res.json({
returnCode: 1,
apiName: "UpsertClientErrorApi",
});
}

View File

@ -0,0 +1,8 @@
import { Request, Response } from "express";
export default function getGameSetting(req: Request, res: Response) {
res.json({
returnCode: 1,
apiName: "UpsertClientSettingApi",
});
}

View File

@ -0,0 +1,8 @@
import { Request, Response } from "express";
export default function upsertClientTestmode(req: Request, res: Response) {
res.json({
returnCode: 1,
apiName: "UpsertClientTestmodeApi",
});
}